#69 added button disabling take part, if cur user already taken part

This commit is contained in:
Nightblade73 2019-04-18 15:38:45 +04:00
parent 8fd352aaa4
commit 96431701df
5 changed files with 35 additions and 8 deletions

View File

@ -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<ConferenceUser> conferenceUsers) {
return conferenceService.isCurrentUserParticipant(conferenceUsers);
}
@ModelAttribute("allParticipation")
public List<ConferenceUser.Participation> getAllParticipation() {
return conferenceService.getAllParticipations();

View File

@ -40,7 +40,7 @@ public class ConferenceDto {
private List<Paper> papers = new ArrayList<>();
private List<Paper> notSelectedPapers = new ArrayList<>();
private List<ConferenceUser> users = new ArrayList<>();
private Integer filterUserId;
private boolean disabledTakePart = false;
public ConferenceDto() {
}
@ -58,7 +58,8 @@ public class ConferenceDto {
@JsonProperty("paperIds") List<Integer> paperIds,
@JsonProperty("users") List<ConferenceUser> users,
@JsonProperty("papers") List<Paper> papers,
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
@JsonProperty("notSelectedPapers") List<Paper> 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<Integer> getRemovedDeadlineIds() {

View File

@ -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<Paper> getConferencePapers(List<Integer> paperIds) {
@ -132,4 +133,12 @@ public class ConferenceService {
}
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
for (ConferenceUser participant : conferenceUsers) {
if (participant.getUser().getId() == userService.getCurrentUser().getId()) {
return true;
}
}
return false;
}
}

View File

@ -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;

View File

@ -122,8 +122,10 @@
</div>
<div class="form-group d-flex justify-content-end">
<input type="hidden" th:value="*{disabledTakePart}" th:name="disabledTakePart"/>
<input id="take-part" class="btn btn-primary"
type="submit" name="takePart" value="Принять участие"/>
type="submit" name="takePart" value="Принять участие"
th:disabled="*{disabledTakePart}"/>
</div>
<div class="form-group">