#91 -- Add markup page menu item #94
@ -5,6 +5,7 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import ru.ulstu.extractor.branch.service.BranchService;
|
||||||
import ru.ulstu.extractor.core.Route;
|
import ru.ulstu.extractor.core.Route;
|
||||||
import ru.ulstu.extractor.markup.model.MarkupForm;
|
import ru.ulstu.extractor.markup.model.MarkupForm;
|
||||||
import ru.ulstu.extractor.markup.model.MarkupRow;
|
import ru.ulstu.extractor.markup.model.MarkupRow;
|
||||||
@ -20,24 +21,50 @@ import java.util.stream.Collectors;
|
|||||||
@ApiIgnore
|
@ApiIgnore
|
||||||
public class TimeSeriesMarkupController {
|
public class TimeSeriesMarkupController {
|
||||||
private final TimeSeriesService timeSeriesService;
|
private final TimeSeriesService timeSeriesService;
|
||||||
|
private final BranchService branchService;
|
||||||
private final MarkupService markupService;
|
private final MarkupService markupService;
|
||||||
|
|
||||||
public TimeSeriesMarkupController(TimeSeriesService timeSeriesService,
|
public TimeSeriesMarkupController(TimeSeriesService timeSeriesService,
|
||||||
|
BranchService branchService,
|
||||||
MarkupService markupService) {
|
MarkupService markupService) {
|
||||||
this.timeSeriesService = timeSeriesService;
|
this.timeSeriesService = timeSeriesService;
|
||||||
|
this.branchService = branchService;
|
||||||
this.markupService = markupService;
|
this.markupService = markupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("time-series-markup")
|
@GetMapping("time-series-markup")
|
||||||
public String markupTs(Model model) {
|
public String markupTs(Model model) {
|
||||||
List<TimeSeries> tss = timeSeriesService.getAllTimeSeries();
|
model.addAttribute("branches", branchService.findAll());
|
||||||
model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())));
|
model.addAttribute("markupForm", new MarkupForm());
|
||||||
|
return "markup";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("time-series-markup")
|
||||||
|
public String filter(Model model, @ModelAttribute MarkupForm markupForm) {
|
||||||
|
model.addAttribute("branches", branchService.findAll());
|
||||||
|
if (markupForm != null && markupForm.getBranchId() != null) {
|
||||||
|
List<TimeSeries> tss = timeSeriesService.getByBranch(markupForm.getBranchId());
|
||||||
|
MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()));
|
||||||
|
markupFormWithTs.setBranchId(markupForm.getBranchId());
|
||||||
|
model.addAttribute("markupForm", markupFormWithTs);
|
||||||
|
} else {
|
||||||
|
model.addAttribute("markupForm", new MarkupForm());
|
||||||
|
}
|
||||||
return "markup";
|
return "markup";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(Route.ADD_MARKUP)
|
@PostMapping(Route.ADD_MARKUP)
|
||||||
public String addMarkups(@ModelAttribute MarkupForm markupForm) {
|
public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) {
|
||||||
markupService.saveMarkup(markupForm);
|
model.addAttribute("branches", branchService.findAll());
|
||||||
|
if (markupForm.getBranchId() != null) {
|
||||||
|
List<TimeSeries> tss = timeSeriesService.getByBranch(markupForm.getBranchId());
|
||||||
|
MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()));
|
||||||
|
markupFormWithTs.setBranchId(markupForm.getBranchId());
|
||||||
|
model.addAttribute("markupForm", markupFormWithTs);
|
||||||
|
if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) {
|
||||||
|
markupService.saveMarkup(markupForm);
|
||||||
|
}
|
||||||
|
}
|
||||||
return "markup";
|
return "markup";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ public class Markup extends BaseEntity {
|
|||||||
public Markup() {
|
public Markup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Markup(MarkupRow markupRow) {
|
public Markup(TimeSeries timeSeries, String markup) {
|
||||||
this.timeSeries = markupRow.getTimeSeries();
|
this.timeSeries = timeSeries;
|
||||||
this.markup = markupRow.getMarkup();
|
this.markup = markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries getTimeSeries() {
|
public TimeSeries getTimeSeries() {
|
||||||
|
@ -5,6 +5,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MarkupForm {
|
public class MarkupForm {
|
||||||
private List<MarkupRow> markupRows = new ArrayList<>();
|
private List<MarkupRow> markupRows = new ArrayList<>();
|
||||||
|
private Integer branchId;
|
||||||
|
private boolean save;
|
||||||
|
private boolean filter;
|
||||||
|
|
||||||
public MarkupForm() {
|
public MarkupForm() {
|
||||||
}
|
}
|
||||||
@ -20,4 +23,28 @@ public class MarkupForm {
|
|||||||
public void setMarkupRows(List<MarkupRow> markupRows) {
|
public void setMarkupRows(List<MarkupRow> markupRows) {
|
||||||
this.markupRows = markupRows;
|
this.markupRows = markupRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getBranchId() {
|
||||||
|
return branchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBranchId(Integer branchId) {
|
||||||
|
this.branchId = branchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSave() {
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSave(boolean save) {
|
||||||
|
this.save = save;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFilter() {
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilter(boolean filter) {
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
package ru.ulstu.extractor.markup.service;
|
package ru.ulstu.extractor.markup.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.extractor.markup.model.Markup;
|
import ru.ulstu.extractor.markup.model.Markup;
|
||||||
import ru.ulstu.extractor.markup.model.MarkupForm;
|
import ru.ulstu.extractor.markup.model.MarkupForm;
|
||||||
import ru.ulstu.extractor.markup.repository.MarkupRepository;
|
import ru.ulstu.extractor.markup.repository.MarkupRepository;
|
||||||
|
import ru.ulstu.extractor.ts.model.TimeSeries;
|
||||||
|
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MarkupService {
|
public class MarkupService {
|
||||||
private final MarkupRepository markupRepository;
|
private final MarkupRepository markupRepository;
|
||||||
|
private final TimeSeriesService timeSeriesService;
|
||||||
|
|
||||||
public MarkupService(MarkupRepository markupRepository) {
|
public MarkupService(MarkupRepository markupRepository,
|
||||||
|
TimeSeriesService timeSeriesService) {
|
||||||
this.markupRepository = markupRepository;
|
this.markupRepository = markupRepository;
|
||||||
|
this.timeSeriesService = timeSeriesService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void saveMarkup(MarkupForm markupForm) {
|
public void saveMarkup(MarkupForm markupForm) {
|
||||||
markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow)));
|
markupForm.getMarkupRows().forEach(markupRow -> {
|
||||||
|
TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId());
|
||||||
|
markupRepository.save(new Markup(timeSeries, markupRow.getMarkup()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,31 @@
|
|||||||
</head>
|
</head>
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<form action="#" th:action="${@route.ADD_MARKUP}" method="post" th:object="${markupForm}">
|
<form action="#" th:action="${@route.ADD_MARKUP}" method="post" th:object="${markupForm}">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2 col-sm-12">
|
||||||
|
Репозиторий-ветка
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<select id="select-branch" class="selectpicker" data-live-search="true" th:field="*{branchId}"
|
||||||
|
data-width="90%">
|
||||||
|
<option value="">Все ветки</option>
|
||||||
|
<option th:each="branch : ${branches}"
|
||||||
|
th:value="${branch.id}"
|
||||||
|
th:utext="${branch.gitRepository.url} + ' - '+ ${branch.name}">
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
$('#select-branch').val([[ * {branchId}]
|
||||||
|
])
|
||||||
|
;
|
||||||
|
$('#select-branch').selectpicker('refresh');
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 col-sm-12">
|
||||||
|
<input type="submit" class="btn btn-outline-success w-100" th:formaction="@{/time-series-markup}"
|
||||||
|
value="Применить"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user