Второе глобальное промежуточное сохранение.

This commit is contained in:
Programmist73 2023-04-24 14:10:55 +04:00
parent 843ec51b8c
commit 167ca7eb82
22 changed files with 1108 additions and 21 deletions

View File

@ -62,6 +62,10 @@ public class ClientDTO {
return tanks;
}
public Long getIdLastTanks(){
return tanks.get(tanks.size() - 1).getId();
}
public void setTanks(List<TankDTO> tanks) {
this.tanks = tanks;
}

View File

@ -0,0 +1,72 @@
package premium_store.controller.DTO;
import com.fasterxml.jackson.annotation.JsonProperty;
import premium_store.model.GameClient;
import java.util.List;
//класс, который соединяет танки клиента в одну строчку (нам так захотелось)
public class SupportClientDTO {
private long id;
private String nickName;
private String email;
private Integer balance;
private Long tankId;
public SupportClientDTO(){ }
public SupportClientDTO(GameClient gameClient){
this.id = gameClient.getId();
this.nickName = gameClient.getNickName();
this.email = gameClient.getEmail();
this.balance = gameClient.getBalance();
if(gameClient.getTanks().size() >= 1){
this.tankId = gameClient.getTanks().get(gameClient.getTanks().size() - 1).getId();
}
else {
this.tankId = null;
}
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public long getId(){
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNickName(){
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getEmail(){
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getBalance(){
return balance;
}
public void setBalance(Integer balance) {
this.balance = balance;
}
public Long getTankId(){
return tankId;
}
public void setTankId(Long tankId) {
this.tankId = tankId;
}
}

View File

@ -0,0 +1,63 @@
package premium_store.controller.DTO;
import com.fasterxml.jackson.annotation.JsonProperty;
import premium_store.model.Tank;
public class SupportTankDTO {
private long id;
private String name;
private Long nationId;
private Long levelId;
private int cost;
public SupportTankDTO(){}
public SupportTankDTO(Tank tank){
this.id = tank.getId();
this.nationId = tank.getNation().getId();
this.levelId = tank.getLevel().getId();
this.name = tank.getName();
this.cost = tank.getCost();
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public Long getId(){
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getNationId(){
return nationId;
}
public void setNationId(Long nationId) {
this.nationId = nationId;
}
public Long getLevelId(){
return levelId;
}
public void setLevelId(Long levelId) {
this.levelId = levelId;
}
public int getCost(){
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
}

View File

@ -0,0 +1,91 @@
package premium_store.controller.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import premium_store.controller.DTO.*;
import premium_store.service.GameClientService;
import premium_store.service.TankService;
import javax.validation.Valid;
import java.util.List;
@Controller
@RequestMapping("/client")
public class ClientMvcController {
private final GameClientService gameClientService;
private final TankService tankService;
public ClientMvcController(GameClientService gameClientService, TankService tankService){
this.gameClientService = gameClientService;
this.tankService = tankService;
}
@GetMapping
public String getClients(Model model){
model.addAttribute("clients",
gameClientService.findAllClients().stream()
.map(ClientDTO::new)
.toList());
return "client";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editClient(@PathVariable(required = false) Long id, Model model){
if(id == null || id <= 0){
model.addAttribute("supportClientDTO", new SupportClientDTO());
}
else {
model.addAttribute("clientId", id);
model.addAttribute("supportClientDTO", new SupportClientDTO(gameClientService.findClient(id)));
}
List<TankDTO> tanks = tankService.findAllTanks().stream()
.map(TankDTO::new)
.toList();
model.addAttribute("tanks", tanks);
return "client-edit";
}
@GetMapping(value = {"/tanksOfClient", "/tanksOfClient/{id}"})
public String editTanksOfClient(@PathVariable(required = false) Long id, Model model){
if(id == null || id <= 0){
model.addAttribute("clientDTO", new ClientDTO());
}
else {
model.addAttribute("clientId", id);
model.addAttribute("clientDTO", new ClientDTO(gameClientService.findClient(id)));
}
return "tanks-of-client-edit";
}
@PostMapping(value = {"", "/{id}"})
public String saveClient(@PathVariable(required = false) Long id,
@ModelAttribute @Valid SupportClientDTO clientDTO,
BindingResult bindingResult,
Model model){
if(bindingResult.hasErrors()){
model.addAttribute("errors", bindingResult.getAllErrors());
return "client-edit";
}
if(id == null || id <= 0){
gameClientService.addClient(clientDTO.getNickName(), clientDTO.getNickName(), clientDTO.getBalance());
} else {
gameClientService.updateClient(clientDTO);
}
return "redirect:/client";
}
@PostMapping("/delete/{id}")
public String deleteClient(@PathVariable Long id){
gameClientService.deleteClient(id);
return "redirect:/tank";
}
}

View File

@ -0,0 +1,71 @@
package premium_store.controller.controller;
import net.bytebuddy.implementation.bind.MethodDelegationBinder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import premium_store.controller.DTO.FullNationDTO;
import premium_store.controller.DTO.LevelDTO;
import premium_store.controller.DTO.SimpleNationDTO;
import premium_store.service.NationService;
import premium_store.service.TankLevelService;
import javax.validation.Valid;
@Controller
@RequestMapping("/level")
public class LevelMvcController {
private final TankLevelService levelService;
public LevelMvcController(TankLevelService levelService){
this.levelService = levelService;
}
@GetMapping
public String getLevels(Model model){
model.addAttribute("levels",
levelService.findAllLevels().stream()
.map(LevelDTO::new)
.toList());
return "level";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editLevel(@PathVariable(required = false) Long id, Model model){
if(id == null || id <= 0){
model.addAttribute("levelDTO", new LevelDTO());
}
else {
model.addAttribute("levelId", id);
model.addAttribute("levelDTO", new LevelDTO(levelService.findLevel(id)));
}
return "level-edit";
}
@PostMapping(value = {"", "/{id}"})
public String saveLevel(@PathVariable(required = false) Long id,
@ModelAttribute @Valid LevelDTO levelDTO,
BindingResult bindingResult,
Model model){
if(bindingResult.hasErrors()){
model.addAttribute("errors", bindingResult.getAllErrors());
return "level-edit";
}
if(id == null || id <= 0){
levelService.addLevel(levelDTO.getLevel());
} else {
levelService.updateLevel(id, levelDTO.getLevel());
}
return "redirect:/level";
}
@PostMapping("/delete/{id}")
public String deleteLevel(@PathVariable Long id){
levelService.deleteLevel(id);
return "redirect:/level";
}
}

View File

@ -0,0 +1,116 @@
package premium_store.controller.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import premium_store.controller.DTO.LevelDTO;
import premium_store.controller.DTO.SimpleNationDTO;
import premium_store.controller.DTO.SupportTankDTO;
import premium_store.controller.DTO.TankDTO;
import premium_store.service.NationService;
import premium_store.service.TankLevelService;
import premium_store.service.TankService;
import javax.validation.Valid;
import java.util.List;
@Controller
@RequestMapping("/tank")
public class TankMvcController {
private final TankService tankService;
private final NationService nationService;
private final TankLevelService tankLevelService;
public TankMvcController(TankService tankService, NationService nationService, TankLevelService tankLevelService){
this.tankService = tankService;
this.nationService = nationService;
this.tankLevelService = tankLevelService;
}
@GetMapping
public String getTanks(Model model){
model.addAttribute("tanks",
tankService.findAllTanks().stream()
.map(TankDTO::new)
.toList());
List<SimpleNationDTO> nations = nationService.findAllNations().stream()
.map(SimpleNationDTO::new)
.toList();
model.addAttribute("nations", nations);
List<LevelDTO> levels = tankLevelService.findAllLevels().stream()
.map(LevelDTO::new)
.toList();
model.addAttribute("levels", levels);
return "tank";
}
@GetMapping(value = {"/edit", "/edit/{id}"})
public String editTank(@PathVariable(required = false) Long id, Model model){
if(id == null || id <= 0){
model.addAttribute("supportTankDTO", new SupportTankDTO());
}
else {
model.addAttribute("tankId", id);
model.addAttribute("supportTankDTO", new SupportTankDTO(tankService.findTank(id)));
}
List<SimpleNationDTO> nations = nationService.findAllNations().stream()
.map(SimpleNationDTO::new)
.toList();
model.addAttribute("nations", nations);
List<LevelDTO> levels = tankLevelService.findAllLevels().stream()
.map(LevelDTO::new)
.toList();
model.addAttribute("levels", levels);
return "tank-edit";
}
@GetMapping("/filteredList/{nation}?{firstLevel}&{secondLevel}")
public String getFilteredTanks(@RequestParam("nation") String nation,
@RequestParam("firstLevel") int firstLevel,
@RequestParam("secondLevel") int secondLevel,
Model model) {
List<TankDTO> tanks = tankService.findListTank(nation, firstLevel, secondLevel).stream()
.map(TankDTO::new)
.toList();
model.addAttribute("tanks", tanks);
return "filter";
}
@PostMapping(value = {"", "/{id}"})
public String saveTank(@PathVariable(required = false) Long id,
@ModelAttribute @Valid SupportTankDTO tankDTO,
BindingResult bindingResult,
Model model){
if(bindingResult.hasErrors()){
model.addAttribute("errors", bindingResult.getAllErrors());
return "tank-edit";
}
if(id == null || id <= 0){
tankService.addTank(tankDTO);
} else {
tankService.updateTank(tankDTO);
}
return "redirect:/tank";
}
@PostMapping("/delete/{id}")
public String deleteTank(@PathVariable Long id){
tankService.deleteTank(id);
return "redirect:/tank";
}
}

View File

@ -3,9 +3,12 @@ package premium_store.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import premium_store.controller.DTO.ClientDTO;
import premium_store.controller.DTO.SupportClientDTO;
import premium_store.model.GameClient;
import premium_store.model.Tank;
import premium_store.repository.GameClientRepository;
import premium_store.repository.TankRepository;
import premium_store.service.exception.ClientNotFoundException;
import premium_store.util.validation.ValidatorUtil;
@ -15,10 +18,12 @@ import java.util.Optional;
@Service
public class GameClientService {
private final GameClientRepository gameClientRepository;
private final TankRepository tankRepository;
private final ValidatorUtil validatorUtil;
public GameClientService(GameClientRepository gameClientRepository, ValidatorUtil validatorUtil){
public GameClientService(GameClientRepository gameClientRepository, TankRepository tankRepository, ValidatorUtil validatorUtil){
this.gameClientRepository = gameClientRepository;
this.tankRepository = tankRepository;
this.validatorUtil = validatorUtil;
}
@ -69,6 +74,25 @@ public class GameClientService {
return gameClientRepository.save(currentGameClient);
}
@Transactional
public GameClient updateClient(SupportClientDTO clientDTO) {
if (clientDTO.getId() <= 0) {
throw new IllegalArgumentException("Invalid id");
}
final GameClient currentGameClient = findClient(clientDTO.getId());
currentGameClient.setNickName(clientDTO.getNickName());
currentGameClient.setEmail(clientDTO.getEmail());
currentGameClient.setBalance(clientDTO.getBalance());
if(clientDTO.getTankId() != null){
currentGameClient.setTanks(tankRepository.getById(clientDTO.getTankId()));
}
return gameClientRepository.save(currentGameClient);
}
@Transactional
public GameClient deleteClient(Long id) {
final GameClient currentGameClient = findClient(id);

View File

@ -3,9 +3,13 @@ package premium_store.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import premium_store.controller.DTO.SupportTankDTO;
import premium_store.controller.DTO.TankDTO;
import premium_store.model.TankLevel;
import premium_store.model.Nation;
import premium_store.model.Tank;
import premium_store.repository.NationRepository;
import premium_store.repository.TankLevelRepository;
import premium_store.repository.TankRepository;
import premium_store.service.exception.TankNotFoundException;
import premium_store.util.validation.ValidatorUtil;
@ -16,10 +20,14 @@ import java.util.Optional;
@Service
public class TankService {
private final TankRepository tankRepository;
private final NationRepository nationRepository;
private final TankLevelRepository levelRepository;
private final ValidatorUtil validatorUtil;
public TankService(TankRepository tankRepository, ValidatorUtil validatorUtil){
public TankService(TankRepository tankRepository, NationRepository nationRepository, TankLevelRepository levelRepository, ValidatorUtil validatorUtil){
this.tankRepository = tankRepository;
this.nationRepository = nationRepository;
this.levelRepository = levelRepository;
this.validatorUtil = validatorUtil;
}
@ -31,6 +39,15 @@ public class TankService {
return tankRepository.save(tank);
}
@Transactional
public Tank addTank(SupportTankDTO tankDTO) {
final Tank tank = new Tank(tankDTO.getName(), nationRepository.getById(tankDTO.getNationId()),
levelRepository.getById(tankDTO.getLevelId()), tankDTO.getCost());
validatorUtil.validate(tank);
return tankRepository.save(tank);
}
@Transactional(readOnly = true)
public Tank findTank(Long id) {
final Optional<Tank> tank = tankRepository.findById(id);
@ -71,6 +88,22 @@ public class TankService {
return tankRepository.save(currentTank);
}
@Transactional
public Tank updateTank(SupportTankDTO tankDTO) {
if (tankDTO.getId() <= 0) {
throw new IllegalArgumentException("Invalid id");
}
final Tank currentTank = findTank(tankDTO.getId());
currentTank.setName(tankDTO.getName());
currentTank.setNation(nationRepository.getById(tankDTO.getNationId()));
currentTank.setLevel(levelRepository.getById(tankDTO.getLevelId()));
currentTank.setCost(tankDTO.getCost());
return tankRepository.save(currentTank);
}
@Transactional
public Tank deleteTank(Long id) {
final Tank currentTank = findTank(id);

View File

@ -0,0 +1,90 @@
.add-nation-input{
padding-left: 10px;
padding-right: 10px;
border: 3px solid;
border-radius: 10px;
border-color: #505050;
}
.add-level-button{
border-radius: 10px;
border-color: #505050;
background-color: #FFE430;
font-weight: 900;
}
.client-card{
display: flex;
width: 100%;
padding: 15px;
margin-top: 5px;
border: 5px solid;
border-color: #14A76C;
border-radius: 10px;
opacity: 0.9;
background-color: #151719;
justify-content: space-around;
align-items: center;
font-family: Courier, monospace;
font-weight: 900;
}
.client-attribute{
padding: 5px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
align-items: center;
}
.client-button-group{
display: flex;
width: 20%;
justify-content: space-around;
align-items: center;
}
.client-button{
padding: 10px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
}
.myModal{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: none;
background: rgba(0, 0, 0, 0.8);
}
.myModal.active{
display: flex;
justify-content: center;
align-items: center;
}
.myModalContent{
display: inline-block;
padding: 15px;
background: #FF652F;
border-radius: 16px;
min-width: 300px;
min-height: 100px;
justify-content: space-between;
align-items: center;
}
.modalButton{
padding: 5px;
border-radius: 10px;
background-color: #FFE430;
font-family: Courier, monospace;
font-weight: 900;
}

View File

@ -0,0 +1,74 @@
.level-card{
display: flex;
width: 100%;
padding: 15px;
margin-top: 5px;
border: 5px solid;
border-color: #14A76C;
border-radius: 10px;
opacity: 0.9;
background-color: #151719;
justify-content: space-around;
align-items: center;
font-family: Courier, monospace;
font-weight: 900;
}
.level-attribute{
padding: 5px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
align-items: center;
}
.level-button-group{
display: flex;
width: 20%;
justify-content: space-around;
align-items: center;
}
.level-button{
padding: 10px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
}
.myModal{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: none;
background: rgba(0, 0, 0, 0.8);
}
.myModal.active{
display: flex;
justify-content: center;
align-items: center;
}
.myModalContent{
display: flex;
padding: 15px;
background: #FF652F;
border-radius: 16px;
min-width: 300px;
min-height: 100px;
justify-content: space-between;
align-items: center;
}
.modalButton{
padding: 5px;
border-radius: 10px;
background-color: #FFE430;
font-family: Courier, monospace;
font-weight: 900;
}

View File

@ -0,0 +1,81 @@
.add-nation-input{
padding-left: 10px;
padding-right: 10px;
border: 3px solid;
border-radius: 10px;
border-color: #505050;
}
.tank-card{
display: flex;
width: 100%;
padding: 15px;
margin-top: 5px;
border: 5px solid;
border-color: #14A76C;
border-radius: 10px;
opacity: 0.9;
background-color: #151719;
justify-content: space-around;
align-items: center;
font-family: Courier, monospace;
font-weight: 900;
}
.tank-attribute{
padding: 5px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
align-items: center;
}
.tank-button-group{
display: flex;
width: 20%;
justify-content: space-around;
align-items: center;
}
.tank-button{
padding: 10px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
}
.myModal{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: none;
background: rgba(0, 0, 0, 0.8);
}
.myModal.active{
display: flex;
justify-content: center;
align-items: center;
}
.myModalContent{
display: inline-block;
padding: 15px;
background: #FF652F;
border-radius: 16px;
min-width: 300px;
min-height: 100px;
align-items: center;
}
.modalButton{
padding: 5px;
border-radius: 10px;
background-color: #FFE430;
font-family: Courier, monospace;
font-weight: 900;
}

View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<link rel="stylesheet" href="/css/client.css"/>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор клиентов</h1>
</div>
<form action="#" th:action="@{/client/{id}(id=${id})}" th:object="${supportClientDTO}" method="post">
<div class="myModalContent">
<label for="name" class="form-label">Никнейм: </label>
<input
type='text'
class="add-nation-input form-control"
id="name"
th:field="${supportClientDTO.nickName}"
required="true"
/>
<label for="email" class="form-label">Почта: </label>
<input
type='text'
class="add-nation-input form-control"
id="email"
th:field="${supportClientDTO.email}"
required="true"
/>
<label for="balance" class="form-label">Баланс: </label>
<input
type='text'
class="add-nation-input form-control"
id="balance"
th:field="${supportClientDTO.balance}"
required="true"
/>
<label for="name" class="form-label">Танк: </label>
<select id="level" class="form-select" th:field="${supportClientDTO.tankId}" required="true">
<option th:each="value: ${tanks}"
th:value="${value.id}"
th:text="${value.name}">
</option>
</select>
<button
class="modalButton"
type="submit"
>
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Сохранить</span>
</button>
<button
class="modalButton"
type="submit"
th:href="@{/client}"
>
Назад
</button>
</div>
</form>
</div>
</body>
</html>

View File

@ -1,10 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="/css/client.css"/>
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор клиентов</h1>
<a class="add-client-button" type="button"
th:href="@{/client/edit/}">
Создать клиента
</a>
</div>
<div>
<h1 style="text-align: center; font-family: courier, monospace; background: #FF652F; border-radius: 10px">
Список существующих клиентов:
</h1>
</div>
<div th:each="client, iterator: ${clients}">
<div class="client-card">
<p class="client-attribute" th:text="'Номер: ' + ${client.id}"/>
<p class="client-attribute" th:text="'Никнейм: ' + ${client.nickName}"/>
<p class="client-attribute" th:text="'Баланс: ' + ${client.balance}"/>
<div class='client-button-group'>
<form th:action="@{/client/edit/{id}(id=${client.id})}" method="get">
<button class="client-button" type="submit"
th:id="'edit-' + ${client.id}"
>
Редактировать
</button>
</form>
<form th:action="@{/client/delete/{id}(id=${client.id})}" method="post">
<button th:id="'remove-' + ${client.id}" class="client-button" type="submit">
Удалить
</button>
</form>
<form th:action="@{/client/tanksOfClient/{id}(id=${client.id})}" method="get">
<button th:id="'list-tank-' + ${client.id}" class="client-button" type="submit">
Список танков
</button>
</form>
</div>
</div>
</div>
</div>
</body>
<th:block layout:fragment="scripts">
</th:block>
</html>

View File

@ -16,8 +16,8 @@
<div>
<h1 class="Main-label">Мир танков</h1>
</div>
<div>
<form className="collapse navbar-collapse">
<div class="justify-content-around">
<div>
<nav class="navbar navbar-expand-lg justify-content-around">
<button class="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
@ -41,7 +41,7 @@
</ul>
</div>
</nav>
</form>
</div>
</div>
<div class="container-fluid body">
<div class="container container-padding" layout:fragment="content"></div>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<link rel="stylesheet" href="/css/level.css"/>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор уровней</h1>
</div>
<form action="#" th:action="@{/level/{id}(id=${id})}" th:object="${levelDTO}" method="post">
<div class="myModalContent">
<input
type='text'
class="add-level-input form-control"
id="level"
th:field="${levelDTO.level}"
required="true"
/>
<button
class="modalButton"
type="submit"
>
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Сохранить</span>
</button>
<button
class="modalButton"
type="submit"
th:href="@{/level}"
>
Назад
</button>
</div>
</form>
</div>
</body>
</html>

View File

@ -1,10 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="/css/level.css"/>
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор уровней</h1>
<a class="add-level-button" type="button"
th:href="@{/level/edit/}">
Создать уровень
</a>
</div>
<div>
<h1 style="text-align: center; font-family: courier, monospace; background: #FF652F; border-radius: 10px">
Список существующих уровней:
</h1>
</div>
<div th:each="level, iterator: ${levels}">
<div class="level-card">
<p class="level-attribute" th:text="'Нация: ' + ${level.id}"/>
<p class="level-attribute" th:text="'Уровень: ' + ${level.level}"/>
<div class='level-button-group'>
<form th:action="@{/level/edit/{id}(id=${level.id})}" method="get">
<button class="level-button" type="submit"
th:id="'edit-' + ${level.id}"
>
Редактировать
</button>
</form>
<form th:action="@{/level/delete/{id}(id=${level.id})}" method="post">
<button th:id="'remove-' + ${level.id}" class="level-button" type="submit">
Удалить
</button>
</form>
</div>
</div>
</div>
</div>
</body>
<th:block layout:fragment="scripts">
</th:block>
</html>

View File

@ -8,6 +8,9 @@
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор наций</h1>
</div>
<form action="#" th:action="@{/nation/{id}(id=${id})}" th:object="${simpleNationDTO}" method="post">
<div class="myModalContent">
<input

View File

@ -27,8 +27,8 @@
</div>
<div th:each="nation, iterator: ${nations}">
<div class="nation-card">
<p class="nation-attribute" th:text="${nation.id}"/>
<p class="nation-attribute" th:text="${nation.nation}"/>
<p class="nation-attribute" th:text="'Номер: ' + ${nation.id}"/>
<p class="nation-attribute" th:text="'Нация: ' + ${nation.nation}"/>
<div class='nation-button-group'>
<form th:action="@{/nation/edit/{id}(id=${nation.id})}" method="get">
<button class="nation-button" type="submit"
@ -50,7 +50,7 @@
</div>
</div>
</div>
<div class="table-responsive">
<!-- <div class="table-responsive">
<table class="table">
<tbody>
<tr th:each="nation, iterator: ${nations}">
@ -77,7 +77,7 @@
</tr>
</tbody>
</table>
</div>
</div> -->
</div>
</body>
<th:block layout:fragment="scripts">

View File

@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<link rel="stylesheet" href="/css/tank.css"/>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор танков</h1>
</div>
<form action="#" th:action="@{/tank/{id}(id=${id})}" th:object="${supportTankDTO}" method="post">
<div class="myModalContent">
<label for="name" class="form-label">Название: </label>
<input
type='text'
class="add-nation-input form-control"
id="name"
th:field="${supportTankDTO.name}"
required="true"
/>
<label for="name" class="form-label">Нация: </label>
<select id="nation" class="form-select" th:field="${supportTankDTO.nationId}" required="true">
<option th:each="value: ${nations}"
th:value="${value.id}"
th:text="${value.nation}">
</option>
</select>
<label for="name" class="form-label">Уровень: </label>
<select id="level" class="form-select" th:field="${supportTankDTO.levelId}" required="true">
<option th:each="value: ${levels}"
th:value="${value.id}"
th:text="${value.level}">
</option>
</select>
<label for="name" class="form-label">Стоимость: </label>
<input
type='text'
class="add-nation-input form-control"
id="cost"
th:field="${supportTankDTO.cost}"
required="true"
/>
<button
class="modalButton"
type="submit"
>
<span th:if="${id == null}">Добавить</span>
<span th:if="${id != null}">Сохранить</span>
</button>
<button
class="modalButton"
type="submit"
th:href="@{/tank}"
>
Назад
</button>
</div>
</form>
</div>
</body>
</html>

View File

@ -1,10 +1,93 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="/css/tank.css"/>
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div layout:fragment="content">
<div class="Group_create_level">
<h1>Генератор танков</h1>
<a class="add-tank-button" type="button"
th:href="@{/tank/edit/}">
Создать танк
</a>
<!--<a class="add-tank-button" type="button"
id="filterStart"
th:href="@{/tank/filteredList/}">
Фильтрация
</a>-->
<!--<form id="filterForm" th:action="@{/tank/filteredList/{nation}(nation=${document.elements['nation'].value}){firstLevel}(firstLevel=${document.elements['firstLevel'].value}){secondLevel}(secondLevel=${document.elements['secondLevel'].value})}" method="get">
<button class="tank-button" type="submit"
th:id="filterStart"
>
Фильтрация
</button>
<select id="nation" class="form-select" required="true">
<option th:each="value: ${nations}"
th:value="${value.nation}"
th:text="${value.nation}">
</option>
</select>
<select id="firstLevel" class="form-select" required="true">
<option th:each="value: ${levels}"
th:value="${value.level}"
th:text="${value.level}">
</option>
</select>
<select id="secondLevel" class="form-select" required="true">
<option th:each="value: ${levels}"
th:value="${value.level}"
th:text="${value.level}">
</option>
</select>
</form>-->
</div>
<div>
<h1 style="text-align: center; font-family: courier, monospace; background: #FF652F; border-radius: 10px">
Список существующих танков:
</h1>
</div>
<div th:each="tank, iterator: ${tanks}">
<div class="tank-card">
<p class="tank-attribute" th:text="'Номер: ' + ${tank.id}"/>
<p class="tank-attribute" th:text="'Название: ' + ${tank.name}"/>
<p class="tank-attribute" th:text="'Нация: ' + ${tank.nation.getNation()}"/>
<p class="tank-attribute" th:text="'Уровень: ' + ${tank.level.getLevel()}"/>
<p class="tank-attribute" th:text="'Стоимость: ' + ${tank.cost}"/>
<div class='tank-button-group'>
<form th:action="@{/tank/edit/{id}(id=${tank.id})}" method="get">
<button class="tank-button" type="submit"
th:id="'edit-' + ${tank.id}"
>
Редактировать
</button>
</form>
<form th:action="@{/tank/delete/{id}(id=${tank.id})}" method="post">
<button th:id="'remove-' + ${tank.id}" class="tank-button" type="submit">
Удалить
</button>
</form>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function() {
$('#filterStart').on('click', function() {
$.ajax({
url: "http://localhost:8080/api/tank/filteredList/?nation='
+escape(document.forms['filterForm'].elements['nation'].value)&
+escape(document.forms['filterForm'].elements['firstLevel'].value)&
+escape(document.forms['filterForm'].elements['secondLevel'].value)"
}).then(function (data) {
});
});
});
</script>
</html>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<link rel="stylesheet" href="/css/tank.css"/>
</head>
<body>
<div layout:fragment="content">
<form action="#" th:action="@{/client/{id}(id=${id})}" th:object="${clientDTO}" method="get">
<div th:each="tank, iterator: ${clientDTO.tanks}">
<div class="tank-card">
<p class="tank-attribute" th:text="'Номер: ' + ${tank.id}"/>
<p class="tank-attribute" th:text="'Название: ' + ${tank.name}"/>
<p class="tank-attribute" th:text="'Стоимость: ' + ${tank.cost}"/>
<p class="tank-attribute" th:text="'Нация: ' + ${tank.nation.nation}"/>
<p class="tank-attribute" th:text="'Уровень: ' + ${tank.level.level}"/>
</div>
</div>
</form>
</div>
</body>
</html>