added "include note" widget to text notes, WIP

This commit is contained in:
zadam
2019-12-29 23:46:40 +01:00
parent 64f32ba38f
commit 2f711a12f8
10 changed files with 246 additions and 6 deletions

View File

@@ -41,6 +41,7 @@ window.glob.isMobile = utils.isMobile;
window.glob.getActiveNode = treeService.getActiveNode;
window.glob.getHeaders = server.getHeaders;
window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());
window.glob.showIncludeNoteDialog = cb => import('./dialogs/include_note.js').then(d => d.showDialog(cb));
// this is required by CKEditor when uploading images
window.glob.noteChanged = noteDetailService.noteChanged;
window.glob.refreshTree = treeService.reload;

View File

@@ -0,0 +1,40 @@
import treeUtils from '../services/tree_utils.js';
import noteAutocompleteService from '../services/note_autocomplete.js';
import utils from "../services/utils.js";
const $dialog = $("#include-note-dialog");
const $form = $("#include-note-form");
const $autoComplete = $("#include-note-autocomplete");
let callback = null;
export async function showDialog(cb) {
callback = cb;
utils.closeActiveDialog();
glob.activeDialog = $dialog;
$autoComplete.val('');
$dialog.modal();
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true });
noteAutocompleteService.showRecentNotes($autoComplete);
}
$form.on('submit', () => {
const notePath = $autoComplete.getSelectedPath();
if (notePath) {
$dialog.modal('hide');
if (callback) {
callback(treeUtils.getNoteIdFromNotePath(notePath));
}
}
else {
console.error("No noteId to include.");
}
return false;
});

View File

@@ -61,7 +61,7 @@ class NoteDetailText {
else {
window.open(src, '_blank');
}
})
});
}
async render() {
@@ -94,6 +94,11 @@ class NoteDetailText {
}
});
if (glob.isDev) {
await import('../../libraries/ckeditor/inspector.js');
CKEditorInspector.attach(this.textEditor);
}
this.onNoteChange(() => this.ctx.noteChanged());
}
}

View File

@@ -6,6 +6,7 @@ const attributeService = require('../services/attributes');
const config = require('../services/config');
const optionService = require('../services/options');
const log = require('../services/log');
const env = require('../services/env');
async function index(req, res) {
const options = await optionService.getOptionsMap();
@@ -24,7 +25,8 @@ async function index(req, res) {
sourceId: await sourceIdService.generateSourceId(),
maxSyncIdAtLoad: await sql.getValue("SELECT MAX(id) FROM sync"),
instanceName: config.General ? config.General.instanceName : null,
appCssNoteIds: await getAppCssNoteIds()
appCssNoteIds: await getAppCssNoteIds(),
isDev: env.isDev()
});
}

View File

@@ -210,6 +210,7 @@
<% include dialogs/clone_to.ejs %>
<% include dialogs/move_to.ejs %>
<% include dialogs/backend_log.ejs %>
<% include dialogs/include_note.ejs %>
</div>
<script type="text/javascript">
@@ -220,7 +221,8 @@
sourceId: '<%= sourceId %>',
maxSyncIdAtLoad: <%= maxSyncIdAtLoad %>,
instanceName: '<%= instanceName %>',
csrfToken: '<%= csrfToken %>'
csrfToken: '<%= csrfToken %>',
isDev: '<%= isDev %>'
};
window.appCssNoteIds = <%- JSON.stringify(appCssNoteIds) %>;
</script>

View File

@@ -0,0 +1,25 @@
<div id="include-note-dialog" class="modal mx-auto" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Include note</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="include-note-form">
<div class="modal-body">
<div class="form-group">
<label for="include-note-autocomplete">Note</label>
<div class="input-group">
<input id="include-note-autocomplete" class="form-control" placeholder="search for note by its name">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Include note <kbd>enter</kbd></button>
</div>
</form>
</div>
</div>
</div>

View File

@@ -97,7 +97,8 @@
sourceId: '<%= sourceId %>',
maxSyncIdAtLoad: <%= maxSyncIdAtLoad %>,
instanceName: '<%= instanceName %>',
csrfToken: '<%= csrfToken %>'
csrfToken: '<%= csrfToken %>',
isDev: '<%= isDev %>'
};
</script>