2020-10-02 15:10:00 +00:00
|
|
|
import {DocModel, IRowModel, refRecord, ViewRec} from 'app/client/models/DocModel';
|
|
|
|
import * as ko from 'knockout';
|
|
|
|
|
|
|
|
// Represents a page entry in the tree of pages.
|
|
|
|
export interface PageRec extends IRowModel<"_grist_Pages"> {
|
|
|
|
view: ko.Computed<ViewRec>;
|
2021-08-27 17:25:20 +00:00
|
|
|
isHidden: ko.Computed<boolean>;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createPageRec(this: PageRec, docModel: DocModel): void {
|
|
|
|
this.view = refRecord(docModel.views, this.viewRef);
|
2021-08-27 17:25:20 +00:00
|
|
|
this.isHidden = ko.pureComputed(() => {
|
|
|
|
const name = this.view().name();
|
2022-04-27 17:46:24 +00:00
|
|
|
const isTableHidden = () => {
|
|
|
|
const viewId = this.view().id();
|
2022-07-06 07:41:09 +00:00
|
|
|
const tables = docModel.rawDataTables.all();
|
2022-04-27 17:46:24 +00:00
|
|
|
const primaryTable = tables.find(t => t.primaryViewId() === viewId);
|
2022-07-21 13:46:29 +00:00
|
|
|
return !!primaryTable && primaryTable.tableId()?.startsWith("GristHidden_");
|
2022-04-27 17:46:24 +00:00
|
|
|
};
|
|
|
|
// Page is hidden when any of this is true:
|
|
|
|
// - It has an empty name (or no name at all)
|
|
|
|
// - It is GristDocTour (unless user wants to see it)
|
|
|
|
// - It is a page generated for a hidden table TODO: Follow up - don't create
|
|
|
|
// pages for hidden tables.
|
|
|
|
// This is used currently only the left panel, to hide pages from the user.
|
|
|
|
return !name || (name === 'GristDocTour' && !docModel.showDocTourTable) || isTableHidden();
|
2021-08-27 17:25:20 +00:00
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|