Merge branch '116-delete-deadline' into 'dev'

Resolve "Удаление дедлайна"

Closes #116

See merge request romanov73/ng-tracker!75
This commit is contained in:
Anton Romanov 2019-04-25 09:48:38 +00:00
commit fc94ea1f26
6 changed files with 39 additions and 8 deletions

View File

@ -97,6 +97,14 @@ public class GrantController {
return GRANT_PAGE; return GRANT_PAGE;
} }
@PostMapping(value = "/grant", params = "removeDeadline")
public String removeDeadline(GrantDto grantDto,
@RequestParam(value = "removeDeadline") Integer deadlineId) {
grantService.removeDeadline(grantDto, deadlineId);
return GRANT_PAGE;
}
@PostMapping(value = "/grant", params = "createProject") @PostMapping(value = "/grant", params = "createProject")
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
if (errors.hasErrors()) { if (errors.hasErrors()) {

View File

@ -64,8 +64,6 @@ public class Grant extends BaseEntity implements UserContainer {
@OrderBy("date") @OrderBy("date")
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
//Описание гранта
@NotNull
private String comment; private String comment;
//Заявка на грант //Заявка на грант

View File

@ -35,6 +35,7 @@ public class GrantDto {
private boolean hasDegree; private boolean hasDegree;
private List<Integer> paperIds = new ArrayList<>(); private List<Integer> paperIds = new ArrayList<>();
private List<Paper> papers = new ArrayList<>(); private List<Paper> papers = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>();
public GrantDto() { public GrantDto() {
deadlines.add(new Deadline()); deadlines.add(new Deadline());
@ -215,4 +216,12 @@ public class GrantDto {
public void setPapers(List<Paper> papers) { public void setPapers(List<Paper> papers) {
this.papers = papers; this.papers = papers;
} }
public List<Integer> getRemovedDeadlineIds() {
return removedDeadlineIds;
}
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
this.removedDeadlineIds = removedDeadlineIds;
}
} }

View File

@ -109,6 +109,7 @@ public class GrantService {
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
fileService.deleteFile(grant.getApplication()); fileService.deleteFile(grant.getApplication());
} }
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
grantRepository.save(copyFromDto(grant, grantDto)); grantRepository.save(copyFromDto(grant, grantDto));
return grant.getId(); return grant.getId();
} }
@ -184,4 +185,12 @@ public class GrantService {
grantDto.getPapers().clear(); grantDto.getPapers().clear();
} }
} }
public void removeDeadline(GrantDto grantDto, Integer deadlineId) {
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
}
grantDto.getDeadlines().remove((int) deadlineId);
}
} }

View File

@ -24,4 +24,8 @@
height: 22px; height: 22px;
width: 22px; width: 22px;
margin: 3px; margin: 3px;
}
.btn-delete-deadline {
color: black;
} }

View File

@ -48,6 +48,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Дедлайны показателей:</label> <label>Дедлайны показателей:</label>
<input type="hidden" th:field="*{removedDeadlineIds}"/>
<div class="row" th:each="deadline, rowStat : *{deadlines}"> <div class="row" th:each="deadline, rowStat : *{deadlines}">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/> <input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
<div class="col-6 div-deadline-date"> <div class="col-6 div-deadline-date">
@ -59,12 +60,14 @@
th:field="*{deadlines[__${rowStat.index}__].description}"/> th:field="*{deadlines[__${rowStat.index}__].description}"/>
</div> </div>
<div class="col-2"> <div class="col-2">
<a class="btn btn-danger float-right" <button type="submit"
th:onclick="|$('#deadlines${rowStat.index}\\.description').val(''); class="btn btn-danger float-right btn-delete-deadline "
$('#deadlines${rowStat.index}\\.date').val(''); id="removeDeadline" name="removeDeadline"
$('#addDeadline').click();|"><span th:value="${rowStat.index}">
aria-hidden="true"><i class="fa fa-times"/></span> <span aria-hidden="true">
</a> <i class="fa fa-times"/>
</span>
</button>
</div> </div>
</div> </div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}" <p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"