From 2d78753b069dd4850375849d50dd0a15fc3451b0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 17 Nov 2018 11:56:52 +0400 Subject: [PATCH] show events --- .../timeline/controller/EventController.java | 5 ++ .../timeline/repository/EventRepository.java | 2 +- .../ulstu/timeline/service/EventService.java | 4 + src/main/resources/public/js/timeline.js | 27 ++++++ src/main/resources/templates/timeline.html | 87 ++----------------- 5 files changed, 44 insertions(+), 81 deletions(-) create mode 100644 src/main/resources/public/js/timeline.js diff --git a/src/main/java/ru/ulstu/timeline/controller/EventController.java b/src/main/java/ru/ulstu/timeline/controller/EventController.java index b2e4a23..77cb118 100644 --- a/src/main/java/ru/ulstu/timeline/controller/EventController.java +++ b/src/main/java/ru/ulstu/timeline/controller/EventController.java @@ -34,6 +34,11 @@ public class EventController { return new Response<>(eventService.findAllDto()); } + @GetMapping("/future") + public Response> getFutureEvents() { + return new Response<>(eventService.findAllFutureDto()); + } + @PostMapping public Response createEvent(@RequestBody @Valid EventDto timelineDto) { return new Response(eventService.create(timelineDto)); diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index 2829261..4848e12 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -10,6 +10,6 @@ public interface EventRepository extends JpaRepository { @Query("SELECT e FROM Event e WHERE e.executeDate = CURRENT_DATE") List findByCurrentDate(); - @Query("SELECT e FROM Event e WHERE e.executeDate > CURRENT_DATE") + @Query("SELECT e FROM Event e WHERE e.executeDate > CURRENT_DATE ORDER BY e.executeDate") List findAllFuture(); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 602e7aa..da32474 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -90,4 +90,8 @@ public class EventService { public List findAllFuture() { return eventRepository.findAllFuture(); } + + public List findAllFutureDto() { + return convert(findAllFuture(), EventDto::new); + } } diff --git a/src/main/resources/public/js/timeline.js b/src/main/resources/public/js/timeline.js new file mode 100644 index 0000000..6f2b52f --- /dev/null +++ b/src/main/resources/public/js/timeline.js @@ -0,0 +1,27 @@ +var urlTimeline = "/api/1.0/events/future"; + +function showTimeline(timelineElement) { + $(timelineElement).empty(); + getFromRest(urlTimeline, function (eventList) { + eventList.forEach(function (event, index) { + var date = new Date(event.executeDate); + var formated_date = date.toLocaleDateString(); + + $(timelineElement).append("
  • " + + "


    " + formated_date + "

    " + + "
    " + + "
    " + + "

    " + event.title + "

    " + + "
    " + + "
    " + + "

    " + event.description + "

    " + + "
    " + + "
    " + + "
  • "); + }); + }); +} + +function eventInverted(index) { + return index % 2 == 1 ? "timeline-inverted" : ""; +} \ No newline at end of file diff --git a/src/main/resources/templates/timeline.html b/src/main/resources/templates/timeline.html index 1109686..5eda9f3 100644 --- a/src/main/resources/templates/timeline.html +++ b/src/main/resources/templates/timeline.html @@ -17,94 +17,21 @@
      -
    • -
      -

      -
      - 02.07.2018 -

      -
      -
      -
      -

      Уход в отпуск

      -
      -
      -

      Наконец-то!

      -
      -
      -
    • -
    • -
      - -
      -
      -
      -

      March 2011

      -

      An Agency is Born

      -
      -
      -

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt - ut - voluptatum eius sapiente, totam reiciendis temporibus qui quibusdam, recusandae - sit - vero unde, sed, incidunt et ea quo dolore laudantium consectetur!

      -
      -
      -
    • -
    • -
      - -
      -
      -
      -

      December 2012

      -

      Transition to Full Service

      -
      -
      -

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt - ut - voluptatum eius sapiente, totam reiciendis temporibus qui quibusdam, recusandae - sit - vero unde, sed, incidunt et ea quo dolore laudantium consectetur!

      -
      -
      -
    • -
    • -
      - -
      -
      -
      -

      July 2014

      -

      Phase Two Expansion

      -
      -
      -

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt - ut - voluptatum eius sapiente, totam reiciendis temporibus qui quibusdam, recusandae - sit - vero unde, sed, incidunt et ea quo dolore laudantium consectetur!

      -
      -
      -
    • -
    • -
      -

      Be Part -
      Of Our -
      Story!

      -
      -
    • +
    - - - + +