WIP: страницы для правил #62

Closed
Ghost wants to merge 132 commits from master into 61-rules-pages
4 changed files with 47 additions and 11 deletions
Showing only changes of commit 616bb3385e - Show all commits

View File

@ -18,6 +18,7 @@ public class Route {
public static final String STATISTIC = "statistic";
public static final String LIST_RULE = "listRules";
public static final String ADD_RULE = "addRule";
public static final String DELETE_RULE = "deleteRule";
public static String getLIST_INDEXED_REPOSITORIES() {
return LIST_INDEXED_REPOSITORIES;

View File

@ -2,19 +2,16 @@ package ru.ulstu.extractor.rule.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import ru.ulstu.extractor.rule.model.AddRuleForm;
import ru.ulstu.extractor.rule.repository.RuleRepository;
import ru.ulstu.extractor.rule.service.AntecedentValueService;
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.ADD_RULE;
import static ru.ulstu.extractor.core.Route.LIST_RULE;
import static ru.ulstu.extractor.core.Route.*;
@Controller
@ApiIgnore
@ -22,13 +19,15 @@ public class RuleController {
private final RuleService ruleService;
private final AntecedentValueService antecedentValueService;
private final TimeSeriesService timeSeriesService;
private final RuleRepository ruleRepository;
public RuleController(RuleService ruleService,
AntecedentValueService antecedentValueService,
TimeSeriesService timeSeriesService) {
TimeSeriesService timeSeriesService, RuleRepository ruleRepository) {
this.ruleService = ruleService;
this.antecedentValueService = antecedentValueService;
this.timeSeriesService = timeSeriesService;
this.ruleRepository = ruleRepository;
}
@GetMapping(LIST_RULE)
@ -50,4 +49,27 @@ public class RuleController {
ruleService.saveRule(ruleForm);
return "redirect:/" + LIST_RULE;
}
@GetMapping(DELETE_RULE)
public String deleteRule(Model model,
@RequestParam Integer id) {
ruleRepository.deleteById(id);
model.addAttribute("rule", ruleRepository.findAll());
return "redirect:/" + LIST_RULE;
}
// @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET)
// public String editRule(Model model,
// @RequestParam Optional<Integer> firstAntecedentValueId,
// @RequestParam Optional<String > firstAntecedentId,
// @RequestParam Optional<Integer> secondAntecedentValueId,
// @RequestParam Optional<String> secondAntecedentId,
// @RequestParam Optional<String> consequent){
// AddRuleForm addRuleForm = new AddRuleForm();
// addRuleForm.setFirstAntecedentId(firstAntecedentValueId.);
// addRuleForm.setFirstAntecedentValueId();
// addRuleForm.setSecondAntecedentId();
// addRuleForm.setSecondAntecedentValueId();
// addRuleForm.setConsequent();
// }
}

View File

@ -34,4 +34,8 @@ public class RuleService {
TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()),
addRuleForm.getConsequent()));
}
public Rule findById(Integer id) {
return ruleRepository.getOne(id);
}
}

View File

@ -10,7 +10,7 @@
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col" colspan="8">Правила</th>
<th scope="col" colspan="10">Правила</th>
</tr>
</thead>
<tbody>
@ -23,11 +23,20 @@
<td><span class="badge badge-success" th:text="${rule.secondAntecedentValue.antecedentValue}"></span></td>
<td><span class="badge badge-info">то</span></td>
<td><span class="badge badge-warning" th:text="${rule.consequent}"></span></td>
<td>
<a role="button" class="btn btn-info" th:href="@{${@route.ADD_RULE} + '?ruleId=' + ${rule.id}}">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</a>
</td>
<td>
<a role="button" class="btn btn-danger" th:href="@{'deleteRule?id=' + ${rule.id}}"
onclick="return confirm('Удалить правило?')">
<i class="fa fa-times" aria-hidden="true"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div class="col-md-4 col-sm-12">
<a href="/addRule" class="btn btn-outline-success">Добавить правило</a>
</div>
<a href="/addRule" class="btn btn-outline-success">Добавить правило</a>
</div>
</html>