From 5bfeaff0540659a3c4d364da3827158d13917c1b Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 22 Apr 2019 11:13:04 +0400 Subject: [PATCH 1/8] #64 added method addPaper --- .../conference/controller/ConferenceController.java | 10 ++++++++++ .../ulstu/conference/service/ConferenceService.java | 8 +++++++- .../java/ru/ulstu/paper/service/PaperService.java | 2 +- .../resources/templates/conferences/conference.html | 12 ++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a416345..cf5017d 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -95,6 +95,16 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "addPaper") + public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.addPaper(conferenceDto); + + return CONFERENCE_PAGE; + } + @PostMapping(value = "/conference", params = "removeDeadline") public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5ce29f..f918812 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -149,7 +149,7 @@ public class ConferenceService { conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { conferenceDto.getPaperIds().forEach(paperId -> - conference.getPapers().add(paperService.findEntityById(paperId))); + conference.getPapers().add(paperService.findPaperById(paperId))); } return conference; } @@ -173,4 +173,10 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public void addPaper(ConferenceDto conferenceDto) { + Paper paper = new Paper(); + paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle()); + conferenceDto.getPapers().add(paper); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 1633c07..85db4ed 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -223,7 +223,7 @@ public class PaperService { return new PaperDto(paperRepository.findOne(paperId)); } - public Paper findEntityById(Integer paperId) { + public Paper findPaperById(Integer paperId) { return paperRepository.findOne(paperId); } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 184f5b5..8425fac 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -135,7 +135,15 @@ From 27674031283161c05cecea5f64f636cb86d21816 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 22 Apr 2019 15:11:52 +0400 Subject: [PATCH 2/8] #64 added saving in db --- .../controller/ConferenceController.java | 22 +++++++++---------- .../ru/ulstu/conference/model/Conference.java | 2 +- .../conference/service/ConferenceService.java | 21 +++++++++++------- .../ru/ulstu/paper/service/PaperService.java | 8 +++++++ .../templates/conferences/conference.html | 4 +++- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index cf5017d..3c5ee10 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -86,7 +86,7 @@ public class ConferenceController { } @PostMapping(value = "/conference", params = "addDeadline") - public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) { + public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); if (errors.hasErrors()) { return CONFERENCE_PAGE; @@ -95,16 +95,6 @@ public class ConferenceController { return CONFERENCE_PAGE; } - @PostMapping(value = "/conference", params = "addPaper") - public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) { - if (errors.hasErrors()) { - return CONFERENCE_PAGE; - } - conferenceService.addPaper(conferenceDto); - - return CONFERENCE_PAGE; - } - @PostMapping(value = "/conference", params = "removeDeadline") public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { @@ -115,6 +105,16 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "addPaper") + public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.addPaper(conferenceDto); + + return CONFERENCE_PAGE; + } + @PostMapping(value = "/conference", params = "removePaper") public String removePaper(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removePaper") Integer paperIndex) throws IOException { diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index e252e4d..8068e04 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -53,7 +53,7 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); - @ManyToMany(fetch = FetchType.EAGER) + @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER) @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index f918812..b96c9cd 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -111,9 +111,19 @@ public class ConferenceService { conferenceDto.getDeadlines().remove((int) deadlineIndex); } + public void addPaper(ConferenceDto conferenceDto) { + Paper paper = new Paper(); + paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle()); + paper.setStatus(Paper.PaperStatus.DRAFT); + + conferenceDto.getPapers().add(paper); + } + public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException { Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex); - conferenceDto.getNotSelectedPapers().add(removedPaper); + if (removedPaper.getId() != null) { + conferenceDto.getNotSelectedPapers().add(removedPaper); + } } public void takePart(ConferenceDto conferenceDto) throws IOException { @@ -144,7 +154,8 @@ public class ConferenceService { conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); - conference.setPapers(conferenceDto.getPapers()); + conference.getPapers().clear(); + conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findPaperById(paper.getId()) : paperService.create(paper))); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { @@ -173,10 +184,4 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } - - public void addPaper(ConferenceDto conferenceDto) { - Paper paper = new Paper(); - paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle()); - conferenceDto.getPapers().add(paper); - } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 85db4ed..6d0456c 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -93,6 +93,14 @@ public class PaperService { return newPaper.getId(); } + @Transactional + public Paper create(Paper paper) { + Paper newPaper = paperRepository.save(paper); + paperNotificationService.sendCreateNotification(newPaper); + eventService.createFromPaper(newPaper); + return newPaper; + } + private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException { paper.setComment(paperDto.getComment()); paper.setUrl(paperDto.getUrl()); diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 8425fac..370d749 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -131,9 +131,11 @@
- +
+ + From 53cc777734bb1b04d2d9835dceafa2443c112b8c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 22 Apr 2019 21:46:42 +0400 Subject: [PATCH 3/8] #64 delete conference refactor --- .../controller/ConferenceController.java | 14 ++++++-------- .../PaperConferenceRelationExistException.java | 7 +++++++ src/main/resources/public/css/conference.css | 8 ++++++-- src/main/resources/public/js/conference.js | 9 ++++----- .../templates/conferences/conferences.html | 3 ++- .../conferences/fragments/confLineFragment.html | 13 ++++++++----- 6 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 3c5ee10..a143e3b 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -6,7 +6,6 @@ import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -68,6 +67,12 @@ public class ConferenceController { } } + @PostMapping(value = "/conferences", params = "deleteConference") + public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException { + conferenceService.delete(conferenceId); + return String.format(REDIRECT_TO, CONFERENCES_PAGE); + } + @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); @@ -76,13 +81,6 @@ public class ConferenceController { } conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); - - } - - @GetMapping("/delete/{conference-id}") - public String delete(@PathVariable("conference-id") Integer conferenceId) throws IOException { - conferenceService.delete(conferenceId); - return String.format(REDIRECT_TO, CONFERENCES_PAGE); } @PostMapping(value = "/conference", params = "addDeadline") diff --git a/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java b/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java new file mode 100644 index 0000000..ddb3b5e --- /dev/null +++ b/src/main/java/ru/ulstu/paper/error/PaperConferenceRelationExistException.java @@ -0,0 +1,7 @@ +package ru.ulstu.paper.error; + +public class PaperConferenceRelationExistException extends RuntimeException { + public PaperConferenceRelationExistException(String message) { + super(message); + } +} diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index ad06b3c..e4243b1 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -2,7 +2,7 @@ body { min-width: 400px; } -.conference-row .col:hover { +.conference-row .d-flex:hover { background-color: #f3f3f3; border-radius: .25rem; } @@ -15,10 +15,14 @@ body { margin-bottom: 10px; } -.conference-row .col .text-decoration { +.conference-row .d-flex .text-decoration { text-decoration: none; } +.conference-row .d-flex { + margin: 0 15px; +} + .form-group textarea { min-height: 206px; diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index d415ca2..18a8c67 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -1,7 +1,6 @@ $(document).ready(function () { - - $('a[data-confirm]').click(function(ev) { - var href = $(this).attr('href'); + $('input[data-confirm]').click(function(ev) { + var value = $(this).attr('value'); if (!$('#dataConfirmModal').length) { $('#modalDelete').append('\n' + ' \n' + '
\n' + @@ -22,7 +21,7 @@ $(document).ready(function () { '
'); } $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); - $('#dataConfirmOK').attr('href', href); + $('#deleteConference').attr('value', value); $('#dataConfirmModal').modal({show:true}); return false; }); diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index 7b0ac8d..f471245 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -8,7 +8,7 @@
-
+
@@ -20,6 +20,7 @@
+
diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index 7d948d4..ecd166d 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -5,16 +5,19 @@
-
+
- - - + + + + +
From 6d6ea3136d1a784b1a7b33e86c9cf32760ded40a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 23 Apr 2019 13:37:56 +0400 Subject: [PATCH 4/8] #64 dont show error message --- .../controller/ConferenceController.java | 10 +++++++++- .../conference/model/ConferenceFilterDto.java | 8 ++++---- .../ru/ulstu/paper/controller/PaperController.java | 12 ++++++++++-- .../templates/conferences/conferences.html | 14 +++++++++++--- src/main/resources/templates/papers/papers.html | 9 +++++++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a143e3b..8560f43 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -68,7 +68,15 @@ public class ConferenceController { } @PostMapping(value = "/conferences", params = "deleteConference") - public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException { + public String delete(@Valid ConferenceFilterDto conferenceFilterDto, + @RequestParam("deleteConference") Integer conferenceId, + Errors errors, + ModelMap modelMap) throws IOException { + if (true) { + errors.reject("relationExist", "Статья прикреплена к конференции"); + filterConferences(conferenceFilterDto, modelMap); + return CONFERENCES_PAGE; + } conferenceService.delete(conferenceId); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 8503b40..0649901 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -11,14 +11,14 @@ public class ConferenceFilterDto { public ConferenceFilterDto() { } - public ConferenceFilterDto(List conferenceDtos, Integer filterUserId, Integer year) { - this.conferences = conferenceDtos; + public ConferenceFilterDto(List conferences, Integer filterUserId, Integer year) { + this.conferences = conferences; this.filterUserId = filterUserId; this.year = year; } - public ConferenceFilterDto(List conferenceDtos) { - this(conferenceDtos, null, null); + public ConferenceFilterDto(List conferences) { + this(conferences, null, null); } public List getConferences() { diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e11e4d9..4b13275 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,5 +1,6 @@ package ru.ulstu.paper.controller; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -95,8 +96,15 @@ public class PaperController { } @GetMapping("/delete/{paper-id}") - public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { - paperService.delete(paperId); + public String delete(@Valid PaperFilterDto paperFilterDto, + @PathVariable("paper-id") Integer paperId, + Errors errors) throws IOException { + try { + paperService.delete(paperId); + } catch (DataIntegrityViolationException e) { + errors.reject("relationExist", "Статья прикреплена к конференции"); + return "/papers/papers"; + } return "redirect:/papers/papers"; } diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index f471245..5f3f127 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -8,7 +8,9 @@
- + +
@@ -18,10 +20,16 @@

