Compare commits
No commits in common. "a64c2772bd7ea2772d9b56f2c18545c890404472" and "8b8d64bd0094bbbe8ef688f4580d029c20beba79" have entirely different histories.
a64c2772bd
...
8b8d64bd00
@ -1,21 +1,10 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@ -31,28 +20,4 @@ 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,13 +8,11 @@ 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;
|
||||||
|
|
||||||
@ -31,11 +29,7 @@ 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",
|
model.addAttribute("indicator", (id != null && id != 0) ? adminService.getIndicatorById(id) : new Indicator());
|
||||||
(id != null && id != 0)
|
|
||||||
? adminService.getIndicatorById(id)
|
|
||||||
: new Indicator());
|
|
||||||
model.addAttribute("courses", Course.values());
|
|
||||||
return "editIndicator";
|
return "editIndicator";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,9 @@ 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)
|
? new Indicator(indicatorForm.getName())
|
||||||
: 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
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,47 +1,20 @@
|
|||||||
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(IndicatorForm indicatorForm) {
|
public Indicator(String name) {
|
||||||
this.name = indicatorForm.getName();
|
this.name = name;
|
||||||
this.max = indicatorForm.getMax();
|
|
||||||
this.proofDocuments = indicatorForm.getProofDocuments();
|
|
||||||
this.courses = indicatorForm.getCourses();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -51,28 +24,4 @@ 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,61 +4,15 @@
|
|||||||
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}"
|
<form action="#" th:action="@{/admin/saveIndicator}" th:object="${indicator}" method="post"
|
||||||
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 th:field="*{name}"
|
<input type="text" class="form-control" id="name" th:field="*{name}" placeholder="Название показателя">
|
||||||
id="name"
|
<p th:if="${#fields.hasErrors('name')}" th:class="${#fields.hasErrors('name')}? error">
|
||||||
type="text"
|
Не может быть пустым</p>
|
||||||
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