package io.loli.sc.server.action.pan;

import io.loli.sc.server.entity.User;
import io.loli.sc.server.entity.pan.FolderEntity;
import io.loli.sc.server.service.pan.FolderService;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(value = "pan/file")
@Named
public class FileAction {

	@Inject
	private FolderService fs;

	@RequestMapping("list")
	public String list(
			@RequestParam(value = "pid", required = false) Integer pid,
			HttpServletRequest request) {
		if (pid == null) {
			pid = 0;
		}
		User user = (User) request.getSession().getAttribute("user");
		List<FolderEntity> folders = fs.listByUserAndPath(user, pid);
		request.setAttribute("folderList", folders);
		request.setAttribute("rootFolder", fs.findRootByUser(user));
		if (pid != 0) {
			FolderEntity parent = fs.findById(pid);
			request.setAttribute("parent", parent);
		}
		return "pan/fileList";

	}

	@RequestMapping("add")
	public String add(@RequestParam(value = "pid") int parentId,
			@RequestParam(value = "name") String folderName,
			HttpServletRequest request) {
		FolderEntity parent = fs.findById(parentId);
		FolderEntity fe = new FolderEntity();
		fe.setParent(parent);
		fe.setName(folderName);
		fe.setFullPath(parent.getFullPath() + folderName + "/");
		fe.setCreateDate(new Date());

		User user = (User) request.getSession().getAttribute("user");

		fe.setUser(user);
		fs.save(fe);
		return this.list(parentId, request);
	}
}

@@ -521,17 +521,20 @@
  %7B%0A%0A
-%09
+    
 @Inject%0A
 %09pri
@@ -529,17 +529,20 @@
 @Inject%0A
-%09
+    
 private 
@@ -560,17 +560,20 @@
 ce fs;%0A%0A
-%09
+    
 @Request
@@ -588,17 +588,20 @@
 %22list%22)%0A
-%09
+    
 public S
@@ -611,20 +611,16 @@
 ng list(
-%0A%09%09%09
 @Request
@@ -670,20 +670,17 @@
 ger pid,
-%0A%09%09%09
+ 
 HttpServ
@@ -701,18 +701,24 @@
 uest) %7B%0A
-%09%09
+        
 if (pid 
@@ -732,26 +732,47 @@
 ) %7B%0A
-%09%09%09pid = 0;%0A%09%09%7D%0A%09%09
+            pid = 0;%0A        %7D%0A        
 User
@@ -829,18 +829,24 @@
 user%22);%0A
-%09%09
+        
 List%3CFol
@@ -899,18 +899,24 @@
 , pid);%0A
-%09%09
+        
 request.
@@ -952,18 +952,24 @@
 lders);%0A
-%09%09
+        
 request.
@@ -1021,18 +1021,24 @@
 user));%0A
-%09%09
+        
 if (pid 
@@ -1045,19 +1045,28 @@
 != 0) %7B%0A
-%09%09%09
+            
 FolderEn
@@ -1097,19 +1097,28 @@
 d(pid);%0A
-%09%09%09
+            
 request.
@@ -1153,14 +1153,26 @@
 t);%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 retu
@@ -1195,13 +1195,19 @@
 %22;%0A%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Req
@@ -1225,17 +1225,20 @@
 (%22add%22)%0A
-%09
+    
 public S
@@ -1289,20 +1289,17 @@
 arentId,
-%0A%09%09%09
+ 
 @Request
@@ -1343,11 +1343,16 @@
 me,%0A
-%09%09%09
+        
 Http
@@ -1377,18 +1377,24 @@
 uest) %7B%0A
-%09%09
+        
 FolderEn
@@ -1430,18 +1430,24 @@
 entId);%0A
-%09%09
+        
 FolderEn
@@ -1476,18 +1476,24 @@
 tity();%0A
-%09%09
+        
 fe.setPa
@@ -1506,18 +1506,24 @@
 arent);%0A
-%09%09
+        
 fe.setNa
@@ -1538,18 +1538,24 @@
 rName);%0A
-%09%09
+        
 fe.setFu
@@ -1603,18 +1603,24 @@
 + %22/%22);%0A
-%09%09
+        
 fe.setCr
@@ -1642,18 +1642,24 @@
 te());%0A%0A
-%09%09
+        
 User use
@@ -1713,18 +1713,24 @@
 ser%22);%0A%0A
-%09%09
+        
 fe.setUs
@@ -1739,18 +1739,24 @@
 (user);%0A
-%09%09
+        
 fs.save(
@@ -1764,10 +1764,16 @@
 e);%0A
-%09%09
+        
 retu
@@ -1809,9 +1809,12 @@
 t);%0A
-%09
+    
 %7D%0A%7D%0A

Change tab to space