# HG changeset patch # User ymh # Date 1364904356 -7200 # Node ID 93a1fbe6a848f4b37d00b688e2917dc0f91aa067 # Parent 906fed13c1e172f8a0b0a69e24ff44eeafeaf847 Correct add space and improve space form validation message diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/main/java/org/iri_research/renkan/controller/AdminController.java --- a/server/src/main/java/org/iri_research/renkan/controller/AdminController.java Tue Apr 02 01:56:11 2013 +0200 +++ b/server/src/main/java/org/iri_research/renkan/controller/AdminController.java Tue Apr 02 14:05:56 2013 +0200 @@ -63,19 +63,28 @@ return "admin/spacesList"; } - @RequestMapping(value="/spaces/{space_id}", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"}) - public String editSpace(Model model, @PathVariable(value="space_id") String spaceId) { + @RequestMapping(value="/spaces/edit/", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"}) + public String editSpace(Model model) { + return editSpace(model, null); + } + + @RequestMapping(value="/spaces/edit/{spaceId}", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"}) + public String editSpace(Model model, @PathVariable(value="spaceId") String spaceId) { + + SpaceForm spaceForm = null; - if(spaceId == null || spaceId.length() == 0) { - throw new IllegalArgumentException("AdminContoller.editSpace: space id is null or empty."); + if(spaceId == null || spaceId.length() == 0 || "_".equals(spaceId)) { + spaceForm = new SpaceForm(); + } + else { + Space space = this.spacesRepository.findOne(spaceId); + if(space == null) { + throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "space " + spaceId + " not found"); + } + spaceForm = new SpaceForm(space); } - Space space = this.spacesRepository.findOne(spaceId); - if(space == null) { - throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "space " + spaceId + " not found"); - } - - model.addAttribute("space", new SpaceForm(space)); + model.addAttribute("space", spaceForm); return "admin/spaceEdit"; } @@ -88,12 +97,7 @@ logger.debug("space description " + spaceForm.getDescription()); if(bindingResult.hasErrors()) { - if(spaceForm.getId() != null && spaceForm.getId().length() > 0) { - return "admin/spaceEdit"; - } - else { - return "admin/spaceNew"; - } + return "admin/spaceEdit"; } spaceForm.setSpacesRepository(spacesRepository); diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/main/java/org/iri_research/renkan/forms/SpaceForm.java --- a/server/src/main/java/org/iri_research/renkan/forms/SpaceForm.java Tue Apr 02 01:56:11 2013 +0200 +++ b/server/src/main/java/org/iri_research/renkan/forms/SpaceForm.java Tue Apr 02 14:05:56 2013 +0200 @@ -1,5 +1,8 @@ package org.iri_research.renkan.forms; +import java.util.Date; +import java.util.UUID; + import org.iri_research.renkan.models.Space; import org.iri_research.renkan.repositories.IRenkanRepository; import org.iri_research.renkan.repositories.SpacesRepository; @@ -40,6 +43,10 @@ @Override protected void saveToModel() { + if(this.getId() == null || this.getId().length() == 0) { + this.model.setId(UUID.randomUUID().toString()); + this.model.setCreated(new Date()); + } this.model.setBinConfig(binConfig); this.model.setImage(image); } diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/main/webapp/WEB-INF/templates/admin/spaceNew.html --- a/server/src/main/webapp/WEB-INF/templates/admin/spaceNew.html Tue Apr 02 01:56:11 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ - - - - Renkan Admin - new space - - - - - - - - - - - - - -
-
-

Renkan administration

-

Spaces List / Edit space

-
-
-
-
-
© 2013 IRI - Version 0.0
-
-
- - \ No newline at end of file diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/main/webapp/WEB-INF/templates/admin/spacesList.html --- a/server/src/main/webapp/WEB-INF/templates/admin/spacesList.html Tue Apr 02 01:56:11 2013 +0200 +++ b/server/src/main/webapp/WEB-INF/templates/admin/spacesList.html Tue Apr 02 14:05:56 2013 +0200 @@ -36,7 +36,7 @@
@@ -50,8 +50,8 @@ - - + + diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html --- a/server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html Tue Apr 02 01:56:11 2013 +0200 +++ b/server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html Tue Apr 02 14:05:56 2013 +0200 @@ -20,7 +20,7 @@ } function spaceFormSubmit() { - + var errors = {}; var valid = true; @@ -29,16 +29,16 @@ valid = false; } - try - { - var json = JSON.parse($('#binConfig').val()); - } - catch(e) - { - console.log(e); - errors['binConfigDiv'] = /*[[#{renkan.error.bin_config.json}]]*/"renkan.error.bin_config.json"; - valid = false; - } + if($('#binConfig').val()) { + + var editor = ace.edit("binConfigDiv"); + var annotations = editor.getSession().getAnnotations(); + if(annotations.length>0) { + var error_message = /*[[#{renkan.error.bin_config.json}]]*/"renkan.error.bin_config.json"; + errors['binConfigDiv'] = error_message + ". "+ annotations[0].type + ": (" +(annotations[0].row+1)+","+annotations[0].column+") " + annotations[0].text; + valid = false; + } + } showformErrors(errors); diff -r 906fed13c1e1 -r 93a1fbe6a848 server/src/test/java/org/iri_research/renkan/test/controller/AdminControllerTest.java --- a/server/src/test/java/org/iri_research/renkan/test/controller/AdminControllerTest.java Tue Apr 02 01:56:11 2013 +0200 +++ b/server/src/test/java/org/iri_research/renkan/test/controller/AdminControllerTest.java Tue Apr 02 14:05:56 2013 +0200 @@ -135,6 +135,8 @@ Assert.assertEquals("Uri equals", "http://ldt.iri.centrepompidou.fr/new/uri", sp.getUri()); Assert.assertEquals("Color equals", "#ffffff", sp.getColor()); Assert.assertEquals("BinConfig equals", "{}", sp.getBinConfig()); + Assert.assertTrue("id sould match uuid regex", sp.getId().matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")); + Assert.assertNotNull("Date created should be not null", sp.getCreated()); } } } @@ -177,7 +179,7 @@ this.mvc.perform(post) .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.view().name("admin/spaceNew")) + .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit")) .andExpect(MockMvcResultMatchers.model().hasErrors()) .andExpect(MockMvcResultMatchers.model().errorCount(1)) .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space")) @@ -225,7 +227,7 @@ this.mvc.perform(post) .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.view().name("admin/spaceNew")) + .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit")) .andExpect(MockMvcResultMatchers.model().hasErrors()) .andExpect(MockMvcResultMatchers.model().errorCount(1)) .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space")) @@ -275,7 +277,7 @@ this.mvc.perform(post) .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.view().name("admin/spaceNew")) + .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit")) .andExpect(MockMvcResultMatchers.model().hasErrors()) .andExpect(MockMvcResultMatchers.model().errorCount(2)) .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
titlecreatedEditcreatedEdit Delete