mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(views/table): display both promoted and non-promoted attributes
This commit is contained in:
		
							parent
							
								
									e4a2a8e56d
								
							
						
					
					
						commit
						71863752cd
					
				@ -6,7 +6,7 @@ import { LabelType } from "../../../services/promoted_attribute_definition_parse
 | 
			
		||||
 | 
			
		||||
type ColumnType = LabelType | "relation";
 | 
			
		||||
 | 
			
		||||
export interface PromotedAttributeInformation {
 | 
			
		||||
export interface AttributeDefinitionInformation {
 | 
			
		||||
    name: string;
 | 
			
		||||
    title?: string;
 | 
			
		||||
    type?: ColumnType;
 | 
			
		||||
@ -42,7 +42,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export function buildColumnDefinitions(info: PromotedAttributeInformation[], existingColumnData?: ColumnDefinition[]) {
 | 
			
		||||
export function buildColumnDefinitions(info: AttributeDefinitionInformation[], existingColumnData?: ColumnDefinition[]) {
 | 
			
		||||
    const columnDefs: ColumnDefinition[] = [
 | 
			
		||||
        {
 | 
			
		||||
            title: "#",
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ import "tabulator-tables/dist/css/tabulator.css";
 | 
			
		||||
import "../../../../src/stylesheets/table.css";
 | 
			
		||||
import { canReorderRows, configureReorderingRows } from "./dragging.js";
 | 
			
		||||
import buildFooter from "./footer.js";
 | 
			
		||||
import getPromotedAttributeInformation, { buildRowDefinitions } from "./rows.js";
 | 
			
		||||
import getAttributeDefinitionInformation, { buildRowDefinitions } from "./rows.js";
 | 
			
		||||
import { buildColumnDefinitions } from "./columns.js";
 | 
			
		||||
import { setupContextMenu } from "./context_menu.js";
 | 
			
		||||
 | 
			
		||||
@ -121,7 +121,7 @@ export default class TableView extends ViewMode<StateInfo> {
 | 
			
		||||
 | 
			
		||||
    private async initialize(el: HTMLElement) {
 | 
			
		||||
        const notes = await froca.getNotes(this.args.noteIds);
 | 
			
		||||
        const info = getPromotedAttributeInformation(this.parentNote);
 | 
			
		||||
        const info = getAttributeDefinitionInformation(this.parentNote);
 | 
			
		||||
 | 
			
		||||
        const viewStorage = await this.viewStorage.restore();
 | 
			
		||||
        this.persistentData = viewStorage?.tableData || {};
 | 
			
		||||
@ -245,7 +245,7 @@ export default class TableView extends ViewMode<StateInfo> {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const info = getPromotedAttributeInformation(this.parentNote);
 | 
			
		||||
        const info = getAttributeDefinitionInformation(this.parentNote);
 | 
			
		||||
        const columnDefs = buildColumnDefinitions(info, this.persistentData?.columns);
 | 
			
		||||
        this.api.setColumns(columnDefs);
 | 
			
		||||
    }
 | 
			
		||||
@ -256,7 +256,7 @@ export default class TableView extends ViewMode<StateInfo> {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const notes = await froca.getNotes(this.args.noteIds);
 | 
			
		||||
        const info = getPromotedAttributeInformation(this.parentNote);
 | 
			
		||||
        const info = getAttributeDefinitionInformation(this.parentNote);
 | 
			
		||||
        this.api.replaceData(await buildRowDefinitions(this.parentNote, notes, info));
 | 
			
		||||
 | 
			
		||||
        if (this.noteIdToEdit) {
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
import FNote from "../../../entities/fnote.js";
 | 
			
		||||
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
 | 
			
		||||
import type { PromotedAttributeInformation } from "./columns.js";
 | 
			
		||||
import type { AttributeDefinitionInformation } from "./columns.js";
 | 
			
		||||
 | 
			
		||||
export type TableData = {
 | 
			
		||||
    iconClass: string;
 | 
			
		||||
@ -11,7 +11,7 @@ export type TableData = {
 | 
			
		||||
    branchId: string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) {
 | 
			
		||||
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: AttributeDefinitionInformation[]) {
 | 
			
		||||
    const definitions: TableData[] = [];
 | 
			
		||||
    for (const branch of parentNote.getChildBranches()) {
 | 
			
		||||
        const note = await branch.getNote();
 | 
			
		||||
@ -41,17 +41,19 @@ export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], inf
 | 
			
		||||
    return definitions;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default function getPromotedAttributeInformation(parentNote: FNote) {
 | 
			
		||||
    const info: PromotedAttributeInformation[] = [];
 | 
			
		||||
    for (const promotedAttribute of parentNote.getPromotedDefinitionAttributes()) {
 | 
			
		||||
        const def = promotedAttribute.getDefinition();
 | 
			
		||||
export default function getAttributeDefinitionInformation(parentNote: FNote) {
 | 
			
		||||
    const info: AttributeDefinitionInformation[] = [];
 | 
			
		||||
    const attrDefs = parentNote.getAttributes()
 | 
			
		||||
        .filter(attr => attr.isDefinition());
 | 
			
		||||
    for (const attrDef of attrDefs) {
 | 
			
		||||
        const def = attrDef.getDefinition();
 | 
			
		||||
        if (def.multiplicity !== "single") {
 | 
			
		||||
            console.warn("Multiple values are not supported for now");
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const [ labelType, name ] = promotedAttribute.name.split(":", 2);
 | 
			
		||||
        if (promotedAttribute.type !== "label") {
 | 
			
		||||
        const [ labelType, name ] = attrDef.name.split(":", 2);
 | 
			
		||||
        if (attrDef.type !== "label") {
 | 
			
		||||
            console.warn("Relations are not supported for now");
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user