|
|
|
@ -12,10 +12,14 @@ import TaskContext from "../../services/task_context.js";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import utc from "dayjs/plugin/utc";
|
|
|
|
import utc from "dayjs/plugin/utc";
|
|
|
|
import eventService from "../../services/events.js";
|
|
|
|
import eventService from "../../services/events.js";
|
|
|
|
import { AttachmentRow, NoteRow, NoteType, RevisionRow } from './rows';
|
|
|
|
import { AttachmentRow, AttributeType, NoteRow, NoteType, RevisionRow } from './rows';
|
|
|
|
import BBranch from "./bbranch.js";
|
|
|
|
import BBranch from "./bbranch.js";
|
|
|
|
import BAttribute from "./battribute.js";
|
|
|
|
import BAttribute from "./battribute.js";
|
|
|
|
import { NotePojo } from '../becca-interface';
|
|
|
|
import { NotePojo } from '../becca-interface';
|
|
|
|
|
|
|
|
import searchService from "../../services/search/services/search.js";
|
|
|
|
|
|
|
|
import cloningService, { CloneResponse } from "../../services/cloning.js";
|
|
|
|
|
|
|
|
import noteService from "../../services/notes.js";
|
|
|
|
|
|
|
|
import handlers from "../../services/handlers.js";
|
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(utc);
|
|
|
|
|
|
|
|
|
|
|
|
const LABEL = 'label';
|
|
|
|
const LABEL = 'label';
|
|
|
|
@ -890,11 +894,9 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const searchService = require('../../services/search/services/search');
|
|
|
|
const result = searchService.searchFromNote(this);
|
|
|
|
const {searchResultNoteIds} = searchService.searchFromNote(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const becca = this.becca;
|
|
|
|
const becca = this.becca;
|
|
|
|
return (searchResultNoteIds as string[]) // TODO: remove cast once search is converted
|
|
|
|
return (result.searchResultNoteIds)
|
|
|
|
.map(resultNoteId => becca.notes[resultNoteId])
|
|
|
|
.map(resultNoteId => becca.notes[resultNoteId])
|
|
|
|
.filter(note => !!note);
|
|
|
|
.filter(note => !!note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1261,7 +1263,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
* @param name - attribute name
|
|
|
|
* @param name - attribute name
|
|
|
|
* @param value - attribute value (optional)
|
|
|
|
* @param value - attribute value (optional)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setAttribute(type: string, name: string, value?: string) {
|
|
|
|
setAttribute(type: AttributeType, name: string, value?: string) {
|
|
|
|
const attributes = this.getOwnedAttributes();
|
|
|
|
const attributes = this.getOwnedAttributes();
|
|
|
|
const attr = attributes.find(attr => attr.type === type && attr.name === name);
|
|
|
|
const attr = attributes.find(attr => attr.type === type && attr.name === name);
|
|
|
|
|
|
|
|
|
|
|
|
@ -1274,8 +1276,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
const BAttribute = require('./battribute');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new BAttribute({
|
|
|
|
new BAttribute({
|
|
|
|
noteId: this.noteId,
|
|
|
|
noteId: this.noteId,
|
|
|
|
type: type,
|
|
|
|
type: type,
|
|
|
|
@ -1310,9 +1310,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
* @param name - name of the attribute, not including the leading ~/#
|
|
|
|
* @param name - name of the attribute, not including the leading ~/#
|
|
|
|
* @param value - value of the attribute - text for labels, target note ID for relations; optional.
|
|
|
|
* @param value - value of the attribute - text for labels, target note ID for relations; optional.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
addAttribute(type: string, name: string, value: string = "", isInheritable: boolean = false, position: number | null = null): BAttribute {
|
|
|
|
addAttribute(type: AttributeType, name: string, value: string = "", isInheritable: boolean = false, position: number | null = null): BAttribute {
|
|
|
|
const BAttribute = require('./battribute');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new BAttribute({
|
|
|
|
return new BAttribute({
|
|
|
|
noteId: this.noteId,
|
|
|
|
noteId: this.noteId,
|
|
|
|
type: type,
|
|
|
|
type: type,
|
|
|
|
@ -1351,7 +1349,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
* @param name - attribute name
|
|
|
|
* @param name - attribute name
|
|
|
|
* @param value - attribute value (optional)
|
|
|
|
* @param value - attribute value (optional)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
toggleAttribute(type: string, enabled: boolean, name: string, value?: string) {
|
|
|
|
toggleAttribute(type: AttributeType, enabled: boolean, name: string, value?: string) {
|
|
|
|
if (enabled) {
|
|
|
|
if (enabled) {
|
|
|
|
this.setAttribute(type, name, value);
|
|
|
|
this.setAttribute(type, name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1423,8 +1421,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
searchNotesInSubtree(searchString: string) {
|
|
|
|
searchNotesInSubtree(searchString: string) {
|
|
|
|
const searchService = require('../../services/search/services/search');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return searchService.searchNotes(searchString) as BNote[];
|
|
|
|
return searchService.searchNotes(searchString) as BNote[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -1432,12 +1428,16 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
return this.searchNotesInSubtree(searchString)[0];
|
|
|
|
return this.searchNotesInSubtree(searchString)[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cloneTo(parentNoteId: string) {
|
|
|
|
cloneTo(parentNoteId: string): CloneResponse {
|
|
|
|
const cloningService = require('../../services/cloning');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const branch = this.becca.getNote(parentNoteId)?.getParentBranches()[0];
|
|
|
|
const branch = this.becca.getNote(parentNoteId)?.getParentBranches()[0];
|
|
|
|
|
|
|
|
if (!branch?.branchId) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: "Unable to find the branch ID to clone."
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cloningService.cloneNoteToBranch(this.noteId, branch?.branchId);
|
|
|
|
return cloningService.cloneNoteToBranch(this.noteId, branch.branchId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) {
|
|
|
|
isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) {
|
|
|
|
@ -1508,7 +1508,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
|
|
|
|
|
|
|
|
parentNote.setContent(fixedContent);
|
|
|
|
parentNote.setContent(fixedContent);
|
|
|
|
|
|
|
|
|
|
|
|
const noteService = require('../../services/notes');
|
|
|
|
|
|
|
|
noteService.asyncPostProcessContent(parentNote, fixedContent); // to mark an unused attachment for deletion
|
|
|
|
noteService.asyncPostProcessContent(parentNote, fixedContent); // to mark an unused attachment for deletion
|
|
|
|
|
|
|
|
|
|
|
|
this.deleteNote();
|
|
|
|
this.deleteNote();
|
|
|
|
@ -1535,7 +1534,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// needs to be run before branches and attributes are deleted and thus attached relations disappear
|
|
|
|
// needs to be run before branches and attributes are deleted and thus attached relations disappear
|
|
|
|
const handlers = require('../../services/handlers');
|
|
|
|
|
|
|
|
handlers.runAttachedRelations(this, 'runOnNoteDeletion', this);
|
|
|
|
handlers.runAttachedRelations(this, 'runOnNoteDeletion', this);
|
|
|
|
taskContext.noteDeletionHandlerTriggered = true;
|
|
|
|
taskContext.noteDeletionHandlerTriggered = true;
|
|
|
|
|
|
|
|
|
|
|
|
|