diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 370e996..a416345 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -54,6 +54,11 @@ public class ConferenceController { conferenceFilterDto.getYear())); } + @GetMapping("/dashboard") + public void getDashboard(ModelMap modelMap) { + modelMap.put("conferences", conferenceService.findAllActiveDto()); + } + @GetMapping("/conference") public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 99f311e..cb8a488 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -6,9 +6,14 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; import ru.ulstu.user.model.User; +import java.util.Date; 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); + @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) ORDER BY begin_date DESC") + List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); + + @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") + List findAllActive(@Param("date") Date date); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index b03e9d3..e5ce29f 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.service; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; @@ -17,6 +18,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -59,7 +61,7 @@ public class ConferenceService { public List findAll() { - return conferenceRepository.findAll(); + return conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate")); } public List findAllDto() { @@ -158,9 +160,17 @@ public class ConferenceService { } public List filter(ConferenceFilterDto conferenceFilterDto) { - return convert(conferenceRepository.filter( + return convert(conferenceRepository.findByUserAndYear( conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()), conferenceFilterDto.getYear()), ConferenceDto::new); } + + public List findAllActiveDto() { + return convert(findAllActive(), ConferenceDto::new); + } + + public List findAllActive() { + return conferenceRepository.findAllActive(new Date()); + } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 478ebcb..184f5b5 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -38,7 +38,7 @@
+ placeholder="http://"/>
diff --git a/src/main/resources/templates/conferences/actual.html b/src/main/resources/templates/conferences/dashboard.html similarity index 71% rename from src/main/resources/templates/conferences/actual.html rename to src/main/resources/templates/conferences/dashboard.html index 7e99e74..cb4f2c0 100644 --- a/src/main/resources/templates/conferences/actual.html +++ b/src/main/resources/templates/conferences/dashboard.html @@ -16,11 +16,10 @@

-
-
- - -
+
+ +
+
diff --git a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html index 080946c..17f4aa6 100644 --- a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html +++ b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html @@ -10,8 +10,14 @@
- title -

+

+

+ + title +
diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html index 45a945e..7e67365 100644 --- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html +++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html @@ -13,7 +13,7 @@