Files
Trilium/apps/client/src/widgets/bulk_actions/abstract_bulk_action.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-01-19 22:10:24 +01:00
import server from "../../services/server.js";
import ws from "../../services/ws.js";
import type FAttribute from "../../entities/fattribute.js";
import { VNode } from "preact";
2021-01-19 22:10:24 +01:00
export interface ActionDefinition {
script: string;
relationName: string;
targetNoteId: string;
targetParentNoteId: string;
oldRelationName?: string;
newRelationName?: string;
newTitle?: string;
labelName?: string;
labelValue?: string;
oldLabelName?: string;
newLabelName?: string;
}
export default abstract class AbstractBulkAction {
attribute: FAttribute;
actionDef: ActionDefinition;
constructor(attribute: FAttribute, actionDef: ActionDefinition) {
2021-01-19 22:10:24 +01:00
this.attribute = attribute;
this.actionDef = actionDef;
}
// to be overridden
2025-08-09 20:37:45 +03:00
abstract doRender(): VNode;
2025-01-09 18:07:02 +02:00
static get actionName() {
return "";
}
2021-01-19 22:10:24 +01:00
async saveAction(data: {}) {
const actionObject = Object.assign({ name: (this.constructor as typeof AbstractBulkAction).actionName }, data);
2021-01-19 22:10:24 +01:00
await server.put(`notes/${this.attribute.noteId}/attribute`, {
attributeId: this.attribute.attributeId,
2025-01-09 18:07:02 +02:00
type: "label",
name: "action",
2021-01-19 22:10:24 +01:00
value: JSON.stringify(actionObject)
});
await ws.waitForMaxKnownEntityChangeId();
}
2021-01-26 10:48:28 +01:00
async deleteAction() {
await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
await ws.waitForMaxKnownEntityChangeId();
}
2021-01-19 22:10:24 +01:00
}