123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- 'use strict';
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2018, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define([], function () {
- 'use strict';
- // widget spec notation => IR spec notation
- var FILTER_AGGREGATION_MAP = {
- sum: 'SUM'
- };
- var FILTER_PREPOST_MAP = {
- pre: 'PRE',
- post: 'POST',
- PRE: 'pre',
- POST: 'post'
- };
- /*
- * This has utility helpers related to conversion between dashboard 'specs' and IR
- */
- var IRUtils = function () {
- function IRUtils() {
- _classCallCheck(this, IRUtils);
- }
- /**
- * find an dataItem entry using provided filter function
- * @param {object} spec widget spec
- * @param {function} filter
- * @return {{viewIndex: number, viewItemIndex: number}}
- */
- IRUtils.findDataItem = function findDataItem(spec, filter) {
- var targetDataViewIndex = -1;
- var targetDataViewItemIndex = -1;
- for (var dataViewIndex in spec.data.dataViews || []) {
- var viewItem = spec.data.dataViews[dataViewIndex];
- var dataItems = viewItem.dataItems || [];
- for (var dataViewItemIndex in dataItems) {
- if (filter(dataItems[dataViewItemIndex], dataViewItemIndex)) {
- targetDataViewIndex = dataViewIndex;
- targetDataViewItemIndex = dataViewItemIndex;
- }
- }
- }
- if (targetDataViewIndex === -1 || targetDataViewItemIndex === -1) {
- // nothing found...
- return;
- }
- return {
- viewIndex: targetDataViewIndex,
- viewItemIndex: targetDataViewItemIndex
- };
- };
- IRUtils.getColumnInfo = function getColumnInfo(currentColumnCombinations, visualization, itemId) {
- var columnEntry = currentColumnCombinations.find(function (combination) {
- return combination.itemId === itemId;
- });
- var isProjected = true;
- if (!columnEntry) {
- isProjected = false;
- var metadataColumn = visualization.getDataSource().getMetadataColumn(itemId);
- columnEntry = {
- id: metadataColumn.getId(),
- label: metadataColumn.getLabel()
- };
- }
- return _extends({}, columnEntry, {
- isProjected: isProjected
- });
- };
- IRUtils.IRAggregateType = function IRAggregateType(dashboardAggType) {
- return {
- sum: 'SUM',
- countdistinct: 'COUNT_DISTINCT',
- count: 'COUNT',
- avg: 'AVERAGE',
- min: 'MINIMUM',
- max: 'MAXIMUM'
- }[dashboardAggType];
- };
- IRUtils.fromIRAggregateType = function fromIRAggregateType(IRAggregateType) {
- return {
- SUM: 'sum',
- COUNT_DISTINCT: 'countdistinct',
- COUNT: 'count',
- AVERAGE: 'avg',
- MINIMUM: 'min',
- MAXIMUM: 'max'
- }[IRAggregateType];
- };
- IRUtils.IRTopBottomType = function IRTopBottomType(ty) {
- return ty === 'topcount' || ty === 'toppercent' ? 'TOP' : 'BOTTOM';
- };
- IRUtils.IRTopBottomMethod = function IRTopBottomMethod(ty) {
- return ty === 'bottompercent' || ty === 'toppercent' ? 'PERCENTAGE' : 'COUNT'; //?
- };
- IRUtils.IRToTopBottomType = function IRToTopBottomType(ty, method) {
- var _ty = { BOTTOM: 'bottom', TOP: 'top' };
- var _suffix = { PERCENTAGE: 'percent', COUNT: 'count' }; //TODO
- return _ty[ty] + _suffix[method];
- };
- /**
- * converts dashboard local filters to IR form
- * @param {array} filters input dashboard filters
- * @param {array} filtersForRequest output IR filters
- * @param {visualization} visualization - visualization API
- */
- IRUtils.localFilters2IRFilters = function localFilters2IRFilters(filters, filtersForRequest, visualization) {
- filters.forEach(function (filter) {
- var entry = {};
- entry.filterId = filter.id;
- entry.columnId = filter.columnId;
- entry.label = filter.binsLabel;
- if (!entry.label && visualization) {
- entry.label = visualization.getDataSource().getMetadataColumn(filter.columnId).getLabel();
- }
- if (filter.operator === 'in' || filter.operator === 'notin') {
- var inclusionValues = (filter.values || []).map(function (val) {
- return {
- uniqueValue: val.u,
- displayValue: val.d
- };
- });
- var exclusionValues = (filter.excludedValues || []).map(function (val) {
- return {
- uniqueValue: val.u,
- displayValue: val.d
- };
- });
- if (filter.conditions && (filter.conditions.or || filter.conditions.and)) {
- //TODO support for conditions will be added later
- //Not supported for now, will revisit this once dashboard filtering issues are resolved
- } else if (filter.conditions && filter.conditions.not) {
- //TODO support for conditions will be added later
- } else if (!filter.conditions) {
- entry.type = 'INCLUSION_EXCLUSION';
- entry.inclusionValues = inclusionValues;
- entry.exclusionValues = exclusionValues;
- entry.invertFlag = filter.operator !== 'in';
- }
- } else if (filter.operator === 'between' || filter.operator === 'notbetween') {
- entry.lowValue = {
- value: filter.values[0].u,
- inclusive: false // TODO
- };
- entry.highValue = {
- value: filter.values[1].u,
- inclusive: false // TODO
- };
- entry.invertFlag = filter.operator === 'notbetween';
- entry.type = 'NUMERICRANGE';
- entry.filterAggregation = {
- aggregationType: FILTER_AGGREGATION_MAP[filter.aggregationType],
- preOrPostAggregation: FILTER_PREPOST_MAP[filter.preOrPost]
- };
- } else {
- entry.type = 'GENERIC';
- entry.expression = '';
- }
- if (entry.type) {
- filtersForRequest.push(entry);
- }
- });
- };
- /**
- * converts dashboard topbottom filters to IR form
- * @param {array} topBottom input topBottom filters
- * @param {array} filtersForRequest output IR filters
- */
- IRUtils.topBottomToIRFilters = function topBottomToIRFilters(topBottom, filtersForRequest) {
- topBottom.forEach(function (tbEntry) {
- var entry = {};
- entry.filterId = tbEntry.id;
- entry.columnId = tbEntry.itemId;
- entry.topBottomType = IRUtils.IRTopBottomType(tbEntry.selection.topBottom.type);
- entry.method = IRUtils.IRTopBottomMethod(tbEntry.selection.topBottom.type);
- entry.domainSize = tbEntry.selection.topBottom.value;
- if (tbEntry.selection.context) {
- entry.byColumn = tbEntry.selection.context[0].itemId;
- }
- entry.type = 'TOP_BOTTOM';
- filtersForRequest.push(entry);
- });
- };
- /**
- * converts IR top bottom filters to dashboard form
- * @param {object} irFilter input IR filter
- * @param {object} widgetSpec
- * @return {object} dataItem with top bottom
- *
- * example IR top Bottom filter
- * {
- * "id" : "Movies.Genre",
- * "filterId" : "0",
- * "topBottomType" : "TOP",
- * "method" : "PERCENTAGE",
- * "byColumn" : "Movies.Budget",
- * "domainSize" : 10,
- * "type" : "TOP_BOTTOM"
- * }
- * example dashboard top bottom filter
- * {
- * "id":"id643437162",
- * "itemId":"HollywoodMovies_csv.Budget",
- * "itemLabel":"Budget",
- * "selection":[
- * {
- * "operation":"keep",
- * "topBottom":{
- * "type":"topcount",
- * "value":10
- * }
- * }
- *
- */
- IRUtils.IRFilters2TopBottom = function IRFilters2TopBottom(irFilter, widgetSpec, currentColumnCombinations, details, visualization) {
- if (details.reason === 'RECOMMEND_FILTER') {
- details.type = 'PART_TO_WHOLE';
- } else if (details.reason === 'INVERT_FILTER') {
- details.type = 'INVERT_FILTER_TOP_BOTTOM';
- }
- var dataItemRef = IRUtils.findDataItem(widgetSpec, function (dataItem) {
- return dataItem.id === irFilter.filterId;
- });
- var itemLabel = void 0;
- var selectionAggregate = void 0;
- if (dataItemRef) {
- var originalDataItem = widgetSpec.data.dataViews[dataItemRef.viewIndex].dataItems[dataItemRef.viewItemIndex];
- itemLabel = originalDataItem.itemLabel;
- var selection = originalDataItem.selection[0];
- // TODO: find a better way
- if (selection && selection.context && selection.context[0] && selection.context[0].aggregate) {
- selectionAggregate = selection.context[0].aggregate;
- }
- } else {
- var columnIdParts = (irFilter.columnId || '').split('.');
- itemLabel = columnIdParts[columnIdParts.length - 1];
- }
- var dataItem = {};
- dataItem.id = irFilter.filterId; //TODO
- dataItem.itemId = irFilter.columnId; // irFilter.byColumn ??;
- dataItem.itemLabel = itemLabel; //TODO
- var columnEntry = IRUtils.getColumnInfo(currentColumnCombinations, visualization, irFilter.columnId);
- details.column = columnEntry;
- var selectionItem = {
- operation: 'keep',
- topBottom: {
- type: IRUtils.IRToTopBottomType(irFilter.topBottomType, irFilter.method),
- value: irFilter.domainSize
- }
- };
- details.info = selectionItem.topBottom;
- if (irFilter.byColumn) {
- selectionItem.context = [{
- aggregate: selectionAggregate,
- itemId: irFilter.byColumn
- }];
- var byColumnEntry = IRUtils.getColumnInfo(currentColumnCombinations, visualization, irFilter.byColumn);
- details.byColumn = byColumnEntry;
- }
- dataItem.selection = [selectionItem];
- return dataItem;
- };
- /**
- * converts IR local filters to dashboard form
- * @param {object} irFilter input IR filter
- * @param {object} widgetSpec
- * @return {object} local filter
- *
- * example IR local filter
- * "filters" : [ {
- * "id" : "Movies.Budget",
- * "filterId" : "0",
- * "lowValue" : "5",
- * "highValue" : "10",
- * "invertFlag" : false,
- * "type" : "NUMERIC",
- * "numericOperator" : "LESS_THAN"
- * }
- *
- * example dashboard range local filter
- * "columnId": "Hollywood_Movies_csv.Budget",
- * "values": [
- * {
- * "d": 3511.265923566879,
- * "u": 3511.265923566879
- * },
- * {
- * "d": 12870,
- * "u": 12870
- * }
- * ],
- * "excludedValues": [],
- * "operator": "notbetween",
- * "aggregationType": "sum",
- * "preOrPost": "post
- *
- * example dashboard inclusion/exclusion local filter
- * {
- * "id": "Hollywood_Movies_csv.Movie_Genre",
- * "columnId": "Hollywood_Movies_csv.Movie_Genre",
- * "values": [
- * {
- * "d": "Action",
- * "u": "Hollywood_Movies_csv.Movie_Genre->[Action]"
- * }
- * ],
- * "excludedValues": [
- * {
- * "d": "Biopic",
- * "u": "Hollywood_Movies_csv.Movie_Genre->[Biopic]"
- * }
- * ],
- * "conditions": {
- * "operator": "containsignorecase",
- * "itemId": "Hollywood_Movies_csv.Movie_Genre",
- * "ignoreCase": true,
- * "values": [
- * "Bio"
- * ],
- * "valueType": "display"
- * },
- * "operator": "in",
- * "type": null,
- * "binsLabel": "Movie Genre"
- * }
- */
- IRUtils.IRFilters2LocalFilter = function IRFilters2LocalFilter(irFilter, widgetSpec) {
- var currentColumnCombinations = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
- var details = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
- var visualization = arguments[4];
- if (details.reason === 'INVERT_FILTER') {
- details.type = 'INVERT_FILTER_LOCAL';
- }
- var filter = {};
- filter.id = irFilter.filterId; //TODO
- filter.columnId = irFilter.columnId;
- var columnEntry = currentColumnCombinations.find(function (combination) {
- return combination.itemId === irFilter.columnId;
- });
- if (columnEntry) {
- details.column = {
- id: irFilter.columnId,
- label: columnEntry.label
- };
- } else if (visualization) {
- details.column = {
- id: irFilter.columnId,
- label: visualization.getDataSource().getMetadataColumn(irFilter.columnId).getLabel()
- };
- }
- if (irFilter.type === 'NUMERICRANGE') {
- if (irFilter.invertFlag) {
- filter.operator = 'notbetween';
- } else {
- filter.operator = 'between';
- }
- filter.values = [{
- d: irFilter.lowValue.value,
- u: irFilter.lowValue.value
- }, {
- d: irFilter.highValue.value,
- u: irFilter.highValue.value
- }];
- // filter.excludedValues = [] ; //TODO
- if (irFilter.filterAggregation) {
- filter.aggregationType = irFilter.filterAggregation.aggregationType;
- filter.preOrPost = FILTER_PREPOST_MAP[irFilter.filterAggregation.preOrPostAggregation];
- } else if (widgetSpec) {
- var localFilter = widgetSpec.localFilters.find(function (filter) {
- return filter.id === irFilter.filterId;
- });
- filter.aggregationType = localFilter.aggregationType;
- filter.preOrPost = localFilter.preOrPost;
- }
- } else if (irFilter.type === 'COMPOSITE') {
- //Not supported for now, will revisit this once dashboard filtering issues are resolved
- // const firstCompositeIrFilter = irFilter.filter1;
- //
- // const isInvert = irFilter.filter1.invertFlag && irFilter.filter1.invertFlag === irFilter.filter2.invertFlag;
- // // filter.operator = (isInvert ? 'notin' : 'in');
- // filter.operator = 'in';
- //
- // let valuesToUse, excludedValuesToUse;
- // if(!isInvert) {
- // valuesToUse = firstCompositeIrFilter.inclusionValues;
- // excludedValuesToUse = firstCompositeIrFilter.exclusionValues;
- // } else {
- // valuesToUse = firstCompositeIrFilter.exclusionValues;
- // excludedValuesToUse = firstCompositeIrFilter.inclusionValues;
- // }
- // filter.values = (valuesToUse || [])
- // .map(value => {
- // return {
- // u: value.uniqueValue,
- // d: value.displayValue
- // };
- // });
- //
- // filter.excludedValues = (excludedValuesToUse || [] )
- // .map(value => {
- // return {
- // u: value.uniqueValue,
- // d: value.displayValue
- // };
- // });
- // filter.binsLabel = firstCompositeIrFilter.label;
- // filter.columnId = firstCompositeIrFilter.columnId;
- // filter.id = irFilter.filterId;
- //
- //
- // const conditionOperator = irFilter.operator === 'OR' ? 'or': 'and';
- // filter.conditions = {};
- // filter.conditions[conditionOperator] = [];
- //
- // const irFiltersToProcess = [ irFilter.filter1, irFilter.filter2 ];
- // irFiltersToProcess.forEach( (irSubFilter) => {
- // const condition = this._fromIRCompositeFilterToCondition( irSubFilter );
- // if( condition ) {
- // if( irSubFilter.invertFlag ) {
- // filter.conditions[conditionOperator].push( { not: condition } );
- // } else {
- // filter.conditions[conditionOperator].push(condition);
- // }
- // }
- // } );
- } else if (irFilter.type === 'INCLUSION_EXCLUSION' && !irFilter.filterCondition) {
- filter.columnId = irFilter.columnId;
- filter.id = irFilter.filterId;
- filter.operator = irFilter.invertFlag ? 'notin' : 'in';
- filter.values = (irFilter.inclusionValues || irFilter.values || []).map(function (value) {
- return {
- u: value.uniqueValue,
- d: value.displayValue
- };
- });
- //TODO support for conditions will be added later
- // if( irFilter.filterCondition ) {
- // filter.conditions = this._fromIRCompositeFilterToCondition( irFilter );
- // }
- filter.binsLabel = irFilter.label;
- } else if (irFilter.type === 'GENERIC') {
- filter.columnId = irFilter.columnId;
- filter.id = irFilter.filterId;
- }
- return filter;
- };
- //not used for current release, will revisit this in a later change
- // _toIRCondition : function (conditions, index) {
- // if( !conditions ) {
- // return undefined;
- // }
- // let isInvert = false;
- // const op = conditions.or ? 'or' : conditions.and ? 'and': conditions.not ? 'not' : undefined;
- //
- // let condition = conditions;
- // if( op === 'not') {
- // isInvert = true;
- // condition = conditions.not;
- // } else if (op && index !== undefined) {
- // condition = conditions[op][index]; //and, or
- // if( condition.not) {
- // isInvert = true;
- // condition = condition.not;
- // }
- // } else {
- // condition = conditions; //simple condition
- // }
- //
- // const conditionMap = {
- // 'in': 'EQUALS',
- // 'containsignorecase': 'CONTAINS',
- // 'beginswith': 'BEGINS_WITH',
- // 'endswith': 'ENDS_WITH'
- // };
- //
- // return {
- // condition: conditionMap[condition.operator],
- // isInclude: !isInvert,
- // values: condition.values
- // };
- // },
- //
- // _fromIRCompositeFilterToCondition : function (irSubFilter) {
- // if( !irSubFilter || irSubFilter && !irSubFilter.filterCondition ) {
- // return undefined;
- // }
- // const conditionMap = {
- // 'EQUALS': 'in',
- // 'CONTAINS': 'containsignorecase',
- // 'BEGINS_WITH': 'beginswith',
- // 'ENDS_WITH': 'endswith'
- // };
- //
- // const condition = {
- // operator: conditionMap[irSubFilter.filterCondition.condition],
- // itemId: irSubFilter.columnId,
- // ignoreCase: true,
- // values: irSubFilter.filterCondition.values,
- // valueType: 'display'
- // };
- //
- // if( irSubFilter.filterCondition.isInclude === false ) {
- // return {
- // not: condition
- // };
- // }
- // return condition;
- // }
- return IRUtils;
- }();
- return IRUtils;
- });
- //# sourceMappingURL=IRUtils.js.map
|