EpisodeActs.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI
  5. * (C) Copyright IBM Corp. 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['gemini/lib/@waca/dashboard-common/dist/core/Collection', './EpisodeActEntry'], function (Collection, EpisodeActEntry) {
  9. var EpisodeActs;
  10. EpisodeActs = Collection.extend({
  11. modelClass: EpisodeActEntry,
  12. init: function init() {
  13. EpisodeActs.inherited('init', this, arguments);
  14. },
  15. /*
  16. * A highlight payload is an array of columns.
  17. * This method updates the array to add or remove columns based on the exemplar provided
  18. *
  19. * Columns in payload and not in blankPayloadExemplar are removed
  20. * Columns in payloadEntryExemplar and not in paload are added.
  21. *
  22. * @param {Object} blankPayloadExemplar blank in the sense that it contains the default 'includes all' highlight
  23. * {
  24. * columnId: id of the column
  25. * // other properties we should not look at here. like values
  26. * }
  27. */
  28. updateHighlightPayloadColumns: function updateHighlightPayloadColumns(blankPayloadExemplar, options) {
  29. options = options || {};
  30. var values = [];
  31. var prevValues = [];
  32. this.filter(function (act) {
  33. return act.action === 'highlight';
  34. }).forEach(function (act) {
  35. // copy the array so that we can do a correct undo/redo operation later.
  36. // I.e we only change the copy.
  37. var payloadCopy = act.payload.slice();
  38. var containsColumn = function containsColumn(array, columnId) {
  39. return array.find(function (entry) {
  40. return entry.columnId === columnId;
  41. });
  42. };
  43. // if it's in 'new' and not in 'existing' it needs to be added.
  44. blankPayloadExemplar.forEach(function (item) {
  45. if (!containsColumn(payloadCopy, item.columnId)) {
  46. // add a deep copy of the item since we might be adding it to multiple highlights.
  47. var itemCopy = JSON.parse(JSON.stringify(item));
  48. payloadCopy.push(itemCopy);
  49. }
  50. });
  51. // if it's in 'existing' and not in 'new' it needs to be removed.
  52. payloadCopy = payloadCopy.filter(function (item) {
  53. return containsColumn(blankPayloadExemplar, item.columnId);
  54. });
  55. values.push({
  56. id: act.id,
  57. payload: payloadCopy
  58. });
  59. prevValues.push({
  60. id: act.id,
  61. payload: act.payload
  62. });
  63. });
  64. //do we want a unique event?
  65. this._updateAndTriggerEvent('change:payload', values, prevValues, options);
  66. },
  67. _updateAndTriggerEvent: function _updateAndTriggerEvent(name, values, prevValues, options) {
  68. // values should be an array of sub models (sub as in id and some properties)
  69. this.set(values, { remove: false, merge: true, silent: true });
  70. var event = {
  71. name: name,
  72. eventName: name,
  73. collection: this,
  74. value: values,
  75. prevValue: prevValues,
  76. options: options,
  77. data: options.payloadData,
  78. sender: options.sender ? options.sender : this,
  79. senderContext: {
  80. applyFn: function (value, sender) {
  81. this.set(value, { remove: false, merge: true, silent: true });
  82. this.trigger(name, Object.assign({}, options, { sender: sender }));
  83. }.bind(this)
  84. }
  85. };
  86. this.trigger(name, event);
  87. }
  88. });
  89. return EpisodeActs;
  90. });
  91. //# sourceMappingURL=EpisodeActs.js.map