Compare commits

...

4 Commits

Author SHA1 Message Date
a64c2772bd Add indicator courses 2025-01-29 12:54:07 +04:00
ec97b15c39 Add controller permissions 2025-01-29 10:35:08 +04:00
779ae11861 Add indicator proof docs description 2025-01-29 10:31:57 +04:00
bf57c20b96 Add indicator max value 2025-01-29 10:21:00 +04:00
6 changed files with 168 additions and 9 deletions

View File

@ -1,10 +1,21 @@
package ru.ulstu.admin.model;
import ru.ulstu.indicator.model.Course;
import java.util.ArrayList;
import java.util.List;
public class IndicatorForm {
private Integer id;
private String name;
private int max;
private String proofDocuments;
private List<Course> courses = new ArrayList<>();
public String getName() {
return name;
}
@ -20,4 +31,28 @@ public class IndicatorForm {
public void setId(Integer 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;
}
}

View File

@ -8,11 +8,13 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.admin.model.IndicatorForm;
import ru.ulstu.indicator.model.Course;
import ru.ulstu.indicator.model.Indicator;
import ru.ulstu.model.UserRoleConstants;
@Controller
@RequestMapping("/admin")
@Secured({UserRoleConstants.ADMIN})
public class AdminController {
private final AdminService adminService;
@ -29,7 +31,11 @@ public class AdminController {
@GetMapping("/editIndicator/{indicatorId}")
@Secured({UserRoleConstants.ADMIN})
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";
}

View File

@ -21,9 +21,12 @@ public class AdminService {
public void saveIndicator(IndicatorForm indicatorForm) {
Indicator indicator = indicatorForm.getId() == null
? new Indicator(indicatorForm.getName())
? new Indicator(indicatorForm)
: indicatorService.getIndicatorById(indicatorForm.getId());
indicator.setName(indicatorForm.getName());
indicator.setMax(indicatorForm.getMax());
indicator.setProofDocuments(indicatorForm.getProofDocuments());
indicator.setCourses(indicatorForm.getCourses());
indicatorService.save(indicator);
}

View 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;
}
}

View File

@ -1,20 +1,47 @@
package ru.ulstu.indicator.model;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
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 ru.ulstu.admin.model.IndicatorForm;
import ru.ulstu.model.BaseEntity;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Indicator extends BaseEntity {
@NotBlank
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(String name) {
this.name = name;
public Indicator(IndicatorForm indicatorForm) {
this.name = indicatorForm.getName();
this.max = indicatorForm.getMax();
this.proofDocuments = indicatorForm.getProofDocuments();
this.courses = indicatorForm.getCourses();
}
public String getName() {
@ -24,4 +51,28 @@ public class Indicator extends BaseEntity {
public void setName(String 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;
}
}

View File

@ -4,15 +4,61 @@
layout:decorate="~{default}">
<div class="container" layout:fragment="content">
<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">
<input type="hidden" th:field="*{id}">
<input type="hidden" th:field="*{version}">
<div class="form-group">
<label for="name">Название</label>
<input type="text" class="form-control" id="name" th:field="*{name}" placeholder="Название показателя">
<p th:if="${#fields.hasErrors('name')}" th:class="${#fields.hasErrors('name')}? error">
Не может быть пустым</p>
<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 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>
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>