TimelineEpisodeEntry.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling
  5. * (C) Copyright IBM Corp. 2017, 2018
  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/Model', './EpisodeActs', 'underscore'], function (Model, EpisodeActs, _) {
  9. var TimelineEpisodeEntry = Model.extend({
  10. nestedCollections: { acts: EpisodeActs },
  11. whitelistAttrs: ['id', 'type', 'title', 'acts'],
  12. _default_entrance: {
  13. timer: 0,
  14. action: 'show'
  15. },
  16. _default_exit: {
  17. timer: 5000,
  18. action: 'hide'
  19. },
  20. //should match _endBufferTime in TimeQueue
  21. _endBufferTime: 200,
  22. init: function init() {
  23. TimelineEpisodeEntry.inherited('init', this, arguments);
  24. //we don't allow empty episodes so we silently add the default entry and exit acts.
  25. if (!this.acts) {
  26. this.set({
  27. 'acts': [this._default_entrance, this._default_exit]
  28. }, { silent: true });
  29. }
  30. },
  31. // Note that callers must go through TimelineController.updateTimelineDuration
  32. // if they do not desire the model updates to be silent.
  33. // The latter was optimized to trigger the necessary events once for the
  34. // whole collection rather than once per updated act timer.
  35. updateDuration: function updateDuration(start, end, options) {
  36. // we enforce _endBufferTime to be the minimum duration.
  37. // also we prevent the end from getting to be before the start.
  38. if (end <= start + this._endBufferTime) {
  39. end = start + this._endBufferTime;
  40. }
  41. options = _.clone(options) || {};
  42. _.extend(options, {
  43. 'add': false,
  44. 'remove': false,
  45. 'merge': true,
  46. 'silent': true
  47. });
  48. var entranceAct = this.getEntranceAct();
  49. var exitAct = this.getExitAct();
  50. var acts = [];
  51. this.acts.each(function (act) {
  52. var timer = act.timer;
  53. if (act.id === entranceAct.id) {
  54. timer = start < 0 ? 0 : start;
  55. } else if (act.id === exitAct.id) {
  56. timer = end;
  57. } else {
  58. // if the duration is the same (I.e we are moving things) we attempt to preserve the relative positions
  59. if (options.isMove) {
  60. timer = act.timer - entranceAct.timer + start;
  61. }
  62. // limit the non end/start values to be within the end/start
  63. timer = Math.max(timer, start + 1);
  64. timer = Math.min(timer, end - 1);
  65. }
  66. acts.push({
  67. id: act.id,
  68. timer: timer
  69. });
  70. });
  71. this.acts.set(acts, options);
  72. },
  73. getEntranceAct: function getEntranceAct() {
  74. return this.acts.min(function (act) {
  75. return act.timer;
  76. });
  77. },
  78. getExitAct: function getExitAct() {
  79. return this.acts.max(function (act) {
  80. return act.timer;
  81. });
  82. },
  83. getDuration: function getDuration() {
  84. return this.getExitAct().timer - this.getEntranceAct().timer;
  85. },
  86. touchesEnd: function touchesEnd(duration) {
  87. // Touches the end if the exit act is within _endBufferTime of duration.
  88. return duration - this._endBufferTime < this.getExitAct().timer;
  89. },
  90. touchesStart: function touchesStart() {
  91. // Touches the start if the entrance act is within _endBufferTime of the start
  92. return this.getEntranceAct().timer - this._endBufferTime < 0;
  93. }
  94. });
  95. return TimelineEpisodeEntry;
  96. });
  97. //# sourceMappingURL=TimelineEpisodeEntry.js.map