From e9a4a6d97a01794c902495bdfe1abe5faf994b7e Mon Sep 17 00:00:00 2001 From: Connor <brockcc1@cardiff.ac.uk> Date: Thu, 30 Nov 2023 12:50:41 +0000 Subject: [PATCH] Added thymeleaf fragmented list into Dragons Tale html page --- .../Team5/SmartTowns/Landmarks/Landmarks.java | 34 +++++++++++----- .../Landmarks/LandmarksController.java | 15 +++---- .../java/Team5/SmartTowns/trails/Trail.java | 13 +++--- .../SmartTowns/trails/TrailsController.java | 13 +++--- .../css/dragonstaless.css} | 0 .../images/landmarks}/dragonone.png | Bin .../images/trails}/dragonstalehome.png | Bin .../templates/fragments/landmarkFrag.html | 8 ++++ .../towns/trails/dragonstale/index.html | 10 +++-- .../dragonstale/trailcheckpoints/one/one.html | 37 ------------------ 10 files changed, 60 insertions(+), 70 deletions(-) rename src/main/resources/{templates/towns/trails/dragonstale/stylesheet.css => static/css/dragonstaless.css} (100%) rename src/main/resources/{templates/towns/trails/dragonstale/trailcheckpoints/one => static/images/landmarks}/dragonone.png (100%) rename src/main/resources/{templates/towns/trails/dragonstale => static/images/trails}/dragonstalehome.png (100%) create mode 100644 src/main/resources/templates/fragments/landmarkFrag.html delete mode 100644 src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/one.html diff --git a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java index ee6628f3..c956572a 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/Landmarks.java @@ -1,29 +1,45 @@ package Team5.SmartTowns.Landmarks; +import Team5.SmartTowns.trails.Trail; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotEmpty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + @Data @AllArgsConstructor +@NoArgsConstructor public class Landmarks { + + // Intialised object to getID from trail. + Trail trail = new Trail(); + + //Predefined Landmark for Dragons Tale. + public static List<Landmarks> landmarksDragonstrail = List.of( + new Landmarks( 1, "A scent of...Dragon", "The Dragon has been spotted near by, find the QR code to continue" , "location test"), + new Landmarks( 2, "They've been found!", "Don't let them escape, find the next QR code to continue!", "location test") + ); + + private Integer trailID; + private int landmarkID; @NotEmpty(message = "You must type in a username.") private String landmarkName; @Email(message = "You must attach a contact address.") private String landmarkEmail; private String landmarkDescription; private String landmarkLocation; - private Integer trailID; - + private String landmarkPicture; - public Landmarks(){ - this.landmarkName =""; - this.landmarkEmail=""; - this.landmarkDescription =""; - this.landmarkLocation =""; - this.trailID =0; - } + // Constructor for List above. + public Landmarks( int landmarkID, String landmarkName, String landmarkDescription, String landmarkLocation) { + this.landmarkID = landmarkID; + this.landmarkName = landmarkName; + this.landmarkDescription = landmarkDescription; + this.landmarkLocation = landmarkLocation; } } diff --git a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java index 7a116a00..dfdcde40 100644 --- a/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java +++ b/src/main/java/Team5/SmartTowns/Landmarks/LandmarksController.java @@ -1,5 +1,6 @@ package Team5.SmartTowns.Landmarks; +import Team5.SmartTowns.trails.Trail; import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -24,23 +25,23 @@ public class LandmarksController { } @PostMapping("/landmarkSub") 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{ System.out.println(landmarks); // current functionality only prints successful Landmarks, (todo )database integration is necessary here - - ModelAndView modelAndView = new ModelAndView("redirect:/test.html"); return modelAndView; - } + } - } +// @GetMapping("/dragonstale/{") +// public ModelAndView getAllTrails(){ +// ModelAndView mav = new ModelAndView("allTrails/allTrails"); +// mav.addObject("landmarks", Landmarks.landmarks); //Mock data for trails +// return mav; +// } diff --git a/src/main/java/Team5/SmartTowns/trails/Trail.java b/src/main/java/Team5/SmartTowns/trails/Trail.java index c4b4e3ca..7843e9a7 100644 --- a/src/main/java/Team5/SmartTowns/trails/Trail.java +++ b/src/main/java/Team5/SmartTowns/trails/Trail.java @@ -7,12 +7,15 @@ import java.util.List; @Data public class Trail { + + //List not existing upon creation of database. public static List<Trail> trails = List.of( new Trail(1,"Caerphilly Castle Trail", "Take a stroll through the grounds of one of Europe's finest historic buildings and you will see stunning views of the castle and the lakes. The route of the trail is marked with eight special circular markers, which depict various fascinating historical facts relating to the castle. Pupils from Ysgol Gynradd Gymraeg Caerffili, Plasyfelin Junior School, Ysgol Y Castell and Twyn Primary worked with the artist to come up with the different designs. You do not need to pay to go in the castle to complete this trail. This Trail is fairly short at 1.5 miles and very suitable for wheelchairs and pushchairs as the route stays mostly on well-marked and ramped paths with just a couple of short diversions onto grassed areas."), new Trail(2,"Trail2", "This is trail two"), new Trail(3,"Trail3", "This is trail three"), new Trail(4,"Trail4", "This is trail four"), - new Trail(5,"Trail5", "EDITING THIS") + new Trail(5,"Trail5", "EDITING THIS"), + new Trail(6, "A Dragon's Tale", "Adventurers... embark through mystical historical landmarks to ultimately discover the lair of the dragon. Legend has it that within this ominous lair, mighty dragons, guardians of ancient wisdom and treasures untold lay....") ); int id; String name; @@ -28,6 +31,10 @@ public class Trail { imgPath = findImagePath(); } + public Trail() { + this.id = id; + } + private String findImagePath(){ /* Finds the image in the Path folder, if image is not found assigns default image */ String imgPath = "images/trails/trail" + id + ".jpg"; @@ -36,8 +43,4 @@ public class Trail { File imgFile = new File("src/main/resources/static/" + imgPath); return imgFile.exists() ? imgPath : notFoundPath; } - - public static List<Trail> getTrails() { - return trails; - } } diff --git a/src/main/java/Team5/SmartTowns/trails/TrailsController.java b/src/main/java/Team5/SmartTowns/trails/TrailsController.java index 12540fcd..0b9b8f6c 100644 --- a/src/main/java/Team5/SmartTowns/trails/TrailsController.java +++ b/src/main/java/Team5/SmartTowns/trails/TrailsController.java @@ -1,6 +1,7 @@ package Team5.SmartTowns.trails; +import Team5.SmartTowns.Landmarks.Landmarks; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -12,6 +13,8 @@ import org.springframework.web.servlet.ModelAndView; import java.util.ArrayList; import java.util.List; +import static Team5.SmartTowns.Landmarks.Landmarks.landmarksDragonstrail; + @Controller public class TrailsController { @GetMapping("/allTrails") @@ -32,22 +35,16 @@ public class TrailsController { List<Trail> trailList= Trail.trails;//results from db ModelAndView mv= new ModelAndView("fragments/allTrailsFrags :: trailSection"); mv.addObject("trail", trailList.get(id-1)); - return mv; } - //Leave this, I'll create a thymeleaf redirect for multiple different trails, rather then just have one for each trail. @GetMapping("/dragonstale") public ModelAndView getDragonsTale(){ + List<Landmarks> landmarksList = landmarksDragonstrail; ModelAndView modelAndView = new ModelAndView("towns/trails/dragonstale/index"); + modelAndView.addObject("landmarksList", landmarksList); return modelAndView; } - //Same for this - @GetMapping("/dragonstale/landmarkone") - public ModelAndView getLandmark(){ - ModelAndView modelAndView = new ModelAndView("towns/trails/dragonstale/trailcheckpoints/one/one"); - return modelAndView; } -} diff --git a/src/main/resources/templates/towns/trails/dragonstale/stylesheet.css b/src/main/resources/static/css/dragonstaless.css similarity index 100% rename from src/main/resources/templates/towns/trails/dragonstale/stylesheet.css rename to src/main/resources/static/css/dragonstaless.css diff --git a/src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/dragonone.png b/src/main/resources/static/images/landmarks/dragonone.png similarity index 100% rename from src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/dragonone.png rename to src/main/resources/static/images/landmarks/dragonone.png diff --git a/src/main/resources/templates/towns/trails/dragonstale/dragonstalehome.png b/src/main/resources/static/images/trails/dragonstalehome.png similarity index 100% rename from src/main/resources/templates/towns/trails/dragonstale/dragonstalehome.png rename to src/main/resources/static/images/trails/dragonstalehome.png diff --git a/src/main/resources/templates/fragments/landmarkFrag.html b/src/main/resources/templates/fragments/landmarkFrag.html new file mode 100644 index 00000000..67eaed5a --- /dev/null +++ b/src/main/resources/templates/fragments/landmarkFrag.html @@ -0,0 +1,8 @@ +<!-- TODO Develop each individual landmark for DragonsTrail --> +<!-- Each trail should have a preestablished set of landmarks --> + +<div th:fragment="landmarkList" class="centre" id="landmarkList"> + <ul> + <li th:each="item : ${landmarksList}" th:text="${item}"></li> + </ul> +</div> \ No newline at end of file diff --git a/src/main/resources/templates/towns/trails/dragonstale/index.html b/src/main/resources/templates/towns/trails/dragonstale/index.html index 99122f59..894df0b7 100644 --- a/src/main/resources/templates/towns/trails/dragonstale/index.html +++ b/src/main/resources/templates/towns/trails/dragonstale/index.html @@ -1,15 +1,15 @@ <!DOCTYPE html> <html lang="en"> -<head> +<html xmlns:th="http://www.thymeleaf.org"> <meta charset="UTF-8"> <title>A Dragon's Tale</title> - <link rel="stylesheet" href="stylesheet.css"> + <link rel="stylesheet" th:href="@{/css/dragonstaless.css}"> </head> <body> <div class="centre"> <h1> Welcome, to a dragon's tale! </h1> - <img src="dragonstalehome.png" alt="Image of a dragon"> + <img th:src="@{/images/trails/dragonstalehome.png}" alt="Image of a dragon"> <h2> Discover the mystery of the dragon, track its location and follow it throughout the town of (thymeleaf element) to discover a prize! </h2> </div> @@ -21,7 +21,9 @@ </div> <div class="centre"> - <!-- TO DO, --> + <ul> + <li th:insert="fragments/landmarkFrag.html :: landmarkList"></li> + </ul> </div> <div class="centre"> diff --git a/src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/one.html b/src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/one.html deleted file mode 100644 index df1237ce..00000000 --- a/src/main/resources/templates/towns/trails/dragonstale/trailcheckpoints/one/one.html +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Checkpoint One <filler></title> -</head> -<body> - <!-- constant use of divs used to separate important sections of the website that'll be maintained throughout the project --> - <div> - <h1>Checkpoint one... The Beginning of an adventure!</h1> - </div> - - <div> - <!-- Insert a thymeleaf attribute here to layer this image onto a background of the town--> - <img src="dragonone.png" alt="Image of a Red Dragon"> - </div> - - <div> - <p> Enter a story about the checkpoint here.....</p> - </div> - - <div> - <p> Here goes where the user must go next. Hints, etc. </p> - </div> - - <div> - <p> Greyed out image of something that can be dynamically altered upon scanning QR code.</p> - </div> - - <div> - <p> Here a total progress bar...</p> - </div> - - - -</body> -</html> \ No newline at end of file -- GitLab