Skip to content
Snippets Groups Projects
Commit 335ed2da authored by Rhys Evans's avatar Rhys Evans
Browse files

fixed minor bug and added error message to approval form

parent d28f1871
No related branches found
No related tags found
1 merge request!44Location apporval form validation update
...@@ -79,6 +79,7 @@ public class LandmarksController { ...@@ -79,6 +79,7 @@ public class LandmarksController {
int locationID = locationRepository.nametoLocationID(location.getLocationName()); int locationID = locationRepository.nametoLocationID(location.getLocationName());
// converts valid response using Location constructor into a submittable format to the sql table // converts valid response using Location constructor into a submittable format to the sql table
System.out.println(locCoord.getLocationCoordsLong());
LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID, locCoord.getLocationCoordsLat(), locCoord.getLocationCoordsLong()); LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID, locCoord.getLocationCoordsLat(), locCoord.getLocationCoordsLong());
boolean checkIfCoorsWithinBoundaries = placesCoordinatesRepo.checkIfCoordsAreWithinTownBoundary(ALocCoord); boolean checkIfCoorsWithinBoundaries = placesCoordinatesRepo.checkIfCoordsAreWithinTownBoundary(ALocCoord);
if (checkIfCoorsWithinBoundaries==false){ // if coords outside associated town, form is returned to original state if (checkIfCoorsWithinBoundaries==false){ // if coords outside associated town, form is returned to original state
......
...@@ -16,8 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -16,8 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Controller @Controller
...@@ -35,6 +34,70 @@ public class PlacesController { ...@@ -35,6 +34,70 @@ public class PlacesController {
private RewardsRepository rewardsRepository; private RewardsRepository rewardsRepository;
@GetMapping("/towns")
public ModelAndView getTownPages(){
ModelAndView modelAndView = new ModelAndView("towns/townsPageList.html");
List<TownWithTrails> townsList = placeRepo.getAllTownCoords();
List<Trail> trailslocations = trailsRepo.getAllTrails();
modelAndView.addObject("trails", trailslocations);
modelAndView.addObject("towns", townsList);
return modelAndView;
}
@RequestMapping(value="/town", method= RequestMethod.POST)
public String sendHtmlFragmentTown(Model map) {
map.addAttribute("foo", "bar");
return "checkpoint/checkpoint";
}
@GetMapping("/towns/{town}")
public ModelAndView getResultBySearchKeyTowns(@PathVariable String town) {
List<TownWithTrails> townsList = placeRepo.getAllTownCoords();
List<Trail> trailslocations = trailsRepo.getAllTrails();
List<Trail> correctTrails = new ArrayList<>();
String townNamee="";
int indexTown=999;
for (int i=0;i<townsList.size();i++){
if (Objects.equals(townsList.get(i).getTownName(), town)){
indexTown=i;
townNamee=town;
}
}
if (indexTown!=999){
int townIDFromTable= placeRepo.getTownIDFromName(townNamee);
for (int i=0;i<trailslocations.size();i++){
int trailID = trailsRepo.getTrailIDFromTrailName(trailslocations.get(i).getTrailName());
if ((trailID>100)&&(trailID<200)&&(Objects.equals(townNamee, "Caerphilly"))){
correctTrails.add(trailslocations.get(i));
}
if ((trailID>200)&&(trailID<300)&&(Objects.equals(townNamee, "Risca"))){
correctTrails.add(trailslocations.get(i));
}
if ((trailID>300)&&(trailID<400)&& (Objects.equals(townNamee, "Penarth")) ){
correctTrails.add(trailslocations.get(i));
}
}
}
ModelAndView modelAndView= new ModelAndView("fragments/townsPageFrags :: townSection");
modelAndView.addObject("town", townsList.get(indexTown));
modelAndView.addObject("trails", correctTrails);
return modelAndView;}
@GetMapping("/checkpoints") @GetMapping("/checkpoints")
public ModelAndView getLocationPages(){ public ModelAndView getLocationPages(){
ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html"); ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html");
...@@ -42,7 +105,7 @@ public class PlacesController { ...@@ -42,7 +105,7 @@ public class PlacesController {
List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); List<Location> approvedLocations = locationRepo.getAllApprovedLocations();
modelAndView.addObject("location", approvedLocations); modelAndView.addObject("location", approvedLocations);
modelAndView.addObject("locationCoords", locCoords); modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords));
return modelAndView; return modelAndView;
} }
...@@ -55,19 +118,19 @@ public class PlacesController { ...@@ -55,19 +118,19 @@ public class PlacesController {
@GetMapping("/checkpoints/{location}") @GetMapping("/checkpoints/{location}")
public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) { public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) {
List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); List<LocationsCoordinates> locCoords = reorderCoordsWRTLocations(placeRepo.getAllLocationCoords());
List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); List<Location> approvedLocations = locationRepo.getAllApprovedLocations();
int locationID = 999; int locationID = 999;
for (int i=0;i<approvedLocations.size();i++){ for (int i=0;i<approvedLocations.size();i++){
if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){
locationID= i; locationID= i;
}
} }
}
String trailName=trailsRepo.getTrailNameWithID(approvedLocations.get(locationID).getLocationTrailID()).replace(' ', '-').trim(); String trailName=trailsRepo.getTrailNameWithID(approvedLocations.get(locationID).getLocationTrailID()).replace(' ', '-').trim();
ModelAndView modelAndView= new ModelAndView("fragments/locationPageFrags :: locationSection"); ModelAndView modelAndView= new ModelAndView("fragments/locationPageFrags :: locationSection");
modelAndView.addObject("locCoord", locCoords.get(locationID)); modelAndView.addObject("locCoord", locCoords.get(locationID));
modelAndView.addObject("trail", trailName); modelAndView.addObject("trail", trailName);
...@@ -77,6 +140,7 @@ public class PlacesController { ...@@ -77,6 +140,7 @@ public class PlacesController {
/// Trail webpage mapping /// Trail webpage mapping
...@@ -90,10 +154,11 @@ public class PlacesController { ...@@ -90,10 +154,11 @@ public class PlacesController {
modelAndView.addObject("trails", trailslocations); modelAndView.addObject("trails", trailslocations);
modelAndView.addObject("locations", approvedLocations); modelAndView.addObject("locations", approvedLocations);
modelAndView.addObject("locationCoords", locCoords); modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords));
return modelAndView; return modelAndView;
} }
@RequestMapping(value="/trail", method= RequestMethod.POST) @RequestMapping(value="/trail", method= RequestMethod.POST)
public String sendHtmlFragmentTrail(Model map) { public String sendHtmlFragmentTrail(Model map) {
map.addAttribute("foo", "bar"); map.addAttribute("foo", "bar");
...@@ -131,5 +196,41 @@ public class PlacesController { ...@@ -131,5 +196,41 @@ public class PlacesController {
modelAndView.addObject("stickers", rewardsRepository.getAllStickersFromPack(1)); modelAndView.addObject("stickers", rewardsRepository.getAllStickersFromPack(1));
return modelAndView; return modelAndView;
} }
// public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
// List<Location> approvedList = locationRepo.getAllLocation();
//// List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords();
// List<Integer> locationID= new ArrayList<Integer>();
// System.out.println(locCoords);
// System.out.println("///////");
// Collections.swap(locCoords,0,10);
// for(int i=0;i<locCoords.size();i++){
// if (i==locCoords.size()-1){
// if (locCoords.get(i).getLocationID()<locCoords.get(i-1).getLocationID()){
// Collections.swap(locCoords,i,i--);
// i=0;
// }
//
// }
// if (locCoords.get(i).getLocationID()>locCoords.get(i++).getLocationID()){
// System.out.println("ASDSADASD");
// Collections.swap(locCoords,i,i++);
// i=0;
// }
//
// } System.out.println(locCoords);
// return locCoords;
//
//
//
// }
// When adding to the locationsCoordinates table, the order is not based on LocationID order, therefore it is needed to rearrange this list to
// follow ascending locationID so that any new coordinates match up with their intended locations.
public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
Collections.sort(locCoords,
Comparator.comparingInt(LocationsCoordinates::getLocationID));
return locCoords;
}
} }
...@@ -65,7 +65,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit ...@@ -65,7 +65,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit
public void addLocationCoord(LocationsCoordinates locCoords) { public void addLocationCoord(LocationsCoordinates locCoords) {
String sql = "insert into locationCoordinates(locationID, locationCoordsLat,locationCoordsLong) values (?,?,?)"; String sql = "insert into locationCoordinates(locationID, locationCoordsLat,locationCoordsLong) values (?,?,?)";
jdbc.update(sql,locCoords.getLocationID(), locCoords.getLocationCoordsLong(),locCoords.getLocationCoordsLat()); jdbc.update(sql,locCoords.getLocationID(), locCoords.getLocationCoordsLat(),locCoords.getLocationCoordsLong());
} }
@Override @Override
......
...@@ -13,6 +13,11 @@ and (min-device-width: 1000px) { ...@@ -13,6 +13,11 @@ and (min-device-width: 1000px) {
grid-area: submitButton; grid-area: submitButton;
} }
.reviewLand{
grid-area: reviewButton;
}
.Banner { .Banner {
margin-top: 20px; margin-top: 20px;
background-color: darkslategrey; background-color: darkslategrey;
...@@ -146,14 +151,15 @@ and (min-device-width: 1000px) { ...@@ -146,14 +151,15 @@ and (min-device-width: 1000px) {
.gridContainer1 { .gridContainer1 {
display: grid; display:grid;
grid-template-columns: 10% 10% 60% 5% 5% 10%; grid-template-columns: 10% 10% 60% 5% 5% 10%;
grid-template-rows: auto; grid-template-rows: auto;
grid-template-areas: grid-template-areas:
". pageTitle pageTitle pageTitle pageTitle ." ". pageTitle pageTitle pageTitle pageTitle ."
". . . submitButton submitButton ."; ". reviewButton . submitButton submitButton .";
} }
.gridContainer2 { .gridContainer2 {
display: grid; display: grid;
grid-template-columns: 10% 10% 60% 5% 5% 10%; grid-template-columns: 10% 10% 60% 5% 5% 10%;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<form action="/checkpointSubmitted" method="post" id="adminCheckpointApproval" name="adminCheckpointApproval" th:object="${locationCoord}" onsubmit="return acceptanceValidation()"> <form action="/checkpointSubmitted" method="post" id="adminCheckpointApproval" name="adminCheckpointApproval" th:object="${locationCoord}" onsubmit="return acceptanceValidation()">
<label> Location: <label> Location:
<select th:object="${location}" th:field="*{locationName}"}> <select th:object="${location}" th:field="*{locationName}">
<!-- <select th:field="*{locationName}">--> <!-- <select th:field="*{locationName}">-->
<option value="" hidden="true">Select Location</option> <option value="" hidden="true">Select Location</option>
<option value="" selected disabled>Select Location</option> <option value="" selected disabled>Select Location</option>
...@@ -27,14 +27,13 @@ ...@@ -27,14 +27,13 @@
</select> </select>
</label> </label>
<br><br> <br><br>
<div th:if="${param.error}" class="coordError">Invalid Coordinates entered</div>
<label> Location Latitude: <label> Location Latitude:
<input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here"> <input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here">
<div th:if="${param==error}" class="coordError">Invalid Coordinates entered</div>
<br><br> <br><br>
<label> Location Longitude: <label> Location Longitude:
<input type="text" th:field="*{locationCoordsLong}" placeholder="Latitude Here"> <input type="text" th:field="*{locationCoordsLong}" placeholder="Longitude Here">
</label><br><br> </label><br><br>
<div th:if="${param==error}" class="coordError">Invalid Coordinates entered<
<input type="submit"> <input type="submit">
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment