UNPKG

@adaptabletools/adaptable

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

142 lines (141 loc) 7.08 kB
import { ApiBase } from '../Implementation/ApiBase'; export class PredicateInternalApi extends ApiBase { /** * Returns true if the predicate has a dropdown. * * @param predicate */ hasPredicateValues(predicate) { return predicate?.PredicateId === 'In' || predicate?.PredicateId === 'NotIn'; } /** * Get all Filter Predicate Definitions - System and Custom */ getFilterPredicateDefs(scope) { return this.mergeSystemAndCustomPredicates(this.getSystemFilterPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('columnFilter')); } getSystemFilterPredicateIds(scope) { const systemFilterPredicates = this.getPredicateOptions().systemFilterPredicates; if (typeof systemFilterPredicates === 'function') { const systemPredicateContext = { ...this.getAdaptableInternalApi().buildBaseContext(), systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('columnFilter'), moduleScope: 'columnFilter', columnScope: scope, }; return systemFilterPredicates(systemPredicateContext); } return systemFilterPredicates; } /** * Get all Alert Predicate Definitions - System and Custom */ getAlertPredicateDefs(scope) { return this.mergeSystemAndCustomPredicates(this.getSystemAlertPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('alert')); } getSystemAlertPredicateIds(scope) { const systemAlertPredicates = this.getPredicateOptions().systemAlertPredicates; if (typeof systemAlertPredicates === 'function') { const systemPredicateContext = { ...this.getAdaptableInternalApi().buildBaseContext(), systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('alert'), moduleScope: 'alert', columnScope: scope, }; return systemAlertPredicates(systemPredicateContext); } return systemAlertPredicates; } getSystemBadgeStylePredicateIds(scope) { const systemBadgeStylePredicates = this.getPredicateOptions().systemBadgeStylePredicates; if (typeof systemBadgeStylePredicates === 'function') { const systemPredicateContext = { ...this.getAdaptableInternalApi().buildBaseContext(), systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('badgeStyle'), moduleScope: 'badgeStyle', columnScope: scope, }; return systemBadgeStylePredicates(systemPredicateContext); } return systemBadgeStylePredicates; } /** * Get all Format Column Predicate Definitions - System and Custom */ getFormatColumnPredicateDefs(scope) { return this.mergeSystemAndCustomPredicates(this.getSystemFormatColumnPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('formatColumn')); } getSystemFormatColumnPredicateIds(scope) { const systemFormatColumnPredicates = this.getPredicateOptions().systemFormatColumnPredicates; if (typeof systemFormatColumnPredicates === 'function') { const systemPredicateContext = { ...this.getAdaptableInternalApi().buildBaseContext(), systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('formatColumn'), moduleScope: 'formatColumn', columnScope: scope, }; return systemFormatColumnPredicates(systemPredicateContext); } return systemFormatColumnPredicates; } /** * Get all Flashing Cell Predicate Definitions - System and Custom */ getFlashingCellPredicateDefs(scope) { return this.mergeSystemAndCustomPredicates(this.getSystemFlashingCellPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('flashingcell')); } getSystemFlashingCellPredicateIds(scope) { const systemFlashingCellPredicates = this.getPredicateOptions().systemFlashingCellPredicates; if (typeof systemFlashingCellPredicates === 'function') { const systemPredicateContext = { systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('flashingcell'), moduleScope: 'flashingcell', columnScope: scope, ...this.getAdaptableInternalApi().buildBaseContext(), }; return systemFlashingCellPredicates(systemPredicateContext); } return systemFlashingCellPredicates; } /** * Gets the correct Equality-type System Predicate for a particular DataType * @param dataType DataType of Column */ getEqualityPredicateForDataType(dataType) { let predicateId; switch (dataType) { case 'number': predicateId = 'Equals'; break; case 'date': case 'dateString': predicateId = 'On'; break; case 'text': predicateId = 'Is'; break; default: predicateId = 'Equals'; break; } return predicateId; } /** * Get all Badge Style Predicate Definitions - System and Custom */ getBadgeStylePredicateDefs(scope) { return this.mergeSystemAndCustomPredicates(this.getSystemBadgeStylePredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('badgeStyle')); } /** * Merges System and Custom Predicate Definitions but ensures that Custom ones take precedence * (i.e. if there is a Custom Predicate with the same Id as a System one, the Custom one is used) */ mergeSystemAndCustomPredicates(systemDefs, customDefs) { const systemDefsToUse = systemDefs.map((systemDef) => { const customDef = customDefs.find((customDef) => customDef.id === systemDef.id); return customDef ? customDef : systemDef; }); const customDefsToUse = customDefs.filter((customDef) => !systemDefsToUse.find((systemDef) => systemDef.id === customDef.id)); return [...systemDefsToUse, ...customDefsToUse]; } }