+ + +
+

+
+ +
- - +
diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 7a033fe..5efd860 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -7,7 +7,8 @@
- +
@@ -17,7 +18,11 @@
+
+
+

+
@@ -43,7 +48,7 @@
-
+
From 8f2f6adc3b788923c39c4fd7d39a307e5d4bf592 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 23 Apr 2019 23:15:22 +0400 Subject: [PATCH 5/8] #64 show global message --- .../repository/ConferenceRepository.java | 3 ++ .../conference/service/ConferenceService.java | 4 ++ .../core/controller/AdviceController.java | 5 +++ .../paper/controller/PaperController.java | 41 +++++++++--------- .../paper/controller/PaperRestController.java | 6 +-- ...{PaperFilterDto.java => PaperListDto.java} | 15 +++++-- .../ru/ulstu/paper/service/PaperService.java | 4 +- src/main/resources/public/js/papers.js | 8 +++- src/main/resources/templates/default.html | 42 +++++++++++++------ .../papers/fragments/paperLineFragment.html | 3 +- 10 files changed, 85 insertions(+), 46 deletions(-) rename src/main/java/ru/ulstu/paper/model/{PaperFilterDto.java => PaperListDto.java} (67%) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index cb8a488..f217db9 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -16,4 +16,7 @@ public interface ConferenceRepository extends JpaRepository @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") List findAllActive(@Param("date") Date date); + + @Query("SELECT case when count(c) > 0 then true else false end FROM Conference c JOIN c.papers p WHERE p.id = :paperId") + boolean isPaperAttached(@Param("paperId") Integer paperId); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index b96c9cd..1346894 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -184,4 +184,8 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public boolean isAttachedToConference(Integer paperId) { + return conferenceRepository.isPaperAttached(paperId); + } } diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 8238797..27ba6c9 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -39,6 +39,11 @@ public class AdviceController { return userService.getCurrentUser().getUserAbbreviate(); } + @ModelAttribute("flashMessage") + public String getFlashMessage() { + return null; + } + private Response handleException(ErrorConstants error) { log.warn(error.toString()); return new Response<>(error); diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 4b13275..41d5586 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,6 +1,5 @@ package ru.ulstu.paper.controller; -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -9,14 +8,14 @@ import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -39,23 +38,34 @@ import static org.springframework.util.StringUtils.isEmpty; @ApiIgnore public class PaperController { private final PaperService paperService; + private final ConferenceService conferenceService; private final LatexService latexService; - public PaperController(PaperService paperService, LatexService latexService) { + public PaperController(PaperService paperService, + ConferenceService conferenceService, + LatexService latexService) { this.paperService = paperService; + this.conferenceService = conferenceService; this.latexService = latexService; } @GetMapping("/papers") public void getPapers(ModelMap modelMap) { - modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null)); + modelMap.put("filteredPapers", new PaperListDto(paperService.findAllDto(), null, null)); } @PostMapping("/papers") - public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) { - modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto), - paperFilterDto.getFilterAuthorId(), - paperFilterDto.getYear())); + public void listPapers(@Valid PaperListDto paperListDto, ModelMap modelMap) { + if (paperListDto.getPaperDeleteId() != null) { + if (conferenceService.isAttachedToConference(paperListDto.getPaperDeleteId())) { + modelMap.put("flashMessage", "Статью нельзя удалить, она прикреплена к конференции"); + } else { + paperService.delete(paperListDto.getPaperDeleteId()); + } + } + modelMap.put("filteredPapers", new PaperListDto(paperService.filter(paperListDto), + paperListDto.getFilterAuthorId(), + paperListDto.getYear())); } @GetMapping("/dashboard") @@ -95,19 +105,6 @@ public class PaperController { return "/papers/paper"; } - @GetMapping("/delete/{paper-id}") - public String delete(@Valid PaperFilterDto paperFilterDto, - @PathVariable("paper-id") Integer paperId, - Errors errors) throws IOException { - try { - paperService.delete(paperId); - } catch (DataIntegrityViolationException e) { - errors.reject("relationExist", "Статья прикреплена к конференции"); - return "/papers/papers"; - } - return "redirect:/papers/papers"; - } - @ModelAttribute("allStatuses") public List getPaperStatuses() { return paperService.getPaperStatuses(); diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 2bd8384..d98ba98 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -58,8 +58,8 @@ public class PaperRestController { } @PostMapping("/filter") - public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { - return new Response<>(paperService.filter(paperFilterDto)); + public Response> filter(@RequestBody @Valid PaperListDto paperListDto) throws IOException { + return new Response<>(paperService.filter(paperListDto)); } @GetMapping("formatted-list") diff --git a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java b/src/main/java/ru/ulstu/paper/model/PaperListDto.java similarity index 67% rename from src/main/java/ru/ulstu/paper/model/PaperFilterDto.java rename to src/main/java/ru/ulstu/paper/model/PaperListDto.java index f7aef29..871047a 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperFilterDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperListDto.java @@ -2,15 +2,16 @@ package ru.ulstu.paper.model; import java.util.List; -public class PaperFilterDto { +public class PaperListDto { private List papers; private Integer filterAuthorId; + private Integer paperDeleteId; private Integer year; - public PaperFilterDto() { + public PaperListDto() { } - public PaperFilterDto(List paperDtos, Integer filterAuthorId, Integer year) { + public PaperListDto(List paperDtos, Integer filterAuthorId, Integer year) { this.papers = paperDtos; this.filterAuthorId = filterAuthorId; this.year = year; @@ -39,4 +40,12 @@ public class PaperFilterDto { public void setYear(Integer year) { this.year = year; } + + public Integer getPaperDeleteId() { + return paperDeleteId; + } + + public void setPaperDeleteId(Integer paperDeleteId) { + this.paperDeleteId = paperDeleteId; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 6d0456c..32561a9 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -9,7 +9,7 @@ import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -181,7 +181,7 @@ public class PaperService { return paper; } - public List filter(PaperFilterDto filterDto) { + public List filter(PaperListDto filterDto) { return convert(sortPapers(paperRepository.filter( filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()), filterDto.getYear())), PaperDto::new); diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index 78d3120..7a937ba 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -13,7 +13,8 @@ $(document).ready(function () { }); $('a[data-confirm]').click(function(ev) { - var href = $(this).attr('href'); + var id = $(this).parent().parent().find('.id-class').val(); + if (!$('#dataConfirmModal').length) { $('#modalDelete').append(''); } $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm')); - $('#dataConfirmOK').attr('href', href); + $('#dataConfirmOK').click(function () { + $("#paperDeleteId").val(id); + $('form').submit(); + }); $('#dataConfirmModal').modal({show:true}); return false; }); diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 00e2c0f..89bc9ec 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -55,7 +55,8 @@ Сайт кафедры
From 7eb5dce94e4fef3678b0e348eabea936f489b94f Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 09:42:00 +0400 Subject: [PATCH 6/8] #64 style fixes --- .../conference/controller/ConferenceController.java | 10 +--------- src/main/resources/public/css/conference.css | 10 ++++++++-- .../resources/templates/conferences/conferences.html | 4 ---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 8560f43..a143e3b 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -68,15 +68,7 @@ public class ConferenceController { } @PostMapping(value = "/conferences", params = "deleteConference") - public String delete(@Valid ConferenceFilterDto conferenceFilterDto, - @RequestParam("deleteConference") Integer conferenceId, - Errors errors, - ModelMap modelMap) throws IOException { - if (true) { - errors.reject("relationExist", "Статья прикреплена к конференции"); - filterConferences(conferenceFilterDto, modelMap); - return CONFERENCES_PAGE; - } + public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException { conferenceService.delete(conferenceId); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index e4243b1..452f8dd 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -19,6 +19,12 @@ body { text-decoration: none; } +.conference-row .d-flex .text-decoration:nth-child(1) { + margin-left: 10px; +} + + + .conference-row .d-flex { margin: 0 15px; } @@ -121,14 +127,14 @@ body { } .icon-delete { - background-color: #f44; + background-color: #ff7272; background-image: url(/img/conference/delete.png); background-repeat: round; color: transparent !important; } .icon-delete:hover { - background-color: #ff2929; + background-color: #ff0000; transition: background-color .15s ease-in-out; } diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index 5f3f127..1c2d64e 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -20,13 +20,9 @@

