#21 -- Add save report period
This commit is contained in:
parent
a8912f8d8c
commit
07fcbce47b
@ -0,0 +1,47 @@
|
|||||||
|
package ru.ulstu.report.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
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.report.model.ReportPeriod;
|
||||||
|
import ru.ulstu.report.service.ReportPeriodService;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("admin")
|
||||||
|
public class ReportPeriodController {
|
||||||
|
private final ReportPeriodService reportPeriodService;
|
||||||
|
|
||||||
|
public ReportPeriodController(ReportPeriodService reportPeriodService) {
|
||||||
|
this.reportPeriodService = reportPeriodService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("reportPeriodList")
|
||||||
|
public String getReportPeriods(Model model) {
|
||||||
|
model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods());
|
||||||
|
return "admin/reportPeriodList";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("editReportPeriod/{reportPeriodId}")
|
||||||
|
public String getReportPeriods(@PathVariable(value = "reportPeriodId") Integer reportPeriodId, Model model) {
|
||||||
|
model.addAttribute("reportPeriod",
|
||||||
|
reportPeriodId == 0
|
||||||
|
? new ReportPeriod()
|
||||||
|
: reportPeriodService.getById(reportPeriodId));
|
||||||
|
return "admin/editReportPeriod";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "saveReportPeriod", params = "save")
|
||||||
|
public String saveReportPeriods(ReportPeriod reportPeriod) {
|
||||||
|
reportPeriodService.save(reportPeriod);
|
||||||
|
return "redirect: admin/reportPeriodList";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "saveReportPeriod", params = "delete")
|
||||||
|
public String delete(ReportPeriod reportPeriod) {
|
||||||
|
reportPeriodService.save(reportPeriod);
|
||||||
|
return "redirect: admin/reportPeriodList";
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package ru.ulstu.report.model;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Temporal;
|
import jakarta.persistence.Temporal;
|
||||||
import jakarta.persistence.TemporalType;
|
import jakarta.persistence.TemporalType;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.model.BaseEntity;
|
import ru.ulstu.model.BaseEntity;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -10,9 +11,11 @@ import java.util.Date;
|
|||||||
@Entity
|
@Entity
|
||||||
public class ReportPeriod extends BaseEntity {
|
public class ReportPeriod extends BaseEntity {
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date startDate;
|
private Date startDate;
|
||||||
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate;
|
private Date endDate;
|
||||||
|
|
||||||
public Date getStartDate() {
|
public Date getStartDate() {
|
||||||
|
@ -3,5 +3,8 @@ package ru.ulstu.report.repository;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.ulstu.report.model.ReportPeriod;
|
import ru.ulstu.report.model.ReportPeriod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ReportPeriodRepository extends JpaRepository<ReportPeriod, Integer> {
|
public interface ReportPeriodRepository extends JpaRepository<ReportPeriod, Integer> {
|
||||||
|
List<ReportPeriod> findAllByOrderByStartDateDesc();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package ru.ulstu.report.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.report.model.ReportPeriod;
|
||||||
|
import ru.ulstu.report.repository.ReportPeriodRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ReportPeriodService {
|
||||||
|
private final ReportPeriodRepository reportPeriodRepository;
|
||||||
|
|
||||||
|
public ReportPeriodService(ReportPeriodRepository reportPeriodRepository) {
|
||||||
|
this.reportPeriodRepository = reportPeriodRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReportPeriod> getReportPeriods() {
|
||||||
|
return reportPeriodRepository.findAllByOrderByStartDateDesc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportPeriod save(ReportPeriod reportPeriod) {
|
||||||
|
ReportPeriod dbReportPeriod;
|
||||||
|
if (reportPeriod.getId() != null) {
|
||||||
|
dbReportPeriod = getById(reportPeriod.getId());
|
||||||
|
dbReportPeriod.setStartDate(reportPeriod.getStartDate());
|
||||||
|
dbReportPeriod.setEndDate(reportPeriod.getEndDate());
|
||||||
|
} else {
|
||||||
|
dbReportPeriod = reportPeriod;
|
||||||
|
}
|
||||||
|
return reportPeriodRepository.save(dbReportPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(ReportPeriod reportPeriod) {
|
||||||
|
reportPeriodRepository.delete(reportPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportPeriod getById(Integer reportPeriodId) {
|
||||||
|
return reportPeriodRepository
|
||||||
|
.findById(reportPeriodId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Report period not found by id"));
|
||||||
|
}
|
||||||
|
}
|
49
src/main/resources/templates/admin/editReportPeriod.html
Normal file
49
src/main/resources/templates/admin/editReportPeriod.html
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<!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}">
|
||||||
|
<div class="container" layout:fragment="content">
|
||||||
|
<h3>Редактирование отчетного периода:</h3>
|
||||||
|
<form action="#" th:action="@{/admin/saveReportPeriod}"
|
||||||
|
th:object="${reportPeriod}"
|
||||||
|
method="post">
|
||||||
|
<input type="hidden" th:field="*{id}">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="startDate">Дата начала</label>
|
||||||
|
<input th:field="*{startDate}"
|
||||||
|
id="startDate"
|
||||||
|
type="date"
|
||||||
|
required
|
||||||
|
class="form-control">
|
||||||
|
<p th:if="${#fields.hasErrors('startDate')}"
|
||||||
|
th:class="${#fields.hasErrors('startDate')}? error">
|
||||||
|
Ошибка
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="endDate">Дата окончания</label>
|
||||||
|
<input th:field="*{endDate}"
|
||||||
|
id="endDate"
|
||||||
|
type="date"
|
||||||
|
required
|
||||||
|
class="form-control">
|
||||||
|
<p th:if="${#fields.hasErrors('endDate')}"
|
||||||
|
th:class="${#fields.hasErrors('endDate')}? error">
|
||||||
|
Ошибка
|
||||||
|
</p>
|
||||||
|
</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="/admin/reportPeriodList" class="btn btn-outline-dark">Отмена</a>
|
||||||
|
</form>
|
||||||
|
<link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css"/>
|
||||||
|
<link rel="stylesheet" href="/webjars/bootstrap-glyphicons/bdd2cbfba0/css/bootstrap-glyphicons.css"/>
|
||||||
|
</div>
|
||||||
|
</html>
|
31
src/main/resources/templates/admin/reportPeriodList.html
Normal file
31
src/main/resources/templates/admin/reportPeriodList.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!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}">
|
||||||
|
<div class="container" layout:fragment="content">
|
||||||
|
<a href="/admin/editReportPeriod/0" class="btn btn-outline-dark">
|
||||||
|
<i class="fa fa-plus-square" aria-hidden="true"> Добавить отчетный период</i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Таблица периодов отчетности -->
|
||||||
|
<table class="table table-bordered table-striped mt-3">
|
||||||
|
<thead class="table-dark">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Дата начала</th>
|
||||||
|
<th scope="col">Дата окончания</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="r : ${reportPeriods}">
|
||||||
|
<td th:text="${r.startDate}"></td>
|
||||||
|
<td th:text="${r.endDate}"></td>
|
||||||
|
<td>
|
||||||
|
<!-- Ссылка на редактирование -->
|
||||||
|
<a th:href="@{'/admin/editReportPeriod/' + ${r.id}}" class="btn btn-sm btn-primary">
|
||||||
|
<i class="fa fa-edit" aria-hidden="true"></i> Редактировать
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</html>
|
@ -63,11 +63,12 @@
|
|||||||
<a class="dropdown-item" href="/admin/indicators">Список показателей</a>
|
<a class="dropdown-item" href="/admin/indicators">Список показателей</a>
|
||||||
<a class="dropdown-item" href="/admin/managers">Список научных руководителей</a>
|
<a class="dropdown-item" href="/admin/managers">Список научных руководителей</a>
|
||||||
<a class="dropdown-item" href="/admin/aspirants">Список аспирантов</a>
|
<a class="dropdown-item" href="/admin/aspirants">Список аспирантов</a>
|
||||||
<a class="dropdown-item" href="/admin">Новости и заседания</a>
|
<a class="dropdown-item" href="/admin/reportPeriodList">Список периодов отчетности</a>
|
||||||
<a class="dropdown-item" href="/admin/reports">Отчетность аспирантов</a>
|
<a class="dropdown-item" href="/admin/reports">Отчетность аспирантов</a>
|
||||||
<a class="dropdown-item" href="/admin/rules">Правила БРС</a>
|
<a class="dropdown-item" href="/admin/rules">Правила БРС</a>
|
||||||
<a class="dropdown-item" href="/admin/confirmation">Подтверждение БРС</a>
|
<a class="dropdown-item" href="/admin/confirmation">Подтверждение БРС</a>
|
||||||
<a class="dropdown-item" href="/admin/stats">Статистика по баллам</a>
|
<a class="dropdown-item" href="/admin/stats">Статистика по баллам</a>
|
||||||
|
<a class="dropdown-item" href="/admin">Новости и заседания</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user