some done
This commit is contained in:
parent
e007f51d04
commit
5e26c1aa1e
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.0.2'
|
||||
id 'org.springframework.boot' version '2.6.3'
|
||||
id 'io.spring.dependency-management' version '1.1.0'
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ dependencies {
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
|
||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.kalyshev.yan.cabinet.controller;
|
||||
import com.kalyshev.yan.WebConfiguration;
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.controller.ComputerDto;
|
||||
import jakarta.validation.Valid;
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -0,0 +1,79 @@
|
||||
package com.kalyshev.yan.cabinet.controller;
|
||||
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.kalyshev.yan.computer.controller.ComputerDto;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/index")
|
||||
public class CabinetMvcController {
|
||||
private final CabinetService cabinetService;
|
||||
private final ComputerService computerService;
|
||||
public CabinetMvcController(CabinetService cabinetService,
|
||||
ComputerService computerService) {
|
||||
this.cabinetService = cabinetService;
|
||||
this.computerService = computerService;
|
||||
}
|
||||
@GetMapping
|
||||
public String getCabinets(Model model) {
|
||||
model.addAttribute("cabinets",
|
||||
cabinetService.findAllCabinets().stream()
|
||||
.map(CabinetDto::new)
|
||||
.toList());
|
||||
return "index";
|
||||
}
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editCabinet(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("cabinetDto", new CabinetDto());
|
||||
} else {
|
||||
model.addAttribute("cabinetId", id);
|
||||
model.addAttribute("cabinetDto", new CabinetDto(cabinetService.findCabinet(id)));
|
||||
}
|
||||
model.addAttribute("computers",
|
||||
computerService.findFilteredComputers(null, null, null, null, id).stream()
|
||||
.map(ComputerDto::new)
|
||||
.toList());
|
||||
return "cabinet-edit";
|
||||
}
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
public String saveCabinet(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid CabinetDto cabinetDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "cabinet-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
cabinetService.addCabinet(cabinetDto.getNumber());
|
||||
} else {
|
||||
cabinetService.updateCabinet(id, cabinetDto.getNumber());
|
||||
}
|
||||
return "redirect:/index";
|
||||
}
|
||||
@PostMapping(value = "/{id}/computer/{computerId}")
|
||||
public String addCabinetComputer(@PathVariable(value = "id") Long id,
|
||||
@PathVariable(value = "computerId") Long computerId) {
|
||||
cabinetService.addComputerToCabinet(computerId, id);
|
||||
return "redirect:/index";
|
||||
}
|
||||
@PostMapping(value = "/{id}/computerDelete/{computerId}")
|
||||
public String deleteCabinetComputer(@PathVariable(value = "id") Long id,
|
||||
@PathVariable(value = "computerId") Long computerId) {
|
||||
cabinetService.deleteComputerFromCabinet(computerId, id);
|
||||
return "redirect:/index";
|
||||
}
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteCabinet(@PathVariable Long id) {
|
||||
cabinetService.deleteCabinet(id);
|
||||
return "redirect:/index";
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.kalyshev.yan.cabinet.model;
|
||||
|
||||
import com.kalyshev.yan.computer.model.Computer;
|
||||
import jakarta.persistence.*;
|
||||
import javax.persistence.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -100,5 +100,6 @@ public class CabinetService {
|
||||
final Computer computer = computerService.findComputer(computerId);
|
||||
final Cabinet cabinet = findCabinet(cabinetId);
|
||||
cabinet.removeComputer(computer);
|
||||
computer.setCabinet(null);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package com.kalyshev.yan.computer.controller;
|
||||
import com.kalyshev.yan.WebConfiguration;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.controller.MonitorDto;
|
||||
import jakarta.validation.Valid;
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,7 +7,9 @@ public class ComputerDto {
|
||||
private String modelName;
|
||||
private String serialNum;
|
||||
private Long monitorId;
|
||||
private String monitorModelName;
|
||||
private Long cabinetId;
|
||||
private String cabinetNumber;
|
||||
public ComputerDto() {}
|
||||
public ComputerDto(Computer computer) {
|
||||
this.id = computer.getId();
|
||||
@ -15,13 +17,17 @@ public class ComputerDto {
|
||||
this.serialNum = computer.getSerialNum();
|
||||
if (computer.getMonitor() == null) {
|
||||
this.monitorId = null;
|
||||
this.monitorModelName = "";
|
||||
} else {
|
||||
this.monitorId = computer.getMonitor().getId();
|
||||
this.monitorModelName = computer.getMonitor().getModelName();
|
||||
}
|
||||
if (computer.getCabinet() == null) {
|
||||
this.cabinetId = null;
|
||||
this.cabinetNumber = "";
|
||||
} else {
|
||||
this.cabinetId = computer.getCabinet().getId();
|
||||
this.cabinetNumber = computer.getCabinet().getNumber();
|
||||
}
|
||||
}
|
||||
public Long getId() { return this.id; }
|
||||
@ -33,4 +39,6 @@ public class ComputerDto {
|
||||
public void setMonitorId(Long monitorId) { this.monitorId = monitorId; }
|
||||
public Long getCabinetId() { return this.cabinetId; }
|
||||
public void setCabinetId(Long cabinetId) { this.cabinetId = cabinetId; }
|
||||
public String getMonitorModelName() { return this.monitorModelName; }
|
||||
public String getCabinetNumber() { return this.cabinetNumber; }
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
package com.kalyshev.yan.computer.controller;
|
||||
|
||||
import com.kalyshev.yan.cabinet.controller.CabinetDto;
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/computers")
|
||||
public class ComputerMvcController {
|
||||
private final ComputerService computerService;
|
||||
private final MonitorService monitorService;
|
||||
public ComputerMvcController(ComputerService computerService,
|
||||
MonitorService monitorService) {
|
||||
this.computerService = computerService;
|
||||
this.monitorService = monitorService;
|
||||
}
|
||||
@GetMapping
|
||||
public String getComputers(Model model) {
|
||||
model.addAttribute("computers",
|
||||
computerService.findAllComputers().stream()
|
||||
.map(ComputerDto::new)
|
||||
.toList());
|
||||
return "computers";
|
||||
}
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editComputer(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("computerDto", new ComputerDto());
|
||||
} else {
|
||||
model.addAttribute("computerId", id);
|
||||
model.addAttribute("computerDto", new ComputerDto(computerService.findComputer(id)));
|
||||
}
|
||||
model.addAttribute("monitors",
|
||||
monitorService.findAllMonitors());
|
||||
return "computer-edit";
|
||||
}
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
public String saveComputer(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid ComputerDto computerDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "computer-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
computerService.addComputer(computerDto.getModelName(), computerDto.getSerialNum(), computerDto.getMonitorId());
|
||||
} else {
|
||||
computerService.updateComputer(id, computerDto.getModelName(), computerDto.getSerialNum(), computerDto.getMonitorId(), computerDto.getCabinetId());
|
||||
}
|
||||
return "redirect:/computers";
|
||||
}
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteComputer(@PathVariable Long id) {
|
||||
computerService.deleteComputer(id);
|
||||
return "redirect:/computers";
|
||||
}
|
||||
}
|
@ -2,8 +2,8 @@ package com.kalyshev.yan.computer.model;
|
||||
|
||||
import com.kalyshev.yan.cabinet.model.Cabinet;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
|
@ -7,7 +7,7 @@ import com.kalyshev.yan.computer.repository.ComputerRepository;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import com.kalyshev.yan.util.validation.ValidatorUtil;
|
||||
import jakarta.annotation.Nullable;
|
||||
import javax.validation.constraints.Null;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -27,7 +27,7 @@ public class ComputerService {
|
||||
this.validatorUtil = validatorUtil;
|
||||
}
|
||||
@Transactional
|
||||
public Computer addComputer(String modelName, String serialNum, @Nullable Long monitorId) {
|
||||
public Computer addComputer(String modelName, String serialNum, @Null Long monitorId) {
|
||||
if (!StringUtils.hasText(modelName)) {
|
||||
throw new IllegalArgumentException("Computer model name is null or empty");
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.kalyshev.yan.monitor.controller;
|
||||
import com.kalyshev.yan.WebConfiguration;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import jakarta.validation.Valid;
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -0,0 +1,62 @@
|
||||
package com.kalyshev.yan.monitor.controller;
|
||||
|
||||
import com.kalyshev.yan.cabinet.controller.CabinetDto;
|
||||
import com.kalyshev.yan.cabinet.service.CabinetService;
|
||||
import com.kalyshev.yan.computer.service.ComputerService;
|
||||
import com.kalyshev.yan.monitor.model.Monitor;
|
||||
import com.kalyshev.yan.monitor.service.MonitorService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/monitors")
|
||||
public class MonitorMvcController {
|
||||
private final MonitorService monitorService;
|
||||
public MonitorMvcController(MonitorService monitorService) {
|
||||
this.monitorService = monitorService;
|
||||
}
|
||||
@GetMapping
|
||||
public String getMonitors(Model model) {
|
||||
model.addAttribute("monitors",
|
||||
monitorService.findAllMonitors().stream()
|
||||
.map(MonitorDto::new)
|
||||
.toList());
|
||||
return "monitors";
|
||||
}
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editMonitor(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("monitorDto", new MonitorDto());
|
||||
} else {
|
||||
model.addAttribute("monitorId", id);
|
||||
model.addAttribute("monitorDto", new MonitorDto(monitorService.findMonitor(id)));
|
||||
}
|
||||
return "monitor-edit";
|
||||
}
|
||||
@PostMapping(value = {"", "/{id}"})
|
||||
public String saveComputer(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid MonitorDto monitorDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "monitor-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
monitorService.addMonitor(monitorDto.getModelName());
|
||||
} else {
|
||||
monitorService.updateMonitor(id, monitorDto.getModelName());
|
||||
}
|
||||
return "redirect:/monitors";
|
||||
}
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteComputer(@PathVariable Long id) {
|
||||
monitorService.deleteMonitor(monitorService.findMonitor(id));
|
||||
return "redirect:/monitors";
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.kalyshev.yan.monitor.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.kalyshev.yan.util.validation;
|
||||
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.Validator;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
|
15
src/main/resources/public/css/style.css
Normal file
15
src/main/resources/public/css/style.css
Normal file
@ -0,0 +1,15 @@
|
||||
.container-padding {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.margin-bottom {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.button-fixed {
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.button-sm {
|
||||
padding: 1px;
|
||||
}
|
71
src/main/resources/templates/cabinet-edit.html
Normal file
71
src/main/resources/templates/cabinet-edit.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/index/{id}(id=${id})}" th:object="${cabinetDto}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="number" class="form-label">Номер кабинета</label>
|
||||
<input type="text" class="form-control" id="number" th:field="${cabinetDto.number}" required="true">
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Серийный номер</th>
|
||||
<th scope="col">Монитор</th>
|
||||
<th scope="col">Кабинет</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="computer, iterator: ${computers}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${computer.modelName}" style="width: 60%"/>
|
||||
<td th:text="${computer.serialNum}" style="width: 60%"/>
|
||||
<td th:text="${computer.monitorModelName}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить?') && document.getElementById('remove-${computer.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/index/{id}/computerDelete/{computerId}(id=${id}, computerId=${computer.id})}" method="post">
|
||||
<button th:id="'remove-' + ${computer.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/index}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
<form th:action="@{/index/{id}/computer(id=${id})}" id="addComputerForm" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="computers" class="form-label">Добавить компьютер</label>
|
||||
<select class="form-select" id="computers" required>
|
||||
<option disabled value="">Выберите компьютер</option>
|
||||
<option th:each="computer, iterator: ${computers}" th:text="${computer.modelName}" th:value="${computer.id}">
|
||||
</select>
|
||||
<button class="btn btn-outline-secondary" id="addComputerButton" th:attr="onclick=|document.getElementById('addComputerForm').action = document.getElementById('addComputerForm').action + '/' + document.getElementById('computers').value ; document.getElementById('addComputerForm}').submit()|">Добавить</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
38
src/main/resources/templates/computer-edit.html
Normal file
38
src/main/resources/templates/computer-edit.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/computers/{id}(id=${id})}" th:object="${computerDto}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="modelName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="modelName" th:field="${computerDto.modelName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="serialNum" class="form-label">Серийный номер</label>
|
||||
<input type="text" class="form-control" id="serialNum" th:field="${computerDto.serialNum}" required="true">
|
||||
</div>
|
||||
<label for="monitor" class="form-label">Монитор</label>
|
||||
<select class="form-select" id="monitor" th:field="${computerDto.monitorId}">
|
||||
<option value="">Выберите монитор</option>
|
||||
<option th:each="monitor, iterator: ${monitors}" th:text="${monitor.modelName}" th:value="${monitor.id}"
|
||||
th:selected="${monitor.id==computerDto.monitorId}">
|
||||
</option>
|
||||
</select>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/computers}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
57
src/main/resources/templates/computers.html
Normal file
57
src/main/resources/templates/computers.html
Normal file
@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/computers/edit/}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Серийный номер</th>
|
||||
<th scope="col">Монитор</th>
|
||||
<th scope="col">Кабинет</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="computer, iterator: ${computers}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${computer.modelName}" style="width: 60%"/>
|
||||
<td th:text="${computer.serialNum}" style="width: 60%"/>
|
||||
<td th:text="${computer.monitorModelName}" style="width: 60%"/>
|
||||
<td th:text="${computer.cabinetNumber}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/computers/edit/{id}(id=${computer.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${computer.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/computers/delete/{id}(id=${computer.id})}" method="post">
|
||||
<button th:id="'remove-' + ${computer.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
44
src/main/resources/templates/default.html
Normal file
44
src/main/resources/templates/default.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>MVC App</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<i class="fa-solid fa-font-awesome"></i>
|
||||
Рабочее место оператора пункта выдачи заказов
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav" th:with="activeLink=${#request.requestURI}">
|
||||
<a class="nav-link" href="/index"
|
||||
th:classappend="${#strings.equals(activeLink, '/index')} ? 'active' : ''">Кабинеты</a>
|
||||
<a class="nav-link" href="/computers"
|
||||
th:classappend="${#strings.equals(activeLink, '/computers')} ? 'active' : ''">Компьютеры</a>
|
||||
<a class="nav-link" href="/monitors"
|
||||
th:classappend="${#strings.equals(activeLink, '/monitors')} ? 'active' : ''">Мониторы</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
13
src/main/resources/templates/error.html
Normal file
13
src/main/resources/templates/error.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div><span th:text="${error}"></span></div>
|
||||
<a href="/">На главную</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
51
src/main/resources/templates/index.html
Normal file
51
src/main/resources/templates/index.html
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/index/edit/}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Номер кабинета</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="cabinet, iterator: ${cabinets}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${cabinet.number}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/index/edit/{id}(id=${cabinet.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${cabinet.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/index/delete/{id}(id=${cabinet.id})}" method="post">
|
||||
<button th:id="'remove-' + ${cabinet.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
src/main/resources/templates/monitor-edit.html
Normal file
27
src/main/resources/templates/monitor-edit.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/monitors/{id}(id=${id})}" th:object="${monitorDto}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="modelName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="modelName" th:field="${monitorDto.modelName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/monitors}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
51
src/main/resources/templates/monitors.html
Normal file
51
src/main/resources/templates/monitors.html
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/monitors/edit/}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="monitor, iterator: ${monitors}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${monitor.modelName}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/monitors/edit/{id}(id=${monitor.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${monitor.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/monitors/delete/{id}(id=${monitor.id})}" method="post">
|
||||
<button th:id="'remove-' + ${monitor.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user