| author | ymh <ymh.work@gmail.com> |
| Mon, 21 Oct 2013 17:55:12 +0200 | |
| branch | user_management |
| changeset 224 | 0167b777ad15 |
| parent 223 | 5ad314cb2337 |
| permissions | -rw-r--r-- |
| 51 | 1 |
package org.iri_research.renkan.controller; |
2 |
||
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
||
|
76
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
6 |
import javax.servlet.http.HttpServletRequest; |
|
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
7 |
|
|
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
8 |
import org.iri_research.renkan.Constants; |
| 51 | 9 |
import org.iri_research.renkan.models.Project; |
| 71 | 10 |
import org.iri_research.renkan.models.Space; |
| 51 | 11 |
import org.iri_research.renkan.repositories.ProjectsRepository; |
| 71 | 12 |
import org.iri_research.renkan.repositories.SpacesRepository; |
| 51 | 13 |
import org.slf4j.Logger; |
14 |
import org.slf4j.LoggerFactory; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
|
76
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
16 |
import org.springframework.data.domain.Page; |
|
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
17 |
import org.springframework.data.domain.Pageable; |
|
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
18 |
import org.springframework.data.domain.Sort.Direction; |
|
224
0167b777ad15
remove deprecated warnings + fix date picker default langauge
ymh <ymh.work@gmail.com>
parents:
223
diff
changeset
|
19 |
import org.springframework.data.web.PageableDefault; |
| 71 | 20 |
import org.springframework.http.HttpStatus; |
| 51 | 21 |
import org.springframework.stereotype.Controller; |
|
76
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
22 |
import org.springframework.ui.Model; |
| 71 | 23 |
import org.springframework.web.bind.annotation.PathVariable; |
| 51 | 24 |
import org.springframework.web.bind.annotation.RequestMapping; |
25 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
| 137 | 26 |
import org.springframework.web.bind.annotation.RequestParam; |
| 71 | 27 |
import org.springframework.web.client.HttpClientErrorException; |
| 51 | 28 |
import org.springframework.web.servlet.ModelAndView; |
29 |
||
30 |
@Controller |
|
31 |
@RequestMapping("/") |
|
32 |
public class RenkanRootController { |
|
33 |
||
| 223 | 34 |
private final Logger logger = LoggerFactory |
35 |
.getLogger(RenkanRootController.class); |
|
36 |
||
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( |
|
45 |
Model model, |
|
|
224
0167b777ad15
remove deprecated warnings + fix date picker default langauge
ymh <ymh.work@gmail.com>
parents:
223
diff
changeset
|
46 |
@PageableDefault(sort = { "created" }, direction = Direction.DESC, page = 0, value = Constants.PAGINATION_SIZE) Pageable p, |
| 223 | 47 |
HttpServletRequest request) { |
|
76
523f0647513e
add the count of project by spaces, add pagination, update libraries and add some more unit tests.
ymh <ymh.work@gmail.com>
parents:
71
diff
changeset
|
48 |
|
| 223 | 49 |
Page<Space> page = this.spacesRepository.findAll(p); |
50 |
||
51 |
model.addAttribute("page", page); |
|
52 |
model.addAttribute("baseUrl", Utils.buildBaseUrl(request)); |
|
53 |
model.addAttribute("projectsCount", |
|
54 |
this.projectsRepository.getCountBySpace()); |
|
| 71 | 55 |
|
| 223 | 56 |
return "renkanIndex"; |
57 |
} |
|
58 |
||
59 |
@RequestMapping(value = "/s/{space_id}", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" }) |
|
60 |
public ModelAndView spaceIndex( |
|
61 |
@PathVariable("space_id") String spaceId, |
|
62 |
@RequestParam(required = false) String filter, |
|
|
224
0167b777ad15
remove deprecated warnings + fix date picker default langauge
ymh <ymh.work@gmail.com>
parents:
223
diff
changeset
|
63 |
@PageableDefault(sort = { "updated", "created" }, direction = Direction.DESC, page = 0, value = Constants.PAGINATION_SIZE) Pageable p, |
| 223 | 64 |
HttpServletRequest request) { |
| 71 | 65 |
|
| 223 | 66 |
logger.debug("SpaceId : " + (spaceId == null ? "null" : spaceId)); |
67 |
||
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 |
||
| 51 | 96 |
} |