#5 -- Show and edit rules
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m47s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m47s
This commit is contained in:
parent
486981c0ff
commit
11fc4e46d1
@ -25,9 +25,9 @@ public class RuleController {
|
|||||||
@PathVariable(value = "ruleId") Integer id, Model model) {
|
@PathVariable(value = "ruleId") Integer id, Model model) {
|
||||||
model.addAttribute("projectId", projectId);
|
model.addAttribute("projectId", projectId);
|
||||||
model.addAttribute("rule",
|
model.addAttribute("rule",
|
||||||
new RuleForm((id != null && id != 0)
|
new RuleForm(id, (id != null && id != 0)
|
||||||
? ruleService.getById(id)
|
? ruleService.getById(id).getProject().getId()
|
||||||
: new FuzzyRule()));
|
: projectId));
|
||||||
|
|
||||||
return "rule/edit";
|
return "rule/edit";
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,14 @@ package ru.ulstu.fc.rule.model;
|
|||||||
public class RuleForm {
|
public class RuleForm {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer projectId;
|
private Integer projectId;
|
||||||
private String value;
|
private String content;
|
||||||
|
|
||||||
public RuleForm() {
|
public RuleForm() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuleForm(FuzzyRule rule) {
|
public RuleForm(Integer id, Integer projectId) {
|
||||||
this.projectId = (rule == null || rule.getProject() == null)
|
this.id = id;
|
||||||
? null
|
this.projectId = projectId;
|
||||||
: rule.getProject().getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getProjectId() {
|
public Integer getProjectId() {
|
||||||
@ -30,12 +29,12 @@ public class RuleForm {
|
|||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getContent() {
|
||||||
return value;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setContent(String content) {
|
||||||
this.value = value;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ public class RuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object save(RuleForm ruleForm) {
|
public Object save(RuleForm ruleForm) {
|
||||||
if (ruleForm.getId() == null) {
|
if (ruleForm.getId() == null || ruleForm.getId() == 0) {
|
||||||
FuzzyRule rule = new FuzzyRule();
|
FuzzyRule rule = new FuzzyRule();
|
||||||
rule.setProject(projectService.getById(ruleForm.getProjectId()));
|
rule.setProject(projectService.getById(ruleForm.getProjectId()));
|
||||||
rule.setContent(ruleForm.getValue());
|
rule.setContent(ruleForm.getContent());
|
||||||
return ruleRepository.save(rule);
|
return ruleRepository.save(rule);
|
||||||
}
|
}
|
||||||
FuzzyRule dbRule = getById(ruleForm.getId());
|
FuzzyRule dbRule = getById(ruleForm.getId());
|
||||||
dbRule.setProject(projectService.getById(ruleForm.getProjectId()));
|
dbRule.setProject(projectService.getById(ruleForm.getProjectId()));
|
||||||
dbRule.setContent(ruleForm.getValue());
|
dbRule.setContent(ruleForm.getContent());
|
||||||
return ruleRepository.save(dbRule);
|
return ruleRepository.save(dbRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
<h4> Список правил</h4>
|
<h4> Список правил</h4>
|
||||||
<div class="row" th:each="r, iter : ${rules}">
|
<div class="row" th:each="r, iter : ${rules}">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<span class="badge badge-light" th:text="${iter} + ' Если'"></span>
|
<span class="badge badge-light" th:text="${iter.index+1} + '. ' + ${r.content}"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-md-2 offset-md-3">
|
<!-- <div class="col col-md-2 offset-md-3">
|
||||||
<span class="badge badge-primary">Переменная</span>
|
<span class="badge badge-primary">Переменная</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-md-2">
|
<div class="col col-md-2">
|
||||||
@ -66,8 +66,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-md-1">
|
<div class="col col-md-1">
|
||||||
<span class="badge badge-danger">И / ИЛИ</span>
|
<span class="badge badge-danger">И / ИЛИ</span>
|
||||||
</div>
|
</div>-->
|
||||||
</div>
|
</div>
|
||||||
<a th:href="@{'/rule/edit/' + ${projectId}+'/0'}" class="btn btn-outline-dark">Добавить правило</a>
|
<a th:href="@{'/rule/edit/' + ${projectId}+'/0'}" class="btn btn-outline-dark">Добавить правило</a>
|
||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
@ -9,18 +9,18 @@
|
|||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<h3>Редактирование правила:</h3>
|
<h3>Редактирование правила:</h3>
|
||||||
<form th:action="@{/rule/save}" th:object="${rule}" method="post">
|
<form th:action="@{/rule/save}" th:object="${rule}" method="post">
|
||||||
<input type="hidden" th:field="${projectId}">
|
<input type="hidden" th:field="*{projectId}">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="value">Правило</label>
|
<label for="content">Правило</label>
|
||||||
<input th:field="*{value}"
|
<input th:field="*{content}"
|
||||||
id="value"
|
id="content"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder="Правило">
|
placeholder="Правило">
|
||||||
<p th:if="${#fields.hasErrors('value')}"
|
<p th:if="${#fields.hasErrors('content')}"
|
||||||
th:class="${#fields.hasErrors('value')}? error">
|
th:class="${#fields.hasErrors('content')}? error">
|
||||||
Не может быть пустым
|
Не может быть пустым
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user