mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 18:05:55 +01:00
feat(views/table): actually add attributes
This commit is contained in:
@@ -93,11 +93,7 @@ export class TypedComponent<ChildT extends TypedComponent<ChildT>> {
|
|||||||
|
|
||||||
if (fun) {
|
if (fun) {
|
||||||
return this.callMethod(fun, data);
|
return this.callMethod(fun, data);
|
||||||
} else {
|
} else if (this.parent) {
|
||||||
if (!this.parent) {
|
|
||||||
throw new Error(`Component "${this.componentId}" does not have a parent attached to propagate a command.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.parent.triggerCommand(name, data);
|
return this.parent.triggerCommand(name, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import froca from "./froca.js";
|
|||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
import type { AttributeRow } from "./load_results.js";
|
import type { AttributeRow } from "./load_results.js";
|
||||||
|
|
||||||
async function addLabel(noteId: string, name: string, value: string = "") {
|
async function addLabel(noteId: string, name: string, value: string = "", isInheritable = false) {
|
||||||
await server.put(`notes/${noteId}/attribute`, {
|
await server.put(`notes/${noteId}/attribute`, {
|
||||||
type: "label",
|
type: "label",
|
||||||
name: name,
|
name: name,
|
||||||
value: value
|
value: value,
|
||||||
|
isInheritable
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,4 +166,13 @@ export default class NoteListWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
triggerCommand<K extends CommandNames>(name: K, data?: CommandMappings[K]): Promise<unknown> | undefined | null {
|
||||||
|
// Pass the commands to the view mode, which is not actually attached to the hierarchy.
|
||||||
|
if (this.viewMode?.triggerCommand(name, data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.triggerCommand(name, data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import froca from "../../../services/froca.js";
|
import froca from "../../../services/froca.js";
|
||||||
import ViewMode, { type ViewModeArgs } from "../view_mode.js";
|
import ViewMode, { type ViewModeArgs } from "../view_mode.js";
|
||||||
import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
|
import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
|
||||||
import { setLabel } from "../../../services/attributes.js";
|
import attributes, { setLabel } from "../../../services/attributes.js";
|
||||||
import getPromotedAttributeInformation, { buildData, TableData } from "./data.js";
|
import getPromotedAttributeInformation, { buildData, TableData } from "./data.js";
|
||||||
import applyHeaderCustomization from "./header-customization.js";
|
import applyHeaderCustomization from "./header-customization.js";
|
||||||
import server from "../../../services/server.js";
|
import server from "../../../services/server.js";
|
||||||
@@ -9,6 +9,7 @@ import type { GridApi, GridState } from "ag-grid-community";
|
|||||||
import SpacedUpdate from "../../../services/spaced_update.js";
|
import SpacedUpdate from "../../../services/spaced_update.js";
|
||||||
import branches from "../../../services/branches.js";
|
import branches from "../../../services/branches.js";
|
||||||
import type { CommandListenerData } from "../../../components/app_context.js";
|
import type { CommandListenerData } from "../../../components/app_context.js";
|
||||||
|
import type { Attribute } from "../../../services/attribute_parser.js";
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="table-view">
|
<div class="table-view">
|
||||||
@@ -53,6 +54,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
private args: ViewModeArgs;
|
private args: ViewModeArgs;
|
||||||
private spacedUpdate: SpacedUpdate;
|
private spacedUpdate: SpacedUpdate;
|
||||||
private api?: GridApi;
|
private api?: GridApi;
|
||||||
|
private newAttribute?: Attribute;
|
||||||
|
|
||||||
constructor(args: ViewModeArgs) {
|
constructor(args: ViewModeArgs) {
|
||||||
super(args, "table");
|
super(args, "table");
|
||||||
@@ -164,16 +166,23 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveAttributesCommand() {
|
|
||||||
console.log("Save attributes");
|
|
||||||
}
|
|
||||||
|
|
||||||
async reloadAttributesCommand() {
|
async reloadAttributesCommand() {
|
||||||
console.log("Reload attributes");
|
console.log("Reload attributes");
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAttributeListCommand({ attributes }: CommandListenerData<"updateAttributeList">) {
|
async updateAttributeListCommand({ attributes }: CommandListenerData<"updateAttributeList">) {
|
||||||
console.log("Update attributes", { attributes });
|
this.newAttribute = attributes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async saveAttributesCommand() {
|
||||||
|
if (!this.newAttribute) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name, value } = this.newAttribute;
|
||||||
|
attributes.addLabel(this.parentNote.noteId, name, value, true);
|
||||||
|
console.log("Save attributes", this.newAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ function updateNoteAttribute(req: Request) {
|
|||||||
attribute = new BAttribute({
|
attribute = new BAttribute({
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
type: body.type
|
type: body.type,
|
||||||
|
isInheritable: body.isInheritable
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user