123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: CA
- *| (C) Copyright IBM Corp. 2016, 2019
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['jquery'], function ($) {
- 'use strict';
- var REQUIRED_PERMISSIONS = ['read', 'execute', 'write', 'traverse'];
- var RefreshDataSourceAction = function () {
- function RefreshDataSourceAction() {
- _classCallCheck(this, RefreshDataSourceAction);
- }
- // Called by Glass when actionController is created.
- RefreshDataSourceAction.prototype.initialize = function initialize(context) {
- var _this = this;
- return context.glassContext.getSvc('.DatasetExecutionService').then(function (datasetExecutionService) {
- _this.datasetExecutionService = datasetExecutionService;
- });
- };
- /**
- * Determine when we show/hide the menu item
- */
- RefreshDataSourceAction.prototype.isItemVisible = function isItemVisible(options) {
- var objectInfo = this._getObjectInfo(options);
- if (!objectInfo) {
- return false;
- }
- if (objectInfo.type !== 'dataSet2') {
- return false;
- }
- var permissions = objectInfo.permissions;
- for (var i = 0; i < REQUIRED_PERMISSIONS.length; i = i + 1) {
- if ($.inArray(REQUIRED_PERMISSIONS[i], permissions) === -1) {
- return false;
- }
- }
- return !this.datasetExecutionService.isExecuting(objectInfo.id);
- };
- /**
- * Default action handler
- */
- RefreshDataSourceAction.prototype.onSelectItem = function onSelectItem(options) {
- var objectInfo = this._getObjectInfo(options);
- if (!objectInfo) {
- return;
- }
- this.datasetExecutionService.execute({
- 'id': objectInfo.id,
- 'name': objectInfo.defaultName,
- 'glassContext': options.glassContext,
- 'isRefresh': true
- });
- var dataSource;
- if (options && options.target && options.target.activeObject && options.target.activeObject) {
- var activeObj = options.target.activeObject;
- if (activeObj.dataSource) {
- dataSource = options.target.activeObject.dataSource;
- } else if (activeObj.parentSlideout) {
- dataSource = options.target.activeObject.parentSlideout.dataSource;
- }
- }
- var originalState = dataSource && dataSource.getState();
- if (dataSource) {
- dataSource.setState('loading');
- }
- return this.datasetExecutionService.whenComplete(objectInfo.id).then(function () {
- if (dataSource) {
- // Reset the original state before trying to reload the metadata.
- // If we were in an error state we might go down a different path
- dataSource.setState(originalState);
- dataSource.reloadMetadata(originalState);
- dataSource.setState('ready');
- }
- }).catch(function (err) {
- if (options && options.glassContext) {
- options.glassContext.getCoreSvc('.Logger').error(err);
- }
- if (dataSource) {
- dataSource.setState('error');
- }
- });
- };
- RefreshDataSourceAction.prototype._getObjectInfo = function _getObjectInfo(options) {
- if (options && options.target && options.target.activeObject) {
- var aSelectedContext = options.target.activeObject.aSelectedContext;
- if (aSelectedContext.length === 1) {
- return aSelectedContext[0];
- }
- }
- return null;
- };
- return RefreshDataSourceAction;
- }();
- return RefreshDataSourceAction;
- });
- //# sourceMappingURL=RefreshDataSourceAction.js.map
|