#127 autocomplete
This commit is contained in:
parent
512a805e8c
commit
24a1276005
@ -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()))
|
||||
|
42
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
42
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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<Reference, Integer> {
|
||||
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();
|
||||
}
|
||||
|
@ -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<Paper> 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;
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,11 @@
|
||||
|
||||
#nav-references #formattedReferencesArea {
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.ui-autocomplete {
|
||||
max-height: 200px;
|
||||
max-width: 400px;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
}
|
@ -4,6 +4,10 @@
|
||||
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<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>
|
||||
<body>
|
||||
|
||||
@ -74,54 +78,56 @@
|
||||
th:field="*{comment}"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title">Ссылка на сайт конференции:</label>
|
||||
<input class="form-control" id="url" type="text"
|
||||
placeholder="Url"
|
||||
th:field="*{url}"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="title">Ссылка на сайт конференции:</label>
|
||||
<input class="form-control" id="url" type="text"
|
||||
placeholder="Url"
|
||||
th:field="*{url}"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Дедлайны:</label>
|
||||
<div class="row" th:each="deadline, rowStat : *{deadlines}">
|
||||
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
||||
<div class="col-6">
|
||||
<input type="date" class="form-control" name="deadline"
|
||||
th:field="*{deadlines[__${rowStat.index}__].date}"/>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<input class="form-control" type="text" placeholder="Описание"
|
||||
th:field="*{deadlines[__${rowStat.index}__].description}"/>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<a class="btn btn-danger float-right"
|
||||
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
|
||||
<div class="form-group">
|
||||
<label>Дедлайны:</label>
|
||||
<div class="row" th:each="deadline, rowStat : *{deadlines}">
|
||||
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
||||
<div class="col-6">
|
||||
<input type="date" class="form-control" name="deadline"
|
||||
th:field="*{deadlines[__${rowStat.index}__].date}"/>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<input class="form-control" type="text" placeholder="Описание"
|
||||
th:field="*{deadlines[__${rowStat.index}__].description}"/>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<a class="btn btn-danger float-right"
|
||||
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
|
||||
$('#deadlines${rowStat.index}\\.date').val('');
|
||||
$('#addDeadline').click();|"><span
|
||||
aria-hidden="true"><i class="fa fa-times"/></span>
|
||||
</a>
|
||||
aria-hidden="true"><i class="fa fa-times"/></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
</div>
|
||||
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary"
|
||||
value="Добавить
|
||||
<div class="form-group">
|
||||
<input type="submit" id="addDeadline" name="addDeadline"
|
||||
class="btn btn-primary"
|
||||
value="Добавить
|
||||
дедлайн"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Авторы:</label>
|
||||
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
||||
title="-- Выберите авторов --"
|
||||
th:field="*{authorIds}">
|
||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||
th:text="${author.lastName}">Status
|
||||
</option>
|
||||
</select>
|
||||
<p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Авторы:</label>
|
||||
<select class="selectpicker form-control" multiple="true"
|
||||
data-live-search="true"
|
||||
title="-- Выберите авторов --"
|
||||
th:field="*{authorIds}">
|
||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||
th:text="${author.lastName}">Status
|
||||
</option>
|
||||
</select>
|
||||
<p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
|
||||
class="alert alert-danger">Incorrect title</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group files-list" id="files-list">
|
||||
<label>Файлы:</label>
|
||||
@ -215,14 +221,14 @@
|
||||
<div class="form-group col-12">
|
||||
<label class="col-4">Авторы:</label>
|
||||
<input type="text"
|
||||
class="form-control col-7"
|
||||
class="form-control col-7 autocomplete author"
|
||||
name="authors"
|
||||
th:field="*{references[__${rowStat.index}__].authors}"/>
|
||||
</div>
|
||||
<div class="form-group col-12">
|
||||
<label class="col-4 ">Название публикации:</label>
|
||||
<input type="text"
|
||||
class="form-control col-7"
|
||||
class="form-control col-7 autocomplete publicationTitle"
|
||||
name="publicationTitle"
|
||||
th:field="*{references[__${rowStat.index}__].publicationTitle}"/>
|
||||
</div>
|
||||
@ -235,7 +241,7 @@
|
||||
<div class="form-group col-12">
|
||||
<label class="col-4">Издательство:</label>
|
||||
<input type="text"
|
||||
class="form-control col-7"
|
||||
class="form-control col-7 autocomplete publisher"
|
||||
name="publisher"
|
||||
th:field="*{references[__${rowStat.index}__].publisher}"/>
|
||||
</div>
|
||||
@ -248,7 +254,7 @@
|
||||
<label class="col-4">Название журнала или сборника статей
|
||||
конференции:</label>
|
||||
<input type="text"
|
||||
class="form-control col-7"
|
||||
class="form-control col-7 autocomplete journalOrCollectionTitle"
|
||||
name="journalOrCollectionTitle"
|
||||
th:field="*{references[__${rowStat.index}__].journalOrCollectionTitle}"/>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user