diff --git a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java index f7005bed0229ebaffaa4ee283fb5368001694cec..773fe4e95e0f689bd398736d2f848ae602ed53a3 100644 --- a/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/landmarks/LandmarksController.java @@ -79,15 +79,16 @@ public class LandmarksController { int locationID = locationRepository.nametoLocationID(location.getLocationName()); // 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()); boolean checkIfCoorsWithinBoundaries = placesCoordinatesRepo.checkIfCoordsAreWithinTownBoundary(ALocCoord); if (checkIfCoorsWithinBoundaries==false){ // if coords outside associated town, form is returned to original state - return new ModelAndView("redirect:/checkpointApproval"); + return new ModelAndView("redirect:/checkpointApproval?error"); } placesCoordinatesRepo.addLocationCoord(ALocCoord); // adds valid landmark to locations table locationRepository.updateApprovalStatus(locationID); // updates approval status accordingly System.out.println(placesCoordinatesRepo.getAllLocationCoords()); - ModelAndView modelAndView = new ModelAndView("redirect:/home"); //redirects back top form in case admin wants to input second location + ModelAndView modelAndView = new ModelAndView("redirect:/mobile-home"); //redirects back top form in case admin wants to input second location return modelAndView; // } diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java index 94200d14799ebe4dbc7f9356b78848bcb0df873c..d5c1f96a6a50744b9b54fdf88cd52fc31d4be264 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesController.java @@ -5,6 +5,8 @@ import Team5.SmartTowns.data.LocationRepository; import Team5.SmartTowns.data.Trail; import Team5.SmartTowns.data.TrailsRepository; import Team5.SmartTowns.rewards.RewardsRepository; +import Team5.SmartTowns.users.UserRepository; +import jakarta.validation.constraints.Max; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -15,13 +17,18 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; @Controller public class PlacesController { @Autowired private PlacesCoordinatesRepository placeRepo; + @Autowired + private LocationRepository locationRepo; @Autowired private TrailsRepository trailsRepo; @@ -29,18 +36,79 @@ public class PlacesController { @Autowired private RewardsRepository rewardsRepository; - @Autowired - private LocationRepository locationRepository; + + + + @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") public ModelAndView getLocationPages(){ ModelAndView modelAndView = new ModelAndView("landmarks/locationPage.html"); List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); modelAndView.addObject("location", approvedLocations); - modelAndView.addObject("locationCoords", locCoords); + modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); return modelAndView; } @@ -53,19 +121,19 @@ public class PlacesController { - @GetMapping("/checkpoints/{location}") + @GetMapping("/checkpoints/{location}") public ModelAndView getResultBySearchKeyLocation(@PathVariable String location) { - List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<LocationsCoordinates> locCoords = reorderCoordsWRTLocations(placeRepo.getAllLocationCoords()); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); - int locationID = 999; - for (int i=0;i<approvedLocations.size();i++){ - if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ - locationID= i; - } + int locationID = 999; + for (int i=0;i<approvedLocations.size();i++){ + if ( (approvedLocations.get(i).getLocationName().replace(' ', '-').trim().equals(location)) ){ + 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.addObject("locCoord", locCoords.get(locationID)); modelAndView.addObject("trail", trailName); @@ -82,13 +150,13 @@ public class PlacesController { public ModelAndView getTrailsPage(){ ModelAndView modelAndView = new ModelAndView("landmarks/trailsPage.html"); List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); List<Trail> trailslocations = trailsRepo.getAllTrails(); List<Location> locationCoordsWorkaround = new ArrayList<Location>(); modelAndView.addObject("trails", trailslocations); modelAndView.addObject("locations", approvedLocations); - modelAndView.addObject("locationCoords", locCoords); + modelAndView.addObject("locationCoords", reorderCoordsWRTLocations(locCoords)); return modelAndView; } @@ -101,9 +169,8 @@ public class PlacesController { @GetMapping("/trails/{trail}") public ModelAndView getResultBySearchKeyTrails(@PathVariable String trail) { List<LocationsCoordinates> locCoords = placeRepo.getAllLocationCoords(); - List<Location> approvedLocations = locationRepository.getAllApprovedLocations(); + List<Location> approvedLocations = locationRepo.getAllApprovedLocations(); List<Trail> trailslocations = trailsRepo.getAllTrails(); - int trailID = 999;// otherwise cases errors e.g. null used. 999 unlikely to be used so safe until then for (int i=0;i<trailslocations.size();i++){ @@ -112,6 +179,9 @@ public class PlacesController { break;} } ModelAndView modelAndView= new ModelAndView("fragments/trailsPageFrags :: trailsSection"); + System.out.println(locCoords.get(0).getLocationID()); + System.out.println(approvedLocations.get(0).getLocationID()); +// locations[indexValue.index].getLocationTrailID()==trail.getTrailsId()} final int trailIDFINAL = trailID; @@ -127,5 +197,41 @@ public class PlacesController { modelAndView.addObject("stickers", rewardsRepository.getAllStickersFromPack(1)); 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; + + } } diff --git a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java index 4258c7e598c3296b7851b843807f8a040af6a31e..9065ea29fe0ee822c0ad895bc81dbb441c3f31f5 100644 --- a/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java +++ b/src/main/java/Team5/SmartTowns/placeswithcoordinates/PlacesCoordinatesRepositoryJDBC.java @@ -66,7 +66,7 @@ public class PlacesCoordinatesRepositoryJDBC implements PlacesCoordinatesReposit public void addLocationCoord(LocationsCoordinates locCoords) { 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 diff --git a/src/main/resources/static/css/homePageStyle.css b/src/main/resources/static/css/homePageStyle.css index 4d69af3c489fc11c8772ed8e68eda94d2d536b75..271119c67ab8434f1e99a4525d119a18d1e34649 100644 --- a/src/main/resources/static/css/homePageStyle.css +++ b/src/main/resources/static/css/homePageStyle.css @@ -13,6 +13,11 @@ and (min-device-width: 1000px) { grid-area: submitButton; } + + .reviewLand{ + grid-area: reviewButton; + } + .Banner { margin-top: 20px; background-color: darkslategrey; @@ -146,14 +151,15 @@ and (min-device-width: 1000px) { .gridContainer1 { - display: grid; + display:grid; grid-template-columns: 10% 10% 60% 5% 5% 10%; grid-template-rows: auto; grid-template-areas: ". pageTitle pageTitle pageTitle pageTitle ." - ". . . submitButton submitButton ."; + ". reviewButton . submitButton submitButton ."; } + .gridContainer2 { display: grid; grid-template-columns: 10% 10% 60% 5% 5% 10%; diff --git a/src/main/resources/static/css/locationApprovalFormStyle.css b/src/main/resources/static/css/locationApprovalFormStyle.css index 3ff324e5832368502608b039b96fd17beb52f9b2..e89a755a91fe9c31b0a42456a9cd2462bb9f07ea 100644 --- a/src/main/resources/static/css/locationApprovalFormStyle.css +++ b/src/main/resources/static/css/locationApprovalFormStyle.css @@ -12,7 +12,9 @@ main { max-width: 80vw; margin: 0 auto } - +.coordError{ + color:darkred; +} #formHeader{ padding-top: 10px; color:white; diff --git a/src/main/resources/templates/landmarks/locationApprovalFormTh.html b/src/main/resources/templates/landmarks/locationApprovalFormTh.html index 7315b62f8a7e80175686d97fc940ab6609dff714..df465b669fa5b2b12b5fbeed252ea32c0b26e4b8 100644 --- a/src/main/resources/templates/landmarks/locationApprovalFormTh.html +++ b/src/main/resources/templates/landmarks/locationApprovalFormTh.html @@ -18,7 +18,7 @@ <form action="/checkpointSubmitted" method="post" id="adminCheckpointApproval" name="adminCheckpointApproval" th:object="${locationCoord}" onsubmit="return acceptanceValidation()"> <label> Location: - <select th:object="${location}" th:field="*{locationName}"}> + <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> @@ -27,14 +27,13 @@ </select> </label> <br><br> + <div th:if="${param.error}" class="coordError">Invalid Coordinates entered.</div> <label> Location Latitude: <input type="text" th:field="*{locationCoordsLat}" placeholder="Latitude Here"> - <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="Longitude Here"> </label><br><br> - <div th:errors="*{locationCoordsLong}" th:if="${#fields.hasErrors('locationCoordsLong')}">ErrorlocationCoordsLat</div> <input type="submit"> </form>