Browse Source

Census date changed to CensusDate in forms
Closes #12
Closes #10

Andrew Grant 7 months ago
parent
commit
139ae69d58

+ 6 - 6
docs/additions.txt

@@ -8,12 +8,12 @@
 7: Converter Test
 8: Bootstrap (use personal details)
 9: Bootstrap
-10: Validator
-11: Validator Test
-13: Modify the form
-14: Switch to uat
-15: Generate changelog (ctrl-shift-A) as sql
-16: Add the new file to master.xml
+10: Modify the form
+11: Validator
+12: Validator Test
+13: Switch to uat
+14: Generate changelog (ctrl-shift-A) as sql
+15: Add the new file to master.xml
 16: Run in terminal  mvn clean test liquibase:update
 
 

+ 7 - 5
docs/enums.txt

@@ -12,9 +12,11 @@
 12: Bootstrap Test
 12a: Check using the h2 console
 13: Modify the form
-14: Switch to uat
-15: Generate changelog (ctrl-shift-A) as sql
-16: Add the new file to master.xml
-16: Run in terminal  mvn clean test liquibase:update
-17: Check using dbeaver that the database has changed
+14: Validator
+15: Validator test
+16: Switch to uat
+17: Generate changelog (ctrl-shift-A) as sql
+18: Add the new file to master.xml
+19: Run in terminal  mvn clean test liquibase:update
+20: Check using dbeaver that the database has changed
 

+ 1 - 1
src/main/java/scot/carricksoftware/grants/constants/ValidationConstants.java

@@ -35,5 +35,5 @@ public class ValidationConstants {
     public static final String SECOND_PARTY_IS_NULL = "The second party cannot be null.";
     public static final String SAME_TWO_PARTIES = "The two parties cannot be the same person.";
 
-
+    public static final String BOUNDARY_TYPE_IS_NULL = "The boundary type cannot be null.";
 }

+ 9 - 1
src/main/java/scot/carricksoftware/grants/controllers/census/census/CensusFormControllerImpl.java

@@ -22,6 +22,7 @@ import scot.carricksoftware.grants.constants.MappingConstants;
 import scot.carricksoftware.grants.constants.ViewConstants;
 import scot.carricksoftware.grants.converters.census.CensusConverter;
 import scot.carricksoftware.grants.services.census.CensusService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
 import scot.carricksoftware.grants.validators.census.CensusCommandValidator;
 
 @SuppressWarnings("LoggingSimilarMessage")
@@ -32,14 +33,16 @@ public class CensusFormControllerImpl implements CensusFormController {
     private final CensusService censusService;
     private final CensusCommandValidator censusCommandValidator;
     private final CensusConverter censusConverter;
+    private final PlaceService placeService;
 
 
     public CensusFormControllerImpl(CensusService censusService,
                                     CensusCommandValidator censusCommandValidator,
-                                    CensusConverter censusConverter) {
+                                    CensusConverter censusConverter, PlaceService placeService) {
         this.censusService = censusService;
         this.censusCommandValidator = censusCommandValidator;
         this.censusConverter = censusConverter;
+        this.placeService = placeService;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -47,6 +50,7 @@ public class CensusFormControllerImpl implements CensusFormController {
     public final String getNewCensus(final Model model) {
         logger.debug("CensusFormControllerImpl::getNewCensus");
         model.addAttribute(AttributeConstants.CENSUS_COMMAND, new CensusCommandImpl());
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.CENSUS_FORM;
     }
 
@@ -55,6 +59,7 @@ public class CensusFormControllerImpl implements CensusFormController {
     public final String censusEdit(@Valid @PathVariable final String id, Model model) {
         logger.debug("CensusFormControllerImpl::censusEdit");
         model.addAttribute(AttributeConstants.CENSUS_COMMAND, censusService.findById(Long.valueOf(id)));
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.CENSUS_FORM;
     }
 
@@ -69,12 +74,14 @@ public class CensusFormControllerImpl implements CensusFormController {
 
         if (bindingResult.hasErrors()) {
             bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));
+            model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
             return ViewConstants.CENSUS_FORM;
         }
 
 
         CensusCommand savedCommand = censusService.saveCensusCommand(censusCommand);
         model.addAttribute(AttributeConstants.CENSUS_COMMAND, savedCommand);
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return MappingConstants.REDIRECT + MappingConstants.CENSUS_SHOW.replace("{id}", "" + savedCommand.getId());
     }
 
@@ -85,6 +92,7 @@ public class CensusFormControllerImpl implements CensusFormController {
         logger.debug("CensusFormControllerImpl::saveOrUpdate");
         CensusCommand savedCommand = censusConverter.convert(censusService.findById(Long.valueOf(id)));
         model.addAttribute(AttributeConstants.CENSUS_COMMAND, savedCommand);
+        model.addAttribute(AttributeConstants.PLACES, placeService.findAll());
         return ViewConstants.CENSUS_FORM;
     }
 

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/census/CensusCommandConverterImpl.java

@@ -20,6 +20,7 @@ public class CensusCommandConverterImpl implements CensusCommandConverter {
         result.setCensusEntries(source.getCensusEntries());
         result.setPlace(source.getPlace());
         result.setBoundaryType(source.getBoundaryType());
+        result.setDate(source.getDate());
 
 
         return result;

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/census/CensusConverterImpl.java

@@ -20,6 +20,7 @@ public class CensusConverterImpl implements CensusConverter {
         result.setCensusEntries(source.getCensusEntries());
         result.setPlace(source.getPlace());
         result.setBoundaryType(source.getBoundaryType());
+        result.setDate(source.getDate());
         return result;
     }
 }

+ 11 - 0
src/main/java/scot/carricksoftware/grants/validators/census/CensusCommandValidator.java

@@ -24,6 +24,17 @@ public class CensusCommandValidator {
                     null,
                     ValidationConstants.DATE_IS_NULL);
         }
+        if (censusCommand.getBoundaryType() == null) {
+            bindingResult.rejectValue("boundaryType", ApplicationConstants.EMPTY_STRING,
+                    null,
+                    ValidationConstants.BOUNDARY_TYPE_IS_NULL);
+        }
+        if (censusCommand.getPlace() == null) {
+            bindingResult.rejectValue("place", ApplicationConstants.EMPTY_STRING,
+                    null,
+                    ValidationConstants.PLACE_IS_NULL);
+        }
+
     }
 }
 

