diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 6867be5..370e996 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -15,10 +15,13 @@ import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; +import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -44,6 +47,13 @@ public class ConferenceController { modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto())); } + @PostMapping("/conferences") + public void filterConferences(@Valid ConferenceFilterDto conferenceFilterDto, ModelMap modelMap) { + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.filter(conferenceFilterDto), + conferenceFilterDto.getFilterUserId(), + conferenceFilterDto.getYear())); + } + @GetMapping("/conference") public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { @@ -119,6 +129,20 @@ public class ConferenceController { return conferenceService.getAllDeposit(); } + @ModelAttribute("allUsers") + public List getAllUsers() { + return conferenceService.getAllUsers(); + } + + @ModelAttribute("allYears") + public List getAllYears() { + List years = new ArrayList<>(); + for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i--) { + years.add(i); + } + return years; + } + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index a3f80c9..2e2f13b 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -18,6 +18,9 @@ import static ru.ulstu.core.util.StreamApiUtils.convert; public class ConferenceDto { + private final static String BEGIN_DATE = "Начало: "; + private final static String END_DATE = "Конец: "; + private Integer id; @NotEmpty @Size(min = 2, max = 400) @@ -211,4 +214,8 @@ public class ConferenceDto { this.notSelectedPapers = notSelectedPapers; } + public String getDatesString() { + return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0]; + } + } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 37878b2..8503b40 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -5,15 +5,15 @@ import java.util.List; public class ConferenceFilterDto { private List conferences; - private Integer filterAuthorId; + private Integer filterUserId; private Integer year; public ConferenceFilterDto() { } - public ConferenceFilterDto(List conferenceDtos, Integer filterAuthorId, Integer year) { + public ConferenceFilterDto(List conferenceDtos, Integer filterUserId, Integer year) { this.conferences = conferenceDtos; - this.filterAuthorId = filterAuthorId; + this.filterUserId = filterUserId; this.year = year; } @@ -29,12 +29,12 @@ public class ConferenceFilterDto { this.conferences = conferences; } - public Integer getFilterAuthorId() { - return filterAuthorId; + public Integer getFilterUserId() { + return filterUserId; } - public void setFilterAuthorId(Integer filterAuthorId) { - this.filterAuthorId = filterAuthorId; + public void setFilterUserId(Integer filterUserId) { + this.filterUserId = filterUserId; } public Integer getYear() { diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 4325633..99f311e 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,7 +1,14 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; +import ru.ulstu.user.model.User; + +import java.util.List; public interface ConferenceRepository extends JpaRepository { + @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) AND (YEAR(c.beginDate) = :year OR :year IS NULL)") + List filter(@Param("user") User user, @Param("year") Integer year); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 6295d5c..b03e9d3 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -5,11 +5,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; +import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; @@ -121,6 +123,10 @@ public class ConferenceService { return paperService.findAllNotSelect(paperIds); } + public List getAllUsers() { + return userService.findAll(); + } + public List getAllParticipations() { return Arrays.asList(ConferenceUser.Participation.values()); } @@ -150,4 +156,11 @@ public class ConferenceService { public boolean isCurrentUserParticipant(List conferenceUsers) { return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser())); } + + public List filter(ConferenceFilterDto conferenceFilterDto) { + return convert(conferenceRepository.filter( + conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()), + conferenceFilterDto.getYear()), ConferenceDto::new); + + } } diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index fe19fd0..ad06b3c 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -3,7 +3,7 @@ body { } .conference-row .col:hover { - background-color: #eaeaea; + background-color: #f3f3f3; border-radius: .25rem; } @@ -11,7 +11,13 @@ body { color: white; } +.filter .dropdown { + margin-bottom: 10px; +} +.conference-row .col .text-decoration { + text-decoration: none; +} .form-group textarea { diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index dd843ca..d415ca2 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -1,17 +1,5 @@ $(document).ready(function () { - $(".conference-row").mouseenter(function (event) { - var conferenceRow = $(event.target).closest(".conference-row"); - $(conferenceRow).css("background-color", "#f8f9fa"); - $(conferenceRow).find(".remove-conference").removeClass("d-none"); - - }); - $(".conference-row").mouseleave(function (event) { - var conferenceRow = $(event.target).closest(".conference-row"); - $(conferenceRow).css("background-color", "white"); - $(conferenceRow).closest(".conference-row").find(".remove-conference").addClass("d-none"); - }); - $('a[data-confirm]').click(function(ev) { var href = $(this).attr('href'); if (!$('#dataConfirmModal').length) { diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index 46b2e73..7b0ac8d 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -27,16 +27,19 @@
Фильтр:
- + + - -
diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index d104952..7d948d4 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -5,13 +5,14 @@