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

Added front-end verification to approval form

parent 7d1d4a12
No related branches found
No related tags found
1 merge request!42Resolve "As a site administrator I want to be able to review submitted trail checkpoints by business owners, so that they might be added to the existing trails
...@@ -20,9 +20,9 @@ import java.util.List; ...@@ -20,9 +20,9 @@ import java.util.List;
@Controller @Controller
public class LandmarksController { public class LandmarksController {
// Controllers for LandmarkFormTh.html landmark submission form // Controllers for LandmarkFormTh.html landmark submission form
@GetMapping("/landmarkSubmission") @GetMapping("/landmarkSubmission")
public ModelAndView landmarkSubmission(){ public ModelAndView landmarkSubmission() {
ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html"); ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html");
modelAndView1.addObject("landmarkData", new Landmarks()); modelAndView1.addObject("landmarkData", new Landmarks());
return modelAndView1; return modelAndView1;
...@@ -31,32 +31,33 @@ public class LandmarksController { ...@@ -31,32 +31,33 @@ public class LandmarksController {
@Autowired @Autowired
private LocationRepository locationRepository; private LocationRepository locationRepository;
@PostMapping("/landmarkSub") @PostMapping("/landmarkSub")
public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) { public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap()); ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap());
return modelAndView; return modelAndView;
} else{ } else {
// 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
Location loc= new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false); Location loc = new Location(landmarks.getLandmarkName(), landmarks.getLandmarkEmail(), landmarks.getLandmarkDescription(), landmarks.getLandmarkLocation(), landmarks.getTrailID(), false);
locationRepository.addLocation(loc); // adds valid landmark to locations table locationRepository.addLocation(loc); // adds valid landmark to locations table
ModelAndView modelAndView = new ModelAndView("redirect:/home"); ModelAndView modelAndView = new ModelAndView("redirect:/home");
return modelAndView; return modelAndView;
} }
} }
@Autowired @Autowired
private PlacesCoordinatesRepository placesCoordinatesRepo; private PlacesCoordinatesRepository placesCoordinatesRepo;
// For form that allows an administrator to add an unapproved location to a trail
@GetMapping("/checkpointApproval") @GetMapping("/checkpointApproval")
public ModelAndView adminCheckpointApproval(){ public ModelAndView adminCheckpointApproval() {
List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); //change to unauthorised once merger 68 accepted!! todo List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); //change to unauthorised once merger 68 accepted!! todo
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html"); ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html");
...@@ -66,21 +67,19 @@ public class LandmarksController { ...@@ -66,21 +67,19 @@ public class LandmarksController {
return modelAndView; return modelAndView;
} }
// @ModelAttribute("locationCoord")
@PostMapping("/checkpointSubmitted") @PostMapping("/checkpointSubmitted")
public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model ) { public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model) {
System.out.println(111);
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
return modelAndView;
// if (bindingResult.hasErrors()) { } else {
// ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
// return modelAndView;
//
// } else{
int locationID= locationRepository.nametoLocationID(location.getLocationName()); int locationID = locationRepository.nametoLocationID(location.getLocationName());
System.out.println( locationID);
// 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
LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID,locCoord.getLocationCoordsLat(),locCoord.getLocationCoordsLong()); LocationsCoordinates ALocCoord = new LocationsCoordinates(locationID, locCoord.getLocationCoordsLat(), locCoord.getLocationCoordsLong());
placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table
locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly
System.out.println(placesCoordinatesRepo.getAllLocationCoords()); System.out.println(placesCoordinatesRepo.getAllLocationCoords());
...@@ -89,6 +88,7 @@ public class LandmarksController { ...@@ -89,6 +88,7 @@ public class LandmarksController {
// } // }
}
} }
} }
...@@ -4,6 +4,10 @@ package Team5.SmartTowns.placeswithcoordinates; ...@@ -4,6 +4,10 @@ package Team5.SmartTowns.placeswithcoordinates;
import Team5.SmartTowns.data.Location; import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepositoryJDBC; import Team5.SmartTowns.data.LocationRepositoryJDBC;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -18,7 +22,12 @@ import java.util.List; ...@@ -18,7 +22,12 @@ import java.util.List;
public class LocationsCoordinates { public class LocationsCoordinates {
/// separate class to location to cover all locations within trails that have been approved and have long/lat coords attached for mapping. /// separate class to location to cover all locations within trails that have been approved and have long/lat coords attached for mapping.
private int locationID; private int locationID;
// @NotEmpty(message = "You must enter a Latitude.")
@Min(value=0,message = "You must enter a Latitude.")
private Double locationCoordsLat; private Double locationCoordsLat;
// @NotEmpty(message = "You must type in a Longitude.")
@Min(value=0,message = "You must type in a Longitude.")
private Double locationCoordsLong; private Double locationCoordsLong;
private JdbcTemplate jdbc; private JdbcTemplate jdbc;
......
...@@ -13,6 +13,8 @@ public interface PlacesCoordinatesRepository { ...@@ -13,6 +13,8 @@ public interface PlacesCoordinatesRepository {
List<TownWithTrails> getAllTownCoords(); List<TownWithTrails> getAllTownCoords();
void addTownWithCoords(TownWithTrails town); void addTownWithCoords(TownWithTrails town);
int getLocationTableIDValue(List<Location> locations, String locationName);
// List<Location> getFullApprovedLocations(JdbcTemplate aJdbc); // List<Location> getFullApprovedLocations(JdbcTemplate aJdbc);
......
package Team5.SmartTowns.placeswithcoordinates; package Team5.SmartTowns.placeswithcoordinates;
import Team5.SmartTowns.data.Location; import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.data.LocationRepositoryJDBC;
import org.springframework.boot.autoconfigure.integration.IntegrationProperties;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -121,7 +119,9 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit ...@@ -121,7 +119,9 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit
} }
} }
return true;} return true;}
int getLocationTableIDValue(List<Location> locations, String locationName){
@Override
public int getLocationTableIDValue(List<Location> locations, String locationName){
int index; int index;
for(int i=0;i<locations.size();i++){ for(int i=0;i<locations.size();i++){
if (Objects.equals(locations.get(i).getLocationName(), locationName)){ if (Objects.equals(locations.get(i).getLocationName(), locationName)){
...@@ -135,6 +135,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit ...@@ -135,6 +135,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit
// Method used to approve and add locations with associated coordinates. List<Location> unapprovedLocations // Method used to approve and add locations with associated coordinates. List<Location> unapprovedLocations
// public void approveLocationAndAddCoords(String locationsName, Double latCoords, Double longCoords,JdbcTemplate jdbc) { // public void approveLocationAndAddCoords(String locationsName, Double latCoords, Double longCoords,JdbcTemplate jdbc) {
// // need list too // // need list too
......
//script for basic long/lat validation
function acceptanceValidation(){
var pass=true;
var lat = document.forms["adminCheckpointApproval"]["locationCoordsLat"].value
var long = document.forms["adminCheckpointApproval"]["locationCoordsLong"].value
if (lat=="") {
alert('Invalid location inputted. \nPlease input a valid latitude.');
pass = false;
}
if (long==""){
alert('Invalid location inputted. \nPlease input a valid longitude.');
pass = false;
} return pass;
}
\ No newline at end of file
...@@ -3,32 +3,39 @@ ...@@ -3,32 +3,39 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
<link rel="stylesheet" th:href="@{css/templatingstyle.css}">
<script src="/scripts/locationApprovalForm.js"></script>
</head> </head>
<body> <body>
<header th:insert="~{/fragments/Templating.html :: header}"></header>
<main> <main>
<form action="/checkpointSubmitted" method="post" th:object="${locationCoord}"> <form action="/checkpointSubmitted" method="post" name="adminCheckpointApproval" th:object="${locationCoord}" onsubmit="return acceptanceValidation()">
<label> Location To Be Approved: <label> Location To Be Approved:
<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>
<option value="Caerphilly">Caerphilly</option> <option th:each="uloc:${uLocs}" th:value="${uloc.getLocationName()}" th:text="${uloc.getLocationName()}+' ('+${uloc.getLocationTrailID()}+')'">
<option th:each="uloc:${uLocs}" th:value="${uloc.getLocationName()}" th:text="${uloc.getLocationName()}">
</option> </option>
</select> </select>
</label> </label>
<br><label> Location Latitude: <br><br>
<label> Location Latitude:
<input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here"> <input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here">
<br><label> Location Longitude: <div th:errors="*{locationCoordsLat}" th:if="${#fields.hasErrors('locationCoordsLat')}">ErrorlocationCoordsLat</div>
<br><br>
<label> Location Longitude:
<input type="text" th:field="*{locationCoordsLong}" placeholder="Latitude Here"> <input type="text" th:field="*{locationCoordsLong}" placeholder="Latitude Here">
</label><br> </label><br><br>
<div th:errors="*{locationCoordsLong}" th:if="${#fields.hasErrors('locationCoordsLong')}">ErrorlocationCoordsLat</div>
<input type="submit"> <input type="submit">
</form> </form>
</main> </main>
<footer th:insert="~{/fragments/Templating.html :: footer}"></footer>
</body> </body>
</html> </html>
\ No newline at end of file
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