WIP: страницы для правил #62
@ -2,7 +2,11 @@ package ru.ulstu.extractor.rule.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import ru.ulstu.extractor.rule.model.AddRuleForm;
|
||||
import ru.ulstu.extractor.rule.repository.RuleRepository;
|
||||
@ -11,7 +15,9 @@ import ru.ulstu.extractor.rule.service.RuleService;
|
||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import static ru.ulstu.extractor.core.Route.*;
|
||||
import static ru.ulstu.extractor.core.Route.ADD_RULE;
|
||||
import static ru.ulstu.extractor.core.Route.DELETE_RULE;
|
||||
import static ru.ulstu.extractor.core.Route.LIST_RULE;
|
||||
|
||||
@Controller
|
||||
@ApiIgnore
|
||||
@ -37,10 +43,15 @@ public class RuleController {
|
||||
}
|
||||
|
||||
@GetMapping(ADD_RULE)
|
||||
public String getAntecedent(Model model) {
|
||||
public String getAntecedent(Model model, @RequestParam(required = false) Integer ruleId) {
|
||||
model.addAttribute("antecedentValues", antecedentValueService.getList());
|
||||
model.addAttribute("antecedents", timeSeriesService.getAllTimeSeriesTypes());
|
||||
model.addAttribute("addRuleForm", new AddRuleForm());
|
||||
model.addAttribute("addRuleForm",
|
||||
ruleId != null
|
||||
? new AddRuleForm(ruleRepository
|
||||
.findById(ruleId)
|
||||
.orElseThrow(() -> new RuntimeException("Правило не найдено")))
|
||||
: new AddRuleForm());
|
||||
return ADD_RULE;
|
||||
}
|
||||
|
||||
@ -51,8 +62,7 @@ public class RuleController {
|
||||
}
|
||||
|
||||
@GetMapping(DELETE_RULE)
|
||||
public String deleteRule(Model model,
|
||||
@RequestParam Integer id) {
|
||||
public String deleteRule(Model model, @RequestParam Integer id) {
|
||||
ruleRepository.deleteById(id);
|
||||
model.addAttribute("rule", ruleRepository.findAll());
|
||||
return "redirect:/" + LIST_RULE;
|
||||
|
@ -10,6 +10,14 @@ public class AddRuleForm {
|
||||
public AddRuleForm() {
|
||||
}
|
||||
|
||||
public AddRuleForm(Rule rule) {
|
||||
this.firstAntecedentId = rule.getFirstAntecedent().name();
|
||||
this.secondAntecedentId = rule.getSecondAntecedent().name();
|
||||
this.firstAntecedentValueId = rule.getFirstAntecedentValue().getId();
|
||||
this.secondAntecedentValueId = rule.getSecondAntecedentValue().getId();
|
||||
this.consequent = rule.getConsequent();
|
||||
}
|
||||
|
||||
public Integer getFirstAntecedentValueId() {
|
||||
return firstAntecedentValueId;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
Если
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<select id="select-antecedent" class="selectpicker" data-live-search="true"
|
||||
<select id="select-antecedent" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{firstAntecedentId}"
|
||||
data-width="90%">
|
||||
<option th:each="antecedent : ${antecedents}"
|
||||
@ -26,7 +26,7 @@
|
||||
имеет тенденцию
|
||||
</div>
|
||||
<div class="col-md-2 col-sm-12">
|
||||
<select id="select-measures" class="selectpicker" data-live-search="true"
|
||||
<select id="select-measures" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{firstAntecedentValueId}"
|
||||
data-width="100%">
|
||||
<option th:each="antecedentValue : ${antecedentValues}"
|
||||
@ -39,7 +39,7 @@
|
||||
и
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<select id="select-second-antecedent" class="selectpicker" data-live-search="true"
|
||||
<select id="select-second-antecedent" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{secondAntecedentId}"
|
||||
data-width="90%">
|
||||
<option th:each="antecedent : ${antecedents}"
|
||||
@ -52,7 +52,7 @@
|
||||
имеет тенденцию
|
||||
</div>
|
||||
<div class="col-md-2 col-sm-12">
|
||||
<select id="select-second-measures" class="selectpicker" data-live-search="true"
|
||||
<select id="select-second-measures" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{secondAntecedentValueId}"
|
||||
data-width="100%">
|
||||
<option th:each="antecedentValue : ${antecedentValues}"
|
||||
@ -65,13 +65,13 @@
|
||||
то:
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<input type="text" class="form-control" th:field="*{consequent}">
|
||||
<input type="text" class="form-control m-1" th:field="*{consequent}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-12"></div>
|
||||
<div class="col-md-4 col-sm-12">
|
||||
<input type="submit" class="btn btn-outline-success" value="Создать правило"/>
|
||||
<input type="submit" class="btn btn-outline-success m-2" value="Создать правило"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -18,8 +18,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2020, 5, 2, 2, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.MONTH, timeSeries);
|
||||
Assert.assertEquals(1, timeSeries.getValues().size());
|
||||
@ -33,8 +33,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2020, 5, 2, 1, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.MONTH, timeSeries);
|
||||
Assert.assertEquals(1, timeSeries.getValues().size());
|
||||
@ -48,8 +48,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2020, 5, 2, 1, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.MONTH, timeSeries);
|
||||
Assert.assertEquals(1, timeSeries.getValues().size());
|
||||
@ -63,8 +63,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2020, 6, 2, 1, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.MONTH, timeSeries);
|
||||
Assert.assertEquals(2, timeSeries.getValues().size());
|
||||
@ -78,8 +78,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2020, 5, 2, 1, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.YEAR, timeSeries);
|
||||
Assert.assertEquals(1, timeSeries.getValues().size());
|
||||
@ -93,8 +93,8 @@ public class TimeSeriesMapperTest {
|
||||
Calendar c2 = GregorianCalendar.getInstance();
|
||||
c2.set(2021, 5, 2, 1, 1, 1);
|
||||
TimeSeries timeSeries = new TimeSeries("Тестовый",
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10),
|
||||
new TimeSeriesValue(c2.getTime(), 10)));
|
||||
Arrays.asList(new TimeSeriesValue(c1.getTime(), 10.0),
|
||||
new TimeSeriesValue(c2.getTime(), 10.0)));
|
||||
TimeSeriesDateMapper mapper = new TimeSeriesDateMapper();
|
||||
timeSeries = mapper.mapTimeSeriesToInterval(TimeSeriesDateMapper.TimeSeriesInterval.YEAR, timeSeries);
|
||||
Assert.assertEquals(2, timeSeries.getValues().size());
|
||||
|
Loading…
Reference in New Issue
Block a user