2021-01-19 22:10:24 +01:00
|
|
|
import server from "../../services/server.js";
|
|
|
|
|
import ws from "../../services/ws.js";
|
2025-01-13 23:18:10 +02:00
|
|
|
import type FAttribute from "../../entities/fattribute.js";
|
2025-08-08 23:23:07 +03:00
|
|
|
import { VNode } from "preact";
|
2021-01-19 22:10:24 +01:00
|
|
|
|
2025-08-08 23:23:07 +03:00
|
|
|
export interface ActionDefinition {
|
2024-12-21 09:29:50 +02:00
|
|
|
script: string;
|
2024-12-21 14:39:36 +02:00
|
|
|
relationName: string;
|
|
|
|
|
targetNoteId: string;
|
2024-12-21 15:04:33 +02:00
|
|
|
targetParentNoteId: string;
|
2024-12-21 15:03:45 +02:00
|
|
|
oldRelationName?: string;
|
|
|
|
|
newRelationName?: string;
|
2024-12-21 15:04:33 +02:00
|
|
|
newTitle?: string;
|
2024-12-21 15:05:41 +02:00
|
|
|
labelName?: string;
|
|
|
|
|
labelValue?: string;
|
|
|
|
|
oldLabelName?: string;
|
|
|
|
|
newLabelName?: string;
|
2024-12-21 09:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 00:26:47 +08:00
|
|
|
// 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
|
|
|
|
2024-12-21 09:26:37 +02:00
|
|
|
async saveAction(data: {}) {
|
2024-12-21 09:29:50 +02:00
|
|
|
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
|
|
|
}
|