LegacyOpenActionHandler.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2018
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['./OpenActionHandler', '../../../app/util/ErrorUtils'], function (BaseClass, Utils) {
  13. var ActionHandler = BaseClass.extend({
  14. /**
  15. * This class is a last effort to open a dashboard/story that has no tags. We go to the server to get the spec and look at it.
  16. * Once all the specs are updated on the server (trough a CM upgrade) we can remove this file.
  17. */
  18. _getTargetPerspective: function _getTargetPerspective(id, context) {
  19. return this._getSpec(id, context).then(function (spec) {
  20. return spec.timeline ? 'story' : 'dashboard';
  21. });
  22. },
  23. _hasValidTags: function _hasValidTags(item) {
  24. // if we get here we should have no tags. If we do then it's not a type we understand
  25. return !item.tags || !item.tags.length;
  26. },
  27. /**
  28. * This function is only used to determine if it is a dashboard or story
  29. * In case of an error fetching the spec, we will always resolve so that we default to a dashboard.
  30. * Error cases will be handled later when the dashboard is about to open.
  31. */
  32. _getSpec: function _getSpec(id, context) {
  33. return context.glassContext.getSvc('.Content').then(function (contentSvc) {
  34. return new Promise(function (resolve, reject) {
  35. var itemURL = contentSvc.getBaseObjectsURL() + '/' + id;
  36. var options = {
  37. dataType: 'json',
  38. data: {
  39. 'fields': 'specification'
  40. },
  41. MRUInfo: {}
  42. };
  43. contentSvc.get(itemURL, options).then(function (response) {
  44. var specAsString = response.data && response.data.length && response.data[0].specification;
  45. if (specAsString) {
  46. try {
  47. resolve(JSON.parse(specAsString));
  48. } catch (err) {
  49. reject(err);
  50. }
  51. } else {
  52. resolve(contentSvc.get(itemURL + '/content'));
  53. }
  54. }).fail(function (deferred, request) {
  55. Utils.showError(context.glassContext, request, id);
  56. resolve({});
  57. });
  58. });
  59. });
  60. }
  61. });
  62. return ActionHandler;
  63. });
  64. //# sourceMappingURL=LegacyOpenActionHandler.js.map