mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
feat(book/table): support date type
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url";
|
export type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url";
|
||||||
type Multiplicity = "single" | "multi";
|
type Multiplicity = "single" | "multi";
|
||||||
|
|
||||||
export interface DefinitionObject {
|
export interface DefinitionObject {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { GridOptions } from "ag-grid-community";
|
import { GridOptions } from "ag-grid-community";
|
||||||
import FNote from "../../../entities/fnote";
|
import FNote from "../../../entities/fnote";
|
||||||
|
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||||||
|
|
||||||
type Data = {
|
type Data = {
|
||||||
title: string;
|
title: string;
|
||||||
} & Record<string, string>;
|
} & Record<string, string>;
|
||||||
|
|
||||||
|
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
|
||||||
|
|
||||||
export function buildData(parentNote: FNote, notes: FNote[]) {
|
export function buildData(parentNote: FNote, notes: FNote[]) {
|
||||||
const { columnDefs, expectedLabels } = buildColumnDefinitions(parentNote);
|
const { columnDefs, expectedLabels } = buildColumnDefinitions(parentNote);
|
||||||
const rowData = buildRowDefinitions(notes, expectedLabels);
|
const rowData = buildRowDefinitions(notes, expectedLabels);
|
||||||
@@ -42,7 +45,8 @@ export function buildColumnDefinitions(parentNote: FNote) {
|
|||||||
|
|
||||||
columnDefs.push({
|
columnDefs.push({
|
||||||
field: attributeName,
|
field: attributeName,
|
||||||
headerName: title
|
headerName: title,
|
||||||
|
cellDataType: mapDataType(def.labelType)
|
||||||
});
|
});
|
||||||
expectedLabels.push(attributeName);
|
expectedLabels.push(attributeName);
|
||||||
}
|
}
|
||||||
@@ -50,6 +54,20 @@ export function buildColumnDefinitions(parentNote: FNote) {
|
|||||||
return { columnDefs, expectedLabels };
|
return { columnDefs, expectedLabels };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapDataType(labelType: LabelType | undefined): GridLabelType {
|
||||||
|
if (!labelType) {
|
||||||
|
return "text";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (labelType) {
|
||||||
|
case "date":
|
||||||
|
return "dateString";
|
||||||
|
case "text":
|
||||||
|
default:
|
||||||
|
return "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function buildRowDefinitions(notes: FNote[], expectedLabels: string[]): GridOptions<Data>["rowData"] {
|
export function buildRowDefinitions(notes: FNote[], expectedLabels: string[]): GridOptions<Data>["rowData"] {
|
||||||
const definitions: GridOptions<Data>["rowData"] = [];
|
const definitions: GridOptions<Data>["rowData"] = [];
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
|
|||||||
Reference in New Issue
Block a user