Merge branch '62-delete-deadline' into 'dev'
Resolve "Удаление дедлайна" Closes #62 See merge request romanov73/ng-tracker!50
This commit is contained in:
commit
9e657a7d2d
@ -52,11 +52,9 @@ public class ConferenceController {
|
||||
@PostMapping(value = "/conference", params = "save")
|
||||
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||
filterEmptyDeadlines(conferenceDto);
|
||||
if (conferenceDto.getDeadlines().isEmpty()) {
|
||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
||||
}
|
||||
if (errors.hasErrors())
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceService.save(conferenceDto);
|
||||
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
||||
|
||||
@ -65,12 +63,23 @@ public class ConferenceController {
|
||||
@PostMapping(value = "/conference", params = "addDeadline")
|
||||
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
|
||||
filterEmptyDeadlines(conferenceDto);
|
||||
if (errors.hasErrors())
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceDto.getDeadlines().add(new Deadline());
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/conference", params = "removeDeadline")
|
||||
public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors,
|
||||
@RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException {
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceService.removeDeadline(conferenceDto, deadlineIndex);
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||
|
@ -56,7 +56,6 @@ public class Conference extends BaseEntity {
|
||||
@OrderBy("date")
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "paper_conference",
|
||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
||||
|
@ -36,8 +36,8 @@ public class ConferenceDto {
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date endDate = new Date();
|
||||
@NotEmpty
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||
private Set<Integer> userIds = new HashSet<>();
|
||||
private Set<Integer> paperIds = new HashSet<>();
|
||||
private Set<PaperDto> papers = new HashSet<>();
|
||||
@ -45,7 +45,6 @@ public class ConferenceDto {
|
||||
private Integer filterUserId;
|
||||
|
||||
public ConferenceDto() {
|
||||
deadlines.add(new Deadline());
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
@ -194,4 +193,13 @@ public class ConferenceDto {
|
||||
public void setFilterUserId(Integer filterUserId) {
|
||||
this.filterUserId = filterUserId;
|
||||
}
|
||||
|
||||
public List<Integer> getRemovedDeadlineIds() {
|
||||
return removedDeadlineIds;
|
||||
}
|
||||
|
||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
||||
this.removedDeadlineIds = removedDeadlineIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,20 +53,24 @@ public class ConferenceService {
|
||||
public Integer create(ConferenceDto conferenceDto) throws IOException {
|
||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
||||
newConference = conferenceRepository.save(newConference);
|
||||
|
||||
|
||||
return newConference.getId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Integer update(ConferenceDto conferenceDto) throws IOException {
|
||||
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
||||
|
||||
conferenceRepository.save(copyFromDto(conference, conferenceDto));
|
||||
|
||||
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||
return conference.getId();
|
||||
}
|
||||
|
||||
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
||||
}
|
||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||
}
|
||||
|
||||
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||
conference.setTitle(conferenceDto.getTitle());
|
||||
conference.setDescription(conferenceDto.getDescription());
|
||||
@ -74,9 +78,7 @@ public class ConferenceService {
|
||||
conference.setPing(0);
|
||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||
conference.setEndDate(conferenceDto.getEndDate());
|
||||
|
||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||
|
||||
return conference;
|
||||
}
|
||||
|
||||
|
@ -41,4 +41,9 @@ public class DeadlineService {
|
||||
newDeadline = deadlineRepository.save(newDeadline);
|
||||
return newDeadline;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove(Integer deadlineId) {
|
||||
deadlineRepository.delete(deadlineId);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ body {
|
||||
.deadline {
|
||||
margin: 0;
|
||||
height: 40px;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.deadline-text {
|
||||
@ -63,6 +64,9 @@ body {
|
||||
|
||||
.icon-delete {
|
||||
background-color: #f44;
|
||||
background-image: url(/img/conference/delete.png);
|
||||
background-repeat: round;
|
||||
color: transparent !important;
|
||||
}
|
||||
|
||||
.icon-delete:hover {
|
||||
|
@ -50,6 +50,7 @@
|
||||
<div class="form-group">
|
||||
<label for="deadlines">Дедлайны:</label>
|
||||
<div class="deadline-list form-control list-group" id="deadlines">
|
||||
<input type="hidden" th:field="*{removedDeadlineIds}"/>
|
||||
<div class="deadline d-flex p-0 list-group-item list-group-horizontal"
|
||||
th:each="deadline, rowStat : *{deadlines}">
|
||||
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
||||
@ -58,11 +59,10 @@
|
||||
th:field="*{deadlines[__${rowStat.index}__].description}"/>
|
||||
<input class="list-group-item" type="date" name="deadline"
|
||||
th:field="*{deadlines[__${rowStat.index}__].date}"/>
|
||||
<img class="icon icon-delete grey-border" src="/img/conference/delete.png"
|
||||
alt="Удалить"
|
||||
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
|
||||
$('#deadlines${rowStat.index}\\.date').val('');
|
||||
$('#addDeadline').click();|"/>
|
||||
<input type="submit" class="icon icon-delete grey-border"
|
||||
alt="Удалить" name="removeDeadline" th:value="${rowStat.index}"
|
||||
/>
|
||||
<!--th:onclick="|$(this).parent().remove();|"-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user