small API additions

This commit is contained in:
zadam 2020-06-14 14:30:57 +02:00
parent 16fef78344
commit fb975849b9
7 changed files with 19 additions and 5 deletions

View file

@ -27,6 +27,10 @@ class Attribute {
return this.treeCache.notes[this.noteId];
}
get targetNoteId() { // alias
return this.type === 'relation' ? this.value : undefined;
}
get jsonValue() {
try {
return JSON.parse(this.value);

View file

@ -484,6 +484,15 @@ class NoteShort {
.map(attributeId => this.treeCache.attributes[attributeId]);
}
/**
* Return note complement which is most importantly note's content
*
* @return {Promise<NoteComplement>}
*/
async getNoteComplement() {
return await this.treeCache.getNoteComplement(this.noteId);
}
get toString() {
return `Note(noteId=${this.noteId}, title=${this.title})`;
}

View file

@ -1,7 +1,6 @@
import ScriptContext from "./script_context.js";
import server from "./server.js";
import toastService from "./toast.js";
import treeCache from "./tree_cache.js";
async function getAndExecuteBundle(noteId, originEntity = null) {
const bundle = await server.get('script/bundle/' + noteId);

View file

@ -276,6 +276,9 @@ class TreeCache {
return child.parentToBranch[parentNoteId];
}
/**
* @return {Promise<NoteComplement>}
*/
async getNoteComplement(noteId) {
if (!this.noteComplementPromises[noteId]) {
this.noteComplementPromises[noteId] = server.get('notes/' + noteId).then(row => new NoteComplement(row));

View file

@ -285,7 +285,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
const relation = attrs.find(attr =>
attr.type === 'relation'
&& ['template', 'runOnNoteView', 'renderNote'].includes(attr.name)
&& ['template', 'renderNote'].includes(attr.name)
&& attr.isAffecting(this.note));
if (label || relation) {

View file

@ -29,7 +29,6 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'bookZoomLevel', isDangerous: false },
// relation names
{ type: 'relation', name: 'runOnNoteView', isDangerous: true },
{ type: 'relation', name: 'runOnNoteCreation', isDangerous: true },
{ type: 'relation', name: 'runOnNoteTitleChange', isDangerous: true },
{ type: 'relation', name: 'runOnNoteChange', isDangerous: true },