mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
chore(views/table): bring back editing title
This commit is contained in:
parent
a31ac17792
commit
9a6a8580de
@ -56,7 +56,8 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "title",
|
field: "title",
|
||||||
title: "Title"
|
title: "Title",
|
||||||
|
editor: "input"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "position",
|
field: "position",
|
||||||
@ -68,6 +69,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
columnDefs.push({
|
columnDefs.push({
|
||||||
field: `labels.${name}`,
|
field: `labels.${name}`,
|
||||||
title: title ?? name,
|
title: title ?? name,
|
||||||
|
editable: true
|
||||||
// cellDataType: mapDataType(type),
|
// cellDataType: mapDataType(type),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import branches from "../../../services/branches.js";
|
|||||||
import type { CommandListenerData, EventData } from "../../../components/app_context.js";
|
import type { CommandListenerData, EventData } from "../../../components/app_context.js";
|
||||||
import type { Attribute } from "../../../services/attribute_parser.js";
|
import type { Attribute } from "../../../services/attribute_parser.js";
|
||||||
import note_create from "../../../services/note_create.js";
|
import note_create from "../../../services/note_create.js";
|
||||||
import {Tabulator, SortModule, FormatModule, InteractionModule} from 'tabulator-tables';
|
import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule} from 'tabulator-tables';
|
||||||
import "tabulator-tables/dist/css/tabulator_bootstrap5.min.css";
|
import "tabulator-tables/dist/css/tabulator_midnight.min.css";
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="table-view">
|
<div class="table-view">
|
||||||
@ -81,7 +81,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
const viewStorage = await this.viewStorage.restore();
|
const viewStorage = await this.viewStorage.restore();
|
||||||
const initialState = viewStorage?.gridState;
|
const initialState = viewStorage?.gridState;
|
||||||
|
|
||||||
const modules = [SortModule, FormatModule, InteractionModule];
|
const modules = [SortModule, FormatModule, InteractionModule, EditModule];
|
||||||
for (const module of modules) {
|
for (const module of modules) {
|
||||||
Tabulator.registerModule(module);
|
Tabulator.registerModule(module);
|
||||||
}
|
}
|
||||||
@ -98,6 +98,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
columns: buildColumnDefinitions(info),
|
columns: buildColumnDefinitions(info),
|
||||||
data: await buildRowDefinitions(this.parentNote, notes, info)
|
data: await buildRowDefinitions(this.parentNote, notes, info)
|
||||||
});
|
});
|
||||||
|
this.setupEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
private onSave() {
|
private onSave() {
|
||||||
@ -110,31 +111,36 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupEditing(): GridOptions<TableData> {
|
private setupEditing() {
|
||||||
return {
|
this.api!.on("cellEdited", (cell) => {
|
||||||
onCellValueChanged(event) {
|
const noteId = cell.getRow().getData().noteId;
|
||||||
if (event.type !== "cellValueChanged") {
|
const field = cell.getField();
|
||||||
return;
|
const newValue = cell.getValue();
|
||||||
}
|
|
||||||
|
|
||||||
const noteId = event.data.noteId;
|
console.log("Cell edited", field, newValue);
|
||||||
const name = event.colDef.field;
|
if (field === "title") {
|
||||||
if (!name) {
|
server.put(`notes/${noteId}/title`, { title: newValue });
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { newValue } = event;
|
|
||||||
if (name === "title") {
|
|
||||||
// TODO: Deduplicate with note_title.
|
|
||||||
server.put(`notes/${noteId}/title`, { title: newValue });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.startsWith("labels.")) {
|
|
||||||
const labelName = name.split(".", 2)[1];
|
|
||||||
setLabel(noteId, labelName, newValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// onCellValueChanged(event) {
|
||||||
|
// if (event.type !== "cellValueChanged") {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const noteId = event.data.noteId;
|
||||||
|
// const name = event.colDef.field;
|
||||||
|
// if (!name) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (name.startsWith("labels.")) {
|
||||||
|
// const labelName = name.split(".", 2)[1];
|
||||||
|
// setLabel(noteId, labelName, newValue);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupDragging() {
|
private setupDragging() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user