76-edit-and-delete-rule #77
@ -18,6 +18,7 @@ public class Route {
|
|||||||
public static final String STATISTIC = "statistic";
|
public static final String STATISTIC = "statistic";
|
||||||
public static final String LIST_RULE = "listRules";
|
public static final String LIST_RULE = "listRules";
|
||||||
public static final String ADD_RULE = "addRule";
|
public static final String ADD_RULE = "addRule";
|
||||||
|
public static final String DELETE_RULE = "deleteRule";
|
||||||
|
|
||||||
public static String getLIST_INDEXED_REPOSITORIES() {
|
public static String getLIST_INDEXED_REPOSITORIES() {
|
||||||
return LIST_INDEXED_REPOSITORIES;
|
return LIST_INDEXED_REPOSITORIES;
|
||||||
|
@ -2,19 +2,16 @@ package ru.ulstu.extractor.rule.controller;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
import ru.ulstu.extractor.rule.model.AddRuleForm;
|
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.AntecedentValueService;
|
||||||
import ru.ulstu.extractor.rule.service.RuleService;
|
import ru.ulstu.extractor.rule.service.RuleService;
|
||||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import static ru.ulstu.extractor.core.Route.ADD_RULE;
|
import static ru.ulstu.extractor.core.Route.*;
|
||||||
import static ru.ulstu.extractor.core.Route.LIST_RULE;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ApiIgnore
|
@ApiIgnore
|
||||||
@ -22,13 +19,15 @@ public class RuleController {
|
|||||||
private final RuleService ruleService;
|
private final RuleService ruleService;
|
||||||
private final AntecedentValueService antecedentValueService;
|
private final AntecedentValueService antecedentValueService;
|
||||||
private final TimeSeriesService timeSeriesService;
|
private final TimeSeriesService timeSeriesService;
|
||||||
|
private final RuleRepository ruleRepository;
|
||||||
|
|
||||||
public RuleController(RuleService ruleService,
|
public RuleController(RuleService ruleService,
|
||||||
AntecedentValueService antecedentValueService,
|
AntecedentValueService antecedentValueService,
|
||||||
TimeSeriesService timeSeriesService) {
|
TimeSeriesService timeSeriesService, RuleRepository ruleRepository) {
|
||||||
this.ruleService = ruleService;
|
this.ruleService = ruleService;
|
||||||
this.antecedentValueService = antecedentValueService;
|
this.antecedentValueService = antecedentValueService;
|
||||||
this.timeSeriesService = timeSeriesService;
|
this.timeSeriesService = timeSeriesService;
|
||||||
|
this.ruleRepository = ruleRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(LIST_RULE)
|
@GetMapping(LIST_RULE)
|
||||||
@ -50,4 +49,27 @@ public class RuleController {
|
|||||||
ruleService.saveRule(ruleForm);
|
ruleService.saveRule(ruleForm);
|
||||||
return "redirect:/" + LIST_RULE;
|
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();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,8 @@ public class RuleService {
|
|||||||
TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()),
|
TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()),
|
||||||
addRuleForm.getConsequent()));
|
addRuleForm.getConsequent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rule findById(Integer id) {
|
||||||
|
return ruleRepository.getOne(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" colspan="8">Правила</th>
|
<th scope="col" colspan="10">Правила</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -23,11 +23,20 @@
|
|||||||
<td><span class="badge badge-success" th:text="${rule.secondAntecedentValue.antecedentValue}"></span></td>
|
<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-info">то</span></td>
|
||||||
<td><span class="badge badge-warning" th:text="${rule.consequent}"></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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="col-md-4 col-sm-12">
|
|
||||||
<a href="/addRule" class="btn btn-outline-success">Добавить правило</a>
|
<a href="/addRule" class="btn btn-outline-success">Добавить правило</a>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user