2020-10-02 15:10:00 +00:00
|
|
|
var _ = require('underscore');
|
|
|
|
var ko = require('knockout');
|
|
|
|
var dispose = require('../lib/dispose');
|
|
|
|
var dom = require('../lib/dom');
|
|
|
|
var kd = require('../lib/koDom');
|
|
|
|
var kf = require('../lib/koForm');
|
|
|
|
var koArray = require('../lib/koArray');
|
|
|
|
var commands = require('./commands');
|
|
|
|
var {CustomSectionElement} = require('../lib/CustomSectionElement');
|
2021-09-15 08:51:18 +00:00
|
|
|
const {ChartConfig} = require('./ChartView');
|
2021-11-03 11:44:28 +00:00
|
|
|
const {Computed, dom: grainjsDom, makeTestId, Observable, styled, MultiHolder} = require('grainjs');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-11-03 11:44:28 +00:00
|
|
|
const {addToSort} = require('app/client/lib/sortUtil');
|
|
|
|
const {updatePositions} = require('app/client/lib/sortUtil');
|
2021-05-04 10:27:15 +00:00
|
|
|
const {attachColumnFilterMenu} = require('app/client/ui/ColumnFilterMenu');
|
|
|
|
const {addFilterMenu} = require('app/client/ui/FilterBar');
|
2022-08-08 13:32:50 +00:00
|
|
|
const {cssIcon, cssRow} = require('app/client/ui/RightPanelStyles');
|
2020-10-02 15:10:00 +00:00
|
|
|
const {basicButton, primaryButton} = require('app/client/ui2018/buttons');
|
2021-11-03 11:44:28 +00:00
|
|
|
const {labeledLeftSquareCheckbox} = require("app/client/ui2018/checkbox");
|
2022-09-06 01:51:57 +00:00
|
|
|
const {theme} = require('app/client/ui2018/cssVars');
|
2020-10-02 15:10:00 +00:00
|
|
|
const {cssDragger} = require('app/client/ui2018/draggableList');
|
|
|
|
const {menu, menuItem, select} = require('app/client/ui2018/menus');
|
2020-11-20 03:49:33 +00:00
|
|
|
const {confirmModal} = require('app/client/ui2018/modals');
|
2021-11-03 11:44:28 +00:00
|
|
|
const {Sort} = require('app/common/SortSpec');
|
2020-10-02 15:10:00 +00:00
|
|
|
const isEqual = require('lodash/isEqual');
|
|
|
|
const {cssMenuItem} = require('popweasel');
|
2022-10-28 16:11:08 +00:00
|
|
|
const {makeT} = require('app/client/lib/localization');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const testId = makeTestId('test-vconfigtab-');
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('components.ViewConfigTab');
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Helper class that combines one ViewSection's data for building dom.
|
|
|
|
*/
|
|
|
|
function ViewSectionData(section) {
|
|
|
|
this.section = section;
|
|
|
|
|
|
|
|
// A koArray reflecting the columns (RowModels) that are not present in the current view.
|
|
|
|
this.hiddenFields = this.autoDispose(koArray.syncedKoArray(section.hiddenColumns));
|
|
|
|
}
|
|
|
|
dispose.makeDisposable(ViewSectionData);
|
|
|
|
|
|
|
|
|
|
|
|
function ViewConfigTab(options) {
|
|
|
|
var self = this;
|
|
|
|
this.gristDoc = options.gristDoc;
|
|
|
|
this.viewModel = options.viewModel;
|
|
|
|
|
|
|
|
// viewModel may point to different views, but viewSectionData is a single koArray reflecting
|
|
|
|
// the sections of the current view.
|
|
|
|
this.viewSectionData = this.autoDispose(
|
|
|
|
koArray.syncedKoArray(this.viewModel.viewSections, function(section) {
|
|
|
|
return ViewSectionData.create(section);
|
|
|
|
})
|
|
|
|
.setAutoDisposeValues()
|
|
|
|
);
|
|
|
|
|
|
|
|
this.activeSectionData = this.autoDispose(ko.computed(function() {
|
|
|
|
return _.find(self.viewSectionData.all(), function(sectionData) {
|
|
|
|
return sectionData.section &&
|
|
|
|
sectionData.section.getRowId() === self.viewModel.activeSectionId();
|
|
|
|
}) || self.viewSectionData.at(0);
|
|
|
|
}));
|
|
|
|
this.isDetail = this.autoDispose(ko.computed(function() {
|
2021-04-26 21:54:09 +00:00
|
|
|
return ['detail', 'single'].includes(this.viewModel.activeSection().parentKey());
|
2020-10-02 15:10:00 +00:00
|
|
|
}, this));
|
|
|
|
this.isChart = this.autoDispose(ko.computed(function() {
|
|
|
|
return this.viewModel.activeSection().parentKey() === 'chart';}, this));
|
|
|
|
this.isGrid = this.autoDispose(ko.computed(function() {
|
|
|
|
return this.viewModel.activeSection().parentKey() === 'record';}, this));
|
|
|
|
this.isCustom = this.autoDispose(ko.computed(function() {
|
|
|
|
return this.viewModel.activeSection().parentKey() === 'custom';}, this));
|
|
|
|
}
|
|
|
|
dispose.makeDisposable(ViewConfigTab);
|
|
|
|
|
|
|
|
|
|
|
|
ViewConfigTab.prototype.buildSortDom = function() {
|
|
|
|
return grainjsDom.maybe(this.activeSectionData, (sectionData) => {
|
|
|
|
const section = sectionData.section;
|
|
|
|
|
|
|
|
// Computed to indicate if sort has changed from saved.
|
|
|
|
const hasChanged = Computed.create(null, (use) =>
|
2021-11-03 11:44:28 +00:00
|
|
|
!isEqual(use(section.activeSortSpec), Sort.parseSortColRefs(use(section.sortColRefs))));
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Computed array of sortable columns.
|
|
|
|
const columns = Computed.create(null, (use) => {
|
|
|
|
// Columns is an observable holding an observable array - must call 'use' on it 2x.
|
|
|
|
const cols = use(use(use(section.table).columns));
|
|
|
|
return cols.filter(col => !use(col.isHiddenCol))
|
|
|
|
.map(col => ({
|
|
|
|
label: use(col.colId),
|
|
|
|
value: col.getRowId(),
|
2021-11-03 11:44:28 +00:00
|
|
|
icon: 'FieldColumn',
|
|
|
|
type: col.type()
|
2020-10-02 15:10:00 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2021-11-03 11:44:28 +00:00
|
|
|
// We only want to recreate rows, when the actual columns change.
|
|
|
|
const colRefs = Computed.create(null, (use) => {
|
|
|
|
return use(section.activeSortSpec).map(col => Sort.getColRef(col));
|
|
|
|
});
|
|
|
|
const sortRows = koArray(colRefs.get());
|
|
|
|
colRefs.addListener((curr, prev) => {
|
|
|
|
if (!isEqual(curr, prev)){
|
|
|
|
sortRows.assign(curr);
|
|
|
|
}
|
|
|
|
})
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Sort row create function for each sort row in the draggableList.
|
2021-11-03 11:44:28 +00:00
|
|
|
const rowCreateFn = colRef =>
|
|
|
|
this._buildSortRow(colRef, section.activeSortSpec, columns);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Reorder function called when sort rows are reordered via dragging.
|
|
|
|
const reorder = (...args) => {
|
2021-11-03 11:44:28 +00:00
|
|
|
const spec = Sort.reorderSortRefs(section.activeSortSpec.peek(), ...args);
|
2020-10-02 15:10:00 +00:00
|
|
|
this._saveSort(spec);
|
|
|
|
};
|
|
|
|
|
|
|
|
return grainjsDom('div',
|
|
|
|
grainjsDom.autoDispose(hasChanged),
|
|
|
|
grainjsDom.autoDispose(columns),
|
2021-11-03 11:44:28 +00:00
|
|
|
grainjsDom.autoDispose(colRefs),
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.autoDispose(sortRows),
|
|
|
|
// Sort rows.
|
|
|
|
kf.draggableList(sortRows, rowCreateFn, {
|
|
|
|
reorder,
|
|
|
|
removeButton: false,
|
|
|
|
drag_indicator: cssDragger,
|
|
|
|
itemClass: cssDragRow.className
|
|
|
|
}),
|
|
|
|
// Add to sort btn & menu & fake sort row.
|
|
|
|
this._buildAddToSortBtn(columns),
|
|
|
|
// Update/save/reset buttons visible when the sort has changed.
|
|
|
|
cssRow(
|
2021-05-04 10:27:15 +00:00
|
|
|
cssExtraMarginTop.cls(''),
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.maybe(hasChanged, () => [
|
2022-10-28 16:11:08 +00:00
|
|
|
primaryButton(t('Save'), {style: 'margin-right: 8px;'},
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.on('click', () => { section.activeSortJson.save(); }),
|
|
|
|
testId('sort-save'),
|
|
|
|
grainjsDom.boolAttr('disabled', this.gristDoc.isReadonly),
|
|
|
|
),
|
|
|
|
// Let's use same label (revert) as the similar button which appear in the view section.
|
|
|
|
// menu.
|
2022-10-28 16:11:08 +00:00
|
|
|
basicButton(t('Revert'),
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.on('click', () => { section.activeSortJson.revert(); }),
|
|
|
|
testId('sort-reset')
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
cssFlex(),
|
|
|
|
grainjsDom.maybe(section.isSorted, () =>
|
2022-10-28 16:11:08 +00:00
|
|
|
basicButton(t('UpdateData'), {style: 'margin-left: 8px; white-space: nowrap;'},
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.on('click', () => { updatePositions(this.gristDoc, section); }),
|
|
|
|
testId('sort-update'),
|
|
|
|
grainjsDom.show((use) => use(use(section.table).supportsManualSort)),
|
|
|
|
grainjsDom.boolAttr('disabled', this.gristDoc.isReadonly),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
grainjsDom.show((use) => use(hasChanged) || use(section.isSorted))
|
|
|
|
),
|
|
|
|
testId('sort-menu')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Builds a single row of the sort dom
|
2021-11-03 11:44:28 +00:00
|
|
|
// Takes the colRef, current sortSpec and array of column select options to show
|
2020-10-02 15:10:00 +00:00
|
|
|
// in the column select dropdown.
|
2021-11-03 11:44:28 +00:00
|
|
|
ViewConfigTab.prototype._buildSortRow = function(colRef, sortSpec, columns) {
|
|
|
|
const holder = new MultiHolder();
|
|
|
|
|
|
|
|
const col = Computed.create(holder, () => colRef);
|
|
|
|
const details = Computed.create(holder, (use) => Sort.specToDetails(Sort.findCol(use(sortSpec), colRef)));
|
|
|
|
const hasSpecs = Computed.create(holder, details, (_, details) => Sort.hasOptions(details));
|
|
|
|
const isAscending = Computed.create(holder, details, (_, details) => details.direction === Sort.ASC);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
col.onWrite((newRef) => {
|
2021-11-03 11:44:28 +00:00
|
|
|
let specs = sortSpec.peek();
|
|
|
|
const colSpec = Sort.findCol(specs, colRef);
|
|
|
|
const newSpec = Sort.findCol(specs, newRef);
|
|
|
|
if (newSpec) {
|
|
|
|
// this column is already there so only swap order
|
|
|
|
specs = Sort.swap(specs, colRef, newRef);
|
|
|
|
// but keep the directions
|
|
|
|
specs = Sort.setSortDirection(specs, colRef, Sort.direction(newSpec))
|
|
|
|
specs = Sort.setSortDirection(specs, newRef, Sort.direction(colSpec))
|
|
|
|
} else {
|
|
|
|
specs = Sort.replace(specs, colRef, Sort.createColSpec(newRef, Sort.direction(colSpec)));
|
|
|
|
}
|
|
|
|
this._saveSort(specs);
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
2021-11-03 11:44:28 +00:00
|
|
|
|
|
|
|
const computedFlag = (flag, allowedTypes, label) => {
|
|
|
|
const computed = Computed.create(holder, details, (_, details) => details[flag] || false);
|
|
|
|
computed.onWrite(value => {
|
|
|
|
const specs = sortSpec.peek();
|
|
|
|
// Get existing details
|
|
|
|
const details = Sort.specToDetails(Sort.findCol(specs, colRef));
|
|
|
|
// Update flags
|
|
|
|
details[flag] = value;
|
|
|
|
// Replace the colSpec at the index
|
|
|
|
this._saveSort(Sort.replace(specs, Sort.getColRef(colRef), details));
|
|
|
|
});
|
|
|
|
return {computed, allowedTypes, flag, label};
|
|
|
|
}
|
2022-10-28 16:11:08 +00:00
|
|
|
const orderByChoice = computedFlag('orderByChoice', ['Choice'], t('UseChoicePosition'));
|
|
|
|
const naturalSort = computedFlag('naturalSort', ['Text'], t('NaturalSort'));
|
|
|
|
const emptyLast = computedFlag('emptyLast', null, t('EmptyValuesLast'));
|
2021-11-03 11:44:28 +00:00
|
|
|
const flags = [orderByChoice, emptyLast, naturalSort];
|
|
|
|
|
|
|
|
const column = columns.get().find(col => col.value === Sort.getColRef(colRef));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
return cssSortRow(
|
2021-11-03 11:44:28 +00:00
|
|
|
grainjsDom.autoDispose(holder),
|
2020-10-02 15:10:00 +00:00
|
|
|
cssSortSelect(
|
|
|
|
select(col, columns)
|
|
|
|
),
|
2021-11-03 11:44:28 +00:00
|
|
|
// Use domComputed method for this icon, for dynamic testId, otherwise
|
|
|
|
// we are not able add it dynamically.
|
|
|
|
grainjsDom.domComputed(isAscending, isAscending =>
|
|
|
|
cssSortIconPrimaryBtn(
|
|
|
|
"Sort",
|
|
|
|
grainjsDom.style("transform", isAscending ? "scaleY(-1)" : "none"),
|
|
|
|
grainjsDom.on("click", () => {
|
|
|
|
this._saveSort(Sort.flipSort(sortSpec.peek(), colRef));
|
|
|
|
}),
|
|
|
|
testId("sort-order"),
|
|
|
|
testId(isAscending ? "sort-order-asc" : "sort-order-desc")
|
|
|
|
)
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
|
|
|
cssSortIconBtn('Remove',
|
|
|
|
grainjsDom.on('click', () => {
|
2021-11-03 11:44:28 +00:00
|
|
|
const specs = sortSpec.peek();
|
|
|
|
if (Sort.findCol(specs, colRef)) {
|
|
|
|
this._saveSort(Sort.removeCol(specs, colRef));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
testId('sort-remove')
|
|
|
|
),
|
2021-11-03 11:44:28 +00:00
|
|
|
cssMenu(
|
|
|
|
cssBigIconWrapper(
|
2022-09-06 01:51:57 +00:00
|
|
|
cssIcon('Dots', grainjsDom.cls(cssBgAccent.className, hasSpecs)),
|
2021-11-03 11:44:28 +00:00
|
|
|
testId('sort-options-icon'),
|
|
|
|
),
|
|
|
|
menu(_ctl => flags.map(({computed, allowedTypes, flag, label}) => {
|
|
|
|
// when allowedTypes is null, flag can be used for every column
|
|
|
|
const enabled = !allowedTypes || allowedTypes.includes(column.type);
|
|
|
|
return cssMenuItem(
|
|
|
|
labeledLeftSquareCheckbox(
|
|
|
|
computed,
|
|
|
|
label,
|
|
|
|
grainjsDom.prop('disabled', !enabled),
|
|
|
|
),
|
|
|
|
grainjsDom.cls(cssOptionMenuItem.className),
|
|
|
|
grainjsDom.cls('disabled', !enabled),
|
|
|
|
testId('sort-option'),
|
|
|
|
testId(`sort-option-${flag}`),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
))
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('sort-row')
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Build the button to open the menu to add a sort item to the sort dom.
|
|
|
|
// Takes the full array of sortable column select options.
|
|
|
|
ViewConfigTab.prototype._buildAddToSortBtn = function(columns) {
|
|
|
|
// Observable indicating whether the add new column row is visible.
|
|
|
|
const showAddNew = Observable.create(null, false);
|
2021-11-03 11:44:28 +00:00
|
|
|
const available = Computed.create(null, (use) => {
|
|
|
|
const currentSection = use(this.activeSectionData).section;
|
|
|
|
const currentSortSpec = use(currentSection.activeSortSpec);
|
|
|
|
const specRowIds = new Set(currentSortSpec.map(_sortRef => Sort.getColRef(_sortRef)));
|
|
|
|
return use(columns)
|
|
|
|
.filter(_col => !specRowIds.has(_col.value))
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
|
|
|
// Add column button.
|
|
|
|
cssRow(
|
|
|
|
grainjsDom.autoDispose(showAddNew),
|
2021-11-03 11:44:28 +00:00
|
|
|
grainjsDom.autoDispose(available),
|
2020-10-02 15:10:00 +00:00
|
|
|
cssTextBtn(
|
2022-10-28 16:11:08 +00:00
|
|
|
cssPlusIcon('Plus'), t('AddColumn'),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('sort-add')
|
|
|
|
),
|
2021-11-03 11:44:28 +00:00
|
|
|
grainjsDom.hide((use) => use(showAddNew) || !use(available).length),
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.on('click', () => { showAddNew.set(true); }),
|
|
|
|
),
|
|
|
|
// Fake add column row that appears only when the menu is open to select a new column
|
|
|
|
// to add to the sort. Immediately destroyed when menu is closed.
|
2021-11-03 11:44:28 +00:00
|
|
|
grainjsDom.maybe((use) => use(showAddNew) && use(available), _columns => {
|
2020-10-02 15:10:00 +00:00
|
|
|
const col = Observable.create(null, 0);
|
|
|
|
const currentSection = this.activeSectionData().section;
|
|
|
|
// Function called when a column select value is clicked.
|
|
|
|
const onClick = (_col) => {
|
|
|
|
showAddNew.set(false); // Remove add row ASAP to prevent flickering
|
2021-11-03 11:44:28 +00:00
|
|
|
addToSort(currentSection.activeSortSpec, _col.value, 1);
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
2021-11-03 11:44:28 +00:00
|
|
|
const menuCols = _columns.map(_col =>
|
|
|
|
menuItem(() => onClick(_col),
|
|
|
|
cssMenuIcon(_col.icon),
|
|
|
|
_col.label,
|
|
|
|
testId('sort-add-menu-row')
|
|
|
|
)
|
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
return cssRow(cssSortRow(
|
|
|
|
dom.autoDispose(col),
|
|
|
|
cssSortSelect(
|
2022-10-28 16:11:08 +00:00
|
|
|
select(col, [], {defaultLabel: t('AddColumn')}),
|
2020-10-02 15:10:00 +00:00
|
|
|
menu(() => [
|
|
|
|
menuCols,
|
|
|
|
grainjsDom.onDispose(() => { showAddNew.set(false); })
|
|
|
|
], {
|
|
|
|
// Trigger to make menu open immediately
|
|
|
|
trigger: [(elem, ctl) => {
|
|
|
|
ctl.open();
|
|
|
|
grainjsDom.onElem(elem, 'click', () => { ctl.close(); });
|
|
|
|
}],
|
|
|
|
stretchToSelector: `.${cssSortSelect.className}`
|
|
|
|
})
|
|
|
|
),
|
|
|
|
cssSortIconPrimaryBtn('Sort',
|
|
|
|
grainjsDom.style('transform', 'scaleY(-1)')
|
|
|
|
),
|
2021-11-03 11:44:28 +00:00
|
|
|
cssSortIconBtn('Remove'),
|
|
|
|
cssBigIconWrapper(cssIcon('Dots')),
|
2020-10-02 15:10:00 +00:00
|
|
|
));
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._saveSort = function(sortSpec) {
|
|
|
|
this.activeSectionData().section.activeSortSpec(sortSpec);
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._makeOnDemand = function(table) {
|
|
|
|
// After saving the changed setting, force the reload of the document.
|
|
|
|
const onConfirm = () => {
|
|
|
|
return table.onDemand.saveOnly(!table.onDemand.peek())
|
|
|
|
.then(() => {
|
|
|
|
return this.gristDoc.docComm.reloadDoc()
|
|
|
|
.catch((err) => {
|
|
|
|
// Ignore the expected error from the socket shutdown that we asked for.
|
|
|
|
if (!err.message.includes('GristWSConnection disposed')) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table.onDemand()) {
|
2020-11-20 03:49:33 +00:00
|
|
|
confirmModal('Unmark table On-Demand?', 'Unmark On-Demand', onConfirm,
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', 'If you unmark table ', dom('b', table), ' as On-Demand, ' +
|
|
|
|
'its data will be loaded into the calculation engine and will be available ' +
|
|
|
|
'for use in formulas. For a big table, this may greatly increase load times.',
|
2020-11-20 03:49:33 +00:00
|
|
|
dom('br'), dom('br'), 'Changing this setting will reload the document for all users.')
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
} else {
|
2020-11-20 03:49:33 +00:00
|
|
|
confirmModal('Make table On-Demand?', 'Make On-Demand', onConfirm,
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', 'If you make table ', dom('b', table), ' On-Demand, ' +
|
|
|
|
'its data will no longer be loaded into the calculation engine and will not be available ' +
|
|
|
|
'for use in formulas. It will remain available for viewing and editing.',
|
2020-11-20 03:49:33 +00:00
|
|
|
dom('br'), dom('br'), 'Changing this setting will reload the document for all users.')
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._buildAdvancedSettingsDom = function() {
|
|
|
|
return kd.maybe(() => {
|
|
|
|
const s = this.activeSectionData();
|
|
|
|
return s && !s.section.table().summarySourceTable() ? s : null;
|
|
|
|
}, (sectionData) => {
|
|
|
|
|
|
|
|
const table = sectionData.section.table();
|
|
|
|
const isCollapsed = ko.observable(true);
|
|
|
|
return [
|
2022-10-28 16:11:08 +00:00
|
|
|
kf.collapserLabel(isCollapsed, t('AdvancedSettings'), dom.testId('ViewConfig_advanced')),
|
2020-10-02 15:10:00 +00:00
|
|
|
kf.helpRow(kd.hide(isCollapsed),
|
2022-10-28 16:11:08 +00:00
|
|
|
t('BigTablesMayBeMarked'),
|
2020-10-02 15:10:00 +00:00
|
|
|
kd.style('text-align', 'left'),
|
|
|
|
kd.style('margin-top', '1.5rem')
|
|
|
|
),
|
|
|
|
kf.row(kd.hide(isCollapsed),
|
|
|
|
kf.label('Table ', dom('b', kd.text(table.tableId)), ':')
|
|
|
|
),
|
|
|
|
kf.row(kd.hide(isCollapsed),
|
|
|
|
kf.buttonGroup(kf.button(() => this._makeOnDemand(table),
|
2022-10-28 16:11:08 +00:00
|
|
|
kd.text(() => table.onDemand() ? t('UnmarkOnDemandButton') : t('MakeOnDemandButton')),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.testId('ViewConfig_onDemandBtn')
|
|
|
|
))
|
|
|
|
),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._buildFilterDom = function() {
|
2021-05-04 10:27:15 +00:00
|
|
|
return grainjsDom.maybe(this.activeSectionData, (sectionData) => {
|
|
|
|
const section = sectionData.section;
|
|
|
|
const docModel = this.gristDoc.docModel;
|
|
|
|
const popupControls = new WeakMap();
|
|
|
|
const activeFilterBar = section.activeFilterBar;
|
|
|
|
|
|
|
|
const hasChangedObs = Computed.create(null, (use) => use(section.filterSpecChanged) || !use(section.activeFilterBar.isSaved))
|
|
|
|
|
|
|
|
async function save() {
|
2022-10-28 16:11:08 +00:00
|
|
|
await docModel.docData.bundleActions(t("UpdateFilterSettings"), () => Promise.all([
|
2021-05-04 10:27:15 +00:00
|
|
|
section.saveFilters(), // Save filter
|
|
|
|
section.activeFilterBar.save(), // Save bar
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
function revert() {
|
|
|
|
section.revertFilters(); // Revert filter
|
|
|
|
section.activeFilterBar.revert(); // Revert bar
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2021-11-19 20:30:11 +00:00
|
|
|
grainjsDom.forEach(section.activeFilters, (filterInfo) => {
|
2021-05-04 10:27:15 +00:00
|
|
|
return cssRow(
|
|
|
|
cssIconWrapper(
|
|
|
|
cssFilterIcon('FilterSimple', cssNoMarginLeft.cls('')),
|
2021-11-19 20:30:11 +00:00
|
|
|
attachColumnFilterMenu(section, filterInfo, {
|
2021-05-04 10:27:15 +00:00
|
|
|
placement: 'bottom-end', attach: 'body',
|
2021-11-19 20:30:11 +00:00
|
|
|
trigger: [
|
|
|
|
'click',
|
|
|
|
(_el, popupControl) => popupControls.set(filterInfo.fieldOrColumn.origCol(), popupControl)
|
|
|
|
],
|
2021-05-04 10:27:15 +00:00
|
|
|
}),
|
|
|
|
),
|
2021-11-19 20:30:11 +00:00
|
|
|
cssLabel(grainjsDom.text(filterInfo.fieldOrColumn.label)),
|
2021-05-04 10:27:15 +00:00
|
|
|
cssIconWrapper(
|
2021-11-19 20:30:11 +00:00
|
|
|
cssFilterIcon('Remove',
|
|
|
|
dom.on('click', () => section.setFilter(filterInfo.fieldOrColumn.origCol().origColRef(), '')),
|
|
|
|
testId('remove-filter')
|
|
|
|
),
|
2021-05-04 10:27:15 +00:00
|
|
|
),
|
|
|
|
testId('filter'),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
cssRow(
|
|
|
|
grainjsDom.domComputed((use) => {
|
2021-11-19 20:30:11 +00:00
|
|
|
const filters = use(section.filters);
|
2021-05-04 10:27:15 +00:00
|
|
|
return cssTextBtn(
|
2022-10-28 16:11:08 +00:00
|
|
|
cssPlusIcon('Plus'), t('AddFilter'),
|
2021-11-19 20:30:11 +00:00
|
|
|
addFilterMenu(filters, section, popupControls, {placement: 'bottom-end'}),
|
2021-05-04 10:27:15 +00:00
|
|
|
testId('add-filter-btn'),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2022-02-07 14:02:26 +00:00
|
|
|
grainjsDom.maybe((use) => !use(section.isRaw),
|
|
|
|
() => cssRow(cssTextBtn(
|
2021-05-04 10:27:15 +00:00
|
|
|
testId('toggle-filter-bar'),
|
|
|
|
grainjsDom.domComputed((use) => {
|
|
|
|
const filterBar = use(activeFilterBar);
|
|
|
|
return cssPlusIcon(
|
|
|
|
filterBar ? "Tick" : "Plus",
|
|
|
|
cssIcon.cls('-green', Boolean(filterBar)),
|
|
|
|
testId('toggle-filter-bar-icon'),
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
2021-05-04 10:27:15 +00:00
|
|
|
}),
|
|
|
|
grainjsDom.on('click', () => activeFilterBar(!activeFilterBar.peek())),
|
|
|
|
'Toggle Filter Bar',
|
2022-02-07 14:02:26 +00:00
|
|
|
))),
|
2021-05-04 10:27:15 +00:00
|
|
|
grainjsDom.maybe(hasChangedObs, () => cssRow(
|
|
|
|
cssExtraMarginTop.cls(''),
|
|
|
|
testId('save-filter-btns'),
|
|
|
|
primaryButton(
|
2022-10-28 16:11:08 +00:00
|
|
|
t('Save'), {style: 'margin-right: 8px'},
|
2021-05-04 10:27:15 +00:00
|
|
|
grainjsDom.on('click', save),
|
|
|
|
grainjsDom.boolAttr('disabled', this.gristDoc.isReadonly),
|
|
|
|
),
|
|
|
|
basicButton(
|
2022-10-28 16:11:08 +00:00
|
|
|
t('Revert'),
|
2021-05-04 10:27:15 +00:00
|
|
|
grainjsDom.on('click', revert),
|
|
|
|
)
|
|
|
|
))
|
|
|
|
];
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._buildThemeDom = function() {
|
|
|
|
return kd.maybe(this.activeSectionData, (sectionData) => {
|
|
|
|
var section = sectionData.section;
|
|
|
|
if (this.isDetail()) {
|
|
|
|
const theme = Computed.create(null, (use) => use(section.themeDef));
|
|
|
|
theme.onWrite(val => section.themeDef.setAndSave(val));
|
|
|
|
return cssRow(
|
|
|
|
dom.autoDispose(theme),
|
|
|
|
select(theme, [
|
2022-10-28 16:11:08 +00:00
|
|
|
{label: t('Form'), value: 'form' },
|
|
|
|
{label: t('Compact'), value: 'compact'},
|
|
|
|
{label: t('Blocks'), value: 'blocks' },
|
2020-10-02 15:10:00 +00:00
|
|
|
]),
|
|
|
|
testId('detail-theme')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._buildChartConfigDom = function() {
|
2021-09-15 08:51:18 +00:00
|
|
|
return grainjsDom.maybe(this.viewModel.activeSection, (section) => grainjsDom.create(ChartConfig, this.gristDoc, section));
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ViewConfigTab.prototype._buildLayoutDom = function() {
|
|
|
|
return kd.maybe(this.activeSectionData, (sectionData) => {
|
|
|
|
if (this.isDetail()) {
|
|
|
|
const view = sectionData.section.viewInstance.peek();
|
|
|
|
const layoutEditorObs = ko.computed(() => view && view.recordLayout && view.recordLayout.layoutEditor());
|
|
|
|
return cssRow({style: 'margin-top: 16px;'},
|
|
|
|
kd.maybe(layoutEditorObs, (editor) => editor.buildFinishButtons()),
|
2022-10-28 16:11:08 +00:00
|
|
|
primaryButton(t('EditCardLayout'),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.autoDispose(layoutEditorObs),
|
|
|
|
dom.on('click', () => commands.allCommands.editLayout.run()),
|
|
|
|
grainjsDom.hide(layoutEditorObs),
|
|
|
|
testId('detail-edit-layout')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the three items for configuring a `Custom View`:
|
|
|
|
* 1) Mode picker: let user choose between 'url' and 'plugin' mode
|
|
|
|
* 2) Show if 'url' mode: let user enter the url
|
|
|
|
* 3) Show if 'plugin' mode: let user pick a plugin and a section from the list of available plugin.
|
|
|
|
*/
|
|
|
|
ViewConfigTab.prototype._buildCustomTypeItems = function() {
|
|
|
|
const docPluginManager = this.gristDoc.docPluginManager;
|
|
|
|
const activeSection = this.viewModel.activeSection;
|
|
|
|
|
|
|
|
// all available custom sections grouped by their plugin id
|
|
|
|
const customSections = _.groupBy(CustomSectionElement.getSections(docPluginManager.pluginsList), s => s.pluginId);
|
|
|
|
|
|
|
|
// all plugin ids which have custom sections
|
|
|
|
const allPlugins = Object.keys(customSections);
|
|
|
|
|
|
|
|
// the list of customSections of the selected plugin (computed)
|
|
|
|
const customSectionIds = ko.pureComputed(() => {
|
|
|
|
const sections = customSections[this.viewModel.activeSection().customDef.pluginId()] || [];
|
|
|
|
return sections.map(({sectionId}) => sectionId);
|
|
|
|
});
|
|
|
|
|
|
|
|
return [{
|
|
|
|
|
|
|
|
// 1)
|
|
|
|
buildDom: () => kd.scope(activeSection, ({customDef}) => kf.buttonSelect(customDef.mode,
|
|
|
|
kf.optionButton('url', 'URL', dom.testId('ViewConfigTab_customView_url')),
|
|
|
|
kf.optionButton('plugin', 'Plugin', dom.testId('ViewConfigTab_customView_plugin'))))
|
|
|
|
}, {
|
|
|
|
|
|
|
|
// 2)
|
2021-11-26 10:43:55 +00:00
|
|
|
// TODO: refactor this part, Custom Widget moved to separate file.
|
2020-10-02 15:10:00 +00:00
|
|
|
}, {
|
|
|
|
|
|
|
|
// 3)
|
|
|
|
showObs: () => activeSection().customDef.mode() === "plugin",
|
|
|
|
buildDom: () => kd.scope(activeSection, ({customDef}) => dom('div',
|
2022-10-28 16:11:08 +00:00
|
|
|
kf.row(5, t("PluginColon"), 13, kf.text(customDef.pluginId, {}, {list: "list_plugin"}, dom.testId('ViewConfigTab_customView_pluginId'))),
|
|
|
|
kf.row(5, t("SectionColon"), 13, kf.text(customDef.sectionId, {}, {list: "list_section"}, dom.testId('ViewConfigTab_customView_sectionId'))),
|
2020-10-02 15:10:00 +00:00
|
|
|
// For both `customPlugin` and `selectedSection` it is possible for the value not to be in the
|
|
|
|
// list of options. Combining <datalist> and <input> allows both to freely edit the value with
|
|
|
|
// keyboard and to select it from a list. Although the content of the list seems to be
|
|
|
|
// filtered by the current value, which could confuse user into thinking that there are no
|
|
|
|
// available options. I think it would be better to have the full list always, but it seems
|
|
|
|
// harder to accomplish and is left as a TODO.
|
|
|
|
dom('datalist#list_plugin', kd.foreach(koArray(allPlugins), value => dom('option', {value}))),
|
|
|
|
dom('datalist#list_section', kd.scope(customSectionIds, sections => kd.foreach(koArray(sections), (value) => dom('option', {value}))))
|
|
|
|
))
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
const cssMenuIcon = styled(cssIcon, `
|
|
|
|
margin: 0 8px 0 0;
|
|
|
|
|
|
|
|
.${cssMenuItem.className}-sel > & {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.iconButtonFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
// Note that the width is set to 0 so that flex-shrink works properly with long text values.
|
|
|
|
const cssSortSelect = styled('div', `
|
|
|
|
flex: 1 1 0px;
|
|
|
|
margin: 0 6px 0 0;
|
|
|
|
min-width: 0;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssSortIconBtn = styled(cssIcon, `
|
|
|
|
flex: none;
|
|
|
|
margin: 0 6px;
|
|
|
|
cursor: pointer;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlSecondaryFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlSecondaryHoverFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssSortIconPrimaryBtn = styled(cssSortIconBtn, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlHoverFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssTextBtn = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlHoverFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssPlusIcon = styled(cssIcon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
cursor: pointer;
|
|
|
|
margin: 0px 4px 3px 0;
|
|
|
|
|
|
|
|
.${cssTextBtn.className}:hover > & {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlHoverFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssDragRow = styled('div', `
|
|
|
|
display: flex !important;
|
|
|
|
align-items: center;
|
|
|
|
margin: 0 16px 0px 0px;
|
|
|
|
& > .kf_draggable_content {
|
|
|
|
margin: 6px 0;
|
|
|
|
flex: 1 1 0px;
|
|
|
|
min-width: 0px;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssSortRow = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
width: 100%;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssFlex = styled('div', `
|
|
|
|
flex: 1 1 0;
|
|
|
|
`);
|
|
|
|
|
2021-05-04 10:27:15 +00:00
|
|
|
const cssLabel = styled('div', `
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-grow: 1;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssExtraMarginTop = styled('div', `
|
|
|
|
margin-top: 28px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssFilterIcon = cssSortIconBtn;
|
|
|
|
|
|
|
|
const cssNoMarginLeft = styled('div', `
|
|
|
|
margin-left: 0;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssIconWrapper = styled('div', ``);
|
|
|
|
|
2021-11-03 11:44:28 +00:00
|
|
|
const cssBigIconWrapper = styled('div', `
|
|
|
|
padding: 3px;
|
|
|
|
border-radius: 3px;
|
|
|
|
cursor: pointer;
|
|
|
|
user-select: none;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssMenu = styled('div', `
|
|
|
|
display: inline-flex;
|
|
|
|
cursor: pointer;
|
|
|
|
border-radius: 3px;
|
|
|
|
border: 1px solid transparent;
|
|
|
|
&:hover, &.weasel-popup-open {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.hover};
|
2021-11-03 11:44:28 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2022-09-06 01:51:57 +00:00
|
|
|
const cssBgAccent = styled(`div`, `
|
|
|
|
background: ${theme.accentIcon}
|
2021-11-03 11:44:28 +00:00
|
|
|
`)
|
|
|
|
|
|
|
|
const cssOptionMenuItem = styled('div', `
|
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.hover};
|
2021-11-03 11:44:28 +00:00
|
|
|
}
|
|
|
|
& label {
|
|
|
|
flex: 1;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
&.disabled * {
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.menuItemDisabledFg} important;
|
2021-11-03 11:44:28 +00:00
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
module.exports = ViewConfigTab;
|