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;
@Controller
public class LandmarksController {
// Controllers for LandmarkFormTh.html landmark submission form
// Controllers for LandmarkFormTh.html landmark submission form
@GetMapping("/landmarkSubmission")
public ModelAndView landmarkSubmission(){
public ModelAndView landmarkSubmission() {
ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html");
modelAndView1.addObject("landmarkData", new Landmarks());
return modelAndView1;
......@@ -31,32 +31,33 @@ public class LandmarksController {
@Autowired
private LocationRepository locationRepository;
@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()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap());
return modelAndView;
} else{
} else {
// 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
ModelAndView modelAndView = new ModelAndView("redirect:/home");
return modelAndView;
}
}
@Autowired
private PlacesCoordinatesRepository placesCoordinatesRepo;
// For form that allows an administrator to add an unapproved location to a trail
@GetMapping("/checkpointApproval")
public ModelAndView adminCheckpointApproval(){
public ModelAndView adminCheckpointApproval() {
List<Location> unapprovedLocations = locationRepository.getAllUnapprovedLocations(); //change to unauthorised once merger 68 accepted!! todo
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html");
......@@ -66,21 +67,19 @@ public class LandmarksController {
return modelAndView;
}
// @ModelAttribute("locationCoord")
@PostMapping("/checkpointSubmitted")
public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model ) {
System.out.println(111);
public ModelAndView checkpointSent(@Valid LocationsCoordinates locCoord, Location location, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
return modelAndView;
// if (bindingResult.hasErrors()) {
// ModelAndView modelAndView = new ModelAndView("Landmarks/locationApprovalFormTh.html", model.asMap());
// return modelAndView;
//
// } else{
} else {
int locationID= locationRepository.nametoLocationID(location.getLocationName());
System.out.println( locationID);
int locationID = locationRepository.nametoLocationID(location.getLocationName());
// 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
locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly
System.out.println(placesCoordinatesRepo.getAllLocationCoords());
......@@ -89,6 +88,7 @@ public class LandmarksController {
// }
}
}
}
......@@ -4,6 +4,10 @@ package Team5.SmartTowns.placeswithcoordinates;
import Team5.SmartTowns.data.Location;
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.Data;
import lombok.NoArgsConstructor;
......@@ -18,7 +22,12 @@ import java.util.List;
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.
private int locationID;
// @NotEmpty(message = "You must enter a Latitude.")
@Min(value=0,message = "You must enter a Latitude.")
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 JdbcTemplate jdbc;
......
......@@ -13,6 +13,8 @@ public interface PlacesCoordinatesRepository {
List<TownWithTrails> getAllTownCoords();
void addTownWithCoords(TownWithTrails town);
int getLocationTableIDValue(List<Location> locations, String locationName);
// List<Location> getFullApprovedLocations(JdbcTemplate aJdbc);
......
package Team5.SmartTowns.placeswithcoordinates;
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.RowMapper;
import org.springframework.stereotype.Repository;
......@@ -121,7 +119,9 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit
}
}
return true;}
int getLocationTableIDValue(List<Location> locations, String locationName){
@Override
public int getLocationTableIDValue(List<Location> locations, String locationName){
int index;
for(int i=0;i<locations.size();i++){
if (Objects.equals(locations.get(i).getLocationName(), locationName)){
......@@ -135,6 +135,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit
// Method used to approve and add locations with associated coordinates. List<Location> unapprovedLocations
// public void approveLocationAndAddCoords(String locationsName, Double latCoords, Double longCoords,JdbcTemplate jdbc) {
// // 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 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" th:href="@{css/templatingstyle.css}">
<script src="/scripts/locationApprovalForm.js"></script>
</head>
<body>
<header th:insert="~{/fragments/Templating.html :: header}"></header>
<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:
<select th:object="${location}" th:field="*{locationName}"}>
<!-- <select th:field="*{locationName}">-->
<option value="" hidden="true">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()}">
<option th:each="uloc:${uLocs}" th:value="${uloc.getLocationName()}" th:text="${uloc.getLocationName()}+' ('+${uloc.getLocationTrailID()}+')'">
</option>
</select>
</label>
<br><label> Location Latitude:
<br><br>
<label> Location Latitude:
<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">
</label><br>
</label><br><br>
<div th:errors="*{locationCoordsLong}" th:if="${#fields.hasErrors('locationCoordsLong')}">ErrorlocationCoordsLat</div>
<input type="submit">
</form>
</main>
<footer th:insert="~{/fragments/Templating.html :: footer}"></footer>
</body>
</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