ExtensionsTab.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  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(['q', 'bi/admin/nls/StringResource', 'bacontentnav/common/ContentListPageView', 'bi/admin/common/Uploader', 'bi/admin/common/services/ExtensionService'], function (Q, StringResource, View, Uploader, ExtensionService) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var ExtensionsTab = View.extend({
  12. getContextMenuId: function getContextMenuId() {
  13. return 'com.ibm.bi.admin.extensionListViewMenu';
  14. },
  15. getViewContainerClass: function getViewContainerClass() {
  16. return 'ContentListPageView ThemesTabPageView';
  17. },
  18. renderContent: function renderContent() {
  19. this.$el.addClass('adminContentListView');
  20. return this.renderContentList({
  21. 'columns': this._getColumnSpecs(),
  22. 'defaultSort': [1, 'asc'],
  23. 'multiSelect': false,
  24. 'getJSONDataCallback': this._getDataObjects.bind(this),
  25. 'setActionPayload': function setActionPayload() {
  26. return Q(true);
  27. },
  28. 'getSelectedObjectFolderCapabilities': function getSelectedObjectFolderCapabilities(selectedObjects) {
  29. return Q(selectedObjects);
  30. },
  31. 'getSelectedObjectWPermissions': function getSelectedObjectWPermissions(selectedObjects) {
  32. return Q(selectedObjects);
  33. },
  34. 'checkSetVersionsSupported': function checkSetVersionsSupported(selectedObjects) {
  35. return Q(selectedObjects);
  36. },
  37. 'getContextMenuId': this.getContextMenuId
  38. });
  39. },
  40. _getDataObjects: function _getDataObjects() {
  41. var ajaxService = this.glassContext.services.ajax;
  42. var promise = ajaxService.ajax({
  43. 'dataType': 'json',
  44. 'type': 'GET',
  45. 'data': {},
  46. 'url': 'v1/plugins/extensions?fields=defaultName,permissions,tenantID,type,modificationTime,id,version'
  47. });
  48. return promise.then(function (list) {
  49. var resultList = [];
  50. var listObject = list.objects;
  51. for (var i = 0; i < listObject.length; i++) {
  52. if (listObject[i].permissions.indexOf('read') > -1) {
  53. var extensionsObj = {
  54. defaultName: listObject[i].defaultName,
  55. modificationTime: listObject[i].modificationTime,
  56. id: listObject[i].id,
  57. tenantID: listObject[i].tenantID,
  58. type: listObject[i].type,
  59. version: listObject[i].version,
  60. _meta: listObject[i]._meta
  61. };
  62. resultList.push(extensionsObj);
  63. }
  64. }
  65. return Promise.resolve({
  66. data: resultList
  67. });
  68. }.bind(this));
  69. },
  70. contentbarItems: function contentbarItems() {
  71. return [{
  72. 'name': 'nameLabel',
  73. 'module': 'bi/content_apps/common/ui/contentbar_components/HiddenLabel',
  74. 'label': this.name
  75. }, {
  76. 'name': 'uploadExt',
  77. 'position': 'trailing',
  78. 'label': StringResource.get('uploadExtension'),
  79. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  80. 'className': 'uploadExtButton',
  81. 'icon': 'common-upload',
  82. 'action': this.uploadExt.bind(this)
  83. }];
  84. },
  85. _getColumnSpecs: function _getColumnSpecs() {
  86. return [{
  87. 'type': 'Text',
  88. 'propertyName': 'defaultName',
  89. '_bNavigable': false,
  90. 'label': StringResource.get('name'),
  91. 'scope': 'row'
  92. }, {
  93. 'type': 'Time',
  94. 'propertyName': 'modificationTime'
  95. }, {
  96. 'type': 'ContextMenu'
  97. }];
  98. },
  99. /**
  100. * Prepares the uploader and calls for an upload, then refreshes the extension list
  101. */
  102. uploadExt: function uploadExt() {
  103. if (!this.extensionService) {
  104. var esOptions = {
  105. 'glassContext': this.glassContext
  106. };
  107. this.extensionService = new ExtensionService(esOptions);
  108. }
  109. var ajaxOptions = {
  110. 'isUpload': true,
  111. 'type': 'extension',
  112. 'tenantID': this.tenantID
  113. };
  114. var uploader = new Uploader({
  115. '$el': this.$el,
  116. 'glassContext': this.glassContext,
  117. 'ajax': this.extensionService.updateOrUpload.bind(this.extensionService),
  118. 'ajaxOptions': ajaxOptions
  119. });
  120. return uploader.doUpload().then(function () {
  121. this.refresh();
  122. }.bind(this));
  123. }
  124. });
  125. return ExtensionsTab;
  126. });