StorytellingPropertiesProvider.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'gemini/lib/@waca/dashboard-common/dist/core/APIFactory', 'gemini/lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', 'baglass/utils/Utils', 'storytelling/nls/StringResources', '../../StoryService', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/guided-journey-1_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/guided-journey-2_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/guided-journey-3_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/guided-journey-4_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/guided-journey-5_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/timesequence_32', '../../lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/help_16'], function (_, APIFactory, PropertiesProviderAPI, GlassUtils, StringResources, StoryService, PanAndZoomLayout1, PanAndZoomLayout2, PanAndZoomLayout3, PanAndZoomLayout4, PanAndZoomLayout5, PanAndZoomLayout6, HelpIcon) {
  9. var PAN_AND_ZOOM_ITEMS = [{
  10. name: 'panAndZoom1',
  11. label: StringResources.get('PanAndZoomLayout1'),
  12. type: 'svg',
  13. value: PanAndZoomLayout1.default.id
  14. }, {
  15. name: 'panAndZoom2',
  16. label: StringResources.get('PanAndZoomLayout2'),
  17. type: 'svg',
  18. value: PanAndZoomLayout2.default.id
  19. }, {
  20. name: 'panAndZoom3',
  21. label: StringResources.get('PanAndZoomLayout3'),
  22. type: 'svg',
  23. value: PanAndZoomLayout3.default.id
  24. }, {
  25. name: 'panAndZoom4',
  26. label: StringResources.get('PanAndZoomLayout4'),
  27. type: 'svg',
  28. value: PanAndZoomLayout4.default.id
  29. }, {
  30. name: 'panAndZoom5',
  31. label: StringResources.get('PanAndZoomLayout5'),
  32. type: 'svg',
  33. value: PanAndZoomLayout5.default.id
  34. }, {
  35. name: 'panAndZoom6',
  36. label: StringResources.get('PanAndZoomLayout6'),
  37. type: 'svg',
  38. value: PanAndZoomLayout6.default.id
  39. }];
  40. var StorytellingPropertiesProvider = function () {
  41. function StorytellingPropertiesProvider(options) {
  42. _classCallCheck(this, StorytellingPropertiesProvider);
  43. this.dashboardApi = options.dashboardApi || options.dashboardAPI;
  44. this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]);
  45. // register self as a properties provider contributing storytelling properties
  46. this.dashboardApi.getFeature('Properties').registerProvider(this.getAPI());
  47. }
  48. StorytellingPropertiesProvider.prototype.getAPI = function getAPI() {
  49. return this._api;
  50. };
  51. StorytellingPropertiesProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  52. return [{
  53. value: StringResources.get('storyProperties'),
  54. id: 'banner',
  55. type: 'Banner',
  56. editable: false
  57. }, {
  58. id: 'scenes',
  59. type: 'Section',
  60. label: StringResources.get('scenesPropertiesSection'),
  61. position: 0
  62. }];
  63. };
  64. StorytellingPropertiesProvider.prototype.getPropertyList = function getPropertyList() {
  65. return this._getScenesPropertiesList();
  66. };
  67. StorytellingPropertiesProvider.prototype._getScenesPropertiesList = function _getScenesPropertiesList() {
  68. var scenesProperties = [];
  69. scenesProperties.push.apply(scenesProperties, this._getStoryPropertiesList());
  70. var storyType = this._getBoardModel().layout.type;
  71. if (storyType === 'slideshow') {
  72. scenesProperties.push.apply(scenesProperties, this._getSlideShowPropertiesList());
  73. } else if (storyType.indexOf('panAndZoom') !== -1) {
  74. scenesProperties.push.apply(scenesProperties, this._getPanAndZoomPropertiesList());
  75. }
  76. return scenesProperties;
  77. };
  78. StorytellingPropertiesProvider.prototype._getBoardModel = function _getBoardModel() {
  79. // TODO: temporary (short term) solution
  80. return this.dashboardApi.getFeature('internal').getBoardModel();
  81. };
  82. StorytellingPropertiesProvider.prototype._getStoryPropertiesList = function _getStoryPropertiesList() {
  83. var _this = this;
  84. var collapsiblePickerSelectedName = void 0;
  85. var currentLayout = this._getPropertyValueFromModel('type') || 'slideshow';
  86. if (currentLayout.indexOf('panAndZoom') != -1) {
  87. var index = currentLayout.substring(currentLayout.length - 1, currentLayout.length) - 1;
  88. currentLayout = currentLayout.substring(0, currentLayout.length - 1);
  89. collapsiblePickerSelectedName = PAN_AND_ZOOM_ITEMS[index].name;
  90. }
  91. var collapsiblePickerOptions = {
  92. type: 'CollapsiblePicker',
  93. name: 'storyType',
  94. label: StringResources.get('layoutLabel'),
  95. selectedName: collapsiblePickerSelectedName,
  96. placeholder: {
  97. name: '',
  98. label: '',
  99. type: 'svg',
  100. value: HelpIcon.default.id
  101. },
  102. contentSize: 'large',
  103. items: PAN_AND_ZOOM_ITEMS,
  104. isRequired: true
  105. };
  106. var dropDownOptions = {
  107. name: 'storyType',
  108. label: StringResources.get('storyTypeLabel'),
  109. defaultValue: currentLayout,
  110. options: [{
  111. label: StringResources.get('slideshowLabel'),
  112. value: 'slideshow'
  113. }, {
  114. label: StringResources.get('panAndZoomLabel'),
  115. value: 'panAndZoom'
  116. }]
  117. };
  118. return [{
  119. id: 'storyType',
  120. getPropertyValue: function getPropertyValue() {
  121. return currentLayout;
  122. },
  123. setPropertyValue: function setPropertyValue(propertyValue) {
  124. var value = propertyValue;
  125. if (propertyValue && propertyValue.name) {
  126. value = value.name;
  127. }
  128. var storyService = new StoryService({
  129. dashboardApi: _this.dashboardApi
  130. });
  131. storyService.updateStory({
  132. boardModel: _this._getBoardModel(),
  133. targetInfo: {
  134. type: value
  135. }
  136. });
  137. },
  138. editor: {
  139. sectionId: 'general.scenes',
  140. position: 1,
  141. uiControl: {
  142. type: 'TwoStageCombo',
  143. dropDownOptions: dropDownOptions,
  144. collapsiblePickerOptions: [null, collapsiblePickerOptions]
  145. }
  146. }
  147. }];
  148. };
  149. StorytellingPropertiesProvider.prototype._getSlideShowPropertiesList = function _getSlideShowPropertiesList() {
  150. var _this2 = this;
  151. return [{
  152. id: 'sceneTransition',
  153. getPropertyValue: function getPropertyValue() {
  154. return _this2._getPropertyValueFromModel('transition');
  155. },
  156. setPropertyValue: function setPropertyValue(propertyValue) {
  157. if (_this2._getBoardModel().layout.layoutPositioning !== 'relative') {
  158. _this2._updateStory(propertyValue);
  159. } else {
  160. _this2._changeTransition(propertyValue);
  161. }
  162. },
  163. editor: {
  164. sectionId: 'general.scenes',
  165. position: 2,
  166. uiControl: {
  167. type: 'DropDown',
  168. label: StringResources.get('sceneTransitionPropertyLabel'),
  169. options: [{
  170. label: StringResources.get('noSceneTransitionLabel'),
  171. value: 'none'
  172. }, {
  173. label: StringResources.get('animatedPathSceneTransitionLabel'),
  174. value: 'animatedPath'
  175. }, {
  176. label: StringResources.get('sweepSceneTransitionLabel'),
  177. value: 'scaleAndSlide'
  178. }],
  179. coachMark: {
  180. render: function render(options) {
  181. GlassUtils.addCoachmark({
  182. id: 'com.ibm.bi.dashboard.storyProperties.animatedPath',
  183. title: StringResources.get('animatedPathCoachmarkTitle'),
  184. contents: StringResources.get('animatedPathCoachmarkContents'),
  185. placement: 'top',
  186. glassContext: options.glassContext,
  187. $el: options.$el
  188. });
  189. }
  190. }
  191. }
  192. }
  193. }];
  194. };
  195. StorytellingPropertiesProvider.prototype._getPanAndZoomPropertiesList = function _getPanAndZoomPropertiesList() {
  196. var _this3 = this;
  197. // the overview property name are very generic
  198. // to prevent clashing with other properties we add a prefix
  199. var propertyPrefix = 'overview_';
  200. var updateOverviewModel = function updateOverviewModel(propertyName, propertyValue) {
  201. var _showOverviews;
  202. var updateOptions = {
  203. updateArray: [{
  204. id: _this3._getBoardModel().layout.id,
  205. showOverviews: (_showOverviews = {}, _showOverviews[propertyName] = propertyValue, _showOverviews)
  206. }]
  207. };
  208. _this3._getBoardModel().layout.updateModel(updateOptions, _this3, {
  209. undoRedoTransactionId: _.uniqueId('layoutShowOverview_')
  210. });
  211. };
  212. return [{
  213. id: propertyPrefix + 'showStart',
  214. getPropertyValue: function getPropertyValue() {
  215. return _this3._getPropertyValueFromModel('showOverviews').showStart;
  216. },
  217. setPropertyValue: function setPropertyValue(value) {
  218. updateOverviewModel('showStart', value);
  219. },
  220. editor: {
  221. sectionId: 'general.scenes',
  222. position: 1,
  223. uiControl: {
  224. type: 'ToggleButton',
  225. label: StringResources.get('propShowStoryOverviewFirstSlide')
  226. }
  227. }
  228. }, {
  229. id: propertyPrefix + 'showEnd',
  230. getPropertyValue: function getPropertyValue() {
  231. return _this3._getPropertyValueFromModel('showOverviews').showEnd;
  232. },
  233. setPropertyValue: function setPropertyValue(value) {
  234. updateOverviewModel('showEnd', value);
  235. },
  236. editor: {
  237. sectionId: 'general.scenes',
  238. position: 2,
  239. uiControl: {
  240. type: 'ToggleButton',
  241. label: StringResources.get('propShowStoryOverviewLastSlide')
  242. }
  243. }
  244. }];
  245. };
  246. StorytellingPropertiesProvider.prototype._getPropertyValueFromModel = function _getPropertyValueFromModel(propName) {
  247. // TODO: temporary (short term) solution
  248. var model = this._getBoardModel().layout;
  249. return model.get(propName);
  250. };
  251. StorytellingPropertiesProvider.prototype._updateStory = function _updateStory(propertyValue) {
  252. var storyService = new StoryService({
  253. dashboardApi: this.dashboardApi
  254. });
  255. storyService.updateStory({
  256. boardModel: this._getBoardModel(),
  257. targetInfo: {
  258. type: 'slideshow',
  259. transition: propertyValue
  260. }
  261. });
  262. };
  263. StorytellingPropertiesProvider.prototype._changeTransition = function _changeTransition(propertyValue) {
  264. var data = { undoRedoTransactionId: _.uniqueId('layout_transitionChange_') };
  265. this._getBoardModel().layout.set({ transition: propertyValue }, { sender: this, payloadData: data });
  266. };
  267. return StorytellingPropertiesProvider;
  268. }();
  269. return StorytellingPropertiesProvider;
  270. });
  271. //# sourceMappingURL=StorytellingPropertiesProvider.js.map