From 96431701dfce3ebfe92500510ddfcbf700943a67 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 18 Apr 2019 15:38:45 +0400 Subject: [PATCH] #69 added button disabling take part, if cur user already taken part --- .../controller/ConferenceController.java | 5 +++++ .../ru/ulstu/conference/model/ConferenceDto.java | 15 ++++++++------- .../conference/service/ConferenceService.java | 9 +++++++++ src/main/resources/public/css/conference.css | 10 ++++++++++ .../templates/conferences/conference.html | 4 +++- 5 files changed, 35 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 b88a0e6..dc57bce 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -51,6 +51,7 @@ public class ConferenceController { if (id != null && id > 0) { ConferenceDto conferenceDto = conferenceService.findOneDto(id); conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); + conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); modelMap.put("conferenceDto", conferenceDto); } else { ConferenceDto conferenceDto = new ConferenceDto(); @@ -119,6 +120,10 @@ public class ConferenceController { return conferenceService.getConferencePapers(paperIds); } + public boolean isCurrentUserParticipant(List conferenceUsers) { + return conferenceService.isCurrentUserParticipant(conferenceUsers); + } + @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index b18e914..a3f80c9 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -40,7 +40,7 @@ public class ConferenceDto { private List papers = new ArrayList<>(); private List notSelectedPapers = new ArrayList<>(); private List users = new ArrayList<>(); - private Integer filterUserId; + private boolean disabledTakePart = false; public ConferenceDto() { } @@ -58,7 +58,8 @@ public class ConferenceDto { @JsonProperty("paperIds") List paperIds, @JsonProperty("users") List users, @JsonProperty("papers") List papers, - @JsonProperty("notSelectedPapers") List notSelectedPapers) { + @JsonProperty("notSelectedPapers") List notSelectedPapers, + @JsonProperty("notSelectedPapers") Boolean disabledTakePart) { this.id = id; this.title = title; this.description = description; @@ -72,6 +73,7 @@ public class ConferenceDto { this.users = users; this.papers = papers; this.notSelectedPapers = notSelectedPapers; + this.disabledTakePart = disabledTakePart; } public ConferenceDto(Conference conference) { @@ -87,7 +89,6 @@ public class ConferenceDto { this.paperIds = convert(conference.getPapers(), paper -> paper.getId()); this.users = conference.getUsers(); this.papers = conference.getPapers(); - } public Integer getId() { @@ -186,12 +187,12 @@ public class ConferenceDto { this.users = users; } - public Integer getFilterUserId() { - return filterUserId; + public boolean isDisabledTakePart() { + return disabledTakePart; } - public void setFilterUserId(Integer filterUserId) { - this.filterUserId = filterUserId; + public void setDisabledTakePart(boolean disabledTakePart) { + this.disabledTakePart = disabledTakePart; } public List getRemovedDeadlineIds() { diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index f9e662e..a9e3fac 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -100,6 +100,7 @@ public class ConferenceService { public void takePart(ConferenceDto conferenceDto) throws IOException { conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser())); + conferenceDto.setDisabledTakePart(true); } public List getConferencePapers(List paperIds) { @@ -132,4 +133,12 @@ public class ConferenceService { } + public boolean isCurrentUserParticipant(List conferenceUsers) { + for (ConferenceUser participant : conferenceUsers) { + if (participant.getUser().getId() == userService.getCurrentUser().getId()) { + return true; + } + } + return false; + } } diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index a608bbd..fe19fd0 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -71,6 +71,16 @@ body { border-right: 1px solid #ced4da; } +#take-part[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#take-part[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + .paper-list { height: 200px; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 5c33ba0..478ebcb 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -122,8 +122,10 @@
+ + type="submit" name="takePart" value="Принять участие" + th:disabled="*{disabledTakePart}"/>