123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- "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(/</g, "<") : null; // If we have ancestors use them to build the path
- if (data.ancestors) {
- var path = this.getPrettyPath(data);
- return Promise.resolve(this.getExpandedRowHtml(path, safeDispName, tr));
- }
- var renderUsingPathProperty = function () {
- return this.getExpandedRowHtml(data.path, safeDispName, tr);
- }.bind(this);
- if (!data.id) {
- return Promise.resolve(renderUsingPathProperty());
- }
- return this.glassContext.services.ajax.ajax({
- method: 'GET',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json',
- url: AJAXUtils.getPath('getAncestors', data.id)
- }).then(function (response) {
- // Store the safePath on the data object so we don't re-query for it.
- data.ancestors = response.data[0].ancestors;
- var path = this.getPrettyPath(data);
- return this.getExpandedRowHtml(path, safeDispName, tr);
- }.bind(this)).catch(function (err) {
- this.glassContext.services.logger.error(err);
- return renderUsingPathProperty();
- }.bind(this));
- },
- getExpandedRowHtml: function getExpandedRowHtml(path, dispatcherName, tr) {
- var safePath = path ? path.replace(/</g, "<") : "";
- var left = $('td:nth-child(3)', tr).position().left;
- var html = '<span title="' + safePath + '" class="path">' + StringResource.get('pathLabel', {
- name: safePath
- }) + '</span>';
- if (dispatcherName) {
- html += '<span title="' + dispatcherName + '" class="dispatcher">' + StringResource.get('dispatcherLabel', {
- name: dispatcherName
- }) + '</span>';
- }
- return '<div class="activity-details" style="width:' + $(tr).width() + 'px;padding-left:' + left + 'px;">' + html + '</div>';
- },
- 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;
- });
|