12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2016, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/commons/ui/core/Class', 'bi/admin/common/utils/AJAXUtils'], function (_, Class, AJAXUtils) {
- 'use strict'; //NOSONAR: meant to be strict
- var DataSourceListController = Class.extend({
- init: function init(options) {
- DataSourceListController.inherited('init', this, arguments);
- _.extend(this, options);
- },
- _formatDataSourceEntry: function _formatDataSourceEntry(ds) {
- var writable = ds.permissions && ds.permissions.indexOf('write') > -1 ? true : false;
- return {
- id: ds.id,
- connections: ds.connections,
- title: ds.defaultName,
- defaultName: ds.defaultName,
- defaultDescription: ds.defaultDescription,
- connectionString: ds.connectionString,
- toolTip: ds.defaultName,
- owner: ds.owner,
- disabled: ds.disabled,
- hidden: ds.hidden,
- modificationTime: ds.modificationTime,
- creationTime: ds.creationTime,
- writable: writable,
- permissions: ds.permissions,
- ancestors: ds.ancestors,
- type: ds.type
- };
- },
- getDataSource: function getDataSource(id) {
- var options = {
- method: 'GET',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- options.url = AJAXUtils.getAJAXURL('datasources') + '/' + id + '?' + encodeURIComponent('fields') + '=' + encodeURIComponent('defaultName,disabled,permissions,owner.defaultName,hidden,capabilities,hasChildren,searchPath,modificationTime,creationTime,ancestors,defaultDescription,tenantID,owner.id');
- return this.glassContext.services.ajax.ajax(options);
- },
- _getDataSources: function _getDataSources() {
- var options = {
- method: 'GET',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- options.url = AJAXUtils.getAJAXURL('datasources') + '?' + encodeURIComponent('fields') + '=' + encodeURIComponent('defaultName,disabled,permissions,modificationTime,type,hidden');
- return this.glassContext.services.ajax.ajax(options);
- },
- deleteDataSource: function deleteDataSource(id) {
- var options = {
- method: 'DELETE',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- };
- options.url = AJAXUtils.getAJAXURL('datasources') + '/' + id;
- return this.glassContext.services.ajax.ajax(options);
- },
- getDataSourceList: function getDataSourceList() {
- var ajaxErr;
- return Promise.try(function () {
- return this._getDataSources().fail(function (dfd, err) {
- ajaxErr = err;
- }.bind(this));
- }.bind(this)).catch(function (err) {
- if (ajaxErr) {
- err = ajaxErr;
- }
- this.logger.error(err);
- return {
- data: []
- };
- }.bind(this)).then(function (dataSources) {
- var sortedDS = _.sortBy(dataSources.data, function (ds) {
- return ds.defaultName.toLowerCase();
- });
- return _.map(sortedDS, this._formatDataSourceEntry.bind(this), function () {
- this.glassContext.services.logger.error('Could not map data serivces');
- }.bind(this));
- }.bind(this));
- }
- });
- return DataSourceListController;
- });
|