2022-07-04 14:14:55 +00:00
|
|
|
import BaseView from 'app/client/components/BaseView';
|
2022-01-27 17:51:37 +00:00
|
|
|
import {CursorPos} from 'app/client/components/Cursor';
|
2023-07-19 17:37:22 +00:00
|
|
|
import {LinkingState} from 'app/client/components/LinkingState';
|
2022-01-27 17:51:37 +00:00
|
|
|
import {KoArray} from 'app/client/lib/koArray';
|
|
|
|
import {
|
|
|
|
ColumnRec,
|
|
|
|
DocModel,
|
|
|
|
FilterRec,
|
|
|
|
IRowModel,
|
|
|
|
recordSet,
|
2022-08-08 13:32:50 +00:00
|
|
|
refListRecords,
|
2022-01-27 17:51:37 +00:00
|
|
|
refRecord,
|
|
|
|
TableRec,
|
|
|
|
ViewFieldRec,
|
|
|
|
ViewRec
|
|
|
|
} from 'app/client/models/DocModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as modelUtil from 'app/client/models/modelUtil';
|
2022-01-27 17:51:37 +00:00
|
|
|
import {LinkConfig} from 'app/client/ui/selectBy';
|
|
|
|
import {getWidgetTypes} from 'app/client/ui/widgetTypes';
|
2023-07-19 17:37:22 +00:00
|
|
|
import {FilterColValues} from "app/common/ActiveDocAPI";
|
2022-01-12 13:30:51 +00:00
|
|
|
import {AccessLevel, ICustomWidget} from 'app/common/CustomWidget';
|
2022-11-17 20:17:51 +00:00
|
|
|
import {UserAction} from 'app/common/DocActions';
|
2022-01-27 17:51:37 +00:00
|
|
|
import {arrayRepeat} from 'app/common/gutil';
|
|
|
|
import {Sort} from 'app/common/SortSpec';
|
2023-07-07 08:54:01 +00:00
|
|
|
import {UIRowId} from 'app/common/TableData';
|
2022-02-08 15:23:14 +00:00
|
|
|
import {ColumnsToMap, WidgetColumnMap} from 'app/plugin/CustomSectionAPI';
|
|
|
|
import {ColumnToMapImpl} from 'app/client/models/ColumnToMap';
|
2022-10-14 10:07:19 +00:00
|
|
|
import {BEHAVIOR} from 'app/client/models/entities/ColumnRec';
|
2022-08-08 13:32:50 +00:00
|
|
|
import {removeRule, RuleOwner} from 'app/client/models/RuleOwner';
|
2022-04-07 15:18:20 +00:00
|
|
|
import {Computed, Holder, Observable} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as ko from 'knockout';
|
|
|
|
import defaults = require('lodash/defaults');
|
|
|
|
|
|
|
|
// Represents a section of user views, now also known as a "page widget" (e.g. a view may contain
|
|
|
|
// a grid section and a chart section).
|
2022-08-08 13:32:50 +00:00
|
|
|
export interface ViewSectionRec extends IRowModel<"_grist_Views_section">, RuleOwner {
|
2020-10-02 15:10:00 +00:00
|
|
|
viewFields: ko.Computed<KoArray<ViewFieldRec>>;
|
|
|
|
|
2023-06-21 14:43:22 +00:00
|
|
|
// List of sections linked from this one, i.e. for whom this one is the selector or link source.
|
|
|
|
linkedSections: ko.Computed<KoArray<ViewSectionRec>>;
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// All table columns associated with this view section, excluding hidden helper columns.
|
|
|
|
columns: ko.Computed<ColumnRec[]>;
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
optionsObj: modelUtil.SaveableObjObservable<any>;
|
|
|
|
|
|
|
|
customDef: CustomViewSectionDef;
|
|
|
|
|
|
|
|
themeDef: modelUtil.KoSaveableObservable<string>;
|
|
|
|
chartTypeDef: modelUtil.KoSaveableObservable<string>;
|
|
|
|
view: ko.Computed<ViewRec>;
|
|
|
|
|
|
|
|
table: ko.Computed<TableRec>;
|
|
|
|
|
2022-04-27 17:46:24 +00:00
|
|
|
// Widget title with a default value
|
2020-10-02 15:10:00 +00:00
|
|
|
titleDef: modelUtil.KoSaveableObservable<string>;
|
2022-04-27 17:46:24 +00:00
|
|
|
// Default widget title (the one that is used in titleDef).
|
|
|
|
defaultWidgetTitle: ko.PureComputed<string>;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-05-12 13:08:28 +00:00
|
|
|
description: modelUtil.KoSaveableObservable<string>;
|
|
|
|
|
2022-02-07 14:02:26 +00:00
|
|
|
// true if this record is its table's rawViewSection, i.e. a 'raw data view'
|
|
|
|
// in which case the UI prevents various things like hiding columns or changing the widget type.
|
|
|
|
isRaw: ko.Computed<boolean>;
|
2023-05-08 22:06:24 +00:00
|
|
|
isVirtual: ko.Computed<boolean>;
|
2023-02-24 11:12:55 +00:00
|
|
|
isCollapsed: ko.Computed<boolean>;
|
2022-02-07 14:02:26 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
borderWidthPx: ko.Computed<string>;
|
|
|
|
|
|
|
|
layoutSpecObj: modelUtil.ObjObservable<any>;
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
_savedFilters: ko.Computed<KoArray<FilterRec>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unsaved client-side filters, keyed by original col ref. Currently only wiped when unsaved filters
|
|
|
|
* are applied or reverted.
|
|
|
|
*
|
|
|
|
* If saved filters exist for a col ref, unsaved filters take priority and are applied instead. This
|
|
|
|
* prevents disruption when changes are made to saved filters for the same field/column, but there
|
|
|
|
* may be some cases where we'd want to reset _unsavedFilters on some indirect change to the document.
|
|
|
|
*
|
|
|
|
* NOTE: See `filters`, where `_unsavedFilters` is merged with `savedFilters`.
|
|
|
|
*/
|
2022-11-17 20:17:51 +00:00
|
|
|
_unsavedFilters: Map<number, Partial<Filter>>;
|
2021-11-19 20:30:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter information for all fields/section in the section.
|
|
|
|
*
|
|
|
|
* Re-computed on changes to `savedFilters`, as well as any changes to `viewFields` or `columns`. Any
|
|
|
|
* unsaved filters saved in `_unsavedFilters` are applied on computation, taking priority over saved
|
|
|
|
* filters for the same field/column, if any exist.
|
|
|
|
*/
|
|
|
|
filters: ko.Computed<FilterInfo[]>;
|
|
|
|
|
|
|
|
// Subset of `filters` containing non-blank active filters.
|
|
|
|
activeFilters: Computed<FilterInfo[]>;
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
// Subset of `activeFilters` that are pinned.
|
|
|
|
pinnedActiveFilters: Computed<FilterInfo[]>;
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Helper metadata item which indicates whether any of the section's fields/columns have unsaved
|
2020-10-02 15:10:00 +00:00
|
|
|
// changes to their filters. (True indicates unsaved changes)
|
|
|
|
filterSpecChanged: Computed<boolean>;
|
|
|
|
|
2022-12-20 02:06:39 +00:00
|
|
|
// Set to true when a second pinned filter is added, to trigger a behavioral prompt. Note that
|
|
|
|
// the popup is only shown once, even if this observable is set to true again in the future.
|
|
|
|
showNestedFilteringPopup: Observable<boolean>;
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Customizable version of the JSON-stringified sort spec. It may diverge from the saved one.
|
|
|
|
activeSortJson: modelUtil.CustomComputed<string>;
|
|
|
|
|
|
|
|
// is an array (parsed from JSON) of colRefs (i.e. rowIds into the columns table), with a
|
|
|
|
// twist: a rowId may be positive or negative, for ascending or descending respectively.
|
2021-11-03 11:44:28 +00:00
|
|
|
activeSortSpec: modelUtil.ObjObservable<Sort.SortSpec>;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Modified sort spec to take into account any active display columns.
|
2021-11-03 11:44:28 +00:00
|
|
|
activeDisplaySortSpec: ko.Computed<Sort.SortSpec>;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Evaluates to an array of column models, which are not referenced by anything in viewFields.
|
|
|
|
hiddenColumns: ko.Computed<ColumnRec[]>;
|
|
|
|
|
|
|
|
hasFocus: ko.Computed<boolean>;
|
|
|
|
|
|
|
|
// Section-linking affects table if linkSrcSection is set. The controller value of the
|
|
|
|
// link is the value of srcCol at activeRowId of linkSrcSection, or activeRowId itself when
|
|
|
|
// srcCol is unset. If targetCol is set, we filter for all rows whose targetCol is equal to
|
|
|
|
// the controller value. Otherwise, the controller value determines the rowId of the cursor.
|
2023-07-07 08:54:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Section selected in the `Select By` dropdown. Used for filtering this section.
|
|
|
|
*/
|
2020-10-02 15:10:00 +00:00
|
|
|
linkSrcSection: ko.Computed<ViewSectionRec>;
|
2023-07-07 08:54:01 +00:00
|
|
|
/**
|
|
|
|
* Column selected in the `Select By` dropdown in the remote section. It points to a column in remote section
|
|
|
|
* that contains a reference to this table (or common table - because we can be linked by having the same reference
|
|
|
|
* to some other section).
|
|
|
|
* Used for filtering this section. Can be empty as user can just link by section.
|
|
|
|
* Watch out, it is not cleared, so it is only valid when we have linkSrcSection.
|
|
|
|
* In UI it is shown as Target Section (dot) Target Column.
|
|
|
|
*/
|
2020-10-02 15:10:00 +00:00
|
|
|
linkSrcCol: ko.Computed<ColumnRec>;
|
2023-07-07 08:54:01 +00:00
|
|
|
/**
|
|
|
|
* In case we have multiple reference columns, that are shown as
|
|
|
|
* Target Section -> My Column or
|
|
|
|
* Target Section . Target Column -> My Column
|
|
|
|
* store the reference to the column (my column) to use.
|
|
|
|
*/
|
2020-10-02 15:10:00 +00:00
|
|
|
linkTargetCol: ko.Computed<ColumnRec>;
|
|
|
|
|
2022-01-27 17:51:37 +00:00
|
|
|
// Linking state maintains .filterFunc and .cursorPos observables which we use for
|
|
|
|
// auto-scrolling and filtering.
|
|
|
|
linkingState: ko.Computed<LinkingState | null>;
|
2022-04-07 15:18:20 +00:00
|
|
|
_linkingState: Holder<LinkingState>; // Holder for the current value of linkingState
|
2022-01-27 17:51:37 +00:00
|
|
|
|
|
|
|
linkingFilter: ko.Computed<FilterColValues>;
|
|
|
|
|
2023-07-07 08:54:01 +00:00
|
|
|
activeRowId: ko.Observable<UIRowId | null>; // May be null when there are no rows.
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// If the view instance for section is instantiated, it will be accessible here.
|
2022-01-27 17:51:37 +00:00
|
|
|
viewInstance: ko.Observable<BaseView | null>;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Describes the most recent cursor position in the section. Only rowId and fieldIndex are used.
|
|
|
|
lastCursorPos: CursorPos;
|
|
|
|
|
|
|
|
// Describes the most recent scroll position.
|
|
|
|
lastScrollPos: {
|
|
|
|
rowIndex: number; // Used for scrolly sections. Indicates the index of the first visible row.
|
|
|
|
offset: number; // Pixel distance past the top of row indicated by rowIndex.
|
|
|
|
scrollLeft: number; // Used for grid sections. Indicates the scrollLeft value of the scroll pane.
|
|
|
|
};
|
|
|
|
|
|
|
|
disableAddRemoveRows: ko.Computed<boolean>;
|
|
|
|
|
|
|
|
isSorted: ko.Computed<boolean>;
|
|
|
|
disableDragRows: ko.Computed<boolean>;
|
2021-06-18 09:22:27 +00:00
|
|
|
// Number of frozen columns
|
|
|
|
rawNumFrozen: modelUtil.CustomComputed<number>;
|
|
|
|
// Number for frozen columns to display.
|
|
|
|
// We won't freeze all the columns on a grid, it will leave at least 1 column unfrozen.
|
|
|
|
numFrozen: ko.Computed<number>;
|
2022-01-12 13:30:51 +00:00
|
|
|
activeCustomOptions: modelUtil.CustomComputed<any>;
|
2022-02-08 15:23:14 +00:00
|
|
|
|
|
|
|
// Temporary fields used to communicate with the Custom Widget. There are set through the Widget API.
|
|
|
|
|
|
|
|
// Temporary variable holding columns mapping requested by the widget (set by API).
|
|
|
|
columnsToMap: ko.Observable<ColumnsToMap|null>;
|
|
|
|
// Temporary variable holding columns mapped by the user;
|
|
|
|
mappedColumns: ko.Computed<WidgetColumnMap|null>;
|
|
|
|
// Temporary variable holding flag that describes if the widget supports custom options (set by API).
|
2022-01-12 13:30:51 +00:00
|
|
|
hasCustomOptions: ko.Observable<boolean>;
|
2022-02-08 15:23:14 +00:00
|
|
|
// Temporary variable holding widget desired access (changed either from manifest or via API).
|
2022-01-12 13:30:51 +00:00
|
|
|
desiredAccessLevel: ko.Observable<AccessLevel|null>;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-02-01 19:51:40 +00:00
|
|
|
// Show widget as linking source. Used by custom widget.
|
|
|
|
allowSelectBy: Observable<boolean>;
|
|
|
|
|
|
|
|
// List of selected rows
|
|
|
|
selectedRows: Observable<number[]>;
|
|
|
|
|
2022-08-08 13:32:50 +00:00
|
|
|
editingFormula: ko.Computed<boolean>;
|
2022-04-27 17:46:24 +00:00
|
|
|
|
2022-10-14 10:07:19 +00:00
|
|
|
// Selected fields (columns) for the section.
|
|
|
|
selectedFields: ko.Observable<ViewFieldRec[]>;
|
|
|
|
|
|
|
|
// Some computed observables for multi-select, used in the creator panel, by more than one widgets.
|
|
|
|
|
|
|
|
// Common column behavior or mixed.
|
|
|
|
columnsBehavior: ko.PureComputed<BEHAVIOR|'mixed'>;
|
|
|
|
// If all selected columns are empty or formula column.
|
|
|
|
columnsAllIsFormula: ko.PureComputed<boolean>;
|
|
|
|
// Common type of selected columns or mixed.
|
|
|
|
columnsType: ko.PureComputed<string|'mixed'>;
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Save all filters of fields/columns in the section.
|
2020-10-02 15:10:00 +00:00
|
|
|
saveFilters(): Promise<void>;
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Revert all filters of fields/columns in the section.
|
2020-10-02 15:10:00 +00:00
|
|
|
revertFilters(): void;
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
// Set `filter` for the field or column identified by `colRef`.
|
|
|
|
setFilter(colRef: number, filter: Partial<Filter>): void;
|
|
|
|
|
|
|
|
// Revert the filter of the field or column identified by `colRef`.
|
|
|
|
revertFilter(colRef: number): void;
|
2021-11-26 10:43:55 +00:00
|
|
|
|
|
|
|
// Saves custom definition (bundles change)
|
|
|
|
saveCustomDef(): Promise<void>;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 15:23:14 +00:00
|
|
|
export type WidgetMappedColumn = number|number[]|null;
|
|
|
|
export type WidgetColumnMapping = Record<string, WidgetMappedColumn>
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
export interface CustomViewSectionDef {
|
|
|
|
/**
|
|
|
|
* The mode.
|
|
|
|
*/
|
2021-11-26 10:43:55 +00:00
|
|
|
mode: modelUtil.KoSaveableObservable<"url"|"plugin">;
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* The url.
|
|
|
|
*/
|
2021-11-26 10:43:55 +00:00
|
|
|
url: modelUtil.KoSaveableObservable<string|null>;
|
|
|
|
/**
|
|
|
|
* Custom widget information.
|
|
|
|
*/
|
|
|
|
widgetDef: modelUtil.KoSaveableObservable<ICustomWidget|null>;
|
2022-01-12 13:30:51 +00:00
|
|
|
/**
|
|
|
|
* Custom widget options.
|
|
|
|
*/
|
|
|
|
widgetOptions: modelUtil.KoSaveableObservable<Record<string, any>|null>;
|
2022-02-08 15:23:14 +00:00
|
|
|
/**
|
|
|
|
* Custom widget interaction options.
|
|
|
|
*/
|
|
|
|
columnsMapping: modelUtil.KoSaveableObservable<WidgetColumnMapping|null>;
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Access granted to url.
|
|
|
|
*/
|
2021-11-26 10:43:55 +00:00
|
|
|
access: modelUtil.KoSaveableObservable<string>;
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* The plugin id.
|
|
|
|
*/
|
2021-11-26 10:43:55 +00:00
|
|
|
pluginId: modelUtil.KoSaveableObservable<string>;
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* The section id.
|
|
|
|
*/
|
2021-11-26 10:43:55 +00:00
|
|
|
sectionId: modelUtil.KoSaveableObservable<string>;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
/** Information about filters for a field or hidden column. */
|
2021-11-19 20:30:11 +00:00
|
|
|
export interface FilterInfo {
|
2022-11-17 20:17:51 +00:00
|
|
|
/** The section that's being filtered. */
|
|
|
|
viewSection: ViewSectionRec;
|
|
|
|
/** The field or column that's being filtered. (Field if column is visible.) */
|
2021-11-19 20:30:11 +00:00
|
|
|
fieldOrColumn: ViewFieldRec|ColumnRec;
|
2022-11-17 20:17:51 +00:00
|
|
|
/** Filter that applies to this field/column, if any. */
|
2021-11-19 20:30:11 +00:00
|
|
|
filter: modelUtil.CustomComputed<string>;
|
2022-11-17 20:17:51 +00:00
|
|
|
/** Whether this filter is pinned to the filter bar. */
|
|
|
|
pinned: modelUtil.CustomComputed<boolean>;
|
|
|
|
/** True if `filter` has a non-blank value. */
|
2021-11-19 20:30:11 +00:00
|
|
|
isFiltered: ko.PureComputed<boolean>;
|
2022-11-17 20:17:51 +00:00
|
|
|
/** True if `pinned` is true. */
|
|
|
|
isPinned: ko.PureComputed<boolean>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Filter {
|
|
|
|
filter: string;
|
|
|
|
pinned: boolean;
|
2021-11-19 20:30:11 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export function createViewSectionRec(this: ViewSectionRec, docModel: DocModel): void {
|
|
|
|
this.viewFields = recordSet(this, docModel.viewFields, 'parentId', {sortBy: 'parentPos'});
|
2023-06-21 14:43:22 +00:00
|
|
|
this.linkedSections = recordSet(this, docModel.viewSections, 'linkSrcSectionRef');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// All table columns associated with this view section, excluding any hidden helper columns.
|
|
|
|
this.columns = this.autoDispose(ko.pureComputed(() => this.table().columns().all().filter(c => !c.isHiddenCol())));
|
2022-08-08 13:32:50 +00:00
|
|
|
this.editingFormula = ko.pureComputed({
|
|
|
|
read: () => docModel.editingFormula(),
|
|
|
|
write: val => {
|
|
|
|
docModel.editingFormula(val);
|
|
|
|
}
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
const defaultOptions = {
|
|
|
|
verticalGridlines: true,
|
|
|
|
horizontalGridlines: true,
|
|
|
|
zebraStripes: false,
|
|
|
|
customView: '',
|
2021-06-18 09:22:27 +00:00
|
|
|
numFrozen: 0
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
this.optionsObj = modelUtil.jsonObservable(this.options,
|
|
|
|
(obj: any) => defaults(obj || {}, defaultOptions));
|
|
|
|
|
|
|
|
const customViewDefaults = {
|
|
|
|
mode: 'url',
|
2021-11-26 10:43:55 +00:00
|
|
|
url: null,
|
|
|
|
widgetDef: null,
|
2020-10-02 15:10:00 +00:00
|
|
|
access: '',
|
|
|
|
pluginId: '',
|
|
|
|
sectionId: ''
|
|
|
|
};
|
|
|
|
const customDefObj = modelUtil.jsonObservable(this.optionsObj.prop('customView'),
|
|
|
|
(obj: any) => defaults(obj || {}, customViewDefaults));
|
|
|
|
|
|
|
|
this.customDef = {
|
|
|
|
mode: customDefObj.prop('mode'),
|
|
|
|
url: customDefObj.prop('url'),
|
2021-11-26 10:43:55 +00:00
|
|
|
widgetDef: customDefObj.prop('widgetDef'),
|
2022-01-12 13:30:51 +00:00
|
|
|
widgetOptions: customDefObj.prop('widgetOptions'),
|
2022-02-08 15:23:14 +00:00
|
|
|
columnsMapping: customDefObj.prop('columnsMapping'),
|
2020-10-02 15:10:00 +00:00
|
|
|
access: customDefObj.prop('access'),
|
|
|
|
pluginId: customDefObj.prop('pluginId'),
|
|
|
|
sectionId: customDefObj.prop('sectionId')
|
|
|
|
};
|
|
|
|
|
2022-10-14 10:07:19 +00:00
|
|
|
this.selectedFields = ko.observable<any>([]);
|
|
|
|
|
|
|
|
// During schema change, some columns/fields might be disposed beyond our control.
|
|
|
|
const selectedColumns = this.autoDispose(ko.pureComputed(() => this.selectedFields()
|
|
|
|
.filter(f => !f.isDisposed())
|
|
|
|
.map(f => f.column())
|
|
|
|
.filter(c => !c.isDisposed())));
|
|
|
|
this.columnsBehavior = ko.pureComputed(() => {
|
|
|
|
const list = new Set(selectedColumns().map(c => c.behavior()));
|
|
|
|
return list.size === 1 ? list.values().next().value : 'mixed';
|
|
|
|
});
|
|
|
|
this.columnsType = ko.pureComputed(() => {
|
|
|
|
const list = new Set(selectedColumns().map(c => c.type()));
|
|
|
|
return list.size === 1 ? list.values().next().value : 'mixed';
|
|
|
|
});
|
|
|
|
this.columnsAllIsFormula = ko.pureComputed(() => {
|
|
|
|
return selectedColumns().every(c => c.isFormula());
|
|
|
|
});
|
|
|
|
|
2022-01-12 13:30:51 +00:00
|
|
|
this.activeCustomOptions = modelUtil.customValue(this.customDef.widgetOptions);
|
|
|
|
|
|
|
|
this.saveCustomDef = async () => {
|
|
|
|
await customDefObj.save();
|
|
|
|
this.activeCustomOptions.revert();
|
2021-11-26 10:43:55 +00:00
|
|
|
};
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
this.themeDef = modelUtil.fieldWithDefault(this.theme, 'form');
|
|
|
|
this.chartTypeDef = modelUtil.fieldWithDefault(this.chartType, 'bar');
|
|
|
|
this.view = refRecord(docModel.views, this.parentId);
|
|
|
|
|
|
|
|
this.table = refRecord(docModel.tables, this.tableRef);
|
|
|
|
|
2022-04-27 17:46:24 +00:00
|
|
|
|
|
|
|
// The user-friendly name of the table, which is the same as tableId for non-summary tables,
|
|
|
|
// and is 'tableId[groupByCols...]' for summary tables.
|
|
|
|
// Consist of 3 parts
|
|
|
|
// - TableId (or primary table id for summary tables) capitalized
|
|
|
|
// - Grouping description (table record contains this for summary tables)
|
|
|
|
// - Widget type description (if not grid)
|
|
|
|
// All concatenated separated by space.
|
|
|
|
this.defaultWidgetTitle = this.autoDispose(ko.pureComputed(() => {
|
|
|
|
const widgetTypeDesc = this.parentKey() !== 'record' ? `${getWidgetTypes(this.parentKey.peek() as any).label}` : '';
|
|
|
|
const table = this.table();
|
|
|
|
return [
|
|
|
|
table.tableNameDef()?.toUpperCase(), // Due to ACL this can be null.
|
|
|
|
table.groupDesc(),
|
|
|
|
widgetTypeDesc
|
|
|
|
].filter(part => Boolean(part?.trim())).join(' ');
|
|
|
|
}));
|
|
|
|
// Widget title.
|
|
|
|
this.titleDef = modelUtil.fieldWithDefault(this.title, this.defaultWidgetTitle);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-05-12 13:08:28 +00:00
|
|
|
// Widget description
|
|
|
|
this.description = modelUtil.fieldWithDefault(this.description, this.description());
|
|
|
|
|
2022-02-07 14:02:26 +00:00
|
|
|
// true if this record is its table's rawViewSection, i.e. a 'raw data view'
|
|
|
|
// in which case the UI prevents various things like hiding columns or changing the widget type.
|
|
|
|
this.isRaw = this.autoDispose(ko.pureComputed(() => this.table().rawViewSectionRef() === this.getRowId()));
|
|
|
|
|
2023-05-08 22:06:24 +00:00
|
|
|
this.isVirtual = this.autoDispose(ko.pureComputed(() => typeof this.id() === 'string'));
|
|
|
|
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
this.borderWidthPx = ko.pureComputed(() => this.borderWidth() + 'px');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
this.layoutSpecObj = modelUtil.jsonObservable(this.layoutSpec);
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
this._savedFilters = recordSet(this, docModel.filters, 'viewSectionRef');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
/**
|
|
|
|
* Unsaved client-side filters, keyed by original col ref. Currently only wiped when unsaved filters
|
|
|
|
* are applied or reverted.
|
|
|
|
*
|
|
|
|
* If saved filters exist for a col ref, unsaved filters take priority and are applied instead. This
|
|
|
|
* prevents disruption when changes are made to saved filters for the same field/column, but there
|
|
|
|
* may be some cases where we'd want to reset _unsavedFilters on some indirect change to the document.
|
|
|
|
*
|
|
|
|
* NOTE: See `filters`, where `_unsavedFilters` is merged with `savedFilters`.
|
|
|
|
*/
|
|
|
|
this._unsavedFilters = new Map();
|
|
|
|
|
|
|
|
/**
|
2022-11-17 20:17:51 +00:00
|
|
|
* Filter information for all fields/columns in the section.
|
2021-11-19 20:30:11 +00:00
|
|
|
*
|
|
|
|
* Re-computed on changes to `savedFilters`, as well as any changes to `viewFields` or `columns`. Any
|
|
|
|
* unsaved filters saved in `_unsavedFilters` are applied on computation, taking priority over saved
|
|
|
|
* filters for the same field/column, if any exist.
|
|
|
|
*/
|
|
|
|
this.filters = this.autoDispose(ko.computed(() => {
|
|
|
|
const savedFiltersByColRef = new Map(this._savedFilters().all().map(f => [f.colRef(), f]));
|
2022-06-23 08:01:12 +00:00
|
|
|
const viewFieldsByColRef = new Map(this.viewFields().all().map(f => [f.origCol().getRowId(), f]));
|
2021-11-19 20:30:11 +00:00
|
|
|
|
|
|
|
return this.columns().map(column => {
|
|
|
|
const savedFilter = savedFiltersByColRef.get(column.origColRef());
|
2022-11-17 20:17:51 +00:00
|
|
|
// Initialize with a saved filter, if one exists. Otherwise, use a blank filter.
|
2021-11-19 20:30:11 +00:00
|
|
|
const filter = modelUtil.customComputed({
|
|
|
|
read: () => { return savedFilter ? savedFilter.activeFilter() : ''; },
|
|
|
|
});
|
2022-11-17 20:17:51 +00:00
|
|
|
const pinned = modelUtil.customComputed({
|
|
|
|
read: () => { return savedFilter ? savedFilter.pinned() : false; },
|
|
|
|
});
|
2021-11-19 20:30:11 +00:00
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
// If an unsaved filter exists, overwrite the filter with it.
|
2021-11-19 20:30:11 +00:00
|
|
|
const unsavedFilter = this._unsavedFilters.get(column.origColRef());
|
2022-11-17 20:17:51 +00:00
|
|
|
if (unsavedFilter) {
|
|
|
|
const {filter: f, pinned: p} = unsavedFilter;
|
|
|
|
if (f !== undefined) { filter(f); }
|
|
|
|
if (p !== undefined) { pinned(p); }
|
|
|
|
}
|
2021-11-19 20:30:11 +00:00
|
|
|
|
|
|
|
return {
|
2022-11-17 20:17:51 +00:00
|
|
|
viewSection: this,
|
2021-11-19 20:30:11 +00:00
|
|
|
filter,
|
2022-11-17 20:17:51 +00:00
|
|
|
pinned,
|
2022-06-23 08:01:12 +00:00
|
|
|
fieldOrColumn: viewFieldsByColRef.get(column.origColRef()) ?? column,
|
2022-11-17 20:17:51 +00:00
|
|
|
isFiltered: ko.pureComputed(() => filter() !== ''),
|
|
|
|
isPinned: ko.pureComputed(() => pinned()),
|
2022-06-23 08:01:12 +00:00
|
|
|
};
|
2021-11-19 20:30:11 +00:00
|
|
|
});
|
|
|
|
}));
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// List of `filters` that have non-blank active filters.
|
2022-11-17 20:17:51 +00:00
|
|
|
this.activeFilters = Computed.create(this, use => use(this.filters).filter(f => use(f.isFiltered)));
|
|
|
|
|
|
|
|
// List of `activeFilters` that are pinned.
|
|
|
|
this.pinnedActiveFilters = Computed.create(this, use => use(this.activeFilters).filter(f => use(f.isPinned)));
|
2021-11-19 20:30:11 +00:00
|
|
|
|
|
|
|
// Helper metadata item which indicates whether any of the section's fields/columns have unsaved
|
|
|
|
// changes to their filters. (True indicates unsaved changes)
|
|
|
|
this.filterSpecChanged = Computed.create(this, use => {
|
2022-11-17 20:17:51 +00:00
|
|
|
return use(this.filters).some(col => !use(col.filter.isSaved) || !use(col.pinned.isSaved));
|
2021-11-19 20:30:11 +00:00
|
|
|
});
|
|
|
|
|
2022-12-20 02:06:39 +00:00
|
|
|
this.showNestedFilteringPopup = Observable.create(this, false);
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Save all filters of fields/columns in the section.
|
2020-10-02 15:10:00 +00:00
|
|
|
this.saveFilters = () => {
|
|
|
|
return docModel.docData.bundleActions(`Save all filters in ${this.titleDef()}`,
|
2021-11-19 20:30:11 +00:00
|
|
|
async () => {
|
|
|
|
const savedFiltersByColRef = new Map(this._savedFilters().all().map(f => [f.colRef(), f]));
|
2022-11-17 20:17:51 +00:00
|
|
|
const updatedFilters: [number, Filter][] = []; // Pairs of row ids and filters to update.
|
2021-11-19 20:30:11 +00:00
|
|
|
const removedFilterIds: number[] = []; // Row ids of filters to remove.
|
2022-11-17 20:17:51 +00:00
|
|
|
const newFilters: [number, Filter][] = []; // Pairs of column refs and filters to add.
|
2021-11-19 20:30:11 +00:00
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
for (const f of this.filters()) {
|
|
|
|
const {fieldOrColumn, filter, pinned} = f;
|
2021-11-19 20:30:11 +00:00
|
|
|
// Skip saved filters (i.e. filters whose local values are unchanged from server).
|
2022-11-17 20:17:51 +00:00
|
|
|
if (filter.isSaved() && pinned.isSaved()) { continue; }
|
2021-11-19 20:30:11 +00:00
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
const savedFilter = savedFiltersByColRef.get(fieldOrColumn.origCol().origColRef());
|
2021-11-19 20:30:11 +00:00
|
|
|
if (!savedFilter) {
|
2022-11-17 20:17:51 +00:00
|
|
|
// Never save blank filters. (This is primarily a sanity check.)
|
|
|
|
if (filter() === '') { continue; }
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Since no saved filter exists, we must add a new record to the filters table.
|
2022-11-17 20:17:51 +00:00
|
|
|
newFilters.push([fieldOrColumn.origCol().origColRef(), {
|
|
|
|
filter: filter(),
|
|
|
|
pinned: pinned(),
|
|
|
|
}]);
|
|
|
|
} else if (filter() === '') {
|
2021-11-19 20:30:11 +00:00
|
|
|
// Mark the saved filter for removal from the filters table.
|
|
|
|
removedFilterIds.push(savedFilter.id());
|
|
|
|
} else {
|
|
|
|
// Mark the saved filter for update in the filters table.
|
2022-11-17 20:17:51 +00:00
|
|
|
updatedFilters.push([savedFilter.id(), {
|
|
|
|
filter: filter(),
|
|
|
|
pinned: pinned(),
|
|
|
|
}]);
|
2021-11-19 20:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
const actions: UserAction[] = [];
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Remove records of any deleted filters.
|
|
|
|
if (removedFilterIds.length > 0) {
|
2022-11-17 20:17:51 +00:00
|
|
|
actions.push(['BulkRemoveRecord', removedFilterIds]);
|
2021-11-19 20:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update existing filter records with new filter values.
|
|
|
|
if (updatedFilters.length > 0) {
|
2022-11-17 20:17:51 +00:00
|
|
|
actions.push(['BulkUpdateRecord',
|
2021-11-19 20:30:11 +00:00
|
|
|
updatedFilters.map(([id]) => id),
|
2022-11-17 20:17:51 +00:00
|
|
|
{
|
|
|
|
filter: updatedFilters.map(([, {filter}]) => filter),
|
|
|
|
pinned: updatedFilters.map(([, {pinned}]) => pinned),
|
|
|
|
}
|
2021-11-19 20:30:11 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new filter records.
|
|
|
|
if (newFilters.length > 0) {
|
2022-11-17 20:17:51 +00:00
|
|
|
actions.push(['BulkAddRecord',
|
2021-11-19 20:30:11 +00:00
|
|
|
arrayRepeat(newFilters.length, null),
|
|
|
|
{
|
|
|
|
viewSectionRef: arrayRepeat(newFilters.length, this.id()),
|
|
|
|
colRef: newFilters.map(([colRef]) => colRef),
|
2022-11-17 20:17:51 +00:00
|
|
|
filter: newFilters.map(([, {filter}]) => filter),
|
|
|
|
pinned: newFilters.map(([, {pinned}]) => pinned),
|
2021-11-19 20:30:11 +00:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
if (actions.length > 0) {
|
|
|
|
await docModel.filters.sendTableActions(actions);
|
|
|
|
}
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Reset client filter state.
|
|
|
|
this.revertFilters();
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-19 20:30:11 +00:00
|
|
|
// Revert all filters of fields/columns in the section.
|
2020-10-02 15:10:00 +00:00
|
|
|
this.revertFilters = () => {
|
2022-11-17 20:17:51 +00:00
|
|
|
this._unsavedFilters.clear();
|
|
|
|
this.filters().forEach(c => {
|
|
|
|
c.filter.revert();
|
|
|
|
c.pinned.revert();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set `filter` for the field or column identified by `colRef`.
|
|
|
|
this.setFilter = (colRef: number, filter: Partial<Filter>) => {
|
|
|
|
this._unsavedFilters.set(colRef, {...this._unsavedFilters.get(colRef), ...filter});
|
|
|
|
const filterInfo = this.filters().find(c => c.fieldOrColumn.origCol().origColRef() === colRef);
|
|
|
|
if (!filterInfo) { return; }
|
|
|
|
|
|
|
|
const {filter: newFilter, pinned: newPinned} = filter;
|
|
|
|
if (newFilter !== undefined) { filterInfo.filter(newFilter); }
|
|
|
|
if (newPinned !== undefined) { filterInfo.pinned(newPinned); }
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
|
2022-11-17 20:17:51 +00:00
|
|
|
// Revert the filter of the field or column identified by `colRef`.
|
|
|
|
this.revertFilter = (colRef: number) => {
|
|
|
|
this._unsavedFilters.delete(colRef);
|
2021-11-19 20:30:11 +00:00
|
|
|
const filterInfo = this.filters().find(c => c.fieldOrColumn.origCol().origColRef() === colRef);
|
2022-11-17 20:17:51 +00:00
|
|
|
if (!filterInfo) { return; }
|
|
|
|
|
|
|
|
filterInfo.filter.revert();
|
|
|
|
filterInfo.pinned.revert();
|
2021-11-19 20:30:11 +00:00
|
|
|
};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Customizable version of the JSON-stringified sort spec. It may diverge from the saved one.
|
|
|
|
this.activeSortJson = modelUtil.customValue(this.sortColRefs);
|
|
|
|
|
|
|
|
// This is an array (parsed from JSON) of colRefs (i.e. rowIds into the columns table), with a
|
|
|
|
// twist: a rowId may be positive or negative, for ascending or descending respectively.
|
|
|
|
// TODO: This method of ignoring columns which are deleted is inefficient and may cause conflicts
|
|
|
|
// with sharing.
|
2021-11-03 11:44:28 +00:00
|
|
|
this.activeSortSpec = modelUtil.jsonObservable(this.activeSortJson, (obj: Sort.SortSpec|null) => {
|
|
|
|
return (obj || []).filter((sortRef: Sort.ColSpec) => {
|
|
|
|
const colModel = docModel.columns.getRowModel(Sort.getColRef(sortRef));
|
2020-10-02 15:10:00 +00:00
|
|
|
return !colModel._isDeleted() && colModel.getRowId();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Modified sort spec to take into account any active display columns.
|
|
|
|
this.activeDisplaySortSpec = this.autoDispose(ko.computed(() => {
|
|
|
|
return this.activeSortSpec().map(directionalColRef => {
|
2021-11-03 11:44:28 +00:00
|
|
|
const colRef = Sort.getColRef(directionalColRef);
|
2020-10-02 15:10:00 +00:00
|
|
|
const field = this.viewFields().all().find(f => f.column().origColRef() === colRef);
|
|
|
|
const effectiveColRef = field ? field.displayColRef() : colRef;
|
2021-11-03 11:44:28 +00:00
|
|
|
return Sort.swapColRef(directionalColRef, effectiveColRef);
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Evaluates to an array of column models, which are not referenced by anything in viewFields.
|
|
|
|
this.hiddenColumns = this.autoDispose(ko.pureComputed(() => {
|
|
|
|
const included = new Set(this.viewFields().all().map((f) => f.column().origColRef()));
|
2021-11-19 20:30:11 +00:00
|
|
|
return this.columns().filter(c => !included.has(c.getRowId()));
|
2020-10-02 15:10:00 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
this.hasFocus = ko.pureComputed({
|
|
|
|
// Read may occur for recently disposed sections, must check condition first.
|
2022-02-03 17:23:53 +00:00
|
|
|
read: () => !this.isDisposed() && this.view().activeSectionId() === this.id(),
|
2022-08-24 11:43:15 +00:00
|
|
|
write: (val) => { this.view().activeSectionId(val ? this.id() : 0); }
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Section-linking affects this table if linkSrcSection is set. The controller value of the
|
|
|
|
// link is the value of srcCol at activeRowId of linkSrcSection, or activeRowId itself when
|
|
|
|
// srcCol is unset. If targetCol is set, we filter for all rows whose targetCol is equal to
|
|
|
|
// the controller value. Otherwise, the controller value determines the rowId of the cursor.
|
2023-07-07 08:54:01 +00:00
|
|
|
this.linkSrcSection = refRecord(docModel.viewSections, this.linkSrcSectionRef);
|
|
|
|
this.linkSrcCol = refRecord(docModel.columns, this.linkSrcColRef);
|
|
|
|
this.linkTargetCol = refRecord(docModel.columns, this.linkTargetColRef);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-07-07 08:54:01 +00:00
|
|
|
this.activeRowId = ko.observable<UIRowId|null>(null);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-04-07 15:18:20 +00:00
|
|
|
this._linkingState = Holder.create(this);
|
2022-01-27 17:51:37 +00:00
|
|
|
this.linkingState = this.autoDispose(ko.pureComputed(() => {
|
2023-07-07 08:54:01 +00:00
|
|
|
if (!this.linkSrcSectionRef()) {
|
|
|
|
// This view section isn't selected by anything.
|
2022-08-30 20:13:57 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-01-27 17:51:37 +00:00
|
|
|
try {
|
|
|
|
const config = new LinkConfig(this);
|
2022-04-07 15:18:20 +00:00
|
|
|
return LinkingState.create(this._linkingState, docModel, config);
|
2022-01-27 17:51:37 +00:00
|
|
|
} catch (err) {
|
2022-08-30 20:13:57 +00:00
|
|
|
console.warn(err);
|
2022-04-07 15:18:20 +00:00
|
|
|
// Dispose old LinkingState in case creating the new one failed.
|
|
|
|
this._linkingState.dispose();
|
2022-01-27 17:51:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.linkingFilter = this.autoDispose(ko.pureComputed(() => {
|
|
|
|
return this.linkingState()?.filterColValues?.() || {filters: {}, operations: {}};
|
|
|
|
}));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// If the view instance for this section is instantiated, it will be accessible here.
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
this.viewInstance = ko.observable<BaseView|null>(null);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Describes the most recent cursor position in the section.
|
|
|
|
this.lastCursorPos = {
|
|
|
|
rowId: 0,
|
|
|
|
fieldIndex: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
// Describes the most recent scroll position.
|
|
|
|
this.lastScrollPos = {
|
|
|
|
rowIndex: 0, // Used for scrolly sections. Indicates the index of the first visible row.
|
|
|
|
offset: 0, // Pixel distance past the top of row indicated by rowIndex.
|
|
|
|
scrollLeft: 0 // Used for grid sections. Indicates the scrollLeft value of the scroll pane.
|
|
|
|
};
|
|
|
|
|
|
|
|
this.disableAddRemoveRows = ko.pureComputed(() => this.table().disableAddRemoveRows());
|
|
|
|
|
|
|
|
this.isSorted = ko.pureComputed(() => this.activeSortSpec().length > 0);
|
|
|
|
this.disableDragRows = ko.pureComputed(() => this.isSorted() || !this.table().supportsManualSort());
|
2021-04-14 15:17:45 +00:00
|
|
|
|
2021-06-18 09:22:27 +00:00
|
|
|
// Number of frozen columns
|
|
|
|
this.rawNumFrozen = modelUtil.customValue(this.optionsObj.prop('numFrozen'));
|
|
|
|
// Number for frozen columns to display
|
|
|
|
this.numFrozen = ko.pureComputed(() =>
|
|
|
|
Math.max(
|
|
|
|
0,
|
|
|
|
Math.min(
|
|
|
|
this.rawNumFrozen(),
|
|
|
|
this.viewFields().all().length - 1
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2022-01-12 13:30:51 +00:00
|
|
|
|
|
|
|
this.hasCustomOptions = ko.observable(false);
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
this.desiredAccessLevel = ko.observable<AccessLevel|null>(null);
|
|
|
|
this.columnsToMap = ko.observable<ColumnsToMap|null>(null);
|
2022-02-08 15:23:14 +00:00
|
|
|
// Calculate mapped columns for Custom Widget.
|
|
|
|
this.mappedColumns = ko.pureComputed(() => {
|
|
|
|
// First check if widget has requested a custom column mapping and
|
|
|
|
// if we have a saved configuration.
|
|
|
|
const request = this.columnsToMap();
|
|
|
|
const mapping = this.customDef.columnsMapping();
|
2022-02-10 12:31:14 +00:00
|
|
|
if (!request || !mapping) {
|
2022-02-08 15:23:14 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// Convert simple column expressions (widget can just specify a name of a column) to a rich column definition.
|
|
|
|
const columnsToMap = request.map(r => new ColumnToMapImpl(r));
|
|
|
|
const result: WidgetColumnMap = {};
|
|
|
|
// Prepare map of existing column, will need this for translating colRefs to colIds.
|
|
|
|
const colMap = new Map(this.columns().map(f => [f.id.peek(), f]));
|
|
|
|
for(const widgetCol of columnsToMap) {
|
|
|
|
// Start with marking this column as not mapped.
|
|
|
|
result[widgetCol.name] = widgetCol.allowMultiple ? [] : null;
|
|
|
|
const mappedCol = mapping[widgetCol.name];
|
|
|
|
if (!mappedCol) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (widgetCol.allowMultiple) {
|
|
|
|
// We expect a list of colRefs be mapped;
|
|
|
|
if (!Array.isArray(mappedCol)) { continue; }
|
|
|
|
result[widgetCol.name] = mappedCol
|
|
|
|
// Remove all colRefs saved but deleted
|
|
|
|
.filter(cId => colMap.has(cId))
|
|
|
|
// And those with wrong type.
|
|
|
|
.filter(cId => widgetCol.canByMapped(colMap.get(cId)!.pureType()))
|
|
|
|
.map(cId => colMap.get(cId)!.colId());
|
|
|
|
} else {
|
|
|
|
// Widget expects a single value and existing column
|
|
|
|
if (Array.isArray(mappedCol) || !colMap.has(mappedCol)) { continue; }
|
|
|
|
const selectedColumn = colMap.get(mappedCol)!;
|
|
|
|
result[widgetCol.name] = widgetCol.canByMapped(selectedColumn.pureType()) ? selectedColumn.colId() : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
2022-02-01 19:51:40 +00:00
|
|
|
|
|
|
|
this.allowSelectBy = Observable.create(this, false);
|
|
|
|
this.selectedRows = Observable.create(this, []);
|
2022-08-08 13:32:50 +00:00
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
this.tableId = this.autoDispose(ko.pureComputed(() => this.table().tableId()));
|
|
|
|
const rawSection = this.autoDispose(ko.pureComputed(() => this.table().rawViewSection()));
|
2022-08-08 13:32:50 +00:00
|
|
|
this.rulesCols = refListRecords(docModel.columns, ko.pureComputed(() => rawSection().rules()));
|
|
|
|
this.rulesColsIds = ko.pureComputed(() => this.rulesCols().map(c => c.colId()));
|
|
|
|
this.rulesStyles = modelUtil.savingComputed({
|
|
|
|
read: () => rawSection().optionsObj.prop("rulesOptions")() ?? [],
|
|
|
|
write: (setter, val) => setter(rawSection().optionsObj.prop("rulesOptions"), val)
|
|
|
|
});
|
|
|
|
this.hasRules = ko.pureComputed(() => this.rulesCols().length > 0);
|
|
|
|
this.addEmptyRule = async () => {
|
|
|
|
const action = [
|
|
|
|
'AddEmptyRule',
|
|
|
|
this.tableId.peek(),
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
];
|
|
|
|
await docModel.docData.sendAction(action, `Update rules for ${this.table.peek().tableId.peek()}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.removeRule = (index: number) => removeRule(docModel, this, index);
|
2023-02-24 11:12:55 +00:00
|
|
|
|
|
|
|
this.isCollapsed = this.autoDispose(ko.pureComputed(() => {
|
|
|
|
const list = this.view().activeCollapsedSections();
|
|
|
|
return list.includes(this.id());
|
|
|
|
}));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|