SchemaListView.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights
  7. * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/datasource/ui/MetaDataListView', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/ErrorView', 'bi/admin/common/dialog/SimpleDialog', 'text!bi/admin/datasource/templates/SchemaListPaneTemplate.html', 'text!bi/admin/datasource/templates/SchemaListTemplate.html'], function (_, MetaDataListView, StringResource, ErrorView, SimpleDialog, SchemaListPaneTemplate, SchemaListTemplate) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var SchemaListView = MetaDataListView.extend({
  12. menuId: 'com.ibm.bi.admin.schemaMenu',
  13. _metaDataColName: 'schemaName',
  14. _statusIcon: {
  15. 'cancelled': '#common-information',
  16. 'executing': '#common-information',
  17. 'failed': '#common-error',
  18. 'pending': '#common-unloaded_schema',
  19. 'purged': '#common-information',
  20. 'succeeded': '#common-success',
  21. 'suspended': '#common-information',
  22. 'scheduled': '#common-information',
  23. 'terminated': '#common-information',
  24. 'inactive': '#common-information',
  25. 'LOADED': '#common-success',
  26. 'loaded': '#common-success',
  27. 'NOTLOADED': '#common-information',
  28. 'not_loaded': '#common-unloaded_schema',
  29. 'LOADING': '#common-information',
  30. 'PENDING': '#common-information',
  31. 'ERROR': '#common-error',
  32. 'error': '#common-error'
  33. },
  34. _statusClass: {
  35. 'cancelled': 'information',
  36. 'executing': 'information',
  37. 'failed': 'failed',
  38. 'pending': 'information',
  39. 'purged': 'information',
  40. 'succeeded': 'succeeded',
  41. 'suspended': 'information',
  42. 'scheduled': 'information',
  43. 'terminated': 'information',
  44. 'inactive': 'information',
  45. 'LOADED': 'succeeded',
  46. 'loaded': 'succeeded',
  47. 'NOTLOADED': 'information',
  48. 'not_loaded': 'information',
  49. 'LOADING': 'information',
  50. 'PENDING': 'information',
  51. 'ERROR': 'failed',
  52. 'error': 'failed'
  53. },
  54. _schemaStatusMsgMap: {
  55. 'loaded': 'metadataLoaded',
  56. 'loading': 'metadataLoading',
  57. 'pending': 'metadataNotLoaded',
  58. 'not_loaded': 'metadataNotLoaded',
  59. 'error': 'Error'
  60. },
  61. _displayLoadingToast: true,
  62. init: function init(options) {
  63. SchemaListView.inherited('init', this, arguments);
  64. _.extend(this, options);
  65. this._template = SchemaListTemplate;
  66. this._paneTemplate = SchemaListPaneTemplate;
  67. this.sortMap = {
  68. 'schemaName': 'defaultName',
  69. 'status': 'status'
  70. };
  71. },
  72. _isItemSelectable: function _isItemSelectable(item) {
  73. return item.schemaType === 'user' || this.showSystemSchemas;
  74. },
  75. _getLoadInformationToShow: function _getLoadInformationToShow(schema) {
  76. //Add logic to determine what to show in the load information column
  77. var loadInfo = "";
  78. if (schema.status === 'loaded' && schema.statusInfo && schema.statusInfo.statistics) {
  79. if (schema.statusInfo.statistics) {
  80. loadInfo = StringResource.get('numberOfTablesLoaded', {
  81. iTablesLoaded: schema.statusInfo.statistics.tablesLoaded,
  82. iTablesAvailable: schema.statusInfo.statistics.tablesSelected
  83. });
  84. } else {
  85. loadInfo = '';
  86. }
  87. }
  88. return loadInfo;
  89. },
  90. _buildItems: function _buildItems(schema) {
  91. schema.connId = this.conn.id;
  92. schema.databaseId = schema.defaultName;
  93. schema.loadInformation = this._getLoadInformationToShow(schema);
  94. schema.errorInformation = this._getErrorInformationToShow(schema);
  95. schema.statusIcon = $(this._statusIcon).attr(schema.status);
  96. schema.statusIconMsg = StringResource.get(this._schemaStatusMsgMap[schema.status]);
  97. schema.iconClass = 'bi-admin-icon-' + $(this._statusClass).attr(schema.status);
  98. return schema;
  99. },
  100. _handleSelection: function _handleSelection(e, contextMenuAction) {
  101. var $item = $(e.target).closest('.bi-admin-list-item');
  102. var id = $item.attr('id').trim();
  103. var selectedItem = this._getItemById(id);
  104. if ($(e.target).hasClass("loadinfo-error")) {
  105. this._createErrorPopup(selectedItem);
  106. } else {
  107. // multi-select
  108. var selectedIndex = _.find(this.selectedRows, function (schema) {
  109. return schema.id === id;
  110. });
  111. var shift = e.shiftKey;
  112. var meta = e.metaKey || e.ctrlKey;
  113. var dirtySelections = [];
  114. if (meta) {
  115. dirtySelections = this._handleMetaSelect(id, $item, selectedIndex, dirtySelections);
  116. } else if (shift) {
  117. dirtySelections = this._handleShiftSelect(selectedItem, dirtySelections);
  118. } else {
  119. dirtySelections = this._handleNormalSelect(id, $item, selectedIndex, dirtySelections, contextMenuAction);
  120. }
  121. this._applySelectionStyling(dirtySelections);
  122. }
  123. },
  124. _createErrorPopup: function _createErrorPopup(selectedItem) {
  125. var errorDialogOptions = {
  126. displayMsgList: selectedItem.statusInfo.messages,
  127. viewObject: ErrorView,
  128. title: StringResource.get('Errors')
  129. };
  130. var errorDialog = new SimpleDialog(errorDialogOptions);
  131. errorDialog.open();
  132. },
  133. _getErrorInformationToShow: function _getErrorInformationToShow(schema) {
  134. if (schema.statusInfo && schema.statusInfo.messages) {
  135. var iErrors = 0;
  136. var iWarnings = 0;
  137. _.each(schema.statusInfo.messages, function (value) {
  138. if (value.severity === 'ERROR') {
  139. ++iErrors;
  140. } else if (value.severity === 'WARNING') {
  141. ++iWarnings;
  142. }
  143. });
  144. return this._getErrorMsg(iErrors, iWarnings);
  145. }
  146. },
  147. _getErrorMsg: function _getErrorMsg(errs, warns) {
  148. //If errors, return msg with number of errors, else show the number of warnings
  149. var errorMsg = "";
  150. var whichString;
  151. if (errs > 0) {
  152. if (errs >= 5) {
  153. whichString = 'ErrorsFivePlus';
  154. } else if (errs > 1) {
  155. whichString = 'ErrorsTwoToFour';
  156. } else {
  157. whichString = 'Error';
  158. }
  159. errorMsg = StringResource.get(whichString, {
  160. num: errs
  161. });
  162. } else if (warns > 0) {
  163. if (warns >= 5) {
  164. whichString = 'WarningsFivePlus';
  165. } else if (warns > 1) {
  166. whichString = 'WarningsTwoToFour';
  167. } else {
  168. whichString = 'Warning';
  169. }
  170. errorMsg = StringResource.get(whichString, {
  171. num: warns
  172. });
  173. }
  174. return errorMsg;
  175. },
  176. _updateStatus: function _updateStatus(id, moserResponse) {
  177. var state = moserResponse.state;
  178. var connectionLV;
  179. if (this.dcPropertySlideout) {
  180. connectionLV = this.dcPropertySlideout.contentView._oPropertyUIControl.items[2].items[1].el;
  181. } else {
  182. // for pane in the MUI perspective - don't have dcPropertySlideout
  183. connectionLV = $('.bi-admin-list');
  184. }
  185. if (state === 'EXECUTING' || state === 'NOT_CANCELLABLE') {
  186. //Change load information for executing task
  187. var loadInfoSpan = $(connectionLV.find(this._escapeId(id))).find('span.bi-admin-schema-lastCached');
  188. var loadInfo = this._getSchemaLoadPercentageComplete(moserResponse);
  189. $(loadInfoSpan[0]).text(loadInfo); //Check for existing loading animation
  190. if (connectionLV.find(this._escapeId(id)).find('.admin_schemaIconLoader').length === 0) {
  191. var currentStatusSvg = $(connectionLV.find(this._escapeId(id)).find('svg')[0]);
  192. if (currentStatusSvg) {
  193. currentStatusSvg.hide();
  194. }
  195. ;
  196. var loadingCircle = '<svg class="svgIcon admin-datasource-svgIcon admin_schemaIconLoader"><circle class="loader__path" cx="12.35px" cy="12.35px" r="6px"></circle></svg> ';
  197. connectionLV.find(this._escapeId(id)).find('.bi-admin-schema-status').append(loadingCircle);
  198. }
  199. } else {
  200. connectionLV.find(this._escapeId(id)).find('use').attr('xlink:href', $(this._statusIcon).attr(state)).attr('class', 'bi-admin-icon-' + $(this._statusClass).attr(state));
  201. }
  202. }
  203. });
  204. return SchemaListView;
  205. });