Compare commits
4 Commits
8b8d64bd00
...
a64c2772bd
Author | SHA1 | Date | |
---|---|---|---|
a64c2772bd | |||
ec97b15c39 | |||
779ae11861 | |||
bf57c20b96 |
@ -1,10 +1,21 @@
|
|||||||
package ru.ulstu.admin.model;
|
package ru.ulstu.admin.model;
|
||||||
|
|
||||||
|
import ru.ulstu.indicator.model.Course;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class IndicatorForm {
|
public class IndicatorForm {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private int max;
|
||||||
|
|
||||||
|
private String proofDocuments;
|
||||||
|
|
||||||
|
private List<Course> courses = new ArrayList<>();
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -20,4 +31,28 @@ public class IndicatorForm {
|
|||||||
public void setId(Integer id) {
|
public void setId(Integer id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(int max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProofDocuments() {
|
||||||
|
return proofDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProofDocuments(String proofDocuments) {
|
||||||
|
this.proofDocuments = proofDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Course> getCourses() {
|
||||||
|
return courses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourses(List<Course> courses) {
|
||||||
|
this.courses = courses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,13 @@ 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.admin.model.IndicatorForm;
|
import ru.ulstu.admin.model.IndicatorForm;
|
||||||
|
import ru.ulstu.indicator.model.Course;
|
||||||
import ru.ulstu.indicator.model.Indicator;
|
import ru.ulstu.indicator.model.Indicator;
|
||||||
import ru.ulstu.model.UserRoleConstants;
|
import ru.ulstu.model.UserRoleConstants;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/admin")
|
@RequestMapping("/admin")
|
||||||
|
@Secured({UserRoleConstants.ADMIN})
|
||||||
public class AdminController {
|
public class AdminController {
|
||||||
private final AdminService adminService;
|
private final AdminService adminService;
|
||||||
|
|
||||||
@ -29,7 +31,11 @@ public class AdminController {
|
|||||||
@GetMapping("/editIndicator/{indicatorId}")
|
@GetMapping("/editIndicator/{indicatorId}")
|
||||||
@Secured({UserRoleConstants.ADMIN})
|
@Secured({UserRoleConstants.ADMIN})
|
||||||
public String editIndicator(@PathVariable(value = "indicatorId") Integer id, Model model) {
|
public String editIndicator(@PathVariable(value = "indicatorId") Integer id, Model model) {
|
||||||
model.addAttribute("indicator", (id != null && id != 0) ? adminService.getIndicatorById(id) : new Indicator());
|
model.addAttribute("indicator",
|
||||||
|
(id != null && id != 0)
|
||||||
|
? adminService.getIndicatorById(id)
|
||||||
|
: new Indicator());
|
||||||
|
model.addAttribute("courses", Course.values());
|
||||||
return "editIndicator";
|
return "editIndicator";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,12 @@ public class AdminService {
|
|||||||
|
|
||||||
public void saveIndicator(IndicatorForm indicatorForm) {
|
public void saveIndicator(IndicatorForm indicatorForm) {
|
||||||
Indicator indicator = indicatorForm.getId() == null
|
Indicator indicator = indicatorForm.getId() == null
|
||||||
? new Indicator(indicatorForm.getName())
|
? new Indicator(indicatorForm)
|
||||||
: indicatorService.getIndicatorById(indicatorForm.getId());
|
: indicatorService.getIndicatorById(indicatorForm.getId());
|
||||||
indicator.setName(indicatorForm.getName());
|
indicator.setName(indicatorForm.getName());
|
||||||
|
indicator.setMax(indicatorForm.getMax());
|
||||||
|
indicator.setProofDocuments(indicatorForm.getProofDocuments());
|
||||||
|
indicator.setCourses(indicatorForm.getCourses());
|
||||||
indicatorService.save(indicator);
|
indicatorService.save(indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/main/java/ru/ulstu/indicator/model/Course.java
Normal file
18
src/main/java/ru/ulstu/indicator/model/Course.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package ru.ulstu.indicator.model;
|
||||||
|
|
||||||
|
public enum Course {
|
||||||
|
FIRST("первый"),
|
||||||
|
SECOND("второй"),
|
||||||
|
THIRD("третий"),
|
||||||
|
FOURTH("четвертый");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
Course(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,47 @@
|
|||||||
package ru.ulstu.indicator.model;
|
package ru.ulstu.indicator.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CollectionTable;
|
||||||
|
import jakarta.persistence.ElementCollection;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import ru.ulstu.admin.model.IndicatorForm;
|
||||||
import ru.ulstu.model.BaseEntity;
|
import ru.ulstu.model.BaseEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Indicator extends BaseEntity {
|
public class Indicator extends BaseEntity {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Min(0)
|
||||||
|
@Max(30)
|
||||||
|
private int max;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Lob
|
||||||
|
private String proofDocuments;
|
||||||
|
|
||||||
|
@ElementCollection(targetClass = Course.class)
|
||||||
|
@CollectionTable
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private List<Course> courses = new ArrayList<>();
|
||||||
|
|
||||||
public Indicator() {
|
public Indicator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Indicator(String name) {
|
public Indicator(IndicatorForm indicatorForm) {
|
||||||
this.name = name;
|
this.name = indicatorForm.getName();
|
||||||
|
this.max = indicatorForm.getMax();
|
||||||
|
this.proofDocuments = indicatorForm.getProofDocuments();
|
||||||
|
this.courses = indicatorForm.getCourses();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -24,4 +51,28 @@ public class Indicator extends BaseEntity {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(int max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProofDocuments() {
|
||||||
|
return proofDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProofDocuments(String proofDocuments) {
|
||||||
|
this.proofDocuments = proofDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Course> getCourses() {
|
||||||
|
return courses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourses(List<Course> courses) {
|
||||||
|
this.courses = courses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,61 @@
|
|||||||
layout:decorate="~{default}">
|
layout:decorate="~{default}">
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<h3>Редактирование показателя:</h3>
|
<h3>Редактирование показателя:</h3>
|
||||||
<form action="#" th:action="@{/admin/saveIndicator}" th:object="${indicator}" method="post"
|
<form action="#" th:action="@{/admin/saveIndicator}"
|
||||||
|
th:object="${indicator}"
|
||||||
|
method="post"
|
||||||
enctype="multipart/form-data">
|
enctype="multipart/form-data">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
<input type="hidden" th:field="*{version}">
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Название</label>
|
<label for="name">Название</label>
|
||||||
<input type="text" class="form-control" id="name" th:field="*{name}" placeholder="Название показателя">
|
<input th:field="*{name}"
|
||||||
<p th:if="${#fields.hasErrors('name')}" th:class="${#fields.hasErrors('name')}? error">
|
id="name"
|
||||||
Не может быть пустым</p>
|
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 for="name">Максимальная сумма баллов</label>
|
||||||
|
<input th:field="*{max}"
|
||||||
|
required
|
||||||
|
id="max"
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
min="0"
|
||||||
|
max="30">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Описание подтверждающих документов</label>
|
||||||
|
<textarea th:field="*{proofDocuments}"
|
||||||
|
required
|
||||||
|
id="proofDocuments"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Описание подтверждающих документов"
|
||||||
|
style="height: 100px">
|
||||||
|
</textarea>
|
||||||
|
<p th:if="${#fields.hasErrors('proofDocuments')}"
|
||||||
|
th:class="${#fields.hasErrors('proofDocuments')}? error">
|
||||||
|
Не может быть пустым
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="courses">Для каких курсов применяется</label>
|
||||||
|
|
||||||
|
<select class="form-select form-control" id="courses" multiple aria-label="multiple select example"
|
||||||
|
th:field="*{courses}"
|
||||||
|
>
|
||||||
|
<option th:each="c : ${courses}"
|
||||||
|
th:value="${c}"
|
||||||
|
th:text="${c.name}">
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
|
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user