mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor(views/table): move bulk action implementation in service
This commit is contained in:
parent
5d619131ec
commit
0d3de92890
@ -15,6 +15,7 @@ import AddRelationBulkAction from "../widgets/bulk_actions/relation/add_relation
|
|||||||
import RenameNoteBulkAction from "../widgets/bulk_actions/note/rename_note.js";
|
import RenameNoteBulkAction from "../widgets/bulk_actions/note/rename_note.js";
|
||||||
import { t } from "./i18n.js";
|
import { t } from "./i18n.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
|
import toast from "./toast.js";
|
||||||
|
|
||||||
const ACTION_GROUPS = [
|
const ACTION_GROUPS = [
|
||||||
{
|
{
|
||||||
@ -89,6 +90,17 @@ function parseActions(note: FNote) {
|
|||||||
.filter((action) => !!action);
|
.filter((action) => !!action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function executeBulkActions(parentNoteId: string, actions: {}[]) {
|
||||||
|
await server.post("bulk-action/execute", {
|
||||||
|
noteIds: [ parentNoteId ],
|
||||||
|
includeDescendants: true,
|
||||||
|
actions
|
||||||
|
});
|
||||||
|
|
||||||
|
await ws.waitForMaxKnownEntityChangeId();
|
||||||
|
toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
addAction,
|
addAction,
|
||||||
parseActions,
|
parseActions,
|
||||||
|
@ -1,45 +1,31 @@
|
|||||||
import { t } from "i18next";
|
import { executeBulkActions } from "../../../services/bulk_action.js";
|
||||||
import server from "../../../services/server";
|
|
||||||
import toast from "../../../services/toast";
|
|
||||||
import ws from "../../../services/ws";
|
|
||||||
|
|
||||||
export async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {
|
export async function renameColumn(parentNoteId: string, type: "label" | "relation", originalName: string, newName: string) {
|
||||||
if (type === "label") {
|
if (type === "label") {
|
||||||
return executeBulkAction(parentNoteId, {
|
return executeBulkActions(parentNoteId, [{
|
||||||
name: "renameLabel",
|
name: "renameLabel",
|
||||||
oldLabelName: originalName,
|
oldLabelName: originalName,
|
||||||
newLabelName: newName
|
newLabelName: newName
|
||||||
});
|
}]);
|
||||||
} else {
|
} else {
|
||||||
return executeBulkAction(parentNoteId, {
|
return executeBulkActions(parentNoteId, [{
|
||||||
name: "renameRelation",
|
name: "renameRelation",
|
||||||
oldRelationName: originalName,
|
oldRelationName: originalName,
|
||||||
newRelationName: newName
|
newRelationName: newName
|
||||||
});
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteColumn(parentNoteId: string, type: "label" | "relation", columnName: string) {
|
export async function deleteColumn(parentNoteId: string, type: "label" | "relation", columnName: string) {
|
||||||
if (type === "label") {
|
if (type === "label") {
|
||||||
return executeBulkAction(parentNoteId, {
|
return executeBulkActions(parentNoteId, [{
|
||||||
name: "deleteLabel",
|
name: "deleteLabel",
|
||||||
labelName: columnName
|
labelName: columnName
|
||||||
});
|
}]);
|
||||||
} else {
|
} else {
|
||||||
return executeBulkAction(parentNoteId, {
|
return executeBulkActions(parentNoteId, [{
|
||||||
name: "deleteRelation",
|
name: "deleteRelation",
|
||||||
relationName: columnName
|
relationName: columnName
|
||||||
});
|
}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeBulkAction(parentNoteId: string, action: {}) {
|
|
||||||
await server.post("bulk-action/execute", {
|
|
||||||
noteIds: [ parentNoteId ],
|
|
||||||
includeDescendants: true,
|
|
||||||
actions: [ action ]
|
|
||||||
});
|
|
||||||
|
|
||||||
await ws.waitForMaxKnownEntityChangeId();
|
|
||||||
toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user