Show indicators list
This commit is contained in:
parent
405060152a
commit
5a4a968015
13
src/main/java/ru/ulstu/admin/model/IndicatorForm.java
Normal file
13
src/main/java/ru/ulstu/admin/model/IndicatorForm.java
Normal file
@ -0,0 +1,13 @@
|
||||
package ru.ulstu.admin.model;
|
||||
|
||||
public class IndicatorForm {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
30
src/main/java/ru/ulstu/admin/service/AdminController.java
Normal file
30
src/main/java/ru/ulstu/admin/service/AdminController.java
Normal file
@ -0,0 +1,30 @@
|
||||
package ru.ulstu.admin.service;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import ru.ulstu.admin.model.IndicatorForm;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
private final AdminService adminService;
|
||||
|
||||
public AdminController(AdminService adminService) {
|
||||
this.adminService = adminService;
|
||||
}
|
||||
|
||||
@GetMapping("indicators")
|
||||
public String getListOfIndicators(Model model) {
|
||||
model.addAttribute("indicators", adminService.getIndicators());
|
||||
return "indicatorsList";
|
||||
}
|
||||
|
||||
@PostMapping("addIndicator")
|
||||
public String addIndicator(IndicatorForm indicatorForm, Model model) {
|
||||
adminService.saveIndicator(indicatorForm);
|
||||
return "indicatorsList";
|
||||
}
|
||||
}
|
30
src/main/java/ru/ulstu/admin/service/AdminService.java
Normal file
30
src/main/java/ru/ulstu/admin/service/AdminService.java
Normal file
@ -0,0 +1,30 @@
|
||||
package ru.ulstu.admin.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.admin.model.IndicatorForm;
|
||||
import ru.ulstu.indicator.model.Indicator;
|
||||
import ru.ulstu.indicator.service.IndicatorService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AdminService {
|
||||
private final IndicatorService indicatorService;
|
||||
|
||||
public AdminService(IndicatorService indicatorService) {
|
||||
this.indicatorService = indicatorService;
|
||||
}
|
||||
|
||||
public List<Indicator> getIndicators() {
|
||||
return indicatorService.getIndicatorList();
|
||||
}
|
||||
|
||||
public void saveIndicator(IndicatorForm indicatorForm) {
|
||||
Indicator indicator = indicatorService.findByName(indicatorForm.getName());
|
||||
if (indicator == null) {
|
||||
indicatorService.save(new Indicator(indicatorForm.getName()));
|
||||
} else {
|
||||
// TODO: update other fields
|
||||
}
|
||||
}
|
||||
}
|
24
src/main/java/ru/ulstu/indicator/model/Indicator.java
Normal file
24
src/main/java/ru/ulstu/indicator/model/Indicator.java
Normal file
@ -0,0 +1,24 @@
|
||||
package ru.ulstu.indicator.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import ru.ulstu.model.BaseEntity;
|
||||
|
||||
@Entity
|
||||
public class Indicator extends BaseEntity {
|
||||
private String name;
|
||||
|
||||
public Indicator() {
|
||||
}
|
||||
|
||||
public Indicator(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package ru.ulstu.indicator.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.indicator.model.Indicator;
|
||||
|
||||
public interface IndicatorRepository extends JpaRepository<Indicator, Integer> {
|
||||
Indicator findByName(String name);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ru.ulstu.indicator.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.indicator.model.Indicator;
|
||||
import ru.ulstu.indicator.repository.IndicatorRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class IndicatorService {
|
||||
private final IndicatorRepository indicatorRepository;
|
||||
|
||||
public IndicatorService(IndicatorRepository indicatorRepository) {
|
||||
this.indicatorRepository = indicatorRepository;
|
||||
}
|
||||
|
||||
public List<Indicator> getIndicatorList() {
|
||||
return indicatorRepository.findAll();
|
||||
}
|
||||
|
||||
public void save(Indicator indicator) {
|
||||
indicatorRepository.save(indicator);
|
||||
}
|
||||
|
||||
public Indicator findByName(String name) {
|
||||
return indicatorRepository.findByName(name);
|
||||
}
|
||||
}
|
@ -58,6 +58,9 @@
|
||||
<li class="nav-item dropdown" sec:authorize="hasRole('ROLE_ADMIN')">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
|
||||
aria-haspopup="true" aria-expanded="false">Администратору</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<a class="dropdown-item" href="/admin/indicators">Список показателей</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" href="#" sec:authorize="hasRole('ROLE_ADMIN')">Личный кабинет
|
||||
@ -118,7 +121,7 @@
|
||||
|
||||
</div>
|
||||
<footer>
|
||||
2022
|
||||
2025
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
13
src/main/resources/templates/indicatorsList.html
Normal file
13
src/main/resources/templates/indicatorsList.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!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="/editIndicator/0" class="btn btn-outline-dark">
|
||||
<i class="fa fa-plus-square" aria-hidden="true"> Добавить показатель</i>
|
||||
</a>
|
||||
|
||||
<div th:each="i : ${indicators}">
|
||||
<div th:text="${i.name}"></div>
|
||||
</div>
|
||||
</div>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user