| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | 'use strict';/** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore'], function (Class, _) {	/**  * Service which facilitates access to contents of the dasboard spec.  */	var Svc = Class.extend({		init: function init(boardModel) {			this.boardModel = boardModel;			//The filterContextAdapters map is responsible for providing functions that convert			//widgetInstance type-specific filters to a portable form needed by the getFilterContext api.			//Currently there is only one type so the function is provided.  In future, this map could be extended or, to be more dynamic			//callers could register their converters			this._filterContextAdapters = {				'data': this._convertDataWidgetFilterContext				//more converters should be referenced by widgetInstance type here.			};		},		/**   * Return mappings that match the condition in the supplied matching function as well as the dataset and optional page specified.   * @param cbMappingMatches a matching function supplied by the caller....only mappings that succeed will be returned.   * @param dataSetId A datasetId that any returned mappings must belong to.   * @param containerPageId (optional) - Only mappings for widgets on the specified page will be processed (pageId is a string eg 'page1')   * @returns an array of mappings that match the criteria defined in the callback function cbMappingMatches   *   */		getMappings: function getMappings(cbMappingMatches, dataSetId, containerPageId) {			var returnMappings = [];			if (!this.boardModel) {				return returnMappings;			}			var fAddMapping = function fAddMapping(mapping) {				if (cbMappingMatches(mapping)) {					returnMappings.push(mapping);				}			};			_.keys(this.boardModel.widgetInstances).forEach(function (widgetInstanceModel) {				var widgetInstance = this.boardModel.widgetInstances[widgetInstanceModel];				var mappings = widgetInstance.mapping;				if (mappings && !Array.isArray(mappings)) {					mappings = [mappings];				}				var dataSetMatches = widgetInstance.dataSet && widgetInstance.dataSet.id === dataSetId;				if (dataSetMatches && mappings) {					//If containerPageId is not specified, all pages match.					var pageIdMatches = !containerPageId;					if (!pageIdMatches) {						var pageForWidget = this.boardModel.layout.findTopLevelParentItem(widgetInstance.id);						pageIdMatches = pageForWidget && pageForWidget.id === containerPageId;					}					if (pageIdMatches) {						_.each(mappings, fAddMapping);					}				}			}, this);			return returnMappings;		},		/**   * Return an array of filterContexts in 'portable form' for all widgets that match the dataset and optional eventGroupId specified.   * Since the datawidget is the only widget instance type with a filter context, portable form is the JSON format   * it serializes but this is likely to change in future as new widgets capable of contributing to filter context are implemented (ie: visControl widget)   *   * For each widget, the array would be.   * {   *		id: %widgetId%,   *		dataSet: %dataSetId,url%,   *		filterContext: { %portablefilterDefinition }   * }   *   * @param dataSetId (optional) - include the filter context for widgets that match this dataSetId (widgets for all dataSets if null).   * @param eventGroupId (optional) - include the filter context for widgets on this event group (widgets for all groups if null).   * @returns the array as described for widgets that match the dataSetId and containerPageId constraints.  */		getFilterContext: function getFilterContext(dataSetId, eventGroupId) {			var returnResults = [];			if (!this.boardModel) {				return returnResults;			}			_.keys(this.boardModel.widgetInstances).forEach(function (widgetInstanceModel) {				var widgetInstance = this.boardModel.widgetInstances[widgetInstanceModel];				var filterContextAdapter = this._filterContextAdapters[widgetInstance.type];				var dataSetMatches = !dataSetId || widgetInstance.dataSet && widgetInstance.dataSet.id === dataSetId;				if (dataSetMatches && filterContextAdapter) {					//If eventGroupId is not specified, all groups match.					var groupIdMatches = !eventGroupId;					if (!groupIdMatches) {						var eventGroup = this.boardModel.eventGroups.findGroup(widgetInstance.id);						groupIdMatches = eventGroup && eventGroup.id === eventGroupId;					}					if (groupIdMatches) {						returnResults.push(filterContextAdapter(widgetInstance));					}				}			}, this);			return returnResults;		},		/**   * This function is responsible for returning the filterContext in the form required by getFilterContext   * for the data widget.  If other widget types require returning   * @param widgetInstance - the widgetInstance   * @returns the filterContext structure which includes a filter specification in portable form that any widget type should be able   * to interpret.   */		_convertDataWidgetFilterContext: function _convertDataWidgetFilterContext(widgetInstance) {			return {				id: widgetInstance.id,				dataSet: widgetInstance.dataSet,				filterContext: widgetInstance.filters			};		}	});	return Svc;});//# sourceMappingURL=DashboardSpecSvc.js.map
 |