'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: dashboard * (C) Copyright IBM Corp. 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../lib/@waca/dashboard-common/dist/core/Collection', './DrillThroughDefinitionEntry', 'underscore'], function (Collection, DrillThroughDefinitionEntry, _) { var findEntryById = function findEntryById(entries, id) { var foundEntry = _.find(entries, function (entry) { return entry.id === id; }); return foundEntry; }; /** * The Synchronize Model implements the boardModelExtension defined in synchronizeData.json * It is used to persist information about mapped colours etc. */ var DrillThroughModel = Collection.extend({ modelClass: DrillThroughDefinitionEntry, init: function init(spec, options) { DrillThroughModel.inherited('init', this, [spec, options]); this.logger = options.logger; this.boardModel = options.boardModel; this.dashboard = options.dashboardApi; this.api = { getDrillDefinitionEntry: this._getDrillDefinitionEntry.bind(this), getDrillDefinitionEntries: this._getDrillDefinitionEntries.bind(this), deleteDrillDefinitionEntry: this._deleteDrillDefinitionEntry.bind(this), addUpdateDrillDefinitionEntry: this._addUpdateDrillDefinitionEntry.bind(this), getNumOfDrillDefinitions: this._getNumOfDrillDefinitions.bind(this), toJSON: this.toJSON.bind(this), applyModelChange: this.reset.bind(this) }; }, destroy: function destroy() { DrillThroughModel.inherited('destroy', this, arguments); }, /** * @returns the public api to the drill through model that is accessible to clients. */ getAPI: function getAPI() { return this.api; }, _getDrillDefinitionEntry: function _getDrillDefinitionEntry(id) { var entry = this.get(id); return entry ? this.get(id).getAPI() : null; }, /** * @param {object} content - the associated content * */ _getDrillDefinitionEntries: function _getDrillDefinitionEntries(content) { var items = []; this.each(function (entry) { var entryAPI = entry.getAPI(); if (content) { // When content is passed in, get entries with the content context if (entryAPI.getScope() === 'visualization') { // drill definition is defined for widget only if (content.getId() === entryAPI.getOwnerId()) { items.push(entryAPI); } } else if (entryAPI.getScope() === 'connection') { var eventGroups = this.dashboard.getFeature('EventGroups'); var contentList = eventGroups && eventGroups.getContentIdList(eventGroups.getGroupId(content.getId())); if (contentList && contentList.indexOf(entryAPI.getOwnerId()) !== -1) { // Drill definition is in the same event group. items.push(entryAPI); } } else if (entryAPI.getScope() === 'dashboard') { items.push(entryAPI); } } else { // Otherwise return all entries items.push(entryAPI); } }.bind(this)); return items; }, /** * Add/Update drill definition entry * * @param {object} context * @param {object} options - hold the newOwnerId for copying/pasting to a new dashboard */ _addUpdateDrillDefinitionEntry: function _addUpdateDrillDefinitionEntry(context, options) { context = context || {}; options = options || {}; var entry = context.id ? findEntryById(this.models, context.id) : null; if (entry) { entry.getAPI().update(context, options); } else { if (options.newOwnerId) { context.ownerId = options.newOwnerId; } entry = new DrillThroughDefinitionEntry(context); this.add([entry], options); } return entry.getAPI(); }, _deleteDrillDefinitionEntry: function _deleteDrillDefinitionEntry(id, options) { var removedEntry; for (var index = 0; index < this.models.length; index++) { var entry = this.models[index]; if (entry.getAPI().getId() === id) { removedEntry = this.remove(entry, options); break; } } return removedEntry && removedEntry.id === id ? true : false; }, _getNumOfDrillDefinitions: function _getNumOfDrillDefinitions() { return this.models.length; } /** * @override */ // toJSON: function() { // }, }); return DrillThroughModel; }); /** drillthrough model [ { "id": "model00000160ffe1034e_00000000", "assetId": "drill through target CM stored id", "name": "drill through definition name provided by user, default to target report name when first created", "modelRefs": [ { "id": "datasource model ref id" } ], "type": "report|exploration", "scope": 'connection', "mappings": [ { "name": "Product_line", "modelFilterItem": "[Sales (query)].[Products].[Product line]", "mapTo": "QC_Data_synchronize_1_xlsx.Product_line" }, { "name": "Order_Method", "capabilities": [ "modelFilterItem": "[Sales (query)].[Order method].[Order method type]", "mapTo": "QC_Data_synchronize_1_xlsx.Order_method" }, { "name": "Year", "modelFilterItem": "[Sales (query)].[Time].[Year]", "mapTo": "none" } ] } ] */ //# sourceMappingURL=DrillThroughModel.js.map