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);
$autoComplete.on('autocomplete:noteselected', function(event, suggestion, dataset) {
console.log("SELECTED", suggestion);
if (!suggestion.notePath) {
return false;
}

View file

@ -13,7 +13,7 @@ export async function showDialog() {
utils.openDialog($dialog);
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
.on('autocomplete:selected', function(event, suggestion, dataset) {
.on('autocomplete:noteselected', function(event, suggestion, dataset) {
if (!suggestion.notePath) {
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
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) {
const activeNoteId = appContext.tabManager.getActiveTabNoteId();
@ -17,9 +35,9 @@ async function autocompleteSource(term, cb) {
if (term.trim().length >= 1) {
results = [
{
action: 'create',
action: 'create-note',
noteTitle: term,
parentNoteId: activeNoteId,
parentNoteId: activeNoteId || 'root',
highlightedNotePathTitle: `Create and link child note "${term}"`
}
].concat(results);
@ -109,7 +127,7 @@ function initNoteAutocomplete($el, options) {
]);
$el.on('autocomplete:selected', async (event, suggestion) => {
if (suggestion.action === 'create') {
if (suggestion.action === 'create-note') {
const {note} = await noteCreateService.createNote(suggestion.parentNoteId, {
title: suggestion.noteTitle,
activate: false
@ -124,7 +142,7 @@ function initNoteAutocomplete($el, options) {
$el.autocomplete("close");
$el.trigger('autocomplete:noteselected', [event, suggestion]);
$el.trigger('autocomplete:noteselected', [suggestion]);
});
$el.on('autocomplete:closed', () => {
@ -173,6 +191,7 @@ function init() {
export default {
autocompleteSource,
autocompleteSourceForCKEditor,
initNoteAutocomplete,
showRecentNotes,
init

View file

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

View file

@ -6,6 +6,8 @@ import attributesParser from "../services/attribute_parser.js";
import libraryLoader from "../services/library_loader.js";
import treeCache from "../services/tree_cache.js";
import attributeRenderer from "../services/attribute_renderer.js";
import noteCreateService from "../services/note_create.js";
import treeService from "../services/tree.js";
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>
@ -73,21 +75,7 @@ const mentionSetup = {
feeds: [
{
marker: '@',
feed: 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
}
}));
});
});
},
feed: queryText => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
itemRenderer: item => {
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) {
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') {
@ -205,7 +205,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
// no need to wait for this
noteAutocompleteService.initNoteAutocomplete($input);
$input.on('autocomplete:selected', (event, suggestion, dataset) => {
$input.on('autocomplete:noteselected', (event, suggestion, dataset) => {
this.promotedAttributeChanged(event);
});

View file

@ -14,21 +14,7 @@ const mentionSetup = {
feeds: [
{
marker: '@',
feed: 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
}
}));
});
});
},
feed: queryText => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
itemRenderer: item => {
const itemElement = document.createElement('button');
@ -259,19 +245,12 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
}
async createNoteForReferenceLink(title) {
const {parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(this.notePath);
const {note} = await noteCreateService.createNote(parentNoteId, {
const {note} = await noteCreateService.createNote(this.noteId, {
activate: false,
title: title,
target: 'after',
targetBranchId: await treeCache.getBranchId(parentNoteId, this.noteId),
type: 'text'
title: title
});
const notePath = treeService.getSomeNotePath(note);
return notePath;
return treeService.getSomeNotePath(note);
}
async refreshIncludedNoteEvent({noteId}) {

View file

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