|
|
|
|
@ -31,63 +31,67 @@ export function buildNotes(notes: NoteDefinition[]) {
|
|
|
|
|
const ids = [];
|
|
|
|
|
|
|
|
|
|
for (const noteDef of notes) {
|
|
|
|
|
const note = new FNote(froca, {
|
|
|
|
|
noteId: noteDef.id ?? utils.randomString(12),
|
|
|
|
|
title: noteDef.title,
|
|
|
|
|
type: "text",
|
|
|
|
|
mime: "text/html",
|
|
|
|
|
isProtected: false,
|
|
|
|
|
blobId: ""
|
|
|
|
|
});
|
|
|
|
|
froca.notes[note.noteId] = note;
|
|
|
|
|
ids.push(note.noteId);
|
|
|
|
|
ids.push(buildNote(noteDef).noteId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildNote(noteDef: NoteDefinition) {
|
|
|
|
|
const note = new FNote(froca, {
|
|
|
|
|
noteId: noteDef.id ?? utils.randomString(12),
|
|
|
|
|
title: noteDef.title,
|
|
|
|
|
type: "text",
|
|
|
|
|
mime: "text/html",
|
|
|
|
|
isProtected: false,
|
|
|
|
|
blobId: ""
|
|
|
|
|
});
|
|
|
|
|
froca.notes[note.noteId] = note;
|
|
|
|
|
|
|
|
|
|
let position = 0;
|
|
|
|
|
for (const [ key, value ] of Object.entries(noteDef)) {
|
|
|
|
|
const attributeId = utils.randomString(12);
|
|
|
|
|
const name = key.substring(1);
|
|
|
|
|
let position = 0;
|
|
|
|
|
for (const [ key, value ] of Object.entries(noteDef)) {
|
|
|
|
|
const attributeId = utils.randomString(12);
|
|
|
|
|
const name = key.substring(1);
|
|
|
|
|
|
|
|
|
|
let attribute: FAttribute | null = null;
|
|
|
|
|
if (key.startsWith("#")) {
|
|
|
|
|
attribute = new FAttribute(froca, {
|
|
|
|
|
noteId: note.noteId,
|
|
|
|
|
attributeId,
|
|
|
|
|
type: "label",
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
position,
|
|
|
|
|
isInheritable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
let attribute: FAttribute | null = null;
|
|
|
|
|
if (key.startsWith("#")) {
|
|
|
|
|
attribute = new FAttribute(froca, {
|
|
|
|
|
noteId: note.noteId,
|
|
|
|
|
attributeId,
|
|
|
|
|
type: "label",
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
position,
|
|
|
|
|
isInheritable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key.startsWith("~")) {
|
|
|
|
|
attribute = new FAttribute(froca, {
|
|
|
|
|
noteId: note.noteId,
|
|
|
|
|
attributeId,
|
|
|
|
|
type: "relation",
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
position,
|
|
|
|
|
isInheritable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (key.startsWith("~")) {
|
|
|
|
|
attribute = new FAttribute(froca, {
|
|
|
|
|
noteId: note.noteId,
|
|
|
|
|
attributeId,
|
|
|
|
|
type: "relation",
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
position,
|
|
|
|
|
isInheritable: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!attribute) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!attribute) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
froca.attributes[attributeId] = attribute;
|
|
|
|
|
note.attributes.push(attributeId);
|
|
|
|
|
position++;
|
|
|
|
|
froca.attributes[attributeId] = attribute;
|
|
|
|
|
note.attributes.push(attributeId);
|
|
|
|
|
position++;
|
|
|
|
|
|
|
|
|
|
// Inject the attribute into the note attribute cache, since FNote.getAttribute() doesn't always work.
|
|
|
|
|
// If we add support for templates into froca, this might cause issues.
|
|
|
|
|
if (!noteAttributeCache.attributes[note.noteId]) {
|
|
|
|
|
noteAttributeCache.attributes[note.noteId] = [];
|
|
|
|
|
}
|
|
|
|
|
noteAttributeCache.attributes[note.noteId].push(attribute);
|
|
|
|
|
// Inject the attribute into the note attribute cache, since FNote.getAttribute() doesn't always work.
|
|
|
|
|
// If we add support for templates into froca, this might cause issues.
|
|
|
|
|
if (!noteAttributeCache.attributes[note.noteId]) {
|
|
|
|
|
noteAttributeCache.attributes[note.noteId] = [];
|
|
|
|
|
}
|
|
|
|
|
noteAttributeCache.attributes[note.noteId].push(attribute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
|
return note;
|
|
|
|
|
}
|
|
|
|
|
|