123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2018
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['bi/admin/common/ui/GenericListView', 'doT', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/datasource/ActionHandler', 'bacontentnav/utils/WidgetNavigator', 'bacontentnav/ui/dialogs/SaveAsDialog', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/commons/ui/content/dialog/SignOnDialog', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/utils/ContentFormatter', 'bi/admin/common/utils/AJAXUtils', 'bi/moser/moser.min', 'bi/admin/datasource/App', 'bi/commons/utils/Utils', 'bi/admin/common/ui/MagicWand'], function (View, dot, _, StringResource, ActionHandler, WidgetNavigator, SaveAsDialog, ConfirmationDialog, SignOnDialog, PropertyUIControl, ContentFormatter, AJAXUtils, MoserJS, App, Utils, MagicWand) {
- 'use strict'; //NOSONAR: meant to be strict
- var MetaDataListView = View.extend({
- showSystemSchemas: false,
- retryCount: 5,
- itemDisplayedCount: 0,
- ITEM_QUEUE: 50,
- init: function init(options) {
- MetaDataListView.inherited('init', this, arguments);
- _.extend(this, options);
- this.conn = options.objectInfo;
- this._runningMetadataTasks = [];
- this.connectionList = [];
- },
- _getConnections: function _getConnections(objectInfo) {
- var options = {
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- var url = AJAXUtils.getAJAXURL('datasources') + '/' + objectInfo.dataSourceId + '/connections' + '?' + encodeURIComponent('fields') + '=' + encodeURIComponent('defaultName,disabled,permissions,owner.defaultName,hidden,capabilities,hasChildren,searchPath,modificationTime,creationTime,ancestors,defaultDescription,connectionString');
- return this.glassContext.services.fetch.get(url, options);
- },
- _getListHtmlNewConn: function _getListHtmlNewConn() {
- return this._getConnections(this.objectInfo).then(function (response) {
- if (response.data.data.length > 0) {
- _.forEach(response.data.data, function (data) {
- if (data.defaultName === this.objectInfo.defaultName) {
- this.objectInfo = data;
- }
- }.bind(this));
- }
- this.conn = this.objectInfo;
- }.bind(this)).then(this._requestSchemaInfo.bind(this));
- },
- _getListHtml: function _getListHtml(refresh) {
- //Check if it's a new connection
- if (!this.objectInfo.ancestors) {
- return this._getListHtmlNewConn();
- } else {
- if (!this.items || refresh) {
- // in the future, can check for a refresh call as well
- return this._requestSchemaInfo();
- } else {
- // already have the schema items, just re-render (ie. sort)
- return Promise.resolve(this._generateListHTMLStr());
- }
- }
- },
- _renderListView: function _renderListView(refresh) {
- return this._renderPane().then(this._renderMetaDataList.bind(this, refresh));
- },
- _renderMetaDataList: function _renderMetaDataList(refresh) {
- return this._getListHtml(refresh).then(this._renderSchemaListItems.bind(this, refresh));
- },
- _renderPane: function _renderPane() {
- return Promise.try(function () {
- if (!this._$loadingAnimationContainer) {
- this._$loadingAnimationContainer = $('<div/>', {
- 'class': 'metaDataListLoading'
- });
- this._$loadingAnimationContainer.append(Utils.getLoadingAnimation(1));
- this.$el.append(this._$loadingAnimationContainer);
- }
- if (!this._$metadataList) {
- this._$metadataList = $('<div/>', {
- 'class': 'metaDataList',
- 'style': 'visibility: hidden'
- });
- this._$metadataList.append(this._generatePaneHTMLStr());
- this._$metadataList.find('.bi-admin-list-headertext').parent().on('primaryaction', function (event) {
- this._sortItems(event.currentTarget.className, true);
- this.displayItems = this.items.slice(0, this.itemDisplayedCount);
- this._renderSchemaListItems(true, this._generateListHTMLStr());
- }.bind(this));
- this._$metadataListTable = this._$metadataList.find('table.bi-admin-list-table').last();
- this._$metadataListTable.parent().scroll(this._onScroll.bind(this));
- this.$el.append(this._$metadataList);
- return this._renderSearch();
- }
- }.bind(this));
- },
- _resetFilteredDisplayList: function _resetFilteredDisplayList() {
- this.filteredDisplayList = this.items.slice(0);
- },
- _renderSearch: function _renderSearch() {
- return MagicWand.searchInput(this.$el).then(function (widgets) {
- if (widgets.length === 1) {
- this._searchInput = widgets[0];
- this._searchInput.options.hint = StringResource.get('filterTips');
- this._searchInput.on('changed', function (e) {
- if (e.text.length === 0) {
- this._resetFilteredDisplayList();
- } else {
- var trimmed = e.text.trim();
- if (trimmed.length > 0) {
- this.filteredDisplayList = _.filter(this.items, function (item) {
- return item.defaultName.toLowerCase().indexOf(trimmed.toLowerCase()) > -1;
- });
- }
- }
- var htmlstr = this._processFilter(this.filteredDisplayList);
- return this._renderSchemaListItems(true, htmlstr);
- }.bind(this));
- }
- }.bind(this));
- },
- _onScroll: function _onScroll(evt) {
- var $target = $(evt.target);
- if ($target.scrollTop() + $target.innerHeight() >= $target[0].scrollHeight - 20) {
- this.displayItems = this.filteredDisplayList.slice(this.itemDisplayedCount, this.itemDisplayedCount + this.ITEM_QUEUE);
- this.itemDisplayedCount = this.itemDisplayedCount + this.ITEM_QUEUE < this.filteredDisplayList.length ? this.itemDisplayedCount + this.ITEM_QUEUE : this.filteredDisplayList.length;
- this._renderMetaDataList(false);
- }
- },
- _setHeights: function _setHeights() {
- var windowHeight = $(window).height();
- var toggleElement = this.$el.find("#admin_showSystemSchemas");
- var tableCont = this._$metadataListTable.parent();
- var headerElementsHeight = tableCont.offset().top;
- var updatedListHeight = windowHeight - toggleElement.height() - headerElementsHeight - 20;
- tableCont.height(updatedListHeight);
- },
- _updateConnectionSignonInfo: function _updateConnectionSignonInfo(connections) {
- var connection = {
- 'datasource': this.conn.ancestors[this.conn.ancestors.length - 1].defaultName
- };
- if (connections && connections.length > 0) {
- connection.connection = connections[0].connection;
- connection.signon = connections[0].signon;
- } else if (this.connectionList && this.connectionList.length > 0 && this.connectionList[0].connection) {
- connection.connection = this.connectionList[0].connection;
- connection.signon = this.connectionList[0].signon;
- }
- if (!connection.connection) {
- connection.connection = this.conn.defaultName;
- }
- if (connection.connection && connection.signon) {
- if (this.connectionList.length > 0) {
- //clear array
- this.connectionList.splice(0, 1);
- }
- this.connectionList.push(connection);
- }
- return connection;
- },
- _extractConnectionInfoFromResolver: function _extractConnectionInfoFromResolver() {
- var connInfo = {};
- if (this.connectionResolver.datasourceConnectionCache && this.connectionResolver.datasourceConnectionCache.datasources) {
- var key = _.keys(this.connectionResolver.datasourceConnectionCache.datasources)[0];
- var info = this.connectionResolver.datasourceConnectionCache.datasources[key];
- if (info) {
- connInfo.datasource = info.name;
- if (info.connection) {
- connInfo.connection = info.connection;
- }
- if (info.signon) {
- connInfo.signon = info.signon;
- }
- } else {
- return null;
- }
- }
- return connInfo;
- },
- _sendSchemaInfoRequest: function _sendSchemaInfoRequest(connections) {
- var connection;
- if (this.connectionResolver) {
- connection = this._extractConnectionInfoFromResolver();
- if (!connection) {
- connection = this._updateConnectionSignonInfo(connections);
- }
- } else {
- connection = this._updateConnectionSignonInfo(connections);
- }
- if (this.connectionList.length === 0 && connection) {
- this.connectionList.push(connection);
- }
- var connObj = {
- connections: this.connectionList
- };
- var connectionSpec = "connectionSpec=" + encodeURIComponent(JSON.stringify(connObj));
- return this._sendSchemas(connectionSpec, 0);
- },
- _sendSchemas: function _sendSchemas(connectionSpec, count) {
- var url = 'v1/metadata/sources/' + encodeURIComponent(this.conn.ancestors[2].id) + '/schemas';
- var ajaxOptions = {
- 'dataType': 'json',
- 'type': 'GET',
- 'url': url,
- 'data': connectionSpec
- };
- return this.glassContext.getCoreSvc('.Ajax').ajax(ajaxOptions).fail(function (error) {
- if (error.jqXHR.responseJSON) {
- return this.handleErrorResponse(error, count, connectionSpec);
- }
- }.bind(this));
- },
- _handle803ErrorResponse: function _handle803ErrorResponse(connectionSpec, count) {
- count++;
- if (count < this.retryCount) {
- return this._getSelectedSignonFromPrompt().then(this._sendSchemas.bind(this, connectionSpec, count)).then(function (dataRetrieved) {
- var htmlStr = this._processDataHandling(dataRetrieved);
- if (htmlStr) {
- this._renderSchemaListItems(true, htmlStr);
- }
- }.bind(this));
- } else {
- var msg = StringResource.get('dataserverFailedLoginAttempts');
- var info = '<span class="msg">' + _.escape(StringResource.get('dataserverFailedLoginAttempts')) + '</span>';
- this.glassContext.appController.showErrorMessage(msg, StringResource.get('error'));
- this.$el.html('<span class="blank-content"><i class="wft_bee"></i>' + info + '</span>');
- return Promise.reject();
- }
- },
- handleErrorResponse: function handleErrorResponse(error, count, connectionSpec) {
- if (error.jqXHR.responseJSON.errors) {
- var errors = error.jqXHR.responseJSON.errors;
- var theError = errors.length > 0 ? errors[0] : null;
- if (!theError) {
- return;
- }
- if (theError.code === 'CQE-803') {
- return this._handle803ErrorResponse(connectionSpec, count);
- } else {
- throw error.jqXHR.responseJSON;
- }
- } else {
- throw error.jqXHR.responseJSON;
- }
- },
- _processDataHandling: function _processDataHandling(dataRetrieved) {
- if (dataRetrieved && dataRetrieved.data) {
- var htmlStr;
- var response = dataRetrieved.data;
- if (response.data && response.data.length > 0) {
- this.items = _.map(response.data, this._buildItems.bind(this));
- this._sortItems(this._metaDataColName);
- this._resetFilteredDisplayList();
- this.itemDisplayedCount = this.ITEM_QUEUE < this.items.length ? this.ITEM_QUEUE : this.items.length;
- this.displayItems = this.items.slice(0, this.itemDisplayedCount);
- this.sortField = '';
- htmlStr = this._generateListHTMLStr();
- } else {
- htmlStr = '<span class="blank-content"><i class="wft_bee"></i><span class="msg">' + StringResource.get('noEntries') + '</span></span>';
- }
- return htmlStr;
- }
- },
- _processFilter: function _processFilter(filteredList) {
- var htmlStr;
- if (filteredList && filteredList.length > 0) {
- this.itemDisplayedCount = this.ITEM_QUEUE < this.items.length ? this.ITEM_QUEUE : this.items.length;
- this._sortItems(this._metaDataColName);
- this.displayItems = filteredList.slice(0, this.itemDisplayedCount);
- this.sortField = '';
- htmlStr = this._generateListHTMLStr();
- } else {
- htmlStr = '<span class="blank-content"><i class="wft_bee"></i><span class="msg">' + StringResource.get('noEntries') + '</span></span>';
- }
- return htmlStr;
- },
- _getNewSignOnDialog: function _getNewSignOnDialog(options) {
- return new SignOnDialog(options);
- },
- _getSelectedSignonFromPrompt: function _getSelectedSignonFromPrompt() {
- return new Promise(function (resolve, reject) {
- var signonPrompt = this._getNewSignOnDialog({
- 'dataSourceName': this.conn.ancestors[this.conn.ancestors.length - 1].defaultName,
- 'dataSourceConnectionName': this.conn.defaultName,
- 'glassContext': this.glassContext,
- 'displayErrMsg': true,
- 'canSaveCredentials': false,
- 'onSubmit': function () {
- var creds = signonPrompt.view.getCredentialsInfo();
- resolve({
- credentialsEx: {
- username: creds.userID,
- password: creds.password
- }
- });
- }.bind(this),
- 'onCancel': function () {
- var info = '<span class="msg">' + _.escape(StringResource.get('cancelled')) + '</span>';
- this.$el.html('<span class="blank-content"><i class="wft_bee"></i>' + info + '</span>');
- reject();
- }.bind(this)
- });
- signonPrompt.view.canSaveCredentials = false;
- signonPrompt.open();
- }.bind(this));
- },
- _requestSchemaInfo: function _requestSchemaInfo() {
- return Promise.try(function () {
- return this.glassContext.getSvc('.DataConnectionServiceFactory').then(function (connectionResolverFactory) {
- return connectionResolverFactory.getDataConnectionResolver();
- }.bind(this)).then(function (connectionResolver) {
- return connectionResolver.execute(this._sendSchemaInfoRequest.bind(this), 'ADMIN_KEY');
- }.bind(this)).then(this._processDataHandling.bind(this), function (error) {
- var info;
- if (error) {
- if (error.reason === 'cancel') {
- info = '<span class="msg">' + _.escape(StringResource.get('cancelled')) + '</span>';
- this.$el.html('<span class="blank-content"><i class="wft_bee"></i>' + info + '</span>');
- } else {
- this.glassContext.appController.showErrorMessage(error.msg, StringResource.get('error'));
- info = '<span class="msg">' + _.escape(error.msg) + '</span>';
- if (error.exceptionMsg) {
- info += '<span class="msg">' + _.escape(error.exceptionMsg) + '</span>';
- }
- this.$el.html('<span class="blank-content"><i class="wft_bee"></i>' + info + '</span>');
- }
- } else {
- this.glassContext.appController.showToast(StringResource.get('cancelLogin'), {
- type: 'warning'
- });
- info = '<span class="msg">' + _.escape(StringResource.get('cancelLogin')) + '</span>';
- this.$el.html('<span class="blank-content"><i class="wft_bee"></i>' + info + '</span>');
- }
- }.bind(this));
- }.bind(this));
- },
- _generateListHTMLStr: function _generateListHTMLStr() {
- var listData = {
- items: this.displayItems,
- strings: {
- 'contextMenuTips': StringResource.get('moreInContext'),
- 'moreActionsLabel': StringResource.get('contextMenuLabel')
- },
- showSystemSchemas: this.showSystemSchemas
- };
- return dot.template(this._template)(listData);
- },
- _generatePaneHTMLStr: function _generatePaneHTMLStr() {
- var listData = {
- strings: {
- 'status': StringResource.get('status'),
- 'colName': StringResource.get(this._metaDataColName),
- 'loadInformation': StringResource.get('loadInformation'),
- 'contextMenuTips': StringResource.get('moreInContext')
- }
- };
- return dot.template(this._paneTemplate)(listData);
- },
- _listHasSystemSchemas: function _listHasSystemSchemas(items) {
- return _.find(items, function (item) {
- return item.schemaType === 'system';
- }) !== undefined;
- },
- _renderSchemaListItems: function _renderSchemaListItems(refresh, htmlStr) {
- if (refresh) {
- this._$metadataListTable.html(htmlStr);
- } else {
- this._$metadataListTable.append(htmlStr);
- }
- $.each(this.$el.find('.bi-admin-link.groupListFocusable'), function (index, value) {
- ContentFormatter.middleShortenString(value);
- });
- this.$el.find('.bi-admin-list-sortable-header').toggleClass('bi-admin-list-sortable-selected', false);
- if (this.sortField) {
- var blueHighlight = this.$el.find('[class*=' + this.sortField + '] > .bi-admin-list-headertext');
- blueHighlight.addClass('bi-admin-list-sortable-selected');
- }
- this._addSystemSchemaToggle();
- this.widgetKeyController = new WidgetNavigator({
- $el: this.$el.find(".groupList-table"),
- focusClass: "groupListFocusable",
- fCallBack: function fCallBack() {}
- });
- this._bindEvents();
- this._$loadingAnimationContainer.css('display', 'none');
- this._$metadataList.css('visibility', 'visible');
- this._setHeights();
- return Promise.resolve();
- },
- _addSystemSchemaToggle: function _addSystemSchemaToggle() {
- if (this._listHasSystemSchemas(this.items)) {
- var $toggleButtonDiv = this._$metadataList.find("#admin_showSystemSchemas");
- if ($toggleButtonDiv.children().length === 0) {
- var configProps = [];
- configProps.push({
- 'type': 'CheckBox',
- 'label': StringResource.get('showSystemSchemas'),
- 'name': 'showSystemSchemas',
- 'checked': this.showSystemSchemas,
- 'onChange': this._setShowSystemSchemas.bind(this)
- });
- this._oPropertyUIControl = new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': $toggleButtonDiv,
- 'items': configProps
- });
- this._oPropertyUIControl.render().then(function () {
- this._setHeights();
- }.bind(this));
- }
- }
- },
- _setShowSystemSchemas: function _setShowSystemSchemas() {
- var modProp = this._oPropertyUIControl.getModifiedProperties();
- if (modProp) {
- //hide or show system schemas in list
- var systemSchemaList = this.$el.find(".bi-admin-list-item.system-schema");
- if (modProp.showSystemSchemas === true) {
- systemSchemaList.removeClass("hidden");
- systemSchemaList.show();
- this.showSystemSchemas = true;
- } else {
- systemSchemaList.hide();
- this.showSystemSchemas = false;
- }
- }
- },
- _getNewActionHandler: function _getNewActionHandler() {
- return new ActionHandler();
- },
- _handleBaseModuleError: function _handleBaseModuleError(task) {
- var msg = task.response ? task.response.entity.msg : task.errorMessage;
- this.glassContext.appController.showErrorMessage(msg, StringResource.get('error'));
- },
- _isBaseModuleDone: function _isBaseModuleDone(id, response) {
- var task = response.data;
- this._updateStatus(id, task);
- var bDone = false;
- if (task.state === 'NOT_AVAILABLE') {
- bDone = true;
- } else if (task.state === 'ERROR') {
- this._handleBaseModuleError(task);
- bDone = true;
- } else if (task.state === 'SUCCESS') {
- if (this._displayLoadingToast) {
- this.glassContext.appController.showToast(StringResource.get('refreshSuccess'), {
- 'type': 'success'
- });
- }
- bDone = true;
- }
- return bDone;
- },
- _getBaseModule: function _getBaseModule(id, xCaAffinity, response) {
- return new Promise(function (resolve, reject) {
- var taskId = response.data.taskID;
- var getTaskUrl = 'v1/metadata/tasks/' + taskId;
- this._runningMetadataTasks.push({
- id: id,
- task: taskId,
- xCaAffinity: xCaAffinity
- });
- var int;
- var options = {
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- if (xCaAffinity) {
- options.headers = {
- Accept: 'application/json',
- 'x-ca-affinity': xCaAffinity
- };
- }
- var func = function () {
- this.glassContext.services.fetch.get(getTaskUrl, options).then(function (response) {
- if (this._isBaseModuleDone(id, response)) {
- clearInterval(int);
- this._removeRunningTask(id);
- if (response.data.state === 'SUCCESS') {
- resolve(response.data.response);
- } else {
- reject();
- }
- }
- }.bind(this), reject);
- }.bind(this);
- int = setInterval(func, 1000);
- }.bind(this));
- },
- RefreshMetadata: function RefreshMetadata(id) {
- var connectionSpec;
- var url;
- if (this.connectionList.length > 0) {
- var connList = [];
- connList.push(this.connectionList[0]);
- var connObj = {
- connections: connList
- };
- connectionSpec = 'connectionSpec=' + encodeURIComponent(JSON.stringify(connObj));
- url = 'v1/metadata/base_modules/' + encodeURIComponent(id) + '?async=true&' + connectionSpec;
- } else {
- url = 'v1/metadata/base_modules/' + encodeURIComponent(id) + '?async=true';
- }
- if (this._displayLoadingToast) {
- this.glassContext.appController.showToast(StringResource.get('refreshStart'), {
- 'type': 'info'
- });
- }
- return this.glassContext.getCoreSvc('.Ajax').ajax({
- contentType: 'application/json; charset=utf-8',
- type: 'POST',
- dataType: 'json',
- url: url
- }).then(function (resp) {
- var xCaAffinity = resp.jqXHR.getResponseHeader('X-CA-Affinity');
- return this._getBaseModule(id, xCaAffinity, resp).then(function (module) {
- return this.render(true).then(function () {
- return module;
- }, function (err) {
- if (this.logger) {
- this.logger.error(err);
- }
- return module;
- }.bind(this));
- }.bind(this), function (err) {
- if (err && err.toString) {
- this.glassContext.appController.showErrorMessage(err.toString(), StringResource.get('error'));
- }
- throw err;
- }.bind(this)).catch(function (e) {
- this.render(true);
- throw e;
- }.bind(this));
- }.bind(this));
- },
- _isLoadingStatusCheck: function _isLoadingStatusCheck(id, status) {
- var stat = status;
- var runningTasks = _.find(this._runningMetadataTasks, function (task) {
- return task.id === id;
- });
- if (runningTasks) {
- stat = 'loading';
- }
- return stat;
- },
- _getLocationFromSelection: function _getLocationFromSelection(selection) {
- var location = selection.url.substr(0, selection.url.length - 6);
- location = location.substr(location.indexOf('objects') + 8);
- return location;
- },
- createModule: function createModule(data) {
- return new Promise(function (resolve, reject) {
- var saveAsDialog = new SaveAsDialog({
- glassContext: this.glassContext,
- defaultFileName: data[0].defaultName,
- service: {
- save: function (service, selection, name) {
- saveAsDialog.hide();
- var location = this._getLocationFromSelection(selection);
- return this.loadSchemaAction(data).then(this._saveModule.bind(this, name, location)).then(function () {
- this.glassContext.appController.showToast(StringResource.get('savedSuccess', {
- name: name
- }), {
- type: 'success'
- });
- }.bind(this), function (err) {
- if (err.jqXHR) {
- var errorRespText = null;
- if (err.jqXHR.responseText) {
- var errorRespJson = JSON.parse(err.jqXHR.responseText);
- errorRespText = errorRespJson.msg ? errorRespJson.msg : err.jqXHR.responseText;
- } else {
- errorRespText = err.toString();
- }
- var errorMessage = err.jqXHR.responseJSON ? err.jqXHR.responseJSON.msg : errorRespText;
- this.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- } else {
- this.glassContext.appController.showErrorMessage(err.toString(), StringResource.get('error'));
- }
- }.bind(this)).then(resolve, resolve);
- }.bind(this)
- }
- });
- saveAsDialog.open();
- }.bind(this));
- },
- _saveModule: function _saveModule(name, location, baseModules) {
- var objFactory = MoserJS.default.createObjectFactory();
- var module = MoserJS.default.ModuleUtils.createModule(objFactory, name, 'en-us');
- baseModules.forEach(function (baseModule) {
- MoserJS.default.ModuleUtils.addSource(module, MoserJS.default.UseSpecType.LW_OLAP, baseModule.id, null, objFactory, true);
- });
- var url = 'v1/metadata/modules/?location=' + location;
- return this.glassContext.services.fetch.post(url, {
- contentType: 'application/json; charset=utf-8',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(module.toJSON())
- });
- },
- loadSchemaAction: function loadSchemaAction(data) {
- var aData = data;
- if (data.constructor !== Array) {
- aData = [data];
- }
- var aDfd = _.map(aData, this._loadSchema.bind(this));
- return Promise.all(aDfd);
- },
- _loadSchema: function _loadSchema(data) {
- if (data.status === 'not_loaded') {
- return App.CreateSchema(data, this).then(function (resp) {
- var location = resp.getResponseHeader('location');
- var storeId = location.substring(location.lastIndexOf('/') + 1, location.length);
- return this.render(true).then(function () {
- return this.RefreshMetadata(storeId);
- }.bind(this));
- }.bind(this));
- } else {
- return this.RefreshMetadata(data.id);
- }
- },
- confirmClearSchemaAction: function confirmClearSchemaAction(data) {
- return new Promise(function (resolve, reject) {
- var oDialog = this._getNewConfirmationDialog('confirmDelete', StringResource.get('confirmClearMetaData'), StringResource.get('confirmClearMetaDataMessage'));
- oDialog.confirm(function () {
- this._clearSchemaAction(data).then(resolve, reject);
- }.bind(this));
- }.bind(this));
- },
- _getNewConfirmationDialog: function _getNewConfirmationDialog(type, title, message) {
- return new ConfirmationDialog(type, title, message);
- },
- _clearSchemaAction: function _clearSchemaAction(data) {
- var aData = data;
- if (data.constructor !== Array) {
- aData = [data];
- }
- return Promise.all(this._clearSchemaActionHelper(aData)).then(function () {
- return this.render(true);
- }.bind(this), function (e) {
- this.glassContext.appController.showErrorMessage(e, StringResource.get('error'));
- }.bind(this));
- },
- _clearSchemaActionHelper: function _clearSchemaActionHelper(aData) {
- var aDfd = [];
- _.forEach(aData, function (d) {
- if (d.status === 'loaded' || d.status === 'loading' || d.status === 'pending' || d.status === 'error') {
- aDfd.push(App.ClearSchema(d)); //Cancel polling task
- if (d.status === 'loading' || d.status === 'pending') {
- aDfd.push(this.CancelSchema(d));
- }
- }
- }.bind(this));
- return aDfd;
- },
- cancelSchemaAction: function cancelSchemaAction(data) {
- var aData = data;
- if (data.constructor !== Array) {
- aData = [data];
- }
- var promises = _.map(aData, function (d) {
- var status = this._isLoadingStatusCheck(d.id, d.status);
- if (status === 'pending' || status === 'executing' || status === 'loading') {
- return this.CancelSchema(d);
- } else {
- return Promise.resolve();
- }
- }.bind(this));
- return Promise.all(promises).then(function () {
- return this.render(true);
- }.bind(this), function (e) {
- this.glassContext.appController.showErrorMessage(e, StringResource.get('error'));
- }.bind(this));
- },
- CancelSchema: function CancelSchema(item) {
- var task = _.find(this._runningMetadataTasks, function (task) {
- return item.id === task.id;
- });
- var taskId = task ? task.task : null;
- var xCaAffinity = task ? task.xCaAffinity : null;
- if (taskId) {
- return App.CancelTask(taskId, xCaAffinity).then(this._removeRunningTask.bind(this, item.id));
- } else {
- return Promise.resolve();
- }
- },
- _removeRunningTask: function _removeRunningTask(itemId) {
- for (var i = 0; i < this._runningMetadataTasks.length; i++) {
- if (this._runningMetadataTasks[i].id === itemId) {
- this._runningMetadataTasks.splice(i, 1);
- break;
- }
- }
- },
- _getSchemaLoadPercentageComplete: function _getSchemaLoadPercentageComplete(moserResponse) {
- var loadInfo = '';
- if (moserResponse) {
- var percentComplete = MoserJS.default.ModuleUtils.taskPercentage(moserResponse);
- loadInfo = StringResource.get('schemaPercentageLoaded', {
- percentLoaded: percentComplete
- });
- }
- return loadInfo;
- },
- _escapeId: function _escapeId(id) {
- return '#' + id.replace(/(:|\.|\[|\]|,|=)/g, '\\$1');
- },
- ShowSchemaLoadOptions: function ShowSchemaLoadOptions(items, tabName) {
- var slideoutId = _.map(items, function (item) {
- return item.id;
- }).join('_');
- var loSlideout = this.glassContext.appController.showSlideOut({
- 'parent': this.slideout,
- 'width': '300px',
- 'onHide': function () {
- if (loSlideout && loSlideout.contentView && loSlideout.contentView.onHide) {
- loSlideout.contentView.onHide();
- }
- }.bind(this),
- 'content': {
- 'id': slideoutId,
- 'title': items.length === 1 ? items[0].defaultName : StringResource.get('numberOfSchemas', {
- 'number': items.length
- }),
- 'module': 'bi/admin/datasource/slideout/LoadOptionsPane',
- 'parentView': this,
- 'items': items,
- 'selectedTabName': tabName,
- 'signonAndConnection': this.connectionList,
- 'glassContext': this.glassContext
- }
- });
- return Promise.resolve();
- }
- });
- return MetaDataListView;
- });
|