LicenseByUserView.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['bacontentnav/common/ContentListPageView', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/multitenancy/services/TenantsCustomizationService'], function (ContentListPageView, _, StringResource, TenantsController) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var LicenseByUserView = ContentListPageView.extend({
  12. init: function init(options) {
  13. LicenseByUserView.inherited('init', this, arguments);
  14. $.extend(this, options);
  15. this.tenantsController = this._getNewTenantsController({
  16. glassContext: this.glassContext
  17. });
  18. },
  19. _getNewTenantsController: function _getNewTenantsController(spec) {
  20. return new TenantsController(spec);
  21. },
  22. _getContentBarAccesibleLabel: function _getContentBarAccesibleLabel() {
  23. return StringResource.get('licenseUsageByUser');
  24. },
  25. _buildColumns: function _buildColumns(AdminRoles) {
  26. var isSysAdmin = AdminRoles[0];
  27. var isTenantAdmin = AdminRoles[1];
  28. var haveTenants = AdminRoles[2] && AdminRoles[2].length > 0;
  29. var columns = [{
  30. 'type': 'Text',
  31. 'name': 'userName',
  32. 'label': StringResource.get('userName'),
  33. 'scope': 'row',
  34. 'getDataFn': function getDataFn(oRowData) {
  35. return _.escape(oRowData.name);
  36. }
  37. }, {
  38. 'type': 'Text',
  39. 'name': 'userID',
  40. 'label': StringResource.get('userId'),
  41. 'scope': 'row',
  42. 'getDataFn': function getDataFn(oRowData) {
  43. return _.escape(oRowData.userId);
  44. }
  45. }, {
  46. 'type': 'Time',
  47. 'name': 'lastLogin',
  48. 'label': StringResource.get('lastLogin'),
  49. 'scope': 'row',
  50. 'getDataFn': function getDataFn(oRowData) {
  51. return oRowData.lastLogon;
  52. }
  53. }];
  54. var tenantColumn = {
  55. 'type': 'Text',
  56. 'name': 'tenant',
  57. 'label': StringResource.get('type_tenant'),
  58. 'scope': 'row',
  59. 'getDataFn': function getDataFn(oRowData) {
  60. return oRowData.tenant;
  61. }
  62. };
  63. if ((isSysAdmin || isTenantAdmin) && haveTenants) {
  64. columns.push(tenantColumn);
  65. }
  66. return columns;
  67. },
  68. _checkColumnsToRender: function _checkColumnsToRender(AdminRoles) {
  69. return this.renderContentList({
  70. 'el': this.$el,
  71. 'ajaxProp': 'users',
  72. 'multiSelect': false,
  73. 'columns': this._buildColumns(AdminRoles),
  74. 'minHeight': 50,
  75. 'url': 'v1/licenses/details?level=' + this.licenseInfo.level
  76. });
  77. },
  78. renderContent: function renderContent() {
  79. return Promise.all([this.parentPane.isSysAdmin(), this.parentPane.isTenantAdmin(), this.tenantsController.getTenantsList()]).catch(function (err) {
  80. this.logger.error(err);
  81. return [false, false, []];
  82. }.bind(this)).then(function (results) {
  83. return this._checkColumnsToRender(results);
  84. }.bind(this));
  85. }
  86. });
  87. return LicenseByUserView;
  88. });