- -

- -
From fe5589051865bcfebbcf7567715bcf7dd5713a17 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 10:12:42 +0400 Subject: [PATCH 7/8] #64 more style fixes --- src/main/resources/public/css/conference.css | 21 ++++++++++++++++--- .../templates/conferences/conference.html | 5 ++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 452f8dd..f84b188 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -3,7 +3,7 @@ body { } .conference-row .d-flex:hover { - background-color: #f3f3f3; + background-color: #f1f1f1; border-radius: .25rem; } @@ -71,13 +71,17 @@ body { padding: 0.5rem 1.75em 0.5rem 0.5em; display: inline-block; background: transparent url("https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-16.png") no-repeat right 7px center; - + cursor: pointer; } .member select:nth-child(4) { border-right: 1px solid #ced4da; } +.member select:hover { + background-color: #f1f1f1; +} + .member-name { padding: .75rem 1.25rem; @@ -114,11 +118,22 @@ body { flex: 1; } +.paper-name:hover { + background-color: #f1f1f1; +} + .paper-name span { - margin: 6px 15px; + margin: 7px 10px; display: inline-block; } +.paper-name span:nth-child(1) { + margin: 3px 0px 3px 10px; + float: left; +} + + + .icon { width: 38px; height: 38px; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 370d749..8d24ca9 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -136,13 +136,16 @@ th:each="paper, rowStat : *{papers}"> + + Имя статьи - + + From d37c9bda57ff86194e0055813e0573e342905a0b Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 10:17:32 +0400 Subject: [PATCH 8/8] #64 excluded adding articles with the same name --- .../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 1346894..e6338fb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -113,7 +113,7 @@ public class ConferenceService { public void addPaper(ConferenceDto conferenceDto) { Paper paper = new Paper(); - paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle()); + paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime()); paper.setStatus(Paper.PaperStatus.DRAFT); conferenceDto.getPapers().add(paper);