Add indicator courses
This commit is contained in:
parent
ec97b15c39
commit
a64c2772bd
@ -1,5 +1,10 @@
|
||||
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;
|
||||
|
||||
@ -9,6 +14,8 @@ public class IndicatorForm {
|
||||
|
||||
private String proofDocuments;
|
||||
|
||||
private List<Course> courses = new ArrayList<>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -40,4 +47,12 @@ public class IndicatorForm {
|
||||
public void setProofDocuments(String proofDocuments) {
|
||||
this.proofDocuments = proofDocuments;
|
||||
}
|
||||
|
||||
public List<Course> getCourses() {
|
||||
return courses;
|
||||
}
|
||||
|
||||
public void setCourses(List<Course> courses) {
|
||||
this.courses = courses;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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;
|
||||
|
||||
@ -30,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";
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ public class AdminService {
|
||||
indicator.setName(indicatorForm.getName());
|
||||
indicator.setMax(indicatorForm.getMax());
|
||||
indicator.setProofDocuments(indicatorForm.getProofDocuments());
|
||||
indicator.setCourses(indicatorForm.getCourses());
|
||||
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,6 +1,10 @@
|
||||
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;
|
||||
@ -8,6 +12,9 @@ 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 {
|
||||
|
||||
@ -22,6 +29,11 @@ public class Indicator extends BaseEntity {
|
||||
@Lob
|
||||
private String proofDocuments;
|
||||
|
||||
@ElementCollection(targetClass = Course.class)
|
||||
@CollectionTable
|
||||
@Enumerated(EnumType.STRING)
|
||||
private List<Course> courses = new ArrayList<>();
|
||||
|
||||
public Indicator() {
|
||||
}
|
||||
|
||||
@ -29,6 +41,7 @@ public class Indicator extends BaseEntity {
|
||||
this.name = indicatorForm.getName();
|
||||
this.max = indicatorForm.getMax();
|
||||
this.proofDocuments = indicatorForm.getProofDocuments();
|
||||
this.courses = indicatorForm.getCourses();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -54,4 +67,12 @@ public class Indicator extends BaseEntity {
|
||||
public void setProofDocuments(String proofDocuments) {
|
||||
this.proofDocuments = proofDocuments;
|
||||
}
|
||||
|
||||
public List<Course> getCourses() {
|
||||
return courses;
|
||||
}
|
||||
|
||||
public void setCourses(List<Course> courses) {
|
||||
this.courses = courses;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,18 @@
|
||||
Не может быть пустым
|
||||
</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>
|
||||
<button name="delete"
|
||||
|
Loading…
Reference in New Issue
Block a user