DrillThroughModel.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: dashboard
  5. * (C) Copyright IBM Corp. 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../lib/@waca/dashboard-common/dist/core/Collection', './DrillThroughDefinitionEntry', 'underscore'], function (Collection, DrillThroughDefinitionEntry, _) {
  9. var findEntryById = function findEntryById(entries, id) {
  10. var foundEntry = _.find(entries, function (entry) {
  11. return entry.id === id;
  12. });
  13. return foundEntry;
  14. };
  15. /**
  16. * The Synchronize Model implements the boardModelExtension defined in synchronizeData.json
  17. * It is used to persist information about mapped colours etc.
  18. */
  19. var DrillThroughModel = Collection.extend({
  20. modelClass: DrillThroughDefinitionEntry,
  21. init: function init(spec, options) {
  22. DrillThroughModel.inherited('init', this, [spec, options]);
  23. this.logger = options.logger;
  24. this.boardModel = options.boardModel;
  25. this.dashboard = options.dashboardApi;
  26. this.api = {
  27. getDrillDefinitionEntry: this._getDrillDefinitionEntry.bind(this),
  28. getDrillDefinitionEntries: this._getDrillDefinitionEntries.bind(this),
  29. deleteDrillDefinitionEntry: this._deleteDrillDefinitionEntry.bind(this),
  30. addUpdateDrillDefinitionEntry: this._addUpdateDrillDefinitionEntry.bind(this),
  31. getNumOfDrillDefinitions: this._getNumOfDrillDefinitions.bind(this),
  32. toJSON: this.toJSON.bind(this),
  33. applyModelChange: this.reset.bind(this)
  34. };
  35. },
  36. destroy: function destroy() {
  37. DrillThroughModel.inherited('destroy', this, arguments);
  38. },
  39. /**
  40. * @returns the public api to the drill through model that is accessible to clients.
  41. */
  42. getAPI: function getAPI() {
  43. return this.api;
  44. },
  45. _getDrillDefinitionEntry: function _getDrillDefinitionEntry(id) {
  46. var entry = this.get(id);
  47. return entry ? this.get(id).getAPI() : null;
  48. },
  49. /**
  50. * @param {object} content - the associated content
  51. *
  52. */
  53. _getDrillDefinitionEntries: function _getDrillDefinitionEntries(content) {
  54. var items = [];
  55. this.each(function (entry) {
  56. var entryAPI = entry.getAPI();
  57. if (content) {
  58. // When content is passed in, get entries with the content context
  59. if (entryAPI.getScope() === 'visualization') {
  60. // drill definition is defined for widget only
  61. if (content.getId() === entryAPI.getOwnerId()) {
  62. items.push(entryAPI);
  63. }
  64. } else if (entryAPI.getScope() === 'connection') {
  65. var eventGroups = this.dashboard.getFeature('EventGroups');
  66. var contentList = eventGroups && eventGroups.getContentIdList(eventGroups.getGroupId(content.getId()));
  67. if (contentList && contentList.indexOf(entryAPI.getOwnerId()) !== -1) {
  68. // Drill definition is in the same event group.
  69. items.push(entryAPI);
  70. }
  71. } else if (entryAPI.getScope() === 'dashboard') {
  72. items.push(entryAPI);
  73. }
  74. } else {
  75. // Otherwise return all entries
  76. items.push(entryAPI);
  77. }
  78. }.bind(this));
  79. return items;
  80. },
  81. /**
  82. * Add/Update drill definition entry
  83. *
  84. * @param {object} context
  85. * @param {object} options - hold the newOwnerId for copying/pasting to a new dashboard
  86. */
  87. _addUpdateDrillDefinitionEntry: function _addUpdateDrillDefinitionEntry(context, options) {
  88. context = context || {};
  89. options = options || {};
  90. var entry = context.id ? findEntryById(this.models, context.id) : null;
  91. if (entry) {
  92. entry.getAPI().update(context, options);
  93. } else {
  94. if (options.newOwnerId) {
  95. context.ownerId = options.newOwnerId;
  96. }
  97. entry = new DrillThroughDefinitionEntry(context);
  98. this.add([entry], options);
  99. }
  100. return entry.getAPI();
  101. },
  102. _deleteDrillDefinitionEntry: function _deleteDrillDefinitionEntry(id, options) {
  103. var removedEntry;
  104. for (var index = 0; index < this.models.length; index++) {
  105. var entry = this.models[index];
  106. if (entry.getAPI().getId() === id) {
  107. removedEntry = this.remove(entry, options);
  108. break;
  109. }
  110. }
  111. return removedEntry && removedEntry.id === id ? true : false;
  112. },
  113. _getNumOfDrillDefinitions: function _getNumOfDrillDefinitions() {
  114. return this.models.length;
  115. }
  116. /**
  117. * @override
  118. */
  119. // toJSON: function() {
  120. // },
  121. });
  122. return DrillThroughModel;
  123. });
  124. /** drillthrough model
  125. [
  126. {
  127. "id": "model00000160ffe1034e_00000000",
  128. "assetId": "drill through target CM stored id",
  129. "name": "drill through definition name provided by user, default to target report name when first created",
  130. "modelRefs": [
  131. {
  132. "id": "datasource model ref id"
  133. }
  134. ],
  135. "type": "report|exploration",
  136. "scope": 'connection',
  137. "mappings": [
  138. {
  139. "name": "Product_line",
  140. "modelFilterItem": "[Sales (query)].[Products].[Product line]",
  141. "mapTo": "QC_Data_synchronize_1_xlsx.Product_line"
  142. },
  143. {
  144. "name": "Order_Method",
  145. "capabilities": [
  146. "modelFilterItem": "[Sales (query)].[Order method].[Order method type]",
  147. "mapTo": "QC_Data_synchronize_1_xlsx.Order_method"
  148. },
  149. {
  150. "name": "Year",
  151. "modelFilterItem": "[Sales (query)].[Time].[Year]",
  152. "mapTo": "none"
  153. }
  154. ]
  155. }
  156. ]
  157. */
  158. //# sourceMappingURL=DrillThroughModel.js.map