lab 5 complete
This commit is contained in:
parent
ec634ba472
commit
acb61a9a8e
11
build.gradle
11
build.gradle
@ -14,10 +14,21 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
||||
|
||||
implementation 'org.webjars:bootstrap:5.1.3'
|
||||
implementation 'org.webjars:jquery:3.6.0'
|
||||
implementation 'org.webjars:font-awesome:6.1.0'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
|
||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
72
front/src/components/ReportStudentCategory.jsx
Normal file
72
front/src/components/ReportStudentCategory.jsx
Normal file
@ -0,0 +1,72 @@
|
||||
import DataService from '../services/DataService';
|
||||
import Student from '../models/Student';
|
||||
import Category from '../models/Category';
|
||||
import { useState, useEffect } from 'react';
|
||||
import Form from 'react-bootstrap/Form';
|
||||
import Button from 'react-bootstrap/Button';
|
||||
import DrivingSchool from '../models/DrivingSchool';
|
||||
import { Link} from "react-router-dom";
|
||||
export default function ReportStudentCategory(props) {
|
||||
const headersEmp = [
|
||||
{name: 'surname', label: "Фамилия"},
|
||||
{name: 'name', label: "Имя"},
|
||||
{name: 'categoriesString', label: 'Категории'},
|
||||
{name: 'phoneNumber', label: "Номер телефона"},
|
||||
];
|
||||
|
||||
|
||||
const url = "/student/category?cat=id"
|
||||
const urlCat = '/category';
|
||||
|
||||
const [itemsCat, setItemsCat] = useState([]);
|
||||
|
||||
const [itemsStud, setItemsStud] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
loadItemsCtegories();
|
||||
});
|
||||
|
||||
function loadItemsCtegories() {
|
||||
DataService.readAll(urlCat, (data) => new Category(data))
|
||||
.then(data => setItemsCat(data));
|
||||
}
|
||||
|
||||
function loadItemsStudents(selectedCategory) {
|
||||
DataService.readAll(url.replace("id", selectedCategory), (data) => new Student(data))
|
||||
.then(data => setItemsStud(data));
|
||||
}
|
||||
|
||||
return <div className="container-lg pt-5 min-vh-100">
|
||||
<h1>Отчет</h1>
|
||||
|
||||
<Form.Select onChange={(e) => {loadItemsStudents(e.target.value)}} aria-label="Default select example">
|
||||
<option selected disabled>Выберите категорию</option>
|
||||
{
|
||||
itemsCat.map((e) => <option key={`stud_${e.id}`} value={`${e.id}`}>{`${e.name}`}</option>)
|
||||
}
|
||||
</Form.Select>
|
||||
|
||||
<div >
|
||||
<table className={`table table-hover`}>
|
||||
<thead>
|
||||
<tr>
|
||||
{
|
||||
headersStud.map((header) => <th key={header.name}>{header.label}</th>)
|
||||
}
|
||||
<th key='company'>Автошкола</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
itemsStud.map((item) => <tr key={item.id}>
|
||||
{
|
||||
headersStud.map((header) => <td key={`${header.name}_${item.id}`}>{item[header.name]}</td>)
|
||||
}
|
||||
<td key={`ds_${item.id}`}><Link to={`/drivingSchool/${item['drivingSchool'].id}`}>{item['drivingSchool'].name}</Link></td>
|
||||
</tr>)
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
@ -13,7 +13,7 @@ function toJSON(data) {
|
||||
}
|
||||
|
||||
export default class DataService {
|
||||
static dataUrlPrefix = 'http://localhost:8080';
|
||||
static dataUrlPrefix = 'http://localhost:8080/api';
|
||||
|
||||
static async readAll(url, transformer) {
|
||||
const response = await axios.get(this.dataUrlPrefix + url);
|
||||
|
@ -1,10 +1,13 @@
|
||||
package ru.ulstu.is.cbapp;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
public static final String REST_API = "/api";
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ru.ulstu.is.cbapp.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import ru.ulstu.is.cbapp.WebConfiguration;
|
||||
import ru.ulstu.is.cbapp.dto.CategoryDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -7,7 +9,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/category")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/category")
|
||||
public class CategoryController {
|
||||
private final CategoryService categoryService;
|
||||
|
||||
@ -28,14 +30,14 @@ public class CategoryController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public CategoryDto create(@RequestParam("name") String name) {
|
||||
return new CategoryDto(categoryService.addCategory(name));
|
||||
public CategoryDto create(@RequestBody @Valid CategoryDto categoryDto) {
|
||||
return new CategoryDto(categoryService.addCategory(categoryDto.getName()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public CategoryDto update(@PathVariable Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return new CategoryDto(categoryService.updateCategory(id, name));
|
||||
@RequestBody @Valid CategoryDto categoryDto) {
|
||||
return new CategoryDto(categoryService.updateCategory(id, categoryDto.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -3,6 +3,7 @@ package ru.ulstu.is.cbapp.controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.cbapp.WebConfiguration;
|
||||
import ru.ulstu.is.cbapp.dto.GroupedStudAndCategoryDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryService;
|
||||
import ru.ulstu.is.cbapp.service.CategoryStudentService;
|
||||
@ -10,7 +11,7 @@ import ru.ulstu.is.cbapp.service.CategoryStudentService;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/categoryStudent")
|
||||
@RequestMapping(WebConfiguration.REST_API+"/categoryStudent")
|
||||
public class CategoryStudentController {
|
||||
|
||||
private CategoryStudentService categoryStudentService;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ru.ulstu.is.cbapp.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import ru.ulstu.is.cbapp.WebConfiguration;
|
||||
import ru.ulstu.is.cbapp.dto.DrivingSchoolDto;
|
||||
import ru.ulstu.is.cbapp.dto.StudentDto;
|
||||
import ru.ulstu.is.cbapp.models.Student;
|
||||
@ -10,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/drivingSchool")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/drivingSchool")
|
||||
public class DrivingSchoolController {
|
||||
private final DrivingSchoolService drivingSchoolService;
|
||||
private final StudentService studentService;
|
||||
@ -38,14 +40,14 @@ public class DrivingSchoolController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public DrivingSchoolDto create(@RequestParam("name") String name) {
|
||||
return new DrivingSchoolDto(drivingSchoolService.addDrivingSchool(name));
|
||||
public DrivingSchoolDto create(@RequestBody @Valid DrivingSchoolDto drivingSchoolDto) {
|
||||
return new DrivingSchoolDto(drivingSchoolService.addDrivingSchool(drivingSchoolDto.getName()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public DrivingSchoolDto update(@PathVariable Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return new DrivingSchoolDto(drivingSchoolService.updateDrivingSchool(id, name));
|
||||
@RequestBody @Valid DrivingSchoolDto drivingSchoolDto) {
|
||||
return new DrivingSchoolDto(drivingSchoolService.updateDrivingSchool(id, drivingSchoolDto.getName()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ru.ulstu.is.cbapp.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import ru.ulstu.is.cbapp.WebConfiguration;
|
||||
import ru.ulstu.is.cbapp.dto.StudentDto;
|
||||
import ru.ulstu.is.cbapp.models.Category;
|
||||
import ru.ulstu.is.cbapp.service.StudentService;
|
||||
@ -9,7 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/student")
|
||||
public class StudentController {
|
||||
private final StudentService studentService;
|
||||
private final CategoryService categoryService;
|
||||
@ -32,21 +34,17 @@ public class StudentController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public StudentDto createStudent(@RequestParam("name") String name,
|
||||
@RequestParam("surname") String surname,
|
||||
@RequestParam("phoneNumber") String phoneNumber) {
|
||||
public StudentDto createStudent(@RequestBody @Valid StudentDto studentDto) {
|
||||
return new StudentDto(studentService.addStudent(
|
||||
surname,
|
||||
name,
|
||||
phoneNumber));
|
||||
studentDto.getSurname(),
|
||||
studentDto.getName(),
|
||||
studentDto.getPhoneNumber()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public StudentDto updateStudent(@PathVariable Long id,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("surname") String surname,
|
||||
@RequestParam("phoneNumber") String phoneNumber) {
|
||||
return new StudentDto(studentService.updateStudent(id, surname, name, phoneNumber));
|
||||
@RequestBody @Valid StudentDto studentDto) {
|
||||
return new StudentDto(studentService.updateStudent(id, studentDto.getSurname(), studentDto.getName(), studentDto.getPhoneNumber()));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -3,14 +3,21 @@ package ru.ulstu.is.cbapp.dto;
|
||||
import ru.ulstu.is.cbapp.models.Category;
|
||||
|
||||
public class CategoryDto {
|
||||
private final Long Id;
|
||||
private final String name;
|
||||
private Long Id;
|
||||
private String name;
|
||||
|
||||
public CategoryDto(Category category) {
|
||||
Id = category.getId();
|
||||
this.name = category.getName();
|
||||
}
|
||||
|
||||
public CategoryDto() {
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return Id;
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
package ru.ulstu.is.cbapp.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import ru.ulstu.is.cbapp.models.DrivingSchool;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DrivingSchoolDto {
|
||||
private final Long Id;
|
||||
private final String name;
|
||||
private final List<StudentDto> students;
|
||||
private Long Id;
|
||||
private String name;
|
||||
private List<StudentDto> students;
|
||||
|
||||
public DrivingSchoolDto(DrivingSchool drivingSchool) {
|
||||
Id = drivingSchool.getId();
|
||||
@ -15,6 +16,11 @@ public class DrivingSchoolDto {
|
||||
this.students = drivingSchool.getStudents().stream().map(StudentDto::new).toList();
|
||||
}
|
||||
|
||||
public DrivingSchoolDto() {
|
||||
|
||||
}
|
||||
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
public Long getId() {
|
||||
return Id;
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ import ru.ulstu.is.cbapp.models.Student;
|
||||
import java.util.List;
|
||||
|
||||
public class StudentDto {
|
||||
private final Long Id;
|
||||
private final String name;
|
||||
private final String phoneNumber;
|
||||
private final String surname;
|
||||
private final List<CategoryDto> categories;
|
||||
private Long Id;
|
||||
private String name;
|
||||
private String phoneNumber;
|
||||
private String surname;
|
||||
private List<CategoryDto> categories;
|
||||
|
||||
private final DrivingSchoolWithoutStudDto drivingSchool;
|
||||
private DrivingSchoolWithoutStudDto drivingSchool;
|
||||
|
||||
public StudentDto(Student student) {
|
||||
Id = student.getId();
|
||||
@ -22,10 +22,25 @@ public class StudentDto {
|
||||
this.drivingSchool = student.getDrivingSchool() != null ? new DrivingSchoolWithoutStudDto(student.getDrivingSchool()) : null;
|
||||
}
|
||||
|
||||
public StudentDto() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return Id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package ru.ulstu.is.cbapp.mvc;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.cbapp.dto.CategoryDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/category")
|
||||
public class CategoryMvcController {
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
public CategoryMvcController(CategoryService categoryService) {
|
||||
this.categoryService = categoryService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getCategories(Model model) {
|
||||
model.addAttribute("categories",
|
||||
categoryService.findAllCategories().stream()
|
||||
.map(CategoryDto::new)
|
||||
.toList());
|
||||
return "category";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit/", "/edit/{id}"})
|
||||
public String editCategory(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("categoryDto", new CategoryDto());
|
||||
} else {
|
||||
model.addAttribute("categoryId", id);
|
||||
model.addAttribute("categoryDto", new CategoryDto(categoryService.findCategory(id)));
|
||||
}
|
||||
return "category-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveCategory(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid CategoryDto categoryDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "category-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
categoryService.addCategory(categoryDto.getName());
|
||||
} else {
|
||||
categoryService.updateCategory(id, categoryDto.getName());
|
||||
}
|
||||
return "redirect:/category";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteStudent(@PathVariable Long id) {
|
||||
categoryService.deleteCategory(id);
|
||||
return "redirect:/category";
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package ru.ulstu.is.cbapp.mvc;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import ru.ulstu.is.cbapp.dto.GroupedStudAndCategoryDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryStudentService;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/categoryStudent")
|
||||
public class CategoryStudentMvcController {
|
||||
private final CategoryStudentService categoryStudentService;
|
||||
|
||||
public CategoryStudentMvcController(CategoryStudentService categoryStudentService) {
|
||||
this.categoryStudentService = categoryStudentService;
|
||||
}
|
||||
|
||||
@GetMapping("/groupbycategory")
|
||||
public String getGroupedStudAndCategory(Model model) {
|
||||
List<GroupedStudAndCategoryDto> GroupedStudAndCategoryDtos = categoryStudentService.getGroupedStudAndCategory();
|
||||
model.addAttribute("GroupedStudAndCategoryDtos", GroupedStudAndCategoryDtos);
|
||||
return "groupbycategory";
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package ru.ulstu.is.cbapp.mvc;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.cbapp.dto.CategoryDto;
|
||||
import ru.ulstu.is.cbapp.dto.DrivingSchoolDto;
|
||||
import ru.ulstu.is.cbapp.dto.StudentDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryService;
|
||||
import ru.ulstu.is.cbapp.service.DrivingSchoolService;
|
||||
import ru.ulstu.is.cbapp.service.StudentService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/drivingSchool")
|
||||
public class DrivingSchoolMvcController {
|
||||
private final DrivingSchoolService drivingSchoolService;
|
||||
private final StudentService studentService;
|
||||
private final CategoryService categoryService;
|
||||
|
||||
public DrivingSchoolMvcController(DrivingSchoolService drivingSchoolService, StudentService studentService, CategoryService categoryService) {
|
||||
this.drivingSchoolService = drivingSchoolService;
|
||||
this.studentService = studentService;
|
||||
this.categoryService = categoryService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getDrivingSchools(Model model) {
|
||||
model.addAttribute("drivingSchools",
|
||||
drivingSchoolService.findAllDrivingSchools().stream()
|
||||
.map(DrivingSchoolDto::new)
|
||||
.toList());
|
||||
return "drivingSchool";
|
||||
}
|
||||
|
||||
@GetMapping("/one/{id}")
|
||||
public String getDrivingSchool(@PathVariable(required = false) Long id, Model model) {
|
||||
model.addAttribute("drivingSchool",
|
||||
new DrivingSchoolDto(drivingSchoolService.findDrivingSchool(id)));
|
||||
model.addAttribute("freeStudents", studentService.findAllFreeStudents().stream().map(StudentDto::new).toList());
|
||||
model.addAttribute("categories", categoryService.findAllCategories().stream().map(CategoryDto::new).toList());
|
||||
return "drivingSchool-one";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/redirect")
|
||||
public String redirectToDrivingSchoolPage(@RequestParam("drivingSchoolId") Long drivingSchoolId) {
|
||||
return "redirect:/drivingSchool/one/" + drivingSchoolId;
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editDrivingSchool(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("drivingSchoolDto", new DrivingSchoolDto());
|
||||
} else {
|
||||
model.addAttribute("drivingSchoolId", id);
|
||||
model.addAttribute("drivingSchoolDto", new DrivingSchoolDto(drivingSchoolService.findDrivingSchool(id)));
|
||||
}
|
||||
return "drivingSchool-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveDrivingSchool(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid DrivingSchoolDto drivingSchoolDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "drivingSchool-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
drivingSchoolService.addDrivingSchool(drivingSchoolDto.getName());
|
||||
} else {
|
||||
drivingSchoolService.updateDrivingSchool(id, drivingSchoolDto.getName());
|
||||
}
|
||||
return "redirect:/drivingSchool";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteDrivingSchool(@PathVariable Long id) {
|
||||
drivingSchoolService.deleteDrivingSchool(id);
|
||||
return "redirect:/drivingSchool";
|
||||
}
|
||||
}
|
16
src/main/java/ru/ulstu/is/cbapp/mvc/HomeController.java
Normal file
16
src/main/java/ru/ulstu/is/cbapp/mvc/HomeController.java
Normal file
@ -0,0 +1,16 @@
|
||||
package ru.ulstu.is.cbapp.mvc;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
@ModelAttribute("requestURI")
|
||||
public String requestURI(final HttpServletRequest request) {
|
||||
return request.getRequestURI();
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package ru.ulstu.is.cbapp.mvc;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.cbapp.dto.CategoryDto;
|
||||
import ru.ulstu.is.cbapp.dto.StudentDto;
|
||||
import ru.ulstu.is.cbapp.service.CategoryService;
|
||||
import ru.ulstu.is.cbapp.service.StudentService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/student")
|
||||
public class StudentMvcController {
|
||||
private final StudentService studentService;
|
||||
private final CategoryService categoryService;
|
||||
|
||||
public StudentMvcController(StudentService studentService, CategoryService categoryService) {
|
||||
this.studentService = studentService;
|
||||
this.categoryService = categoryService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getStudents(Model model) {
|
||||
model.addAttribute("students",
|
||||
studentService.findAllStudents().stream()
|
||||
.map(StudentDto::new)
|
||||
.toList());
|
||||
return "student";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit/", "/edit/{id}"})
|
||||
public String editDrivingSchool(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("studentDto", new StudentDto());
|
||||
} else {
|
||||
model.addAttribute("studentId", id);
|
||||
model.addAttribute("studentDto", new StudentDto(studentService.findStudent(id)));
|
||||
}
|
||||
return "student-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveDrivingSchool(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid StudentDto studentDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "student-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
studentService.addStudent(studentDto.getSurname(), studentDto.getName(), studentDto.getPhoneNumber());
|
||||
} else {
|
||||
studentService.updateStudent(id, studentDto.getSurname(), studentDto.getName(), studentDto.getPhoneNumber());
|
||||
}
|
||||
return "redirect:/student";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteStudent(@PathVariable Long id) {
|
||||
studentService.deleteStudent(id);
|
||||
return "redirect:/student";
|
||||
}
|
||||
|
||||
}
|
9
src/main/resources/static/styles/drivingSchool.css
Normal file
9
src/main/resources/static/styles/drivingSchool.css
Normal file
@ -0,0 +1,9 @@
|
||||
.prokrutka {
|
||||
background: #fff; /* цвет фона, белый */
|
||||
border: 1px solid #C1C1C1; /* размер и цвет границы блока */
|
||||
overflow: auto;
|
||||
width:230px;
|
||||
height:100px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
115
src/main/resources/templates/category.html
Normal file
115
src/main/resources/templates/category.html
Normal file
@ -0,0 +1,115 @@
|
||||
<!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>Категории</div>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
onsubmit="openModalEdit()" data-bs-target="#categoryEditModal" data-bs-toggle="modal">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Элементы управления</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="category, iterator: ${categories}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${category.id}"/>
|
||||
<td th:text="${category.name}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-info button-fixed button-sm" th:data-category="${category.id}"
|
||||
data-bs-target="#categoryEditModal" data-bs-toggle="modal"
|
||||
th:onclick="openModalEdit(this.getAttribute('data-category'))">Изменить</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${category.id}').click()|">
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/category/delete/{id}(id=${category.id})}" method="post">
|
||||
<button th:id="'remove-' + ${category.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal" id="categoryEditModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<form id="form-edit-category">
|
||||
<input type="hidden" id="categoryId" name="id"/>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="name" 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" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
<script th:inline="javascript">
|
||||
function openModalEdit(id) {
|
||||
var categories = [[${categories}]];
|
||||
var category = categories.find(x => x.id + '' === id);
|
||||
if (category !== 'undefined') {
|
||||
$('#categoryId').val(id);
|
||||
$('#name').val(category.name);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('submit', '#form-edit-category', function (e) {
|
||||
e.preventDefault();
|
||||
var categoryName = document.getElementById('name');
|
||||
var idInput = document.getElementById('categoryId');
|
||||
var urlCategory = 'http://localhost:8080/api/category';
|
||||
let category = {name: categoryName.value};
|
||||
var method = 'POST';
|
||||
if (idInput.value !== '') {
|
||||
method = 'PUT';
|
||||
urlCategory = urlCategory + '/' + idInput.value;
|
||||
}
|
||||
$.ajax({
|
||||
url: urlCategory,
|
||||
method: method,
|
||||
data: JSON.stringify(category),
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</th:block>
|
||||
</html>
|
46
src/main/resources/templates/default.html
Normal file
46
src/main/resources/templates/default.html
Normal file
@ -0,0 +1,46 @@
|
||||
<!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>Автошколы, студенты и категории</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="icon" href="/favicon.svg">
|
||||
<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"/>
|
||||
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||
<div class="lg justify-content-center container">
|
||||
<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=${requestURI}">
|
||||
<a class="nav-link" href="/drivingSchool"
|
||||
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Главная страница</a>
|
||||
<a class="nav-link" href="/student"
|
||||
th:classappend="${#strings.equals(activeLink, '/student')} ? 'active' : ''">Студенты</a>
|
||||
<a class="nav-link" href="/drivingSchool"
|
||||
th:classappend="${#strings.equals(activeLink, '/drivingSchool')} ? 'active' : ''">Автошколы</a>
|
||||
<a class="nav-link" href="/category"
|
||||
th:classappend="${#strings.equals(activeLink, '/category')} ? 'active' : ''">Категории</a>
|
||||
<a class="nav-link" href="/categoryStudent/groupbycategory"
|
||||
th:classappend="${#strings.equals(activeLink, '/categoryStudent/groupbycategory')} ? 'active' : ''">Количество студентов в категории</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-lg pt-5 min-vh-100">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
255
src/main/resources/templates/drivingSchool-one.html
Normal file
255
src/main/resources/templates/drivingSchool-one.html
Normal file
@ -0,0 +1,255 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<body>
|
||||
<head>
|
||||
<link th:href="@{/styles/drivingSchool.css}" rel="stylesheet" />
|
||||
</head>
|
||||
<div layout:fragment="content">
|
||||
<h1>Название: <span th:text="${drivingSchool.name}"></span></h1>
|
||||
<h2>Количество студентов: <span th:text="${#arrays.length(drivingSchool.students.toArray())}"></span></h2>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
data-bs-target="#hireModal" data-bs-toggle="modal">
|
||||
Зачислить студента
|
||||
</a>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</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="student, iterator: ${drivingSchool.students}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${student.id}"/>
|
||||
<td th:text="${student.surname}" />
|
||||
<td th:text="${student.name}" />
|
||||
<td th:text="${student.phoneNumber}" />
|
||||
<td th:text="${#strings.listJoin(student.categories.![name],',')}"></td>
|
||||
<th style="width: 20%">
|
||||
<a class="btn btn-danger button-fixed button-sm" th:data-student="${student.id}"
|
||||
data-bs-target="#dismissModal" data-bs-toggle="modal"
|
||||
th:onclick="openModalDismiss(this.getAttribute('data-student'))">Отчислить</a>
|
||||
<a class="btn btn-info button-fixed button-sm" th:data-student="${student.id}"
|
||||
data-bs-target="#manageCategoryModal" data-bs-toggle="modal"
|
||||
th:onclick="openModalManageCategory(this.getAttribute('data-student'))">Категории</a>
|
||||
</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Modal -->
|
||||
<div class="modal" id="dismissModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Отчисление</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="form-dismiss">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="studentSelect">Студент</label>
|
||||
<select class="form-select" id="studentSelect" name="studentId" required>
|
||||
<option th:each="student, iterator: ${drivingSchool.students}" th:value="${student.id}"
|
||||
th:text="${student.surname} + ' ' + ${student.name}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-danger" type="submit">Отчислить</button>
|
||||
<a class="btn btn-secondary button-fixed" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal" id="hireModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="hireModalLabel">Зачислить</h5>
|
||||
<button type="button" class="close" data-bs-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="form-hire">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="studentHireSelect">Студент</label>
|
||||
<select class="form-select" id="studentHireSelect" name="studentId" required>
|
||||
<option selected disabled>Выберите студента</option>
|
||||
<option th:each="student, iterator: ${freeStudents}" th:value="${student.id}"
|
||||
th:text="${student.surname} + ' ' + ${student.name}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-info" type="submit">Зачислить</button>
|
||||
<a class="btn btn-secondary button-fixed" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal" id="manageCategoryModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="manageCategoryModalLabel">Назначение категории</h5>
|
||||
<button type="button" class="close" data-bs-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="form-categories">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="studentCatSelect">Студент</label>
|
||||
<select class="form-select" id="studentCatSelect" name="studentId" required>
|
||||
<option value="0" selected disabled>Выберите студента</option>
|
||||
<option th:each="student, iterator: ${drivingSchool.students}" th:value="${student.id}"
|
||||
th:text="${student.surname} + ' ' + ${student.name}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="studentSelect">Категории</label>
|
||||
<div class="prokrutka">
|
||||
<div style="200px;" th:each="category, iterator: ${categories}">
|
||||
<input type="checkbox" th:value="${category.id}"
|
||||
th:text="${category.name}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-info" type="submit">Зачислить</button>
|
||||
<a class="btn btn-secondary button-fixed" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
<script th:inline="javascript">
|
||||
$(document).on('submit', '#form-dismiss', function (e) {
|
||||
e.preventDefault();
|
||||
var drivingSchool = [[${drivingSchool}]];
|
||||
var url = 'http://localhost:8080/api/drivingSchool/id/dismiss?studentId=studId';
|
||||
url = url.replace("id", drivingSchool.id).replace("studId", $("#studentSelect").val())
|
||||
alert(url);
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'PUT',
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
});
|
||||
$(document).on('submit', '#form-hire', function (e) {
|
||||
e.preventDefault();
|
||||
var drivingSchool = [[${drivingSchool}]];
|
||||
var url = 'http://localhost:8080/api/drivingSchool/id/hire?studentId=studId';
|
||||
url = url.replace("id", drivingSchool.id).replace("studId", $("#studentHireSelect").val())
|
||||
alert(url);
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'PUT',
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
});
|
||||
$(document).on('submit', '#form-categories', function (e) {
|
||||
e.preventDefault();
|
||||
var drivingSchool = [[${drivingSchool}]];
|
||||
var studentId = $("#studentCatSelect").val();
|
||||
var student = drivingSchool.students.find(x => x.id + '' === studentId);
|
||||
var categories = student.categories.map(x => x.id + '');
|
||||
var urlAdd = 'http://localhost:8080/api/student/id/addCat?category=catId';
|
||||
var urlDel = 'http://localhost:8080/api/student/id/delCat?category=catId';
|
||||
$('input[type=checkbox]').each(function(){
|
||||
if(categories.indexOf($(this).val()) !== -1 && $(this).is(":checked") === false){
|
||||
$.ajax({
|
||||
url: urlDel.replace("id", student.id).replace("catId", $(this).val()),
|
||||
method: 'PUT',
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
|
||||
} else if (categories.indexOf($(this).val()) == -1 && $(this).is(":checked")){
|
||||
$.ajax({
|
||||
url: urlAdd.replace("id", student.id).replace("catId", $(this).val()),
|
||||
method: 'PUT',
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#studentCatSelect').change(function(){
|
||||
var selectedStudent = $(this).val();
|
||||
var drivingSchool = [[${drivingSchool}]];
|
||||
var student = drivingSchool.students.find(x => x.id + '' === selectedStudent);
|
||||
var categories = student.categories.map(x => x.id + '');
|
||||
$('input[type=checkbox]').prop('checked', false);
|
||||
$('input[type=checkbox]').each(function(){
|
||||
if(categories.indexOf($(this).val()) !== -1){
|
||||
$(this).prop('checked', true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function openModalDismiss(id) {
|
||||
$('#studentSelect').val(id);
|
||||
$( "#studentSelect" ).prop( "disabled", true );
|
||||
}
|
||||
function openModalManageCategory(id) {
|
||||
$('#studentCatSelect').val(id);
|
||||
$( "#studentCatSelect" ).prop( "disabled", true );
|
||||
var drivingSchool = [[${drivingSchool}]];
|
||||
var student = drivingSchool.students.find(x => x.id + '' === id);
|
||||
var categories = student.categories.map(x => x.id + '');
|
||||
$('input[type=checkbox]').prop('checked', false);
|
||||
$('input[type=checkbox]').each(function(){
|
||||
if(categories.indexOf($(this).val()) !== -1){
|
||||
$(this).prop('checked', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</th:block>
|
||||
</html>
|
148
src/main/resources/templates/drivingSchool.html
Normal file
148
src/main/resources/templates/drivingSchool.html
Normal file
@ -0,0 +1,148 @@
|
||||
<!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>Автошколы</div>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
onsubmit="openModalEdit()" data-bs-target="#drivingSchoolEditModal" data-bs-toggle="modal">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
<!-- <a class="btn btn-info button-fixed" data-bs-toggle="modal" data-bs-target="#drivingSchoolModal">-->
|
||||
<!-- Перейти к компании-->
|
||||
<!-- </a>-->
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Студенты</th>
|
||||
<th scope="col">Элементы управления</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="drivingSchool, iterator: ${drivingSchools}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${drivingSchool.id}"/>
|
||||
<td style="width: 60%"><a th:href="@{/drivingSchool/one/{id}(id=${drivingSchool.id})}" th:text="${drivingSchool.name}"></a></td>
|
||||
<td th:text="${#arrays.length(drivingSchool.students.toArray())}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-info button-fixed button-sm" th:data-drivingSchool="${drivingSchool.id}"
|
||||
data-bs-target="#drivingSchoolEditModal" data-bs-toggle="modal"
|
||||
th:onclick="openModalEdit(this.getAttribute('data-drivingSchool'))">Изменить</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${drivingSchool.id}').click()|">
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/drivingSchool/delete/{id}(id=${drivingSchool.id})}" method="post">
|
||||
<button th:id="'remove-' + ${drivingSchool.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Modal -->
|
||||
<div class="modal" id="drivingSchoolModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Выбор автошколы</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="/drivingSchool/redirect" method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="drivingSchoolSelect">Автошкола</label>
|
||||
<select class="form-select" id="drivingSchoolSelect" name="drivingSchoolId" required>
|
||||
<option selected disabled>Выберите автошколу</option>
|
||||
<option th:each="drivingSchool, iterator: ${drivingSchools}" th:value="${drivingSchool.id}" th:text="${drivingSchool.name}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" type="submit">Перейти</button>
|
||||
<a class="btn btn-secondary button-fixed" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal" id="drivingSchoolEditModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<form id="form-edit-drivingSchool">
|
||||
<input type="hidden" id="drivingSchoolId" name="id"/>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="name" 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" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
<script th:inline="javascript">
|
||||
function openModalEdit(id) {
|
||||
var drivingSchools = [[${drivingSchools}]];
|
||||
var drivingSchool = drivingSchools.find(x => x.id + '' === id);
|
||||
if (drivingSchool !== 'undefined') {
|
||||
$('#drivingSchoolId').val(id);
|
||||
$('#name').val(drivingSchool.name);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('submit', '#form-edit-drivingSchool', function (e) {
|
||||
e.preventDefault();
|
||||
var drivingSchoolName = document.getElementById('name');
|
||||
var idInput = document.getElementById('drivingSchoolId');
|
||||
var urlDrivingSchool = 'http://localhost:8080/api/drivingSchool';
|
||||
let drivingSchool = {name: drivingSchoolName.value};
|
||||
var method = 'POST';
|
||||
if (idInput.value !== '') {
|
||||
method = 'PUT';
|
||||
urlDrivingSchool = urlDrivingSchool + '/' + idInput.value;
|
||||
}
|
||||
$.ajax({
|
||||
url: urlDrivingSchool,
|
||||
method: method,
|
||||
data: JSON.stringify(drivingSchool),
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</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>
|
27
src/main/resources/templates/groupbycategory.html
Normal file
27
src/main/resources/templates/groupbycategory.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">
|
||||
<h1>Отчет (количество студентов в категории)</h1>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название категории</th>
|
||||
<th scope="col">Количество студентов</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="GroupedStudAndCategoryDto : ${GroupedStudAndCategoryDtos}">
|
||||
<td th:text="${GroupedStudAndCategoryDto.categoryName}"></td>
|
||||
<td th:text="${GroupedStudAndCategoryDto.studentsCount}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
13
src/main/resources/templates/index.html
Normal file
13
src/main/resources/templates/index.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>Вроде работает</div>
|
||||
<a href="123">Ошибка :(</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
133
src/main/resources/templates/student.html
Normal file
133
src/main/resources/templates/student.html
Normal file
@ -0,0 +1,133 @@
|
||||
<!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>Студенты</div>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
onsubmit="openModalEdit()" data-bs-target="#studentEditModal" data-bs-toggle="modal">
|
||||
<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">ID</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="student, iterator: ${students}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${student.id}"/>
|
||||
<td th:text="${student.surname}" />
|
||||
<td th:text="${student.name}" />
|
||||
<td th:text="${student.phoneNumber}" />
|
||||
<td th:text="${#strings.listJoin(student.categories.![name],',')}"></td>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-info button-fixed button-sm" th:data-student="${student.id}"
|
||||
data-bs-target="#studentEditModal" data-bs-toggle="modal"
|
||||
th:onclick="openModalEdit(this.getAttribute('data-student'))">
|
||||
Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${student.id}').click()|">
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/student/delete/{id}(id=${student.id})}" method="post">
|
||||
<button th:id="'remove-' + ${student.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal" id="studentEditModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<form id="form-edit-student">
|
||||
<input type="hidden" id="studentId" name="id"/>
|
||||
<div class="mb-3">
|
||||
<label for="surname" class="form-label">Фамилия</label>
|
||||
<input type="text" class="form-control" id="surname" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Имя</label>
|
||||
<input type="text" class="form-control" id="name" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phoneNumber" class="form-label">Номер телефона</label>
|
||||
<input type="text" class="form-control" id="phoneNumber" 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" data-bs-dismiss="modal">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
<script th:inline="javascript">
|
||||
function openModalEdit(id) {
|
||||
var students = [[${students}]];
|
||||
var student = students.find(x => x.id + '' === id);
|
||||
if (student !== 'undefined') {
|
||||
$('#studentId').val(id);
|
||||
$('#surname').val(student.surname);
|
||||
$('#name').val(student.name);
|
||||
$('#phoneNumber').val(student.phoneNumber);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('submit', '#form-edit-student', function (e) {
|
||||
e.preventDefault();
|
||||
var idInput = document.getElementById('studentId');
|
||||
var urlStudent = 'http://localhost:8080/api/student';
|
||||
let student = {surname: $('#surname').val(),
|
||||
name: $('#name').val(),
|
||||
phoneNumber: $('#phoneNumber').val()};
|
||||
var method = 'POST';
|
||||
if (idInput.value !== '') {
|
||||
method = 'PUT';
|
||||
urlStudent = urlStudent + '/' + idInput.value;
|
||||
}
|
||||
$.ajax({
|
||||
url: urlStudent,
|
||||
method: method,
|
||||
data: JSON.stringify(student),
|
||||
contentType: "application/json;"
|
||||
})
|
||||
.done(function() {
|
||||
location.reload();
|
||||
})
|
||||
.fail((err) => {
|
||||
alert(err);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</th:block>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user