mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Port services/bulk_actions
This commit is contained in:
parent
6cedad07e5
commit
6df09cb157
@ -222,7 +222,7 @@ class BAttribute extends AbstractBeccaEntity<BAttribute> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createClone(type: AttributeType, name: string, value: string, isInheritable: boolean) {
|
createClone(type: AttributeType, name: string, value: string, isInheritable?: boolean) {
|
||||||
return new BAttribute({
|
return new BAttribute({
|
||||||
noteId: this.noteId,
|
noteId: this.noteId,
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const becca = require('../../becca/becca');
|
const becca = require('../../becca/becca');
|
||||||
const bulkActionService = require('../../services/bulk_actions.js');
|
const bulkActionService = require('../../services/bulk_actions');
|
||||||
|
|
||||||
function execute(req) {
|
function execute(req) {
|
||||||
const {noteIds, includeDescendants} = req.body;
|
const {noteIds, includeDescendants} = req.body;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const becca = require('../../becca/becca');
|
const becca = require('../../becca/becca');
|
||||||
const SearchContext = require('../../services/search/search_context');
|
const SearchContext = require('../../services/search/search_context');
|
||||||
const searchService = require('../../services/search/services/search');
|
const searchService = require('../../services/search/services/search');
|
||||||
const bulkActionService = require('../../services/bulk_actions.js');
|
const bulkActionService = require('../../services/bulk_actions');
|
||||||
const cls = require('../../services/cls');
|
const cls = require('../../services/cls');
|
||||||
const {formatAttrForSearch} = require('../../services/attribute_formatter');
|
const {formatAttrForSearch} = require('../../services/attribute_formatter');
|
||||||
const ValidationError = require('../../errors/validation_error');
|
const ValidationError = require('../../errors/validation_error');
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
const log = require('./log');
|
import log = require('./log');
|
||||||
const revisionService = require('./revisions');
|
import becca = require('../becca/becca');
|
||||||
const becca = require('../becca/becca');
|
import cloningService = require('./cloning');
|
||||||
const cloningService = require('./cloning');
|
import branchService = require('./branches');
|
||||||
const branchService = require('./branches');
|
import utils = require('./utils');
|
||||||
const utils = require('./utils');
|
import eraseService = require("./erase");
|
||||||
const eraseService = require("./erase");
|
import BNote = require('../becca/entities/bnote');
|
||||||
|
|
||||||
const ACTION_HANDLERS = {
|
interface Action {
|
||||||
|
labelName: string;
|
||||||
|
labelValue: string;
|
||||||
|
oldLabelName: string;
|
||||||
|
newLabelName: string;
|
||||||
|
|
||||||
|
|
||||||
|
relationName: string;
|
||||||
|
oldRelationName: string;
|
||||||
|
newRelationName: string;
|
||||||
|
|
||||||
|
targetNoteId: string;
|
||||||
|
targetParentNoteId: string;
|
||||||
|
newTitle: string;
|
||||||
|
script: string;
|
||||||
|
}
|
||||||
|
type ActionHandler = (action: Action, note: BNote) => void;
|
||||||
|
|
||||||
|
const ACTION_HANDLERS: Record<string, ActionHandler> = {
|
||||||
addLabel: (action, note) => {
|
addLabel: (action, note) => {
|
||||||
note.addLabel(action.labelName, action.labelValue);
|
note.addLabel(action.labelName, action.labelValue);
|
||||||
},
|
},
|
||||||
@ -19,7 +37,10 @@ const ACTION_HANDLERS = {
|
|||||||
note.deleteNote(deleteId);
|
note.deleteNote(deleteId);
|
||||||
},
|
},
|
||||||
deleteRevisions: (action, note) => {
|
deleteRevisions: (action, note) => {
|
||||||
eraseService.eraseRevisions(note.getRevisions().map(rev => rev.revisionId));
|
const revisionIds = note.getRevisions()
|
||||||
|
.map(rev => rev.revisionId)
|
||||||
|
.filter((rev) => !!rev) as string[];
|
||||||
|
eraseService.eraseRevisions(revisionIds);
|
||||||
},
|
},
|
||||||
deleteLabel: (action, note) => {
|
deleteLabel: (action, note) => {
|
||||||
for (const label of note.getOwnedLabels(action.labelName)) {
|
for (const label of note.getOwnedLabels(action.labelName)) {
|
||||||
@ -107,7 +128,7 @@ const ACTION_HANDLERS = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getActions(note) {
|
function getActions(note: BNote) {
|
||||||
return note.getLabels('action')
|
return note.getLabels('action')
|
||||||
.map(actionLabel => {
|
.map(actionLabel => {
|
||||||
let action;
|
let action;
|
||||||
@ -129,7 +150,7 @@ function getActions(note) {
|
|||||||
.filter(a => !!a);
|
.filter(a => !!a);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeActions(note, searchResultNoteIds) {
|
function executeActions(note: BNote, searchResultNoteIds: string[]) {
|
||||||
const actions = getActions(note);
|
const actions = getActions(note);
|
||||||
|
|
||||||
for (const resultNoteId of searchResultNoteIds) {
|
for (const resultNoteId of searchResultNoteIds) {
|
||||||
@ -144,13 +165,13 @@ function executeActions(note, searchResultNoteIds) {
|
|||||||
log.info(`Applying action handler to note ${resultNote.noteId}: ${JSON.stringify(action)}`);
|
log.info(`Applying action handler to note ${resultNote.noteId}: ${JSON.stringify(action)}`);
|
||||||
|
|
||||||
ACTION_HANDLERS[action.name](action, resultNote);
|
ACTION_HANDLERS[action.name](action, resultNote);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
log.error(`ExecuteScript search action failed with ${e.message}`);
|
log.error(`ExecuteScript search action failed with ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
executeActions
|
executeActions
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user