LoggingConfigurationPane.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2017,2018
  6. * US Government Users Restricted Rights -
  7. * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['bi/admin/common/slideout/BasePane', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/nls/StringResource', 'bi/admin/system/services/TopicsListController'], function (BasePane, PropertyUIControl, StringResource, TopicsListController) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var LoggingConfigurationPane = BasePane.extend({
  12. currentTopic: {
  13. topicName: '',
  14. topicType: ''
  15. },
  16. init: function init(options) {
  17. LoggingConfigurationPane.inherited('init', this, arguments);
  18. $.extend(this, options);
  19. this.topicsController = this._getNewTopicsListController({
  20. glassContext: this.glassContext
  21. });
  22. },
  23. _getNewTopicsListController: function _getNewTopicsListController(options) {
  24. return new TopicsListController(options);
  25. },
  26. renderBody: function renderBody($body) {
  27. this.$el.addClass("diagnosticLogging");
  28. return this.topicsController._getCurrentTopic().then(function (currentTopic) {
  29. this.currentTopic = this._renderCurrentTopic(currentTopic);
  30. var aControls = [];
  31. this.logType = {
  32. 'type': 'SingleLineValue',
  33. 'name': 'logType',
  34. 'label': StringResource.get('logType'),
  35. 'value': StringResource.get(this.currentTopic.topicName)
  36. };
  37. this.logDetails = {
  38. 'type': 'TextArea',
  39. 'label': StringResource.get(this.currentTopic.topicName + '_Description'),
  40. 'value': '',
  41. 'editable': false,
  42. 'multiline': false,
  43. 'name': 'logDetails',
  44. 'indent': 2
  45. };
  46. aControls.push(this.logType);
  47. aControls.push(this.logDetails);
  48. var tabItems = [{
  49. 'name': StringResource.get('topics'),
  50. 'module': 'bi/admin/system/BuiltinTopicTab',
  51. 'parentView': this.slideout,
  52. 'onSelectCallback': this.getCurrentSelection.bind(this),
  53. 'currentHomeValue': this.currentTopic
  54. }, {
  55. 'name': StringResource.get('addOnTopics'),
  56. 'module': 'bi/admin/system/CustomTopicTab',
  57. 'parentView': this.slideout,
  58. 'onSelectCallback': this.getCurrentSelection.bind(this),
  59. 'currentHomeValue': this.currentTopic
  60. }];
  61. aControls.push({
  62. 'type': 'TabControl',
  63. 'items': tabItems,
  64. 'name': 'topicTab'
  65. });
  66. aControls.push({
  67. 'type': 'Footer',
  68. 'name': 'topicsFooter',
  69. 'items': [{
  70. 'type': 'Button',
  71. 'label': StringResource.get('apply'),
  72. 'primary': true,
  73. 'onSelect': this.applyLoggingConfiguration.bind(this),
  74. 'name': 'applyButton'
  75. }, {
  76. 'type': 'Button',
  77. 'label': StringResource.get('reset'),
  78. 'primary': false,
  79. 'onSelect': this._resetToDefault.bind(this),
  80. 'name': 'resetButton'
  81. }]
  82. });
  83. this._oPropertyUIControl = this._newPropertyUIControl({
  84. 'glassContext': this.glassContext,
  85. 'el': $body,
  86. 'items': aControls
  87. });
  88. return this._oPropertyUIControl.render().then(function () {
  89. this._disableApplyButton();
  90. }.bind(this));
  91. }.bind(this));
  92. },
  93. _newPropertyUIControl: function _newPropertyUIControl(options) {
  94. return new PropertyUIControl(options);
  95. },
  96. _renderCurrentTopic: function _renderCurrentTopic(topicJson) {
  97. var result = {
  98. topicName: '',
  99. topicType: ''
  100. };
  101. var topicObjArray = topicJson['logsEnabled'];
  102. if (topicObjArray.length === 0) {
  103. result.topicName = 'DEFAULT';
  104. result.topicType = 'BUILTIN';
  105. } else {
  106. for (var i = topicObjArray.length - 1; i >= 0; i--) {
  107. if (topicObjArray[i]['topicName'] && topicObjArray[i]['topicType']) {
  108. result.topicName = topicObjArray[i]['topicName'];
  109. result.topicType = topicObjArray[i]['topicType'];
  110. break;
  111. } else {
  112. result.topicName = topicObjArray[i]['topicName'];
  113. }
  114. }
  115. }
  116. return result;
  117. },
  118. _updateSelectedLogDetails: function _updateSelectedLogDetails() {
  119. // only show selected topic label if the selected topic is in the tab that is active
  120. var tabType = this._oPropertyUIControl.getProperty('topicTab')._selectedTabObject.item.module.includes('Builtin') ? 'BUILTIN' : 'CUSTOM';
  121. if (this.currentSelection && tabType === this.currentSelection.topicType) {
  122. this._setLabelValue(this._oPropertyUIControl.getProperty('selectedLogDetails'), this._getSelectedLogTopicLabel());
  123. } else {
  124. this._setLabelValue(this._oPropertyUIControl.getProperty('selectedLogDetails'), '');
  125. }
  126. },
  127. _setLabelValue: function _setLabelValue(UIProperty, text) {
  128. var $label = UIProperty.getPropertyNode().find('label');
  129. if ($label.length > 0) {
  130. $label.text(text);
  131. }
  132. UIProperty.processEllipses();
  133. },
  134. getCurrentSelection: function getCurrentSelection(selection) {
  135. this.currentSelection = selection;
  136. this.checkApplyButton();
  137. this._oPropertyUIControl.getProperty('logType').setValue(StringResource.get(this.currentSelection.topicName));
  138. this._setLabelValue(this._oPropertyUIControl.getProperty('logDetails'), StringResource.get(this.currentSelection.topicName + '_Description')); //clear the other tab
  139. var topicTabs = this._oPropertyUIControl.getProperty('topicTab')._tabs;
  140. for (var i = 0; i < topicTabs.length; i++) {
  141. if (topicTabs[i].item.name === StringResource.get('topics') && this.currentSelection.topicType === 'CUSTOM' && !_.isUndefined(topicTabs[i].tabContent)) {
  142. topicTabs[i].tabContent._listControl._clearRows();
  143. }
  144. if (topicTabs[i].item.name === StringResource.get('addOnTopics') && this.currentSelection.topicType === 'BUILTIN' && !_.isUndefined(topicTabs[i].tabContent)) {
  145. topicTabs[i].tabContent._listControl._clearRows();
  146. }
  147. }
  148. },
  149. checkApplyButton: function checkApplyButton() {
  150. return this.topicsController._getCurrentTopic().then(function (data) {
  151. var currentActiveTopic = this._renderCurrentTopic(data);
  152. if (currentActiveTopic.topicName !== this.currentSelection.topicName) {
  153. this._enableApplyButton();
  154. } else {
  155. this._disableApplyButton();
  156. }
  157. }.bind(this));
  158. },
  159. applyLoggingConfiguration: function applyLoggingConfiguration() {
  160. this.currentTopic = this.currentSelection;
  161. var loggingSettings;
  162. var loggerList = [];
  163. loggerList.push(this.currentTopic);
  164. loggingSettings = {
  165. '_meta': {
  166. 'type': 'glugLoggingConfiguration',
  167. 'version': '0.0.1'
  168. },
  169. 'defaultLevel': 'ERROR',
  170. 'defaultSessionLevel': 'DEBUG',
  171. 'logsEnabled': loggerList
  172. };
  173. return this.topicsController._updateLoggingConfiguration(loggingSettings).then(function () {
  174. this._disableApplyButton();
  175. return this.glassContext.appController.showToast(StringResource.get('topicEnableSuccessMsg', {
  176. 'topicName': StringResource.get(this.currentTopic.topicName)
  177. }), {
  178. 'type': 'success'
  179. });
  180. }.bind(this));
  181. },
  182. _resetToDefault: function _resetToDefault() {
  183. this.currentSelection = {
  184. topicName: 'DEFAULT',
  185. topicType: 'BUILTIN'
  186. };
  187. return this.applyLoggingConfiguration().then(function () {
  188. this._oPropertyUIControl.getProperty('logType').setValue(StringResource.get(this.currentSelection.topicName));
  189. this._setLabelValue(this._oPropertyUIControl.getProperty('logDetails'), StringResource.get(this.currentSelection.topicName + '_Description'));
  190. var topicTabs = this._oPropertyUIControl.getProperty('topicTab')._tabs;
  191. this._oPropertyUIControl.getProperty('topicTab').selectTabByName(StringResource.get('topics'));
  192. var topicRows = this.$body.find('.listControl tr');
  193. for (var j = 1; j < topicRows.length; j++) {
  194. if (topicRows[j].childNodes[1].firstChild.innerText === StringResource.get(this.currentSelection.topicName)) {
  195. this._oPropertyUIControl.getProperty('topicTab')._selectedTabObject.tabContent._listControl._selectRow(topicRows[j]);
  196. } else {
  197. $(topicRows[j]).removeClass('selected');
  198. }
  199. }
  200. for (var i = 0; i < topicTabs.length; i++) {
  201. if (topicTabs[i].item.name === StringResource.get('addOnTopics')) {
  202. topicTabs[i].tabContent._listControl._clearRows();
  203. }
  204. }
  205. }.bind(this));
  206. },
  207. _getApplyButton: function _getApplyButton() {
  208. var footerSection = this._oPropertyUIControl.getProperty('topicsFooter');
  209. return footerSection._oPropertyUIControl.getProperty('applyButton');
  210. },
  211. _disableApplyButton: function _disableApplyButton() {
  212. this._getApplyButton().disable();
  213. },
  214. _enableApplyButton: function _enableApplyButton() {
  215. this._getApplyButton().enable();
  216. }
  217. });
  218. return LoggingConfigurationPane;
  219. });