"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: admin * Copyright IBM Corp. 2015, 2021 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp.   */ define(['doT', 'q', 'jquery', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/status/services/ApiSvc', 'bi/admin/status/services/SessionDataAdaptor', 'bacontentnav/utils/ContentStoreObject', 'bi/admin/common/utils/AJAXUtils'], function (dot, Q, $, _, StringResource, Api, SessionDataAdaptor, ContentStoreObject, AJAXUtils) { var ActivitiesAdaptor = SessionDataAdaptor.extend({ activityType: Api.ActivityType.SCHEDULE, init: function init(options) { ActivitiesAdaptor.inherited('init', this, arguments); $.extend(this, options); }, getColumnSpecs: function getColumnSpecs() { var colSpecs = [{ 'module': 'bi/admin/common/ui/listview/columns/AccordionColumn', 'width': '1%', 'rowTplFn': this.getPathRowHtml.bind(this) }, { 'type': 'Icon', 'width': '1%' }, { 'type': 'Text', 'label': StringResource.get('name'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'defaultName', 'width': '50%', 'scope': 'row' }]; if (this.checkboxSelection && this.activityType === Api.ActivityType.SCHEDULE) { colSpecs = [{ 'module': 'bi/admin/common/ui/listview/columns/Checkbox', 'width': '32px' }].concat(colSpecs); } ; var specs = []; switch (this.activityType) { case Api.ActivityType.SCHEDULE: specs = [{ 'label': StringResource.get('modified'), 'type': 'Time', 'propertyName': 'modificationTime', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('type'), 'module': 'bi/admin/common/ui/listview/columns/ScheduleTypeIconColumn', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('scheduledBy'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'scheduledBy', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('status'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'status', 'sortable': true, 'width': '10%' }, { 'type': 'Text', 'label': StringResource.get('priority'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'priority', 'showAsActiveLink': false, 'sortable': true }, { 'type': 'ContextMenu' }]; break; case Api.ActivityType.CURRENT: specs = [{ 'label': StringResource.get('requestTime'), 'type': 'Time', 'propertyName': 'requestedStartTime', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('runBy'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'userDefaultName', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('status'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'status', 'sortable': true, 'width': '10%' }, { 'type': 'Text', 'label': StringResource.get('priority'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'priority', 'sortable': true }, { 'type': 'ContextMenu' }]; break; case Api.ActivityType.UPCOMING: specs = [{ 'label': StringResource.get('requestTime'), 'type': 'Time', 'propertyName': 'requestedStartTime', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('scheduledBy'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'userDefaultName', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('status'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'status', 'sortable': true, 'width': '10%' }, { 'type': 'Text', 'label': StringResource.get('priority'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'priority', 'sortable': true }, { 'type': 'ContextMenu' }]; break; case Api.ActivityType.PAST: specs = [{ 'label': StringResource.get('requestTime'), 'propertyName': 'requestedExecutionTime', 'sortable': true, 'type': 'Time' }, { 'type': 'Text', 'label': StringResource.get('runBy'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'runBy', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('status'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'status', 'sortable': true }, { 'type': 'ContextMenu' }]; break; case Api.ActivityType.INTERACTIVE: specs = [{ 'label': StringResource.get('requestTime'), 'propertyName': 'requestedStartTime', 'sortable': true, 'type': 'Time' }, { 'type': 'Text', 'label': StringResource.get('runBy'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'userDefaultName', 'sortable': true }, { 'type': 'Text', 'label': StringResource.get('status'), 'module': 'bi/admin/common/ui/listview/columns/TextColumn', 'propertyName': 'status', 'sortable': true, 'width': '10%' }]; break; default: } ; colSpecs = colSpecs.concat(specs); return colSpecs; }, getPrettyPath: function getPrettyPath(data) { // Depending where we get the ancestors from, the last item might be the container. If it is, we need to append the report name var appendDefaultName = data.ancestors[data.ancestors.length - 1].defaultName !== data.defaultName; return ContentStoreObject.getLocation(data, appendDefaultName); }, getPathRowHtml: function getPathRowHtml(data, tr) { var safeDispName = data.dispatcherName ? data.dispatcherName.replace(/' + StringResource.get('pathLabel', { name: safePath }) + ''; if (dispatcherName) { html += '' + StringResource.get('dispatcherLabel', { name: dispatcherName }) + ''; } return '
' + html + '
'; }, getFilteredRows: function getFilteredRows() { if (this.session === null) { return []; } var rows = this.activityType === 'schedule' ? this.session.schedules : this.session.activities; return rows; }, _getActivities: function _getActivities() { var actPromise; if (this.session && this.hasMore()) { actPromise = Api.getActivities(this.activityType, this.session); } else { actPromise = Api.getActivities(this.activityType, this.filters, null, this.pageSize); } return actPromise; }, /** * Get cached rows by type. */ _getCachedRows: function _getCachedRows(activityType, cachedResults) { var cachedRows = []; if (cachedResults == undefined) { return []; } for (var i = 0; i < cachedResults.length; i++) { if (activityType === cachedResults[i].type) { cachedRows = cachedResults[i].rows; } } return cachedRows; }, /** * Update the cached rows by type. */ _updateCachedRows: function _updateCachedRows(activityType, cachedResults, newRows) { var cachedResult = {}; cachedResult.type = activityType; cachedResult.rows = newRows; if (cachedResults == undefined) { cachedResults = []; cachedResults.push(cachedResult); } else { var bHasResultType = false; for (var i = 0; i < cachedResults.length; i++) { if (activityType === cachedResults[i].type) { cachedResults[i].rows = newRows; bHasResultType = true; break; } } if (!bHasResultType) { cachedResults.push(cachedResult); } } return cachedResults; }, getRows: function getRows() { var deferred = Q.defer(); var requestedActivityType = this.activityType; if (this.isResize) { // we are resizing, reused cached rows. this.isResize = false; var cachedRows = this._getCachedRows(this.activityType, this.cachedResults); if (cachedRows != undefined) { deferred.resolve({ rows: cachedRows }); } } else { this._getActivities().then(function (result) { if (this.activityType === requestedActivityType) { this.cacheSession(result); this.summary = { data: result.summary }; if (this.hasRelease()) { Api.releaseRequest(this.activityType, this.session); } var rows = result.rows = result.activities || result.schedules || []; rows = _.map(rows, function (item) { return this._patchItem(item); }.bind(this)); // saved the result rows for reuse - group them by type (schedule, past, upcoming, current, interactive). this.cachedResults = this._updateCachedRows(this.activityType, this.cachedResults, rows); deferred.resolve({ rows: rows }); } else { deferred.reject(); } }.bind(this), function (dfd, jqXHR) { var errorCode = ""; try { var res = JSON.parse(jqXHR.responseText); if (res && res.errors && res.errors.length > 0) { errorCode = res.errors[0].code; } } catch (e) {} this.glassContext.appController.showErrorMessage(StringResource.get('activitiesError', { errCode: errorCode }), StringResource.get('error')); }.bind(this)); } return deferred.promise; }, _patchItem: function _patchItem(item) { item.statusValue = item.status; item.status = StringResource.get(item.status); if (!this.isMyActivities) { item.dispatcherName = this.dispatcherNameMap[item.dispatcherID]; } return item; } }); return ActivitiesAdaptor; });