25 import org.springframework.web.bind.annotation.RequestMethod; |
25 import org.springframework.web.bind.annotation.RequestMethod; |
26 import org.springframework.web.bind.annotation.RequestParam; |
26 import org.springframework.web.bind.annotation.RequestParam; |
27 import org.springframework.web.client.HttpClientErrorException; |
27 import org.springframework.web.client.HttpClientErrorException; |
28 import org.springframework.web.servlet.ModelAndView; |
28 import org.springframework.web.servlet.ModelAndView; |
29 |
29 |
30 |
|
31 @Controller |
30 @Controller |
32 @RequestMapping("/") |
31 @RequestMapping("/") |
33 public class RenkanRootController { |
32 public class RenkanRootController { |
34 |
33 |
35 private final Logger logger = LoggerFactory.getLogger(RenkanRootController.class); |
34 private final Logger logger = LoggerFactory |
36 |
35 .getLogger(RenkanRootController.class); |
37 @Autowired |
|
38 private ProjectsRepository projectsRepository; |
|
39 |
|
40 @Autowired |
|
41 private SpacesRepository spacesRepository; |
|
42 |
|
43 @RequestMapping(value="", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"}) |
|
44 public String renkanIndex(Model model, @PageableDefaults(sort={"created"}, sortDir=Direction.DESC, pageNumber=0, value=Constants.PAGINATION_SIZE) Pageable p, HttpServletRequest request) { |
|
45 |
36 |
46 Page<Space> page = this.spacesRepository.findAll(p); |
37 @Autowired |
47 |
38 private ProjectsRepository projectsRepository; |
48 model.addAttribute("page", page); |
|
49 model.addAttribute("baseUrl", Utils.buildBaseUrl(request)); |
|
50 model.addAttribute("projectsCount", this.projectsRepository.getCountBySpace()); |
|
51 |
|
52 return "renkanIndex"; |
|
53 } |
|
54 |
39 |
55 @RequestMapping(value="/s/{space_id}", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"}) |
40 @Autowired |
56 public ModelAndView spaceIndex(@PathVariable("space_id") String spaceId, @RequestParam(required=false) String filter, @PageableDefaults(sort={"updated","created"}, sortDir=Direction.DESC, pageNumber=0, value=Constants.PAGINATION_SIZE) Pageable p, HttpServletRequest request) { |
41 private SpacesRepository spacesRepository; |
57 |
|
58 logger.debug("SpaceId : " + (spaceId== null ? "null" : spaceId)); |
|
59 |
|
60 Map<String, Object> model = new HashMap<String, Object>(); |
|
61 |
42 |
62 if("_".equals(spaceId)) { |
43 @RequestMapping(value = "", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" }) |
63 spaceId = null; |
44 public String renkanIndex( |
64 } |
45 Model model, |
65 |
46 @PageableDefaults(sort = { "created" }, sortDir = Direction.DESC, pageNumber = 0, value = Constants.PAGINATION_SIZE) Pageable p, |
66 Space space = this.spacesRepository.findOne(spaceId); |
47 HttpServletRequest request) { |
67 |
48 |
68 if(null == space) { |
49 Page<Space> page = this.spacesRepository.findAll(p); |
69 throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Space " + spaceId + " not found."); |
50 |
70 } |
51 model.addAttribute("page", page); |
71 |
52 model.addAttribute("baseUrl", Utils.buildBaseUrl(request)); |
72 model.put("space", space); |
53 model.addAttribute("projectsCount", |
73 Page<Project> page; |
54 this.projectsRepository.getCountBySpace()); |
74 if(filter != null && !filter.isEmpty()) { |
55 |
75 page = this.projectsRepository.findBySpaceIdAndTitleRegex(spaceId, filter, p); |
56 return "renkanIndex"; |
76 } |
57 } |
77 else { |
58 |
78 page = this.projectsRepository.findBySpaceId(spaceId, p); |
59 @RequestMapping(value = "/s/{space_id}", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" }) |
79 } |
60 public ModelAndView spaceIndex( |
80 |
61 @PathVariable("space_id") String spaceId, |
81 model.put("page", page); |
62 @RequestParam(required = false) String filter, |
82 model.put("baseUrl", Utils.buildBaseUrl(request)); |
63 @PageableDefaults(sort = { "updated", "created" }, sortDir = Direction.DESC, pageNumber = 0, value = Constants.PAGINATION_SIZE) Pageable p, |
83 |
64 HttpServletRequest request) { |
84 return new ModelAndView("projectIndex", model); |
65 |
85 } |
66 logger.debug("SpaceId : " + (spaceId == null ? "null" : spaceId)); |
86 |
67 |
87 |
68 Map<String, Object> model = new HashMap<String, Object>(); |
|
69 |
|
70 if ("_".equals(spaceId)) { |
|
71 spaceId = null; |
|
72 } |
|
73 |
|
74 Space space = this.spacesRepository.findOne(spaceId); |
|
75 |
|
76 if (null == space) { |
|
77 throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Space " |
|
78 + spaceId + " not found."); |
|
79 } |
|
80 |
|
81 model.put("space", space); |
|
82 Page<Project> page; |
|
83 if (filter != null && !filter.isEmpty()) { |
|
84 page = this.projectsRepository.findBySpaceIdAndTitleRegex(spaceId, |
|
85 filter, p); |
|
86 } else { |
|
87 page = this.projectsRepository.findBySpaceId(spaceId, p); |
|
88 } |
|
89 |
|
90 model.put("page", page); |
|
91 model.put("baseUrl", Utils.buildBaseUrl(request)); |
|
92 |
|
93 return new ModelAndView("projectIndex", model); |
|
94 } |
|
95 |
88 } |
96 } |