From b4a2a8086ddd3f3301716ce6971512939e2cd521 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 12 Apr 2019 15:51:06 +0400 Subject: [PATCH 1/5] #62 remove verification of empty deadline list --- .../conference/controller/ConferenceController.java | 9 +++------ .../java/ru/ulstu/conference/model/ConferenceDto.java | 10 ++-------- .../resources/templates/conferences/conference.html | 4 +--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 006a1de..750d46d 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -19,9 +19,7 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -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; +import static ru.ulstu.core.controller.Navigation.*; @Controller() @@ -52,9 +50,6 @@ 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()) return CONFERENCE_PAGE; conferenceService.save(conferenceDto); @@ -69,6 +64,8 @@ public class ConferenceController { return CONFERENCE_PAGE; conferenceDto.getDeadlines().add(new Deadline()); return CONFERENCE_PAGE; + + } private void filterEmptyDeadlines(ConferenceDto conferenceDto) { diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 277e783..eb67d39 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -11,11 +11,7 @@ import ru.ulstu.user.model.UserDto; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.Size; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -36,7 +32,6 @@ public class ConferenceDto { @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy-MM-dd") private Date endDate = new Date(); - @NotEmpty private List deadlines = new ArrayList<>(); private Set userIds = new HashSet<>(); private Set paperIds = new HashSet<>(); @@ -45,8 +40,7 @@ public class ConferenceDto { private Integer filterUserId; public ConferenceDto() { - deadlines.add(new Deadline()); - } + } @JsonCreator public ConferenceDto(@JsonProperty("id") Integer id, diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index cbc0019..08083a5 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -60,9 +60,7 @@ th:field="*{deadlines[__${rowStat.index}__].date}"/> Удалить + th:onclick="|$(this).parent().remove();|"/> From 9711febefb27e3f3fce81f7d4e1f601df70f325e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 13 Apr 2019 13:02:36 +0400 Subject: [PATCH 2/5] #55 added delete deadline --- .../controller/ConferenceController.java | 17 +++++++++++++++-- .../ru/ulstu/conference/model/Conference.java | 1 - .../ulstu/conference/model/ConferenceDto.java | 18 ++++++++++++++++-- .../conference/service/ConferenceService.java | 12 ++++++------ .../deadline/service/DeadlineService.java | 6 ++++++ .../templates/conferences/conference.html | 8 +++++--- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 750d46d..61456c6 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -19,7 +19,9 @@ import java.io.IOException; import java.util.stream.Collectors; 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() @@ -64,8 +66,19 @@ public class ConferenceController { 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); + 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) { diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 1c824b3..faed15c 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -56,7 +56,6 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); - @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index eb67d39..e5efcde 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -11,7 +11,11 @@ import ru.ulstu.user.model.UserDto; import javax.persistence.Temporal; import javax.persistence.TemporalType; 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; @@ -33,6 +37,7 @@ public class ConferenceDto { @DateTimeFormat(pattern = "yyyy-MM-dd") private Date endDate = new Date(); private List deadlines = new ArrayList<>(); + private List removedDeadlineIds = new ArrayList<>(); private Set userIds = new HashSet<>(); private Set paperIds = new HashSet<>(); private Set papers = new HashSet<>(); @@ -40,7 +45,7 @@ public class ConferenceDto { private Integer filterUserId; public ConferenceDto() { - } + } @JsonCreator public ConferenceDto(@JsonProperty("id") Integer id, @@ -188,4 +193,13 @@ public class ConferenceDto { public void setFilterUserId(Integer filterUserId) { this.filterUserId = filterUserId; } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } + } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index c28c637..46e7ff7 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -53,20 +53,20 @@ 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)); - return conference.getId(); } + public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException { + + } + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); @@ -74,9 +74,9 @@ public class ConferenceService { conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); - + conferenceDto.getRemovedDeadlineIds() + .forEach(deadlineService::remove); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); - return conference; } diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 2180025..d4ff2ef 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -41,4 +41,10 @@ public class DeadlineService { newDeadline = deadlineRepository.save(newDeadline); return newDeadline; } + + @Transactional + public void remove(Integer deadlineId) { + deadlineRepository.delete(deadlineId); + + } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 08083a5..c93fc39 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -50,6 +50,7 @@
+
@@ -58,9 +59,10 @@ th:field="*{deadlines[__${rowStat.index}__].description}"/> - Удалить + +
From 34499abd609c1b2e4570f969d63546e56c5c153f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 13 Apr 2019 22:59:59 +0400 Subject: [PATCH 3/5] #62 fix remove deadline in other JPA operation --- .../java/ru/ulstu/conference/service/ConferenceService.java | 3 +-- src/main/java/ru/ulstu/deadline/service/DeadlineService.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 46e7ff7..ac44d4b 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -60,6 +60,7 @@ public class ConferenceService { 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(); } @@ -74,8 +75,6 @@ public class ConferenceService { conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); - conferenceDto.getRemovedDeadlineIds() - .forEach(deadlineService::remove); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); return conference; } diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index d4ff2ef..0ef8a4f 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -45,6 +45,5 @@ public class DeadlineService { @Transactional public void remove(Integer deadlineId) { deadlineRepository.delete(deadlineId); - } } From 8cfc64ea85044ad88403a595b0a8726163ce37d5 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 14 Apr 2019 20:42:11 +0400 Subject: [PATCH 4/5] #55 added delete input style --- .../conference/controller/ConferenceController.java | 13 ++++++------- .../ulstu/conference/service/ConferenceService.java | 5 ++++- src/main/resources/public/css/conference.css | 4 ++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 61456c6..7a229ca 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -52,8 +52,9 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); - if (errors.hasErrors()) + if (errors.hasErrors()) { return CONFERENCE_PAGE; + } conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); @@ -62,8 +63,9 @@ 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; } @@ -71,13 +73,10 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "removeDeadline") public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { - if (errors.hasErrors()) + 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)); + conferenceService.removeDeadline(conferenceDto, deadlineIndex); return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index ac44d4b..13ce1d5 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -65,7 +65,10 @@ public class ConferenceService { } 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(conferenceDto.getDeadlines().get(deadlineIndex)); } private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index ec88796..004fe8c 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -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 { From f88f035e65860038652d9003d6e3dced97fe4002 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 14 Apr 2019 21:34:39 +0400 Subject: [PATCH 5/5] #55 little fix --- .../java/ru/ulstu/conference/service/ConferenceService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 13ce1d5..9c40295 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -68,7 +68,7 @@ public class ConferenceService { if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) { conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId()); } - conferenceDto.getDeadlines().remove(conferenceDto.getDeadlines().get(deadlineIndex)); + conferenceDto.getDeadlines().remove((int) deadlineIndex); } private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {