mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
feat(views/table): basic renaming of fields
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
import { t } from "i18next";
|
||||||
|
import attributes from "../../../services/attributes";
|
||||||
|
import froca from "../../../services/froca";
|
||||||
|
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) {
|
||||||
|
const bulkActionNote = await froca.getNote("_bulkAction");
|
||||||
|
if (!bulkActionNote) {
|
||||||
|
console.warn("Bulk action note not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "label") {
|
||||||
|
attributes.setLabel("_bulkAction", "action", JSON.stringify({
|
||||||
|
name: "renameLabel",
|
||||||
|
oldLabelName: originalName,
|
||||||
|
newLabelName: newName
|
||||||
|
}));
|
||||||
|
await server.post("bulk-action/execute", {
|
||||||
|
noteIds: [ parentNoteId ],
|
||||||
|
includeDescendants: true
|
||||||
|
});
|
||||||
|
|
||||||
|
await ws.waitForMaxKnownEntityChangeId();
|
||||||
|
toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);
|
||||||
|
} else {
|
||||||
|
console.warn("Renaming relation columns is not supported yet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import Component from "../../../components/component";
|
|||||||
import { CommandListenerData, EventData } from "../../../components/app_context";
|
import { CommandListenerData, EventData } from "../../../components/app_context";
|
||||||
import attributes from "../../../services/attributes";
|
import attributes from "../../../services/attributes";
|
||||||
import FNote from "../../../entities/fnote";
|
import FNote from "../../../entities/fnote";
|
||||||
|
import { renameColumn } from "./bulk_actions";
|
||||||
|
|
||||||
export default class TableColumnEditing extends Component {
|
export default class TableColumnEditing extends Component {
|
||||||
|
|
||||||
@@ -73,13 +74,20 @@ export default class TableColumnEditing extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, value } = this.newAttribute;
|
const { name, type, value } = this.newAttribute;
|
||||||
|
|
||||||
|
this.api.blockRedraw();
|
||||||
|
|
||||||
if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== name) {
|
if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== name) {
|
||||||
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
|
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
|
||||||
|
|
||||||
|
const oldName = this.existingAttributeToEdit.name.split(":")[1];
|
||||||
|
const newName = name.split(":")[1];
|
||||||
|
await renameColumn(this.parentNote.noteId, type, oldName, newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes.setLabel(this.parentNote.noteId, name, value);
|
attributes.setLabel(this.parentNote.noteId, name, value);
|
||||||
|
this.api.restoreRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
getNewAttributePosition() {
|
getNewAttributePosition() {
|
||||||
|
|||||||
@@ -197,8 +197,8 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
attr.type === "label" &&
|
attr.type === "label" &&
|
||||||
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
(attr.name?.startsWith("label:") || attr.name?.startsWith("relation:")) &&
|
||||||
attributes.isAffecting(attr, this.parentNote))) {
|
attributes.isAffecting(attr, this.parentNote))) {
|
||||||
console.log("Col update");
|
|
||||||
this.#manageColumnUpdate();
|
this.#manageColumnUpdate();
|
||||||
|
return await this.#manageRowsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId || this.noteIds.includes(branch.parentNoteId ?? ""))
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import bulkActionService from "../../services/bulk_actions.js";
|
|||||||
|
|
||||||
function execute(req: Request) {
|
function execute(req: Request) {
|
||||||
const { noteIds, includeDescendants } = req.body;
|
const { noteIds, includeDescendants } = req.body;
|
||||||
|
if (!Array.isArray(noteIds)) {
|
||||||
|
throw new Error("noteIds must be an array");
|
||||||
|
}
|
||||||
|
|
||||||
const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
|
const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user