create note inline, #1237

This commit is contained in:
zadam 2020-09-21 22:08:54 +02:00
parent 0eef18a799
commit 0e795b2978
10 changed files with 46 additions and 53 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -43,8 +43,6 @@ export async function showDialog(widget) {
noteAutocompleteService.initNoteAutocomplete($autoComplete); noteAutocompleteService.initNoteAutocomplete($autoComplete);
$autoComplete.on('autocomplete:noteselected', function(event, suggestion, dataset) { $autoComplete.on('autocomplete:noteselected', function(event, suggestion, dataset) {
console.log("SELECTED", suggestion);
if (!suggestion.notePath) { if (!suggestion.notePath) {
return false; return false;
} }

View File

@ -13,7 +13,7 @@ export async function showDialog() {
utils.openDialog($dialog); utils.openDialog($dialog);
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true }) noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
.on('autocomplete:selected', function(event, suggestion, dataset) { .on('autocomplete:noteselected', function(event, suggestion, dataset) {
if (!suggestion.notePath) { if (!suggestion.notePath) {
return false; return false;
} }

View File

@ -7,6 +7,24 @@ import treeService from './tree.js';
// this key needs to have this value so it's hit by the tooltip // this key needs to have this value so it's hit by the tooltip
const SELECTED_NOTE_PATH_KEY = "data-note-path"; const SELECTED_NOTE_PATH_KEY = "data-note-path";
async function autocompleteSourceForCKEditor(queryText) {
return await new Promise((res, rej) => {
autocompleteSource(queryText, rows => {
res(rows.map(row => {
return {
action: row.action,
noteTitle: row.noteTitle,
id: '@' + row.notePathTitle,
name: row.notePathTitle,
link: '#' + row.notePath,
notePath: row.notePath,
highlightedNotePathTitle: row.highlightedNotePathTitle
}
}));
});
});
}
async function autocompleteSource(term, cb) { async function autocompleteSource(term, cb) {
const activeNoteId = appContext.tabManager.getActiveTabNoteId(); const activeNoteId = appContext.tabManager.getActiveTabNoteId();
@ -17,9 +35,9 @@ async function autocompleteSource(term, cb) {
if (term.trim().length >= 1) { if (term.trim().length >= 1) {
results = [ results = [
{ {
action: 'create', action: 'create-note',
noteTitle: term, noteTitle: term,
parentNoteId: activeNoteId, parentNoteId: activeNoteId || 'root',
highlightedNotePathTitle: `Create and link child note "${term}"` highlightedNotePathTitle: `Create and link child note "${term}"`
} }
].concat(results); ].concat(results);
@ -109,7 +127,7 @@ function initNoteAutocomplete($el, options) {
]); ]);
$el.on('autocomplete:selected', async (event, suggestion) => { $el.on('autocomplete:selected', async (event, suggestion) => {
if (suggestion.action === 'create') { if (suggestion.action === 'create-note') {
const {note} = await noteCreateService.createNote(suggestion.parentNoteId, { const {note} = await noteCreateService.createNote(suggestion.parentNoteId, {
title: suggestion.noteTitle, title: suggestion.noteTitle,
activate: false activate: false
@ -124,7 +142,7 @@ function initNoteAutocomplete($el, options) {
$el.autocomplete("close"); $el.autocomplete("close");
$el.trigger('autocomplete:noteselected', [event, suggestion]); $el.trigger('autocomplete:noteselected', [suggestion]);
}); });
$el.on('autocomplete:closed', () => { $el.on('autocomplete:closed', () => {
@ -173,6 +191,7 @@ function init() {
export default { export default {
autocompleteSource, autocompleteSource,
autocompleteSourceForCKEditor,
initNoteAutocomplete, initNoteAutocomplete,
showRecentNotes, showRecentNotes,
init init

View File

@ -278,7 +278,7 @@ export default class AttributeDetailWidget extends TabAwareWidget {
this.$inputTargetNote = this.$widget.find('.attr-input-target-note'); this.$inputTargetNote = this.$widget.find('.attr-input-target-note');
noteAutocompleteService.initNoteAutocomplete(this.$inputTargetNote) noteAutocompleteService.initNoteAutocomplete(this.$inputTargetNote)
.on('autocomplete:selected', (event, suggestion, dataset) => { .on('autocomplete:noteselected', (event, suggestion, dataset) => {
if (!suggestion.notePath) { if (!suggestion.notePath) {
return false; return false;
} }

View File

@ -6,6 +6,8 @@ import attributesParser from "../services/attribute_parser.js";
import libraryLoader from "../services/library_loader.js"; import libraryLoader from "../services/library_loader.js";
import treeCache from "../services/tree_cache.js"; import treeCache from "../services/tree_cache.js";
import attributeRenderer from "../services/attribute_renderer.js"; import attributeRenderer from "../services/attribute_renderer.js";
import noteCreateService from "../services/note_create.js";
import treeService from "../services/tree.js";
const HELP_TEXT = ` const HELP_TEXT = `
<p>To add label, just type e.g. <code>#rock</code> or if you want to add also value then e.g. <code>#year = 2020</code></p> <p>To add label, just type e.g. <code>#rock</code> or if you want to add also value then e.g. <code>#year = 2020</code></p>
@ -73,21 +75,7 @@ const mentionSetup = {
feeds: [ feeds: [
{ {
marker: '@', marker: '@',
feed: queryText => { feed: queryText => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
return new Promise((res, rej) => {
noteAutocompleteService.autocompleteSource(queryText, rows => {
res(rows.map(row => {
return {
id: '@' + row.notePathTitle,
name: row.notePathTitle,
link: '#' + row.notePath,
notePath: row.notePath,
highlightedNotePathTitle: row.highlightedNotePathTitle
}
}));
});
});
},
itemRenderer: item => { itemRenderer: item => {
const itemElement = document.createElement('button'); const itemElement = document.createElement('button');
@ -502,6 +490,15 @@ export default class AttributeEditorWidget extends TabAwareWidget {
} }
} }
async createNoteForReferenceLink(title) {
const {note} = await noteCreateService.createNote(this.noteId, {
activate: false,
title: title
});
return treeService.getSomeNotePath(note);
}
updateAttributeList(attributes) { updateAttributeList(attributes) {
this.renderOwnedAttributes(attributes, false); this.renderOwnedAttributes(attributes, false);
} }

View File

@ -154,7 +154,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
} }
}]); }]);
$input.on('autocomplete:selected', e => this.promotedAttributeChanged(e)) $input.on('autocomplete:noteselected', e => this.promotedAttributeChanged(e))
}); });
} }
else if (definition.labelType === 'number') { else if (definition.labelType === 'number') {
@ -205,7 +205,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
// no need to wait for this // no need to wait for this
noteAutocompleteService.initNoteAutocomplete($input); noteAutocompleteService.initNoteAutocomplete($input);
$input.on('autocomplete:selected', (event, suggestion, dataset) => { $input.on('autocomplete:noteselected', (event, suggestion, dataset) => {
this.promotedAttributeChanged(event); this.promotedAttributeChanged(event);
}); });

View File

@ -14,21 +14,7 @@ const mentionSetup = {
feeds: [ feeds: [
{ {
marker: '@', marker: '@',
feed: queryText => { feed: queryText => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
return new Promise((res, rej) => {
noteAutocompleteService.autocompleteSource(queryText, rows => {
res(rows.map(row => {
return {
id: '@' + row.notePathTitle,
name: row.notePathTitle,
link: '#' + row.notePath,
notePath: row.notePath,
highlightedNotePathTitle: row.highlightedNotePathTitle
}
}));
});
});
},
itemRenderer: item => { itemRenderer: item => {
const itemElement = document.createElement('button'); const itemElement = document.createElement('button');
@ -259,19 +245,12 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
} }
async createNoteForReferenceLink(title) { async createNoteForReferenceLink(title) {
const {parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(this.notePath); const {note} = await noteCreateService.createNote(this.noteId, {
const {note} = await noteCreateService.createNote(parentNoteId, {
activate: false, activate: false,
title: title, title: title
target: 'after',
targetBranchId: await treeCache.getBranchId(parentNoteId, this.noteId),
type: 'text'
}); });
const notePath = treeService.getSomeNotePath(note); return treeService.getSomeNotePath(note);
return notePath;
} }
async refreshIncludedNoteEvent({noteId}) { async refreshIncludedNoteEvent({noteId}) {

View File

@ -22,7 +22,7 @@ export default class EmptyTypeWidget extends TypeWidget {
this.$autoComplete = this.$widget.find(".note-autocomplete"); this.$autoComplete = this.$widget.find(".note-autocomplete");
noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true }) noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true })
.on('autocomplete:selected', function(event, suggestion, dataset) { .on('autocomplete:noteselected', function(event, suggestion, dataset) {
if (!suggestion.notePath) { if (!suggestion.notePath) {
return false; return false;
} }