mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
porting autocomplete to algolia, WIP, #203
This commit is contained in:
parent
57e9850ca6
commit
3c23d7085e
@ -8,6 +8,8 @@ const $autoComplete = $("#jump-to-note-autocomplete");
|
|||||||
const $showInFullTextButton = $("#show-in-full-text-button");
|
const $showInFullTextButton = $("#show-in-full-text-button");
|
||||||
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
|
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
|
||||||
|
|
||||||
|
$dialog.on("shown.bs.modal", e => $autoComplete.focus());
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
@ -15,12 +17,25 @@ async function showDialog() {
|
|||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
|
|
||||||
await $autoComplete.autocomplete({
|
$autoComplete.autocomplete({
|
||||||
|
appendTo: document.querySelector('body'),
|
||||||
|
hint: false,
|
||||||
|
autoselect: true,
|
||||||
|
openOnFocus: true
|
||||||
|
}, [
|
||||||
|
{
|
||||||
source: noteautocompleteService.autocompleteSource,
|
source: noteautocompleteService.autocompleteSource,
|
||||||
focus: event => event.preventDefault(),
|
displayKey: 'label',
|
||||||
minLength: 0,
|
templates: {
|
||||||
autoFocus: true,
|
suggestion: function(suggestion) {
|
||||||
select: function (event, ui) {
|
return suggestion.label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).on('autocomplete:selected', function(event, suggestion, dataset) {
|
||||||
|
console.log("selected: ", event, suggestion, dataset);
|
||||||
|
return;
|
||||||
|
|
||||||
if (ui.item.value === 'No results') {
|
if (ui.item.value === 'No results') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -30,10 +45,27 @@ async function showDialog() {
|
|||||||
treeService.activateNote(notePath);
|
treeService.activateNote(notePath);
|
||||||
|
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
showRecentNotes();
|
// await $autoComplete.autocomplete({
|
||||||
|
// source: noteautocompleteService.autocompleteSource,
|
||||||
|
// focus: event => event.preventDefault(),
|
||||||
|
// minLength: 0,
|
||||||
|
// autoFocus: true,
|
||||||
|
// select: function (event, ui) {
|
||||||
|
// if (ui.item.value === 'No results') {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const notePath = linkService.getNotePathFromLabel(ui.item.value);
|
||||||
|
//
|
||||||
|
// treeService.activateNote(notePath);
|
||||||
|
//
|
||||||
|
// $dialog.modal('hide');
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
//showRecentNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showInFullText(e) {
|
function showInFullText(e) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import noteDetailService from "./note_detail.js";
|
import noteDetailService from "./note_detail.js";
|
||||||
|
|
||||||
async function autocompleteSource(request, response) {
|
async function autocompleteSource(term, cb) {
|
||||||
const result = await server.get('autocomplete'
|
const result = await server.get('autocomplete'
|
||||||
+ '?query=' + encodeURIComponent(request.term)
|
+ '?query=' + encodeURIComponent(term)
|
||||||
+ '¤tNoteId=' + noteDetailService.getCurrentNoteId());
|
+ '¤tNoteId=' + noteDetailService.getCurrentNoteId());
|
||||||
|
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
response(result.map(row => {
|
cb(result.map(row => {
|
||||||
return {
|
return {
|
||||||
label: row.label,
|
label: row.label,
|
||||||
value: row.label + ' (' + row.value + ')'
|
value: row.label + ' (' + row.value + ')'
|
||||||
@ -15,7 +15,7 @@ async function autocompleteSource(request, response) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response([{
|
cb([{
|
||||||
label: "No results",
|
label: "No results",
|
||||||
value: "No results"
|
value: "No results"
|
||||||
}]);
|
}]);
|
||||||
|
7
src/public/libraries/autocomplete.jquery.min.js
vendored
Normal file
7
src/public/libraries/autocomplete.jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -540,3 +540,34 @@ table.promoted-attributes-in-tooltip td, table.promoted-attributes-in-tooltip th
|
|||||||
.tooltip.show {
|
.tooltip.show {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.algolia-autocomplete {
|
||||||
|
width: calc(100% - 30px);
|
||||||
|
z-index: 2000 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.algolia-autocomplete .aa-input, .algolia-autocomplete .aa-hint {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.algolia-autocomplete .aa-dropdown-menu {
|
||||||
|
width: 100%;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #999;
|
||||||
|
border-top: none;
|
||||||
|
z-index: 2000 !important;
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 5px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor {
|
||||||
|
background-color: #B2D7FF;
|
||||||
|
}
|
||||||
|
@ -348,6 +348,8 @@
|
|||||||
|
|
||||||
<script src="/libraries/knockout.min.js"></script>
|
<script src="/libraries/knockout.min.js"></script>
|
||||||
|
|
||||||
|
<script src="/libraries/autocomplete.jquery.min.js"></script>
|
||||||
|
|
||||||
<link href="/stylesheets/style.css" rel="stylesheet">
|
<link href="/stylesheets/style.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="/javascripts/services/bootstrap.js" type="module"></script>
|
<script src="/javascripts/services/bootstrap.js" type="module"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user