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

Further work on making the homePage.html town list more dynamic using thymeleaf

parent 28a8671b
No related branches found
No related tags found
1 merge request!20Resolve "As a user I want to see a list of all available towns with trails so I can plan where to go"
package Team5.SmartTowns.Towns;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class TownController {
@GetMapping("/townTest")
public ModelAndView getTownList(){
ModelAndView modelAndView = new ModelAndView("Towns/home/homePageTest");
TownStorage townsCurrent= new TownStorage().getInstance();
List<Towns> towns = townsCurrent.getTownList();
modelAndView.addObject("towns",towns);
return modelAndView;
}
}
package Team5.SmartTowns.Towns;
import java.util.ArrayList;
import java.util.List;
public class TownStorage {
private List<Towns> townList;
private static TownStorage singleton;
TownStorage() {
townList = new ArrayList<>();
townList.addAll(
List.of(
new Towns("Caerphilly",01,3,70,"/images/CaerphillyCastle.jpg"),
new Towns("Risca",02,2,0,"/images/RiscaBanner.jpg"),
new Towns("Penarth",03,5,60,"/images/PenarthBanner.jpg")
)
);
}
public static TownStorage getInstance() {
if (singleton == null) {
singleton = new TownStorage();
}
return singleton;
}
public List<Towns> getTownList() {
return townList;
}
}
......@@ -3,12 +3,14 @@ package Team5.SmartTowns.Towns;
import lombok.Data;
@Data
public class towns {
public class Towns {
private String name;
private Integer id;
private int trailNumber;
private int trailProgress;
private String imageTown;
public String getName() {
return name;
......@@ -42,11 +44,19 @@ public class towns {
this.trailProgress = trailProgress;
}
public String getImageTown() {
return imageTown;
}
public void setImageTown(String imageTown) {
this.imageTown = imageTown;
}
public towns(String name, Integer id, int trailNumber, int trailProgress) {
public Towns(String name, Integer id, int trailNumber, int trailProgress, String imageTown) {
this.name = name;
this.id = id;
this.trailNumber = trailNumber;
this.trailProgress = trailProgress;
this.imageTown = imageTown;
}
}
package Team5.SmartTowns.Towns;
import java.util.ArrayList;
import java.util.List;
public class townsStorage {
private List<towns> townList;
private static townsStorage singelton;
townsStorage() {
townList = new ArrayList<>();
townList.addAll(
List.of(
new towns("Caerphilly",01,3,70),
new towns("Risca",02,2,0),
new towns("Penarth",03,5,60)
)
);
}
}
......@@ -11,25 +11,25 @@ import org.springframework.stereotype.Controller;
public class WebpageController {
@GetMapping("/Caerleon")
public ModelAndView getCaerleonPage(){
ModelAndView modelAndView = new ModelAndView("towns/caerleon");
ModelAndView modelAndView = new ModelAndView("Towns/caerleon");
return modelAndView;
}
@GetMapping("/Caerphilly")
public ModelAndView getCaerphillyPage(){
ModelAndView modelAndView = new ModelAndView("towns/caerphilly");
ModelAndView modelAndView = new ModelAndView("Towns/caerphilly");
return modelAndView;
}
@GetMapping("/Risca")
public ModelAndView getRiscaPage(){
ModelAndView modelAndView = new ModelAndView("towns/risca");
ModelAndView modelAndView = new ModelAndView("Towns/risca");
return modelAndView;
}
@GetMapping("/home")
public ModelAndView getHome(){
ModelAndView modelAndView = new ModelAndView("towns/home/homePage");
ModelAndView modelAndView = new ModelAndView("Towns/home/homePage");
return modelAndView;
}
......
......@@ -9,7 +9,7 @@ import org.springframework.web.servlet.ModelAndView;
public class DragonsTale {
@GetMapping("/dragonstale")
public ModelAndView getDragonsTale(){
ModelAndView modelAndView = new ModelAndView("src/main/resources/templates/towns/trails/dragonstale/index.html");
ModelAndView modelAndView = new ModelAndView("src/main/resources/templates/Towns/trails/dragonstale/index.html");
return modelAndView;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- <link rel="stylesheet" th:href="@{/css/homePageStyle.css}">-->
<link rel="stylesheet" th:href="@{/css/templatingstyle.css}">
</head>
<body>
<header th:insert="~{/towns/Templating.html::header}"></header>
<main>
<div class="gridContainer1">
<H1 id="homeTitle"> VZTA Smart Towns - Trails</H1>
<a class="submitLand" href="/landmarkSubmission"> <button> Submit Landmark!</button></a>
<div th:text="${towns}">
</div>
<ul th:each="town:${towns}">
<a href="/allTrails" class="caerphillyBanner">
<H2 th:text="${town.getName()}"> </H2></a>
<div class="caerphillyBannerTrail">
<div id="trailCountCaer" th:text="'Trails: '+ ${town.getTrailNumber()}">Trails: </div>
<div id="trailProgressCaer" th:text="${town.getTrailProgress()}"></div>
</div>
<!-- //goes through each student in list of students^^-->
<li th:text="${town.getName()}"></li>
</ul>
<a href="/allTrails" class="caerphillyBanner">
<H2> Caerphilly</H2></a>
<div class="caerphillyBannerTrail">
<div id="trailCountCaer">Trails: 3</div>
<div id="trailProgressCaer">70%</div>
</div>
<a href="/allTrails" class="riscaBanner">
<H2> Risca</H2> </a>
<div class="riscaBannerTrail">
<div id="trailCountRisca">Trails: 2</div>
<div id="trailProgressRisca">0%</div>
</div>
<a href="/allTrails" class="penarthBanner">
<H2> Penarth</H2> </a>
<div class="penarthBannerTrail">
<div id="trailCountPenarth">Trails: 5</div>
<div id="trailProgressPenarth">60%</div>
</div>
<div id="aboutUsFlavour"> This is placeholder text about VZTA, this application,
the trails and towns and resultant awards written in an excitable manner!!</div>
</div>
</main>
<footer th:insert="~{/towns/Templating.html::footer}"></footer>
</body>
</html>
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