From 24a1276005ecaac2d95bd0ca20ad5eddd353c778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 24 May 2019 00:14:46 +0400 Subject: [PATCH] #127 autocomplete --- .../paper/controller/PaperController.java | 6 + .../ulstu/paper/model/AutoCompleteData.java | 42 ++++++ .../paper/repository/ReferenceRepository.java | 15 ++ .../ru/ulstu/paper/service/PaperService.java | 10 ++ src/main/resources/public/css/paper.css | 7 + .../resources/templates/papers/paper.html | 139 ++++++++++++------ 6 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 src/main/java/ru/ulstu/paper/model/AutoCompleteData.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e10135f..29da57d 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -13,6 +13,7 @@ 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.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; @@ -162,6 +163,11 @@ public class PaperController { return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK); } + @ModelAttribute("autocompleteData") + public AutoCompleteData getAutocompleteData() { + return paperService.getAutoCompleteData(); + } + private void filterEmptyDeadlines(PaperDto paperDto) { paperDto.setDeadlines(paperDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java new file mode 100644 index 0000000..b70a780 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java @@ -0,0 +1,42 @@ +package ru.ulstu.paper.model; + +import java.util.ArrayList; + +public class AutoCompleteData { + ArrayList authors = new ArrayList<>(); + ArrayList publicationTitles = new ArrayList<>(); + ArrayList publishers = new ArrayList<>(); + ArrayList journalOrCollectionTitles = new ArrayList<>(); + + public ArrayList getAuthors() { + return authors; + } + + public void setAuthors(ArrayList authors) { + this.authors = authors; + } + + public ArrayList getPublicationTitles() { + return publicationTitles; + } + + public void setPublicationTitles(ArrayList publicationTitles) { + this.publicationTitles = publicationTitles; + } + + public ArrayList getPublishers() { + return publishers; + } + + public void setPublishers(ArrayList publishers) { + this.publishers = publishers; + } + + public ArrayList getJournalOrCollectionTitles() { + return journalOrCollectionTitles; + } + + public void setJournalOrCollectionTitles(ArrayList journalOrCollectionTitles) { + this.journalOrCollectionTitles = journalOrCollectionTitles; + } +} diff --git a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java index 68e97d4..1d4321b 100644 --- a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java @@ -1,8 +1,23 @@ package ru.ulstu.paper.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import ru.ulstu.paper.model.Reference; +import java.util.ArrayList; + public interface ReferenceRepository extends JpaRepository { void deleteById(Integer id); + + @Query("SELECT DISTINCT r.authors FROM Reference r") + ArrayList findDistinctAuthors(); + + @Query("SELECT DISTINCT r.publicationTitle FROM Reference r") + ArrayList findDistinctPublicationTitles(); + + @Query("SELECT DISTINCT r.publisher FROM Reference r") + ArrayList findDistinctPublishers(); + + @Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''") + ArrayList findDistinctJournalOrCollectionTitles(); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 8a59486..f452c2f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -7,6 +7,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; +import ru.ulstu.paper.model.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; @@ -378,4 +379,13 @@ public class PaperService { public List findAllCompletedByType(Paper.PaperType type) { return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED); } + + public AutoCompleteData getAutoCompleteData() { + AutoCompleteData autoCompleteData = new AutoCompleteData(); + autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors()); + autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles()); + autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles()); + autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); + return autoCompleteData; + } } diff --git a/src/main/resources/public/css/paper.css b/src/main/resources/public/css/paper.css index 386c5af..b4b3f85 100644 --- a/src/main/resources/public/css/paper.css +++ b/src/main/resources/public/css/paper.css @@ -30,4 +30,11 @@ #nav-references #formattedReferencesArea { height: 150px; +} + +.ui-autocomplete { + max-height: 200px; + max-width: 400px; + overflow-y: scroll; + overflow-x: hidden; } \ No newline at end of file diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index e80fe85..2755aba 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -4,6 +4,10 @@ layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> + + + + @@ -74,54 +78,56 @@ th:field="*{comment}"> -
- - -
+
+ + +
-
- -
- -
- -
-
- -
-
- + +
+ +
+ +
+
+ +
+
+ - + aria-hidden="true"> + +
+
+

Incorrect title

-
-

Incorrect title

-
-
- + -
-
- - -

Incorrect title

-
+ +
+ + +

Incorrect title

+
@@ -215,14 +221,14 @@
@@ -235,7 +241,7 @@
@@ -248,7 +254,7 @@
@@ -519,6 +525,45 @@ } } } + + +