diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a143e3b..4c5ea91 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -56,6 +56,8 @@ public class ConferenceController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("conferences", conferenceService.findAllActiveDto()); + + conferenceService.setChartData(modelMap); // example } @GetMapping("/conference") @@ -132,6 +134,15 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "pingConference") + public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.ping(conferenceDto); + return CONFERENCE_PAGE; + } + @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 8068e04..3f77699 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -35,7 +35,7 @@ public class Conference extends BaseEntity { private String url; - private int ping; + private int ping = 0; @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index f217db9..3a8bbe1 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; @@ -19,4 +20,8 @@ public interface ConferenceRepository extends JpaRepository @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); + + @Modifying + @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") + int updatePingConference(@Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e6338fb..905c208 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.ModelMap; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; @@ -12,6 +13,7 @@ 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.ping.service.PingService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -33,17 +35,20 @@ public class ConferenceService { private final DeadlineService deadlineService; private final PaperService paperService; private final UserService userService; + private final PingService pingService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, - UserService userService) { + UserService userService, + PingService pingService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; + this.pingService = pingService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -151,7 +156,6 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); conference.getPapers().clear(); @@ -188,4 +192,36 @@ public class ConferenceService { public boolean isAttachedToConference(Integer paperId) { return conferenceRepository.isPaperAttached(paperId); } + + @Transactional + public void ping(ConferenceDto conferenceDto) throws IOException { + pingService.addPing(findOne(conferenceDto.getId())); + conferenceRepository.updatePingConference(conferenceDto.getId()); + } + + public Conference findOne(Integer conferenceId) { + return conferenceRepository.findOne(conferenceId); + } + + public void setChartData(ModelMap modelMap) { + //first, add the regional sales + Integer northeastSales = 17089; + Integer westSales = 10603; + Integer midwestSales = 5223; + Integer southSales = 10111; + + modelMap.addAttribute("northeastSales", northeastSales); + modelMap.addAttribute("southSales", southSales); + modelMap.addAttribute("midwestSales", midwestSales); + modelMap.addAttribute("westSales", westSales); + + //now add sales by lure type + List inshoreSales = Arrays.asList(4074, 3455, 4112); + List nearshoreSales = Arrays.asList(3222, 3011, 3788); + List offshoreSales = Arrays.asList(7811, 7098, 6455); + + modelMap.addAttribute("inshoreSales", inshoreSales); + modelMap.addAttribute("nearshoreSales", nearshoreSales); + modelMap.addAttribute("offshoreSales", offshoreSales); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java new file mode 100644 index 0000000..c7e4c5e --- /dev/null +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -0,0 +1,73 @@ +package ru.ulstu.ping.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@Table(name = "ping") +public class Ping extends BaseEntity { + @Temporal(value = TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + @ManyToOne(optional = false) + @JoinColumn(name = "users_id") + private User user; + + @ManyToOne(optional = false) + @JoinColumn(name = "conference_id") + private Conference conference; + + public Ping() { + } + + public Ping(Date date, User user) { + this.date = date; + this.user = user; + } + + public Ping(@JsonProperty("id") Integer id, + @JsonProperty("date") Date date, + @JsonProperty("user") User user, + @JsonProperty("conference") Conference conference) { + setId(id); + this.date = date; + this.user = user; + this.conference = conference; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } +} diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java new file mode 100644 index 0000000..ebafc0c --- /dev/null +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.ping.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.ping.model.Ping; + +public interface PingRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java new file mode 100644 index 0000000..ff0d249 --- /dev/null +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -0,0 +1,30 @@ +package ru.ulstu.ping.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.ping.model.Ping; +import ru.ulstu.ping.repository.PingRepository; +import ru.ulstu.user.service.UserService; + +import java.io.IOException; +import java.util.Date; + +@Service +public class PingService { + private final PingRepository pingRepository; + private final UserService userService; + + public PingService(PingRepository pingRepository, + UserService userService) { + this.pingRepository = pingRepository; + this.userService = userService; + } + + @Transactional + public void addPing(Conference conference) throws IOException { + Ping newPing = new Ping(new Date(), userService.getCurrentUser()); + newPing.setConference(conference); + pingRepository.save(newPing); + } +} diff --git a/src/main/resources/db/changelog-20190424_000000-schema.xml b/src/main/resources/db/changelog-20190424_000000-schema.xml new file mode 100644 index 0000000..d61b38a --- /dev/null +++ b/src/main/resources/db/changelog-20190424_000000-schema.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 6464a66..68b294a 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -33,4 +33,5 @@ + \ No newline at end of file diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index f84b188..6018b9c 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -91,6 +91,16 @@ body { border-right: 1px solid #ced4da; } +#ping-button[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#ping-button[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + #take-part[disabled=disabled] { background-color: #ced4da; border-color: #c2c5c7; @@ -178,6 +188,22 @@ body { float: right; } +.note-1 { + background-color: #bfffce; +} + +.note-2 { + background-color: #eaffb4; +} + +.note-3 { + background-color: #fff69f; +} + +.note-4 { + background-color: #ff9973; +} + @media (max-width: 1199px) and (min-width: 768px){ .paper-control { display: block!important; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 8d24ca9..2d93a5e 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -121,7 +121,11 @@ -
+
+ + +
@@ -21,8 +22,127 @@
+
+ + + +
+
\ No newline at end of file diff --git a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html index 17f4aa6..5aabef2 100644 --- a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html +++ b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html @@ -4,12 +4,13 @@ -
+
-
- -
-
+

diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html index 7e67365..7bf9d27 100644 --- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html +++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html @@ -21,7 +21,7 @@
- Новая конференцию + Новая конференция
diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 89bc9ec..65e0be6 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -107,6 +107,7 @@ } /*]]>*/ + diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 8ac81ab..9c0736d 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -256,6 +256,7 @@ var lid = $("#leaderId option:selected").val(); $("#authors [value='" + lid + "']").attr("disabled", "disabled"); } +