#127 autocomplete

This commit is contained in:
Семенова Мария 2019-05-24 00:14:46 +04:00
parent 512a805e8c
commit 24a1276005
6 changed files with 172 additions and 47 deletions

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceService;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.paper.model.AutoCompleteData;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.model.PaperListDto;
@ -162,6 +163,11 @@ public class PaperController {
return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK); return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK);
} }
@ModelAttribute("autocompleteData")
public AutoCompleteData getAutocompleteData() {
return paperService.getAutoCompleteData();
}
private void filterEmptyDeadlines(PaperDto paperDto) { private void filterEmptyDeadlines(PaperDto paperDto) {
paperDto.setDeadlines(paperDto.getDeadlines().stream() paperDto.setDeadlines(paperDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -0,0 +1,42 @@
package ru.ulstu.paper.model;
import java.util.ArrayList;
public class AutoCompleteData {
ArrayList<String> authors = new ArrayList<>();
ArrayList<String> publicationTitles = new ArrayList<>();
ArrayList<String> publishers = new ArrayList<>();
ArrayList<String> journalOrCollectionTitles = new ArrayList<>();
public ArrayList<String> getAuthors() {
return authors;
}
public void setAuthors(ArrayList<String> authors) {
this.authors = authors;
}
public ArrayList<String> getPublicationTitles() {
return publicationTitles;
}
public void setPublicationTitles(ArrayList<String> publicationTitles) {
this.publicationTitles = publicationTitles;
}
public ArrayList<String> getPublishers() {
return publishers;
}
public void setPublishers(ArrayList<String> publishers) {
this.publishers = publishers;
}
public ArrayList<String> getJournalOrCollectionTitles() {
return journalOrCollectionTitles;
}
public void setJournalOrCollectionTitles(ArrayList<String> journalOrCollectionTitles) {
this.journalOrCollectionTitles = journalOrCollectionTitles;
}
}

View File

@ -1,8 +1,23 @@
package ru.ulstu.paper.repository; package ru.ulstu.paper.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.Reference;
import java.util.ArrayList;
public interface ReferenceRepository extends JpaRepository<Reference, Integer> { public interface ReferenceRepository extends JpaRepository<Reference, Integer> {
void deleteById(Integer id); void deleteById(Integer id);
@Query("SELECT DISTINCT r.authors FROM Reference r")
ArrayList<String> findDistinctAuthors();
@Query("SELECT DISTINCT r.publicationTitle FROM Reference r")
ArrayList<String> findDistinctPublicationTitles();
@Query("SELECT DISTINCT r.publisher FROM Reference r")
ArrayList<String> findDistinctPublishers();
@Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''")
ArrayList<String> findDistinctJournalOrCollectionTitles();
} }

View File

@ -7,6 +7,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService; import ru.ulstu.file.service.FileService;
import ru.ulstu.paper.model.AutoCompleteData;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.model.PaperListDto;
@ -378,4 +379,13 @@ public class PaperService {
public List<Paper> findAllCompletedByType(Paper.PaperType type) { public List<Paper> findAllCompletedByType(Paper.PaperType type) {
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED); 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;
}
} }

View File

@ -31,3 +31,10 @@
#nav-references #formattedReferencesArea { #nav-references #formattedReferencesArea {
height: 150px; height: 150px;
} }
.ui-autocomplete {
max-height: 200px;
max-width: 400px;
overflow-y: scroll;
overflow-x: hidden;
}

View File

@ -4,6 +4,10 @@
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head> <head>
<link rel="stylesheet" href="../css/paper.css"/> <link rel="stylesheet" href="../css/paper.css"/>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head> </head>
<body> <body>
@ -106,13 +110,15 @@
class="alert alert-danger">Incorrect title</p> class="alert alert-danger">Incorrect title</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary" <input type="submit" id="addDeadline" name="addDeadline"
class="btn btn-primary"
value="Добавить value="Добавить
дедлайн"/> дедлайн"/>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Авторы:</label> <label>Авторы:</label>
<select class="selectpicker form-control" multiple="true" data-live-search="true" <select class="selectpicker form-control" multiple="true"
data-live-search="true"
title="-- Выберите авторов --" title="-- Выберите авторов --"
th:field="*{authorIds}"> th:field="*{authorIds}">
<option th:each="author: ${allAuthors}" th:value="${author.id}" <option th:each="author: ${allAuthors}" th:value="${author.id}"
@ -215,14 +221,14 @@
<div class="form-group col-12"> <div class="form-group col-12">
<label class="col-4">Авторы:</label> <label class="col-4">Авторы:</label>
<input type="text" <input type="text"
class="form-control col-7" class="form-control col-7 autocomplete author"
name="authors" name="authors"
th:field="*{references[__${rowStat.index}__].authors}"/> th:field="*{references[__${rowStat.index}__].authors}"/>
</div> </div>
<div class="form-group col-12"> <div class="form-group col-12">
<label class="col-4 ">Название публикации:</label> <label class="col-4 ">Название публикации:</label>
<input type="text" <input type="text"
class="form-control col-7" class="form-control col-7 autocomplete publicationTitle"
name="publicationTitle" name="publicationTitle"
th:field="*{references[__${rowStat.index}__].publicationTitle}"/> th:field="*{references[__${rowStat.index}__].publicationTitle}"/>
</div> </div>
@ -235,7 +241,7 @@
<div class="form-group col-12"> <div class="form-group col-12">
<label class="col-4">Издательство:</label> <label class="col-4">Издательство:</label>
<input type="text" <input type="text"
class="form-control col-7" class="form-control col-7 autocomplete publisher"
name="publisher" name="publisher"
th:field="*{references[__${rowStat.index}__].publisher}"/> th:field="*{references[__${rowStat.index}__].publisher}"/>
</div> </div>
@ -248,7 +254,7 @@
<label class="col-4">Название журнала или сборника статей <label class="col-4">Название журнала или сборника статей
конференции:</label> конференции:</label>
<input type="text" <input type="text"
class="form-control col-7" class="form-control col-7 autocomplete journalOrCollectionTitle"
name="journalOrCollectionTitle" name="journalOrCollectionTitle"
th:field="*{references[__${rowStat.index}__].journalOrCollectionTitle}"/> th:field="*{references[__${rowStat.index}__].journalOrCollectionTitle}"/>
</div> </div>
@ -519,6 +525,45 @@
} }
} }
} }
</script>
<script th:inline="javascript">
/*<![CDATA[*/
var autoCompleteData = /*[[${autocompleteData}]]*/ 'default';
console.log(autoCompleteData);
$(".autocomplete.author").autocomplete({
source: autoCompleteData.authors,
minLength: 0,
}).focus(function () {
$(this).autocomplete("search");
});
$(".autocomplete.publicationTitle").autocomplete({
source: autoCompleteData.publicationTitles,
minLength: 0,
}).focus(function () {
$(this).autocomplete("search");
});
$(".autocomplete.publisher").autocomplete({
source: autoCompleteData.publishers,
minLength: 0,
}).focus(function () {
$(this).autocomplete("search");
});
$(".autocomplete.journalOrCollectionTitle").autocomplete({
source: autoCompleteData.journalOrCollectionTitles,
minLength: 0,
}).focus(function () {
$(this).autocomplete("search");
});
/*]]>*/
</script> </script>
</div> </div>