feat(views/table): add basic row creation mechanism

This commit is contained in:
Elian Doran 2025-06-28 00:07:14 +03:00
parent d31ba39a91
commit 7f2c41940d
No known key found for this signature in database
3 changed files with 18 additions and 2 deletions

View File

@ -107,6 +107,7 @@ export default class NoteListWidget extends NoteContextAwareWidget {
const noteListRenderer = new NoteListRenderer({ const noteListRenderer = new NoteListRenderer({
$parent: this.$content, $parent: this.$content,
parentNote: note, parentNote: note,
parentNotePath: this.notePath,
noteIds: note.getChildNoteIds() noteIds: note.getChildNoteIds()
}); });
this.$widget.toggleClass("full-height", noteListRenderer.isFullHeight); this.$widget.toggleClass("full-height", noteListRenderer.isFullHeight);

View File

@ -2,7 +2,7 @@ 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, themeQuartz, colorSchemeDark } from "ag-grid-community"; import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions, themeQuartz, colorSchemeDark } from "ag-grid-community";
import attributes, { setLabel } from "../../../services/attributes.js"; import attributes, { setLabel } from "../../../services/attributes.js";
import getPromotedAttributeInformation, { buildColumnDefinitions, buildData, TableData } from "./data.js"; import getPromotedAttributeInformation, { buildColumnDefinitions, buildData, buildRowDefinitions, 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";
import type { GridApi, GridState, Theme } from "ag-grid-community"; import type { GridApi, GridState, Theme } from "ag-grid-community";
@ -10,6 +10,7 @@ import SpacedUpdate from "../../../services/spaced_update.js";
import branches from "../../../services/branches.js"; 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";
const TPL = /*html*/` const TPL = /*html*/`
<div class="table-view"> <div class="table-view">
@ -37,6 +38,7 @@ const TPL = /*html*/`
<div class="header"> <div class="header">
<button data-trigger-command="addNoteListItem">Add new column</button> <button data-trigger-command="addNoteListItem">Add new column</button>
<button data-trigger-command="addNewRow">Add new row</button>
</div> </div>
<div class="table-view-container"></div> <div class="table-view-container"></div>
@ -192,6 +194,15 @@ export default class TableView extends ViewMode<StateInfo> {
console.log("Save attributes", this.newAttribute); console.log("Save attributes", this.newAttribute);
} }
addNewRowCommand() {
const parentNotePath = this.args.parentNotePath;
if (parentNotePath) {
note_create.createNote(parentNotePath, {
activate: false
});
}
}
private getTheme(): Theme { private getTheme(): Theme {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) { if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return themeQuartz.withPart(colorSchemeDark) return themeQuartz.withPart(colorSchemeDark)
@ -213,6 +224,10 @@ export default class TableView extends ViewMode<StateInfo> {
}) })
} }
if (loadResults.getBranchRows().some(branch => branch.parentNoteId === this.parentNote.noteId)) {
return true;
}
return false; return false;
} }

View File

@ -2,12 +2,12 @@ import type { EventData } from "../../components/app_context.js";
import Component from "../../components/component.js"; import Component from "../../components/component.js";
import type FNote from "../../entities/fnote.js"; import type FNote from "../../entities/fnote.js";
import type { ViewTypeOptions } from "../../services/note_list_renderer.js"; import type { ViewTypeOptions } from "../../services/note_list_renderer.js";
import type NoteListWidget from "../note_list.js";
import ViewModeStorage from "./view_mode_storage.js"; import ViewModeStorage from "./view_mode_storage.js";
export interface ViewModeArgs { export interface ViewModeArgs {
$parent: JQuery<HTMLElement>; $parent: JQuery<HTMLElement>;
parentNote: FNote; parentNote: FNote;
parentNotePath: string | null | undefined;
noteIds: string[]; noteIds: string[];
showNotePath?: boolean; showNotePath?: boolean;
} }