#55 added delete deadline

This commit is contained in:
Nightblade73 2019-04-13 13:02:36 +04:00
parent b4a2a8086d
commit 9711febefb
6 changed files with 48 additions and 14 deletions

View File

@ -19,7 +19,9 @@ import java.io.IOException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.isEmpty;
import static ru.ulstu.core.controller.Navigation.*; import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
@Controller() @Controller()
@ -64,8 +66,19 @@ public class ConferenceController {
return CONFERENCE_PAGE; return CONFERENCE_PAGE;
conferenceDto.getDeadlines().add(new Deadline()); conferenceDto.getDeadlines().add(new Deadline());
return CONFERENCE_PAGE; 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);
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
}
conferenceDto.getDeadlines().remove(conferenceDto.getDeadlines().get(deadlineIndex));
return CONFERENCE_PAGE;
} }
private void filterEmptyDeadlines(ConferenceDto conferenceDto) { private void filterEmptyDeadlines(ConferenceDto conferenceDto) {

View File

@ -56,7 +56,6 @@ public class Conference extends BaseEntity {
@OrderBy("date") @OrderBy("date")
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
@ManyToMany(fetch = FetchType.EAGER) @ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "paper_conference", @JoinTable(name = "paper_conference",
joinColumns = {@JoinColumn(name = "conference_id")}, joinColumns = {@JoinColumn(name = "conference_id")},

View File

@ -11,7 +11,11 @@ import ru.ulstu.user.model.UserDto;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.*; import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
@ -33,6 +37,7 @@ public class ConferenceDto {
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date endDate = new Date(); private Date endDate = new Date();
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
private List<Integer> removedDeadlineIds = new ArrayList<>();
private Set<Integer> userIds = new HashSet<>(); private Set<Integer> userIds = new HashSet<>();
private Set<Integer> paperIds = new HashSet<>(); private Set<Integer> paperIds = new HashSet<>();
private Set<PaperDto> papers = new HashSet<>(); private Set<PaperDto> papers = new HashSet<>();
@ -188,4 +193,13 @@ public class ConferenceDto {
public void setFilterUserId(Integer filterUserId) { public void setFilterUserId(Integer filterUserId) {
this.filterUserId = filterUserId; this.filterUserId = filterUserId;
} }
public List<Integer> getRemovedDeadlineIds() {
return removedDeadlineIds;
}
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
this.removedDeadlineIds = removedDeadlineIds;
}
} }

View File

@ -53,20 +53,20 @@ public class ConferenceService {
public Integer create(ConferenceDto conferenceDto) throws IOException { public Integer create(ConferenceDto conferenceDto) throws IOException {
Conference newConference = copyFromDto(new Conference(), conferenceDto); Conference newConference = copyFromDto(new Conference(), conferenceDto);
newConference = conferenceRepository.save(newConference); newConference = conferenceRepository.save(newConference);
return newConference.getId(); return newConference.getId();
} }
@Transactional @Transactional
public Integer update(ConferenceDto conferenceDto) throws IOException { public Integer update(ConferenceDto conferenceDto) throws IOException {
Conference conference = conferenceRepository.findOne(conferenceDto.getId()); Conference conference = conferenceRepository.findOne(conferenceDto.getId());
conferenceRepository.save(copyFromDto(conference, conferenceDto)); conferenceRepository.save(copyFromDto(conference, conferenceDto));
return conference.getId(); return conference.getId();
} }
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
}
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
conference.setTitle(conferenceDto.getTitle()); conference.setTitle(conferenceDto.getTitle());
conference.setDescription(conferenceDto.getDescription()); conference.setDescription(conferenceDto.getDescription());
@ -74,9 +74,9 @@ public class ConferenceService {
conference.setPing(0); conference.setPing(0);
conference.setBeginDate(conferenceDto.getBeginDate()); conference.setBeginDate(conferenceDto.getBeginDate());
conference.setEndDate(conferenceDto.getEndDate()); conference.setEndDate(conferenceDto.getEndDate());
conferenceDto.getRemovedDeadlineIds()
.forEach(deadlineService::remove);
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
return conference; return conference;
} }

View File

@ -41,4 +41,10 @@ public class DeadlineService {
newDeadline = deadlineRepository.save(newDeadline); newDeadline = deadlineRepository.save(newDeadline);
return newDeadline; return newDeadline;
} }
@Transactional
public void remove(Integer deadlineId) {
deadlineRepository.delete(deadlineId);
}
} }

View File

@ -50,6 +50,7 @@
<div class="form-group"> <div class="form-group">
<label for="deadlines">Дедлайны:</label> <label for="deadlines">Дедлайны:</label>
<div class="deadline-list form-control list-group" id="deadlines"> <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" <div class="deadline d-flex p-0 list-group-item list-group-horizontal"
th:each="deadline, rowStat : *{deadlines}"> th:each="deadline, rowStat : *{deadlines}">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/> <input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
@ -58,9 +59,10 @@
th:field="*{deadlines[__${rowStat.index}__].description}"/> th:field="*{deadlines[__${rowStat.index}__].description}"/>
<input class="list-group-item" type="date" name="deadline" <input class="list-group-item" type="date" name="deadline"
th:field="*{deadlines[__${rowStat.index}__].date}"/> th:field="*{deadlines[__${rowStat.index}__].date}"/>
<img class="icon icon-delete grey-border" src="/img/conference/delete.png" <input type="submit" class="icon icon-delete grey-border"
alt="Удалить" alt="Удалить" name="removeDeadline" th:value="${rowStat.index}"
th:onclick="|$(this).parent().remove();|"/> />
<!--th:onclick="|$(this).parent().remove();|"-->
</div> </div>
</div> </div>
</div> </div>