11-projects #12

Merged
romanov73 merged 16 commits from 11-projects into master 2025-02-15 14:12:43 +04:00
5 changed files with 97 additions and 9 deletions
Showing only changes of commit 7cc6e88c35 - Show all commits

View File

@ -4,10 +4,11 @@ import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.fc.project.model.Project;
import ru.ulstu.fc.project.model.ProjectForm; import ru.ulstu.fc.project.model.ProjectForm;
import ru.ulstu.fc.project.service.ProjectService; import ru.ulstu.fc.project.service.ProjectService;
import ru.ulstu.fc.user.model.UserRoleConstants; import ru.ulstu.fc.user.model.UserRoleConstants;
@ -26,18 +27,29 @@ public class ProjectController {
@GetMapping("list") @GetMapping("list")
public String getProjects(Model model) { public String getProjects(Model model) {
model.addAttribute("projects", projectService.getCurrentUserProjects()); model.addAttribute("projects", projectService.getCurrentUserProjects());
return "listProjects"; return "project/list";
} }
@PostMapping("save") @GetMapping("/edit/{projectId}")
public String edit(@PathVariable(value = "projectId") Integer id, Model model) {
model.addAttribute("project",
new ProjectForm((id != null && id != 0)
? projectService.getById(id)
: new Project()));
return "project/edit";
}
@PostMapping(value = "save", params = "save")
public String save(ProjectForm projectForm, Model model) { public String save(ProjectForm projectForm, Model model) {
model.addAttribute("project", projectService.save(projectForm)); model.addAttribute("project", projectService.save(projectForm));
return "redirect:/list"; return "redirect:/project/list";
} }
@DeleteMapping("delete") @PostMapping(value = "save", params = "delete")
public String delete(ProjectForm projectForm) { public String delete(ProjectForm projectForm) {
if (projectForm != null && projectForm.getId() != null) {
projectService.delete(projectForm); projectService.delete(projectForm);
return "redirect:/list"; }
return "redirect:/project/list";
} }
} }

View File

@ -1,8 +1,20 @@
package ru.ulstu.fc.project.model; package ru.ulstu.fc.project.model;
import java.util.Date;
public class ProjectForm { public class ProjectForm {
private Integer id; private Integer id;
private String name; private String name;
private Date createDate;
public ProjectForm() {
}
public ProjectForm(Project project) {
this.id = project.getId();
this.name = project.getName();
this.createDate = project.getCreateDate();
}
public Integer getId() { public Integer getId() {
return id; return id;
@ -19,4 +31,8 @@ public class ProjectForm {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public Date getCreateDate() {
return createDate;
}
} }

View File

@ -8,8 +8,7 @@
<body> <body>
<nav layout:fragment="navbar"> <nav layout:fragment="navbar">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="/"><span class="ui-menuitem-text"><i <a class="navbar-brand" href="/"><span class="ui-menuitem-text">Нечеткий контроллер</span></a>
class="fa fa-plane fa-4" aria-hidden="true"></i> Balance</span></a>
</div> </div>
</nav> </nav>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">

View File

@ -0,0 +1,39 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Редактирование проекта</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<h3>Редактирование проекта:</h3>
<form th:action="@{/project/save}" th:object="${project}" method="post">
<input type="hidden" th:field="*{id}">
<div class="form-group">
<label for="name">Название</label>
<input th:field="*{name}"
id="name"
type="text"
required
class="form-control"
placeholder="Название">
<p th:if="${#fields.hasErrors('name')}"
th:class="${#fields.hasErrors('name')}? error">
Не может быть пустым
</p>
</div>
<div class="form-group">
<label th:text="'Дата создания: ' + ${#dates.format(project.createDate, 'dd.MM.yyyy HH:mm')}"></label>
</div>
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
<button name="delete"
type="submit"
class="btn btn-outline-dark"
onclick="return confirm('Удалить запись?')">
Удалить
</button>
<a href="/project/list" class="btn btn-outline-dark">Отмена</a>
</form>
</div>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Список правил</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<a href="/project/edit/0" class="btn btn-outline-dark">
<i class="fa fa-plus-square" aria-hidden="true">Добавить проект</i>
</a>
<ul>
<li th:each="p : ${projects}">
<a th:href="@{'/project/edit/' + ${p.id}}">
<span th:text="${p.name} + ' от ' + ${#dates.format(p.createDate, 'dd.MM.yyyy HH:mm')}"></span>
</a>
</li>
</ul>
</div>
</html>