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>;
|
2022-10-28 08:04:59 +00:00
|
|
|
isCensored: ko.Computed<boolean>;
|
|
|
|
isSpecial: 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);
|
2022-10-28 08:04:59 +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)
|
2023-03-22 13:48:50 +00:00
|
|
|
// - It is GristDocTutorial (and the document is a tutorial fork)
|
2022-10-28 08:04:59 +00:00
|
|
|
// - 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.
|
|
|
|
this.isCensored = ko.pureComputed(() => !this.view().name());
|
|
|
|
this.isSpecial = ko.pureComputed(() => {
|
2021-08-27 17:25:20 +00:00
|
|
|
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
|
|
|
};
|
2023-03-22 13:48:50 +00:00
|
|
|
return (
|
|
|
|
(name === 'GristDocTour' && !docModel.showDocTourTable) ||
|
|
|
|
(name === 'GristDocTutorial' && !docModel.showDocTutorialTable) ||
|
|
|
|
isTableHidden()
|
|
|
|
);
|
2022-10-28 08:04:59 +00:00
|
|
|
});
|
|
|
|
this.isHidden = ko.pureComputed(() => {
|
|
|
|
return this.isCensored() || this.isSpecial();
|
2021-08-27 17:25:20 +00:00
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|