123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- 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) {
- 'use strict'; //NOSONAR: meant to be strict
- var SchemaListView = MetaDataListView.extend({
- menuId: 'com.ibm.bi.admin.schemaMenu',
- _metaDataColName: 'schemaName',
- _statusIcon: {
- 'cancelled': '#common-information',
- 'executing': '#common-information',
- 'failed': '#common-error',
- 'pending': '#common-unloaded_schema',
- 'purged': '#common-information',
- 'succeeded': '#common-success',
- 'suspended': '#common-information',
- 'scheduled': '#common-information',
- 'terminated': '#common-information',
- 'inactive': '#common-information',
- 'LOADED': '#common-success',
- 'loaded': '#common-success',
- 'NOTLOADED': '#common-information',
- 'not_loaded': '#common-unloaded_schema',
- 'LOADING': '#common-information',
- 'PENDING': '#common-information',
- 'ERROR': '#common-error',
- 'error': '#common-error'
- },
- _statusClass: {
- 'cancelled': 'information',
- 'executing': 'information',
- 'failed': 'failed',
- 'pending': 'information',
- 'purged': 'information',
- 'succeeded': 'succeeded',
- 'suspended': 'information',
- 'scheduled': 'information',
- 'terminated': 'information',
- 'inactive': 'information',
- 'LOADED': 'succeeded',
- 'loaded': 'succeeded',
- 'NOTLOADED': 'information',
- 'not_loaded': 'information',
- 'LOADING': 'information',
- 'PENDING': 'information',
- 'ERROR': 'failed',
- 'error': 'failed'
- },
- _schemaStatusMsgMap: {
- 'loaded': 'metadataLoaded',
- 'loading': 'metadataLoading',
- 'pending': 'metadataNotLoaded',
- 'not_loaded': 'metadataNotLoaded',
- 'error': 'Error'
- },
- _displayLoadingToast: true,
- init: function init(options) {
- SchemaListView.inherited('init', this, arguments);
- _.extend(this, options);
- this._template = SchemaListTemplate;
- this._paneTemplate = SchemaListPaneTemplate;
- this.sortMap = {
- 'schemaName': 'defaultName',
- 'status': 'status'
- };
- },
- _isItemSelectable: function _isItemSelectable(item) {
- return item.schemaType === 'user' || this.showSystemSchemas;
- },
- _getLoadInformationToShow: function _getLoadInformationToShow(schema) {
- //Add logic to determine what to show in the load information column
- var loadInfo = "";
- if (schema.status === 'loaded' && schema.statusInfo && schema.statusInfo.statistics) {
- if (schema.statusInfo.statistics) {
- loadInfo = StringResource.get('numberOfTablesLoaded', {
- iTablesLoaded: schema.statusInfo.statistics.tablesLoaded,
- iTablesAvailable: schema.statusInfo.statistics.tablesSelected
- });
- } else {
- loadInfo = '';
- }
- }
- return loadInfo;
- },
- _buildItems: function _buildItems(schema) {
- schema.connId = this.conn.id;
- schema.databaseId = schema.defaultName;
- schema.loadInformation = this._getLoadInformationToShow(schema);
- schema.errorInformation = this._getErrorInformationToShow(schema);
- schema.statusIcon = $(this._statusIcon).attr(schema.status);
- schema.statusIconMsg = StringResource.get(this._schemaStatusMsgMap[schema.status]);
- schema.iconClass = 'bi-admin-icon-' + $(this._statusClass).attr(schema.status);
- return schema;
- },
- _handleSelection: function _handleSelection(e, contextMenuAction) {
- var $item = $(e.target).closest('.bi-admin-list-item');
- var id = $item.attr('id').trim();
- var selectedItem = this._getItemById(id);
- if ($(e.target).hasClass("loadinfo-error")) {
- this._createErrorPopup(selectedItem);
- } else {
- // multi-select
- var selectedIndex = _.find(this.selectedRows, function (schema) {
- return schema.id === id;
- });
- var shift = e.shiftKey;
- var meta = e.metaKey || e.ctrlKey;
- var dirtySelections = [];
- if (meta) {
- dirtySelections = this._handleMetaSelect(id, $item, selectedIndex, dirtySelections);
- } else if (shift) {
- dirtySelections = this._handleShiftSelect(selectedItem, dirtySelections);
- } else {
- dirtySelections = this._handleNormalSelect(id, $item, selectedIndex, dirtySelections, contextMenuAction);
- }
- this._applySelectionStyling(dirtySelections);
- }
- },
- _createErrorPopup: function _createErrorPopup(selectedItem) {
- var errorDialogOptions = {
- displayMsgList: selectedItem.statusInfo.messages,
- viewObject: ErrorView,
- title: StringResource.get('Errors')
- };
- var errorDialog = new SimpleDialog(errorDialogOptions);
- errorDialog.open();
- },
- _getErrorInformationToShow: function _getErrorInformationToShow(schema) {
- if (schema.statusInfo && schema.statusInfo.messages) {
- var iErrors = 0;
- var iWarnings = 0;
- _.each(schema.statusInfo.messages, function (value) {
- if (value.severity === 'ERROR') {
- ++iErrors;
- } else if (value.severity === 'WARNING') {
- ++iWarnings;
- }
- });
- return this._getErrorMsg(iErrors, iWarnings);
- }
- },
- _getErrorMsg: function _getErrorMsg(errs, warns) {
- //If errors, return msg with number of errors, else show the number of warnings
- var errorMsg = "";
- var whichString;
- if (errs > 0) {
- if (errs >= 5) {
- whichString = 'ErrorsFivePlus';
- } else if (errs > 1) {
- whichString = 'ErrorsTwoToFour';
- } else {
- whichString = 'Error';
- }
- errorMsg = StringResource.get(whichString, {
- num: errs
- });
- } else if (warns > 0) {
- if (warns >= 5) {
- whichString = 'WarningsFivePlus';
- } else if (warns > 1) {
- whichString = 'WarningsTwoToFour';
- } else {
- whichString = 'Warning';
- }
- errorMsg = StringResource.get(whichString, {
- num: warns
- });
- }
- return errorMsg;
- },
- _updateStatus: function _updateStatus(id, moserResponse) {
- var state = moserResponse.state;
- var connectionLV;
- if (this.dcPropertySlideout) {
- connectionLV = this.dcPropertySlideout.contentView._oPropertyUIControl.items[2].items[1].el;
- } else {
- // for pane in the MUI perspective - don't have dcPropertySlideout
- connectionLV = $('.bi-admin-list');
- }
- if (state === 'EXECUTING' || state === 'NOT_CANCELLABLE') {
- //Change load information for executing task
- var loadInfoSpan = $(connectionLV.find(this._escapeId(id))).find('span.bi-admin-schema-lastCached');
- var loadInfo = this._getSchemaLoadPercentageComplete(moserResponse);
- $(loadInfoSpan[0]).text(loadInfo); //Check for existing loading animation
- if (connectionLV.find(this._escapeId(id)).find('.admin_schemaIconLoader').length === 0) {
- var currentStatusSvg = $(connectionLV.find(this._escapeId(id)).find('svg')[0]);
- if (currentStatusSvg) {
- currentStatusSvg.hide();
- }
- ;
- var loadingCircle = '<svg class="svgIcon admin-datasource-svgIcon admin_schemaIconLoader"><circle class="loader__path" cx="12.35px" cy="12.35px" r="6px"></circle></svg> ';
- connectionLV.find(this._escapeId(id)).find('.bi-admin-schema-status').append(loadingCircle);
- }
- } else {
- connectionLV.find(this._escapeId(id)).find('use').attr('xlink:href', $(this._statusIcon).attr(state)).attr('class', 'bi-admin-icon-' + $(this._statusClass).attr(state));
- }
- }
- });
- return SchemaListView;
- });
|