mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 20:06:08 +01:00
using ES6 modules for whole frontend SPA app
This commit is contained in:
@@ -1,105 +1,107 @@
|
||||
"use strict";
|
||||
|
||||
const recentNotes = (function() {
|
||||
const $showDialogButton = $("#recent-notes-button");
|
||||
const $dialog = $("#recent-notes-dialog");
|
||||
const $searchInput = $('#recent-notes-search-input');
|
||||
import treeService from '../note_tree.js';
|
||||
import server from '../server.js';
|
||||
import messaging from '../messaging.js';
|
||||
|
||||
// list of recent note paths
|
||||
let list = [];
|
||||
const $showDialogButton = $("#recent-notes-button");
|
||||
const $dialog = $("#recent-notes-dialog");
|
||||
const $searchInput = $('#recent-notes-search-input');
|
||||
|
||||
async function reload() {
|
||||
const result = await server.get('recent-notes');
|
||||
// list of recent note paths
|
||||
let list = [];
|
||||
|
||||
list = result.map(r => r.notePath);
|
||||
}
|
||||
async function reload() {
|
||||
const result = await server.get('recent-notes');
|
||||
|
||||
function addRecentNote(branchId, notePath) {
|
||||
setTimeout(async () => {
|
||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||
if (notePath && notePath === treeService.getCurrentNotePath()) {
|
||||
const result = await server.put('recent-notes/' + branchId + '/' + encodeURIComponent(notePath));
|
||||
list = result.map(r => r.notePath);
|
||||
}
|
||||
|
||||
list = result.map(r => r.notePath);
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
function addRecentNote(branchId, notePath) {
|
||||
setTimeout(async () => {
|
||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||
if (notePath && notePath === treeService.getCurrentNotePath()) {
|
||||
const result = await server.put('recent-notes/' + branchId + '/' + encodeURIComponent(notePath));
|
||||
|
||||
function showDialog() {
|
||||
glob.activeDialog = $dialog;
|
||||
list = result.map(r => r.notePath);
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
$dialog.dialog({
|
||||
modal: true,
|
||||
width: 800,
|
||||
height: 100,
|
||||
position: { my: "center top+100", at: "top", of: window }
|
||||
});
|
||||
function showDialog() {
|
||||
glob.activeDialog = $dialog;
|
||||
|
||||
$searchInput.val('');
|
||||
|
||||
// remove the current note
|
||||
const recNotes = list.filter(note => note !== treeService.getCurrentNotePath());
|
||||
|
||||
$searchInput.autocomplete({
|
||||
source: recNotes.map(notePath => {
|
||||
let noteTitle;
|
||||
|
||||
try {
|
||||
noteTitle = treeService.getNotePathTitle(notePath);
|
||||
}
|
||||
catch (e) {
|
||||
noteTitle = "[error - can't find note title]";
|
||||
|
||||
messaging.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
||||
}
|
||||
|
||||
return {
|
||||
label: noteTitle,
|
||||
value: notePath
|
||||
}
|
||||
}),
|
||||
minLength: 0,
|
||||
autoFocus: true,
|
||||
select: function (event, ui) {
|
||||
treeService.activateNode(ui.item.value);
|
||||
|
||||
$searchInput.autocomplete('destroy');
|
||||
$dialog.dialog('close');
|
||||
},
|
||||
focus: function (event, ui) {
|
||||
event.preventDefault();
|
||||
},
|
||||
close: function (event, ui) {
|
||||
if (event.keyCode === 27) { // escape closes dialog
|
||||
$searchInput.autocomplete('destroy');
|
||||
$dialog.dialog('close');
|
||||
}
|
||||
else {
|
||||
// keep autocomplete open
|
||||
// we're kind of abusing autocomplete to work in a way which it's not designed for
|
||||
$searchInput.autocomplete("search", "");
|
||||
}
|
||||
},
|
||||
create: () => $searchInput.autocomplete("search", ""),
|
||||
classes: {
|
||||
"ui-autocomplete": "recent-notes-autocomplete"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reload();
|
||||
|
||||
$(document).bind('keydown', 'ctrl+e', e => {
|
||||
showDialog();
|
||||
|
||||
e.preventDefault();
|
||||
$dialog.dialog({
|
||||
modal: true,
|
||||
width: 800,
|
||||
height: 100,
|
||||
position: { my: "center top+100", at: "top", of: window }
|
||||
});
|
||||
|
||||
$showDialogButton.click(showDialog);
|
||||
$searchInput.val('');
|
||||
|
||||
return {
|
||||
showDialog,
|
||||
addRecentNote,
|
||||
reload
|
||||
};
|
||||
})();
|
||||
// remove the current note
|
||||
const recNotes = list.filter(note => note !== treeService.getCurrentNotePath());
|
||||
|
||||
$searchInput.autocomplete({
|
||||
source: recNotes.map(notePath => {
|
||||
let noteTitle;
|
||||
|
||||
try {
|
||||
noteTitle = treeService.getNotePathTitle(notePath);
|
||||
}
|
||||
catch (e) {
|
||||
noteTitle = "[error - can't find note title]";
|
||||
|
||||
messaging.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
||||
}
|
||||
|
||||
return {
|
||||
label: noteTitle,
|
||||
value: notePath
|
||||
}
|
||||
}),
|
||||
minLength: 0,
|
||||
autoFocus: true,
|
||||
select: function (event, ui) {
|
||||
treeService.activateNode(ui.item.value);
|
||||
|
||||
$searchInput.autocomplete('destroy');
|
||||
$dialog.dialog('close');
|
||||
},
|
||||
focus: function (event, ui) {
|
||||
event.preventDefault();
|
||||
},
|
||||
close: function (event, ui) {
|
||||
if (event.keyCode === 27) { // escape closes dialog
|
||||
$searchInput.autocomplete('destroy');
|
||||
$dialog.dialog('close');
|
||||
}
|
||||
else {
|
||||
// keep autocomplete open
|
||||
// we're kind of abusing autocomplete to work in a way which it's not designed for
|
||||
$searchInput.autocomplete("search", "");
|
||||
}
|
||||
},
|
||||
create: () => $searchInput.autocomplete("search", ""),
|
||||
classes: {
|
||||
"ui-autocomplete": "recent-notes-autocomplete"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reload();
|
||||
|
||||
$(document).bind('keydown', 'ctrl+e', e => {
|
||||
showDialog();
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$showDialogButton.click(showDialog);
|
||||
|
||||
export default {
|
||||
showDialog,
|
||||
addRecentNote,
|
||||
reload
|
||||
};
|
||||
Reference in New Issue
Block a user