@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
111 lines (110 loc) • 4.5 kB
JavaScript
import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants';
import * as CustomSortRedux from '../../Redux/ActionsReducers/CustomSortRedux';
import { ApiBase } from './ApiBase';
import { CustomSortInternalApi } from '../Internal/CustomSortInternalApi';
export class CustomSortApiImpl extends ApiBase {
constructor(_adaptable) {
super(_adaptable);
this.internalApi = new CustomSortInternalApi(_adaptable);
}
getCustomSortState() {
return this.getAdaptableState().CustomSort;
}
getCustomSorts(config) {
return (this.handleLayoutAssociatedObjects(this.getCustomSortState().CustomSorts, 'CustomSort', config) ?? []);
}
getCustomSortById(id) {
return this.getCustomSorts().find((customSort) => customSort.Uuid === id);
}
getLiveCustomSorts() {
let returnVals = [];
const sortedColIds = this.getGridApi()
.getColumnSorts()
.map((c) => c.ColumnId);
const activeCustomSorts = this.getActiveCustomSorts();
if (sortedColIds == undefined || activeCustomSorts == undefined) {
return returnVals;
}
sortedColIds.forEach((columnId) => {
const customSort = activeCustomSorts.find((c) => c.ColumnId == columnId);
if (customSort) {
returnVals.push(customSort);
}
});
return returnVals;
}
getLiveCustomSortComparers() {
let returnComparers = [];
const sortedColIds = this.getGridApi()
.getColumnSorts()
.map((c) => c.ColumnId);
const sortedCols = this.getColumnApi().getColumnsWithColumnIds(sortedColIds);
const customSortComparers = this.getCustomSortOptions().customSortComparers;
if (sortedColIds == undefined || customSortComparers == undefined) {
return returnComparers;
}
const scopeApi = this.getColumnScopeApi();
sortedCols.forEach((column) => {
const comparer = customSortComparers.find((acs) => scopeApi.isColumnInScope(column, acs.scope));
if (comparer && !returnComparers.includes(comparer)) {
returnComparers.push(comparer);
}
});
return returnComparers;
}
getActiveCustomSorts(config) {
return this.getCustomSorts(config).filter((customSort) => !customSort.IsSuspended);
}
getSuspendedCustomSorts(config) {
return this.getCustomSorts(config).filter((customSort) => customSort.IsSuspended);
}
getCustomSortByColumn(column) {
return this.getCustomSorts().find((cs) => cs.ColumnId == column);
}
getCustomSortForColumn(columnId) {
return this.getCustomSorts().find((cs) => cs.ColumnId == columnId);
}
addCustomSort(customSort) {
this.addUidToAdaptableObject(customSort);
this.dispatchAction(CustomSortRedux.CustomSortAdd(customSort));
return this.getCustomSortById(customSort.Uuid);
}
createCustomSort(columnId, values) {
let customSort = { ColumnId: columnId, SortedValues: values };
return this.addCustomSort(customSort);
}
editCustomSort(columnId, values) {
const previousCustomSort = this.getCustomSortForColumn(columnId);
if (!previousCustomSort) {
this.logWarn(`No custom sort defined for ${columnId}`);
return;
}
const newCustomSort = {
...previousCustomSort,
SortedValues: values,
};
this.dispatchAction(CustomSortRedux.CustomSortEdit(newCustomSort));
return this.getCustomSortByColumn(columnId);
}
deleteCustomSort(column) {
let customSort = this.getCustomSortForColumn(column);
this.dispatchAction(CustomSortRedux.CustomSortDelete(customSort));
}
suspendCustomSort(customSort) {
this.dispatchAction(CustomSortRedux.CustomSortSuspend(customSort));
return this.getCustomSortById(customSort.Uuid);
}
unSuspendCustomSort(customSort) {
this.dispatchAction(CustomSortRedux.CustomSortUnSuspend(customSort));
return this.getCustomSortById(customSort.Uuid);
}
suspendAllCustomSort() {
this.dispatchAction(CustomSortRedux.CustomSortSuspendAll());
}
unSuspendAllCustomSort() {
this.dispatchAction(CustomSortRedux.CustomSortUnSuspendAll());
}
openCustomSortSettingsPanel() {
this.showModulePopup(ModuleConstants.CustomSortModuleId);
}
}