ActivitiesAdaptor.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2015, 2021
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.  
  8. */
  9. 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) {
  10. var ActivitiesAdaptor = SessionDataAdaptor.extend({
  11. activityType: Api.ActivityType.SCHEDULE,
  12. init: function init(options) {
  13. ActivitiesAdaptor.inherited('init', this, arguments);
  14. $.extend(this, options);
  15. },
  16. getColumnSpecs: function getColumnSpecs() {
  17. var colSpecs = [{
  18. 'module': 'bi/admin/common/ui/listview/columns/AccordionColumn',
  19. 'width': '1%',
  20. 'rowTplFn': this.getPathRowHtml.bind(this)
  21. }, {
  22. 'type': 'Icon',
  23. 'width': '1%'
  24. }, {
  25. 'type': 'Text',
  26. 'label': StringResource.get('name'),
  27. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  28. 'propertyName': 'defaultName',
  29. 'width': '50%',
  30. 'scope': 'row'
  31. }];
  32. if (this.checkboxSelection && this.activityType === Api.ActivityType.SCHEDULE) {
  33. colSpecs = [{
  34. 'module': 'bi/admin/common/ui/listview/columns/Checkbox',
  35. 'width': '32px'
  36. }].concat(colSpecs);
  37. }
  38. ;
  39. var specs = [];
  40. switch (this.activityType) {
  41. case Api.ActivityType.SCHEDULE:
  42. specs = [{
  43. 'label': StringResource.get('modified'),
  44. 'type': 'Time',
  45. 'propertyName': 'modificationTime',
  46. 'sortable': true
  47. }, {
  48. 'type': 'Text',
  49. 'label': StringResource.get('type'),
  50. 'module': 'bi/admin/common/ui/listview/columns/ScheduleTypeIconColumn',
  51. 'sortable': true
  52. }, {
  53. 'type': 'Text',
  54. 'label': StringResource.get('scheduledBy'),
  55. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  56. 'propertyName': 'scheduledBy',
  57. 'sortable': true
  58. }, {
  59. 'type': 'Text',
  60. 'label': StringResource.get('status'),
  61. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  62. 'propertyName': 'status',
  63. 'sortable': true,
  64. 'width': '10%'
  65. }, {
  66. 'type': 'Text',
  67. 'label': StringResource.get('priority'),
  68. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  69. 'propertyName': 'priority',
  70. 'showAsActiveLink': false,
  71. 'sortable': true
  72. }, {
  73. 'type': 'ContextMenu'
  74. }];
  75. break;
  76. case Api.ActivityType.CURRENT:
  77. specs = [{
  78. 'label': StringResource.get('requestTime'),
  79. 'type': 'Time',
  80. 'propertyName': 'requestedStartTime',
  81. 'sortable': true
  82. }, {
  83. 'type': 'Text',
  84. 'label': StringResource.get('runBy'),
  85. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  86. 'propertyName': 'userDefaultName',
  87. 'sortable': true
  88. }, {
  89. 'type': 'Text',
  90. 'label': StringResource.get('status'),
  91. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  92. 'propertyName': 'status',
  93. 'sortable': true,
  94. 'width': '10%'
  95. }, {
  96. 'type': 'Text',
  97. 'label': StringResource.get('priority'),
  98. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  99. 'propertyName': 'priority',
  100. 'sortable': true
  101. }, {
  102. 'type': 'ContextMenu'
  103. }];
  104. break;
  105. case Api.ActivityType.UPCOMING:
  106. specs = [{
  107. 'label': StringResource.get('requestTime'),
  108. 'type': 'Time',
  109. 'propertyName': 'requestedStartTime',
  110. 'sortable': true
  111. }, {
  112. 'type': 'Text',
  113. 'label': StringResource.get('scheduledBy'),
  114. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  115. 'propertyName': 'userDefaultName',
  116. 'sortable': true
  117. }, {
  118. 'type': 'Text',
  119. 'label': StringResource.get('status'),
  120. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  121. 'propertyName': 'status',
  122. 'sortable': true,
  123. 'width': '10%'
  124. }, {
  125. 'type': 'Text',
  126. 'label': StringResource.get('priority'),
  127. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  128. 'propertyName': 'priority',
  129. 'sortable': true
  130. }, {
  131. 'type': 'ContextMenu'
  132. }];
  133. break;
  134. case Api.ActivityType.PAST:
  135. specs = [{
  136. 'label': StringResource.get('requestTime'),
  137. 'propertyName': 'requestedExecutionTime',
  138. 'sortable': true,
  139. 'type': 'Time'
  140. }, {
  141. 'type': 'Text',
  142. 'label': StringResource.get('runBy'),
  143. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  144. 'propertyName': 'runBy',
  145. 'sortable': true
  146. }, {
  147. 'type': 'Text',
  148. 'label': StringResource.get('status'),
  149. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  150. 'propertyName': 'status',
  151. 'sortable': true
  152. }, {
  153. 'type': 'ContextMenu'
  154. }];
  155. break;
  156. case Api.ActivityType.INTERACTIVE:
  157. specs = [{
  158. 'label': StringResource.get('requestTime'),
  159. 'propertyName': 'requestedStartTime',
  160. 'sortable': true,
  161. 'type': 'Time'
  162. }, {
  163. 'type': 'Text',
  164. 'label': StringResource.get('runBy'),
  165. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  166. 'propertyName': 'userDefaultName',
  167. 'sortable': true
  168. }, {
  169. 'type': 'Text',
  170. 'label': StringResource.get('status'),
  171. 'module': 'bi/admin/common/ui/listview/columns/TextColumn',
  172. 'propertyName': 'status',
  173. 'sortable': true,
  174. 'width': '10%'
  175. }];
  176. break;
  177. default:
  178. }
  179. ;
  180. colSpecs = colSpecs.concat(specs);
  181. return colSpecs;
  182. },
  183. getPrettyPath: function getPrettyPath(data) {
  184. // Depending where we get the ancestors from, the last item might be the container. If it is, we need to append the report name
  185. var appendDefaultName = data.ancestors[data.ancestors.length - 1].defaultName !== data.defaultName;
  186. return ContentStoreObject.getLocation(data, appendDefaultName);
  187. },
  188. getPathRowHtml: function getPathRowHtml(data, tr) {
  189. var safeDispName = data.dispatcherName ? data.dispatcherName.replace(/</g, "&lt;") : null; // If we have ancestors use them to build the path
  190. if (data.ancestors) {
  191. var path = this.getPrettyPath(data);
  192. return Promise.resolve(this.getExpandedRowHtml(path, safeDispName, tr));
  193. }
  194. var renderUsingPathProperty = function () {
  195. return this.getExpandedRowHtml(data.path, safeDispName, tr);
  196. }.bind(this);
  197. if (!data.id) {
  198. return Promise.resolve(renderUsingPathProperty());
  199. }
  200. return this.glassContext.services.ajax.ajax({
  201. method: 'GET',
  202. contentType: 'application/json; charset=utf-8',
  203. dataType: 'json',
  204. url: AJAXUtils.getPath('getAncestors', data.id)
  205. }).then(function (response) {
  206. // Store the safePath on the data object so we don't re-query for it.
  207. data.ancestors = response.data[0].ancestors;
  208. var path = this.getPrettyPath(data);
  209. return this.getExpandedRowHtml(path, safeDispName, tr);
  210. }.bind(this)).catch(function (err) {
  211. this.glassContext.services.logger.error(err);
  212. return renderUsingPathProperty();
  213. }.bind(this));
  214. },
  215. getExpandedRowHtml: function getExpandedRowHtml(path, dispatcherName, tr) {
  216. var safePath = path ? path.replace(/</g, "&lt;") : "";
  217. var left = $('td:nth-child(3)', tr).position().left;
  218. var html = '<span title="' + safePath + '" class="path">' + StringResource.get('pathLabel', {
  219. name: safePath
  220. }) + '</span>';
  221. if (dispatcherName) {
  222. html += '<span title="' + dispatcherName + '" class="dispatcher">' + StringResource.get('dispatcherLabel', {
  223. name: dispatcherName
  224. }) + '</span>';
  225. }
  226. return '<div class="activity-details" style="width:' + $(tr).width() + 'px;padding-left:' + left + 'px;">' + html + '</div>';
  227. },
  228. getFilteredRows: function getFilteredRows() {
  229. if (this.session === null) {
  230. return [];
  231. }
  232. var rows = this.activityType === 'schedule' ? this.session.schedules : this.session.activities;
  233. return rows;
  234. },
  235. _getActivities: function _getActivities() {
  236. var actPromise;
  237. if (this.session && this.hasMore()) {
  238. actPromise = Api.getActivities(this.activityType, this.session);
  239. } else {
  240. actPromise = Api.getActivities(this.activityType, this.filters, null, this.pageSize);
  241. }
  242. return actPromise;
  243. },
  244. /**
  245. * Get cached rows by type.
  246. */
  247. _getCachedRows: function _getCachedRows(activityType, cachedResults) {
  248. var cachedRows = [];
  249. if (cachedResults == undefined) {
  250. return [];
  251. }
  252. for (var i = 0; i < cachedResults.length; i++) {
  253. if (activityType === cachedResults[i].type) {
  254. cachedRows = cachedResults[i].rows;
  255. }
  256. }
  257. return cachedRows;
  258. },
  259. /**
  260. * Update the cached rows by type.
  261. */
  262. _updateCachedRows: function _updateCachedRows(activityType, cachedResults, newRows) {
  263. var cachedResult = {};
  264. cachedResult.type = activityType;
  265. cachedResult.rows = newRows;
  266. if (cachedResults == undefined) {
  267. cachedResults = [];
  268. cachedResults.push(cachedResult);
  269. } else {
  270. var bHasResultType = false;
  271. for (var i = 0; i < cachedResults.length; i++) {
  272. if (activityType === cachedResults[i].type) {
  273. cachedResults[i].rows = newRows;
  274. bHasResultType = true;
  275. break;
  276. }
  277. }
  278. if (!bHasResultType) {
  279. cachedResults.push(cachedResult);
  280. }
  281. }
  282. return cachedResults;
  283. },
  284. getRows: function getRows() {
  285. var deferred = Q.defer();
  286. var requestedActivityType = this.activityType;
  287. if (this.isResize) {
  288. // we are resizing, reused cached rows.
  289. this.isResize = false;
  290. var cachedRows = this._getCachedRows(this.activityType, this.cachedResults);
  291. if (cachedRows != undefined) {
  292. deferred.resolve({
  293. rows: cachedRows
  294. });
  295. }
  296. } else {
  297. this._getActivities().then(function (result) {
  298. if (this.activityType === requestedActivityType) {
  299. this.cacheSession(result);
  300. this.summary = {
  301. data: result.summary
  302. };
  303. if (this.hasRelease()) {
  304. Api.releaseRequest(this.activityType, this.session);
  305. }
  306. var rows = result.rows = result.activities || result.schedules || [];
  307. rows = _.map(rows, function (item) {
  308. return this._patchItem(item);
  309. }.bind(this)); // saved the result rows for reuse - group them by type (schedule, past, upcoming, current, interactive).
  310. this.cachedResults = this._updateCachedRows(this.activityType, this.cachedResults, rows);
  311. deferred.resolve({
  312. rows: rows
  313. });
  314. } else {
  315. deferred.reject();
  316. }
  317. }.bind(this), function (dfd, jqXHR) {
  318. var errorCode = "";
  319. try {
  320. var res = JSON.parse(jqXHR.responseText);
  321. if (res && res.errors && res.errors.length > 0) {
  322. errorCode = res.errors[0].code;
  323. }
  324. } catch (e) {}
  325. this.glassContext.appController.showErrorMessage(StringResource.get('activitiesError', {
  326. errCode: errorCode
  327. }), StringResource.get('error'));
  328. }.bind(this));
  329. }
  330. return deferred.promise;
  331. },
  332. _patchItem: function _patchItem(item) {
  333. item.statusValue = item.status;
  334. item.status = StringResource.get(item.status);
  335. if (!this.isMyActivities) {
  336. item.dispatcherName = this.dispatcherNameMap[item.dispatcherID];
  337. }
  338. return item;
  339. }
  340. });
  341. return ActivitiesAdaptor;
  342. });