VIPRSlotMapping.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. /**
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2017, 2019
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['underscore', '../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../apiHelpers/SlotAPIHelper'], function (_, Class, SlotAPIHelper) {
  13. // implements IDataSetMapping
  14. var VIPRDatasetMapping = Class.extend({
  15. init: function init(slotAPIs, datasetId) {
  16. this.slotAPIs = slotAPIs;
  17. this.datasetId = datasetId;
  18. },
  19. getDataItemsFor: function getDataItemsFor(slotDef) {
  20. var indices = [];
  21. var index = 0;
  22. _.each(this.slotAPIs, function (slotAPI) {
  23. var id = slotAPI.getId();
  24. if (slotAPI.isStacked() || SlotAPIHelper.isMultiMeasuresSeriesSlot(slotAPI) || SlotAPIHelper.isMultiMeasuresValueSlot(slotAPI)) {
  25. //If a slot is stacked or has multiple measures, all items in the slot have a single index.
  26. if (id === slotDef.name) {
  27. indices.push(index);
  28. }
  29. index++;
  30. } else {
  31. _.each(slotAPI.getDataItemList(), function () {
  32. if (id === slotDef.name) {
  33. indices.push(index);
  34. }
  35. index++;
  36. });
  37. }
  38. });
  39. return indices;
  40. }
  41. });
  42. // implements ISlotMapping
  43. var VIPRSlotMapping = Class.extend({
  44. init: function init(visualization) {
  45. this._aVIPRSlotMapping = [];
  46. var aDataSets = visualization.getDefinition().getDatasetList();
  47. _.each(aDataSets, function (dataset) {
  48. var aMatchedSlots = SlotAPIHelper.getMappedSlotListByDataset(visualization, dataset.id);
  49. if (!aMatchedSlots || aMatchedSlots.length === 0) {
  50. this._aVIPRSlotMapping.push(null);
  51. } else {
  52. this._aVIPRSlotMapping.push(new VIPRDatasetMapping(aMatchedSlots, dataset.id));
  53. }
  54. }.bind(this));
  55. },
  56. // implement IVIPRSlotMapping
  57. getDataSetMapping: function getDataSetMapping(index) {
  58. return this._aVIPRSlotMapping[index];
  59. }
  60. });
  61. return VIPRSlotMapping;
  62. });
  63. //# sourceMappingURL=VIPRSlotMapping.js.map