+ 33 - 9
src/main/resources/templates/census/form.html

@@ -45,14 +45,33 @@ rounded-3 text-center p-4">
                        th:field="*{id}" type="text" readonly>
             </div>
             <div class="col-md-3">
-                <!-- >https://jqueryui.com/datepicker/-->
-                <label for="datepicker">Date</label>
-                <input class="form-control" id="datepicker" th:value="*{date}"
-                       th:field="*{date}" th:type="text">
-                <div th:if="${#fields.hasErrors('date')}">
-                    <ul class="text-danger">
-                        <li th:each="err : ${#fields.errors('date')}" th:text="${err}"/>
-                    </ul>
+                <label for="date">Date</label>
+                <div>
+                    <select id="date" style="width: 200px;" name="date" th:field="*{date}">
+                        <option th:value="${''}" th:text="${''}"></option>
+                        <option th:each="value : ${T(scot.carricksoftware.grants.enums.census.CensusDate).values()}"
+                                th:value="${value}" th:text="${value.label}"></option>
+                    </select>
+                    <div th:if="${#fields.hasErrors('date')}">
+                        <ul class="text-danger">
+                            <li th:each="err : ${#fields.errors('date')}" th:text="${err}"/>
+                        </ul>
+                    </div>
+                </div>
+            </div>
+            <div class="col-md-3">
+                <label for="place">Place</label>
+                <div>
+                    <select id="place" style="width: 200px;" name="place" th:field="*{place}">
+                        <option th:value="${''}" th:text="${''}"></option>
+                        <option th:each="place : ${places}"
+                                th:value="${place.id}" th:text="${place.toString()}"></option>
+                    </select>
+                    <div th:if="${#fields.hasErrors('place')}">
+                        <ul class="text-danger">
+                            <li th:each="err : ${#fields.errors('place')}" th:text="${err}"/>
+                        </ul>
+                    </div>
                 </div>
             </div>
             <div class="col-md-3">
@@ -61,8 +80,13 @@ rounded-3 text-center p-4">
                     <select id="boundaryType" style="width: 200px;" name="boundaryType" th:field="*{boundaryType}">
                         <option th:value="${''}" th:text="${''}"></option>
                         <option th:each="value : ${T(scot.carricksoftware.grants.enums.census.CensusBoundaryType).values()}"
-                                th:value="${value}" th:text="${value}"></option>
+                                th:value="${value}" th:text="${value.label}"></option>
                     </select>
+                    <div th:if="${#fields.hasErrors('boundaryType')}">
+                        <ul class="text-danger">
+                            <li th:each="err : ${#fields.errors('boundaryType')}" th:text="${err}"/>
+                        </ul>
+                    </div>
                 </div>
             </div>
         </div>

+ 1 - 1
src/main/resources/templates/census/list.html

@@ -33,7 +33,7 @@
             <tr th:each="census   : ${censuses}">
                 <td th:text="${census.id}">123</td>
                 <td th:text="${census.place}">123</td>
-                <td th:text="${#temporals.format(census.date, 'dd-MMM-yyyy')}"></td>
+                <td th:text="${census.date.label}"></td>
                 <td><span>
                         <a th:action="delete" class="btn btn-danger btn-sm" href=""
                            th:href="'census/' + ${census.id} + '/delete'"