11-projects #12
@ -4,10 +4,11 @@ import io.swagger.v3.oas.annotations.Hidden;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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.service.ProjectService;
|
||||
import ru.ulstu.fc.user.model.UserRoleConstants;
|
||||
@ -26,18 +27,29 @@ public class ProjectController {
|
||||
@GetMapping("list")
|
||||
public String getProjects(Model model) {
|
||||
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) {
|
||||
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) {
|
||||
projectService.delete(projectForm);
|
||||
return "redirect:/list";
|
||||
if (projectForm != null && projectForm.getId() != null) {
|
||||
projectService.delete(projectForm);
|
||||
}
|
||||
return "redirect:/project/list";
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,20 @@
|
||||
package ru.ulstu.fc.project.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ProjectForm {
|
||||
private Integer id;
|
||||
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() {
|
||||
return id;
|
||||
@ -19,4 +31,8 @@ public class ProjectForm {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,7 @@
|
||||
<body>
|
||||
<nav layout:fragment="navbar">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="/"><span class="ui-menuitem-text"><i
|
||||
class="fa fa-plane fa-4" aria-hidden="true"></i> Balance</span></a>
|
||||
<a class="navbar-brand" href="/"><span class="ui-menuitem-text">Нечеткий контроллер</span></a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container" layout:fragment="content">
|
||||
|
39
src/main/resources/templates/project/edit.html
Normal file
39
src/main/resources/templates/project/edit.html
Normal 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>
|
22
src/main/resources/templates/project/list.html
Normal file
22
src/main/resources/templates/project/list.html
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user