mirror of
https://github.com/zadam/trilium.git
synced 2025-10-26 07:46:30 +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";
|
||||
|
||||
export interface DefinitionObject {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { GridOptions } from "ag-grid-community";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||||
|
||||
type Data = {
|
||||
title: string;
|
||||
} & Record<string, string>;
|
||||
|
||||
type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';
|
||||
|
||||
export function buildData(parentNote: FNote, notes: FNote[]) {
|
||||
const { columnDefs, expectedLabels } = buildColumnDefinitions(parentNote);
|
||||
const rowData = buildRowDefinitions(notes, expectedLabels);
|
||||
@@ -42,7 +45,8 @@ export function buildColumnDefinitions(parentNote: FNote) {
|
||||
|
||||
columnDefs.push({
|
||||
field: attributeName,
|
||||
headerName: title
|
||||
headerName: title,
|
||||
cellDataType: mapDataType(def.labelType)
|
||||
});
|
||||
expectedLabels.push(attributeName);
|
||||
}
|
||||
@@ -50,6 +54,20 @@ export function buildColumnDefinitions(parentNote: FNote) {
|
||||
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"] {
|
||||
const definitions: GridOptions<Data>["rowData"] = [];
|
||||
for (const note of notes) {
|
||||
|
||||
Reference in New Issue
Block a user