DataSourceListController.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2016, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/commons/ui/core/Class', 'bi/admin/common/utils/AJAXUtils'], function (_, Class, AJAXUtils) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var DataSourceListController = Class.extend({
  12. init: function init(options) {
  13. DataSourceListController.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. },
  16. _formatDataSourceEntry: function _formatDataSourceEntry(ds) {
  17. var writable = ds.permissions && ds.permissions.indexOf('write') > -1 ? true : false;
  18. return {
  19. id: ds.id,
  20. connections: ds.connections,
  21. title: ds.defaultName,
  22. defaultName: ds.defaultName,
  23. defaultDescription: ds.defaultDescription,
  24. connectionString: ds.connectionString,
  25. toolTip: ds.defaultName,
  26. owner: ds.owner,
  27. disabled: ds.disabled,
  28. hidden: ds.hidden,
  29. modificationTime: ds.modificationTime,
  30. creationTime: ds.creationTime,
  31. writable: writable,
  32. permissions: ds.permissions,
  33. ancestors: ds.ancestors,
  34. type: ds.type
  35. };
  36. },
  37. getDataSource: function getDataSource(id) {
  38. var options = {
  39. method: 'GET',
  40. contentType: 'application/json; charset=utf-8',
  41. dataType: 'json'
  42. };
  43. 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');
  44. return this.glassContext.services.ajax.ajax(options);
  45. },
  46. _getDataSources: function _getDataSources() {
  47. var options = {
  48. method: 'GET',
  49. contentType: 'application/json; charset=utf-8',
  50. dataType: 'json'
  51. };
  52. options.url = AJAXUtils.getAJAXURL('datasources') + '?' + encodeURIComponent('fields') + '=' + encodeURIComponent('defaultName,disabled,permissions,modificationTime,type,hidden');
  53. return this.glassContext.services.ajax.ajax(options);
  54. },
  55. deleteDataSource: function deleteDataSource(id) {
  56. var options = {
  57. method: 'DELETE',
  58. contentType: 'application/json; charset=utf-8',
  59. dataType: 'json'
  60. };
  61. options.url = AJAXUtils.getAJAXURL('datasources') + '/' + id;
  62. return this.glassContext.services.ajax.ajax(options);
  63. },
  64. getDataSourceList: function getDataSourceList() {
  65. var ajaxErr;
  66. return Promise.try(function () {
  67. return this._getDataSources().fail(function (dfd, err) {
  68. ajaxErr = err;
  69. }.bind(this));
  70. }.bind(this)).catch(function (err) {
  71. if (ajaxErr) {
  72. err = ajaxErr;
  73. }
  74. this.logger.error(err);
  75. return {
  76. data: []
  77. };
  78. }.bind(this)).then(function (dataSources) {
  79. var sortedDS = _.sortBy(dataSources.data, function (ds) {
  80. return ds.defaultName.toLowerCase();
  81. });
  82. return _.map(sortedDS, this._formatDataSourceEntry.bind(this), function () {
  83. this.glassContext.services.logger.error('Could not map data serivces');
  84. }.bind(this));
  85. }.bind(this));
  86. }
  87. });
  88. return DataSourceListController;
  89. });