BuiltinTopicTab.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['bi/admin/nls/StringResource', 'bacontentnav/common/ContentListPageView', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/system/services/TopicsListController', 'bi/commons/utils/Downloader', 'underscore'], function (StringResource, View, PropertyUIControl, TopicsListController, Downloader, _) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var BuiltinTopicTab = View.extend({
  12. loggingConfigUrl: 'v1/glug/config/logging',
  13. builtinTopicUrl: 'v1/glug/topics/builtin',
  14. customTopicUrl: 'v1/glug/topics/custom',
  15. favouriteTopicList: ['AAA', 'CM', 'MOSER', 'DISP', 'POGO_MSGS', 'DEFAULT', 'RSVP'],
  16. getContextMenuId: function getContextMenuId() {
  17. return "com.ibm.bi.admin.loggingTopicListViewMenu";
  18. },
  19. currentBuiltinSelection: {
  20. topicName: '',
  21. topicType: 'BUILTIN'
  22. },
  23. currentTopic: {
  24. topicName: '',
  25. topicType: ''
  26. },
  27. init: function init(options) {
  28. BuiltinTopicTab.inherited('init', this, arguments);
  29. this.showTitle = true;
  30. _.extend(this, options);
  31. this.topicsController = new TopicsListController({
  32. glassContext: this.glassContext
  33. });
  34. if (this.currentHomeValue.topicType === 'BUILTIN') {
  35. this.currentBuiltinSelection = this.currentHomeValue;
  36. }
  37. },
  38. renderContent: function renderContent() {
  39. var aControls = [];
  40. this.$el.addClass("adminContentListView");
  41. this.$el.addClass("builtInTopicList");
  42. aControls.push({
  43. 'type': 'CheckBox',
  44. 'name': 'showAllBuiltinTopic',
  45. 'label': StringResource.get('showAll'),
  46. 'checked': this.checkFavorite(),
  47. 'onChange': this.refreshList.bind(this),
  48. 'controlOnLeft': true
  49. }, {
  50. 'module': 'bi/content_apps/ui/RenderCallback',
  51. 'renderCallback': this.renderListControl.bind(this),
  52. 'el': this.$el,
  53. 'name': 'topicList'
  54. });
  55. this._oPropertyUIControl = this._newPropertyUIControl(aControls);
  56. return this._oPropertyUIControl.render().then(function () {
  57. this.rightAlignLabel();
  58. }.bind(this));
  59. },
  60. _newPropertyUIControl: function _newPropertyUIControl(items) {
  61. return new PropertyUIControl({
  62. 'glassContext': this.glassContext,
  63. 'el': this.$el,
  64. 'items': items
  65. });
  66. },
  67. rightAlignLabel: function rightAlignLabel() {
  68. var $showAllParentDiv = this._oPropertyUIControl.getProperty('showAllBuiltinTopic').getPropertyNode().parent();
  69. $showAllParentDiv.addClass('showAllBuiltinTopicFlexRightAlignControl');
  70. },
  71. checkFavorite: function checkFavorite() {
  72. var isChecked = true;
  73. if (_.contains(this.favouriteTopicList, this.currentBuiltinSelection.topicName)) {
  74. isChecked = false;
  75. }
  76. return isChecked;
  77. },
  78. _getSelectedTopic: function _getSelectedTopic() {
  79. var selectedDefaultItem = this._listControl.getSelectedObjects()[0];
  80. if (!_.isUndefined(selectedDefaultItem)) {
  81. this.currentBuiltinSelection.topicName = selectedDefaultItem.id;
  82. this.currentValue = this.currentBuiltinSelection;
  83. }
  84. },
  85. getSelectedObjects: function getSelectedObjects() {
  86. var i;
  87. var rowObjects = [];
  88. var ancestors = this._listControl.contentView.getAncestors();
  89. for (i = 0; i < this.aSelectedRows.length; i += 1) {
  90. var obj = this._dTable.fnGetData(this.aSelectedRows[i]);
  91. if (!obj[ContentStoreObject.ANCESTORS] && ancestors && ancestors.length > 0) {
  92. obj[ContentStoreObject.ANCESTORS] = ancestors;
  93. }
  94. rowObjects.push(obj);
  95. }
  96. return rowObjects;
  97. },
  98. renderListControl: function renderListControl(container) {
  99. if (!_.isUndefined(container)) {
  100. this.$container = $(container);
  101. }
  102. if (_.isUndefined(this.$container)) {
  103. this.$container = this.$el;
  104. }
  105. this.$wrapper = $('<div>');
  106. this.$container.append(this.$wrapper);
  107. this.$wrapper.append(this.$contentBars);
  108. return this._renderContentList();
  109. },
  110. _getDataTableSource: function _getDataTableSource() {
  111. var getJsonUrl;
  112. if (this._oPropertyUIControl.getProperty('showAllBuiltinTopic').isChecked()) {
  113. getJsonUrl = this.topicsController._getDefaultTopicList.bind(this.topicsController);
  114. } else {
  115. getJsonUrl = this.topicsController._getFavouriteTopicList.bind(this.topicsController);
  116. }
  117. return getJsonUrl;
  118. },
  119. _renderContentList: function _renderContentList() {
  120. var getJsonUrl = this._getDataTableSource();
  121. return this.renderContentList({
  122. 'minHeight': 350,
  123. '$container': this.$el,
  124. 'columns': this._getColumnSpecs(),
  125. 'ajaxProp': '',
  126. 'getJSONDataCallback': getJsonUrl,
  127. 'defaultSort': [1, 'asc'],
  128. 'multiSelect': false,
  129. 'selectedRow': ['name', StringResource.get(this.currentBuiltinSelection.topicName)],
  130. 'disableColumnHeaders': true,
  131. 'singleSelectCallback': this.onSelected.bind(this),
  132. 'getSelectedObjectWPermissions': function getSelectedObjectWPermissions(selectedObjects) {
  133. return Promise.resolve(selectedObjects);
  134. },
  135. 'getContextMenuId': this.getContextMenuId,
  136. 'dataTableOptions': {
  137. 'iDisplayLength': 100
  138. },
  139. '_showLoadBuffer': 100
  140. });
  141. },
  142. onSelected: function onSelected() {
  143. this._getSelectedTopic();
  144. return this.onSelectCallback(this.currentValue);
  145. },
  146. _getContentBarAccesibleLabel: function _getContentBarAccesibleLabel() {
  147. return StringResource.get('topics');
  148. },
  149. _getColumnSpecs: function _getColumnSpecs() {
  150. return [{
  151. 'type': 'RadioButtons'
  152. }, {
  153. 'type': 'Text',
  154. 'propertyName': 'name',
  155. '_bNavigable': true,
  156. 'label': StringResource.get('name'),
  157. 'scope': 'row'
  158. }, {
  159. 'type': 'ContextMenu',
  160. 'width': '10%',
  161. 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
  162. }];
  163. },
  164. _downloadTopic: function _downloadTopic() {
  165. var selectedObj = this._listControl.getSelectedObjects()[0];
  166. if (!_.isUndefined(selectedObj)) {
  167. var name = selectedObj.id;
  168. return this.topicsController._getDefaultTopicDescription(name).then(function (data) {
  169. var downloader = new Downloader({
  170. 'url': 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data, 0, 4)),
  171. 'name': name + '.json'
  172. });
  173. downloader.doDownload();
  174. });
  175. } else {
  176. return Promise.resolve();
  177. }
  178. },
  179. cancel: function cancel() {},
  180. onContextMenu: function onContextMenu(id) {
  181. switch (id) {
  182. case 'deleteTopic':
  183. this._deleteTopic();
  184. break;
  185. case 'downloadTopic':
  186. this._downloadTopic();
  187. break;
  188. default:
  189. this.logger.error("Unexpected context menu id for logging list pane: " + id);
  190. }
  191. },
  192. refreshList: function refreshList() {
  193. this._listControl.remove();
  194. this.renderListControl();
  195. }
  196. });
  197. return BuiltinTopicTab;
  198. });