SavedPrompts.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Business Analytics (C) Copyright IBM Corp. 2018, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. /**
  11. * @class SavedPromptsImpl
  12. *
  13. */
  14. define(['../SavedPromptsAPI', './SavedPromptsAPISpec', '../../lib/@waca/dashboard-common/dist/core/APIFactory', 'underscore'], function (SavedPromptsAPI, SavedPromptsAPISpec, APIFactory, _) {
  15. /**
  16. * [livewidgt-cleanup] todo: we need to revisit this api and redesign the interface:
  17. * e.g. // the logic for savedPrompts.save() is duplicated in dataQueryExecution.js..
  18. */
  19. /** Class representing a SavedPrompts Implementation */
  20. var SavedPromptsImpl = function (_SavedPromptsAPISpec) {
  21. _inherits(SavedPromptsImpl, _SavedPromptsAPISpec);
  22. /**
  23. * Create a SavedPromptsImpl of SavedPromtsAPI
  24. * @param widget the corresponding widget.
  25. */
  26. function SavedPromptsImpl(widgetModel) {
  27. _classCallCheck(this, SavedPromptsImpl);
  28. var _this = _possibleConstructorReturn(this, _SavedPromptsAPISpec.call(this));
  29. _this.widgetModel = widgetModel;
  30. return _this;
  31. }
  32. SavedPromptsImpl.prototype.destroy = function destroy() {
  33. this.widgetModel = null;
  34. };
  35. SavedPromptsImpl.prototype.getAPI = function getAPI() {
  36. return APIFactory.createAPI(this, [SavedPromptsAPI]);
  37. };
  38. SavedPromptsImpl.prototype.save = function save(promptValueSpec) {
  39. var specToSave = _.pick(promptValueSpec, SavedPromptsImpl.PromptValueSpec_KEYS);
  40. var savedPrompts = this.widgetModel.get('savedPrompts') || {};
  41. savedPrompts[specToSave.name] = specToSave;
  42. return this.reset(savedPrompts);
  43. };
  44. SavedPromptsImpl.prototype.reset = function reset(promptValueSpec) {
  45. var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  46. //silently change the model. an api event will be triggered for this method.
  47. this.widgetModel['savedPrompts'] = promptValueSpec;
  48. return refresh;
  49. };
  50. SavedPromptsImpl.prototype.getPromptSpec = function getPromptSpec(promptName) {
  51. var savedPrompts = this.widgetModel.get('savedPrompts');
  52. if (!savedPrompts || promptName && !savedPrompts[promptName]) {
  53. return undefined;
  54. } else {
  55. var savedPromptsCopy = JSON.parse(JSON.stringify(savedPrompts));
  56. return savedPromptsCopy[promptName];
  57. }
  58. };
  59. SavedPromptsImpl.prototype.getPromptSpecList = function getPromptSpecList() {
  60. var savedPrompts = this.widgetModel.get('savedPrompts') || {};
  61. var savedPromptsCopy = JSON.parse(JSON.stringify(savedPrompts));
  62. return _.values(savedPromptsCopy);
  63. };
  64. return SavedPromptsImpl;
  65. }(SavedPromptsAPISpec);
  66. /**
  67. * Enum for PROMPTVALUE_KEY.
  68. * @readonly
  69. * @enum {string}
  70. */
  71. SavedPromptsImpl.PromptValueSpec_KEYS = ['name', 'capabilities', 'dataType', 'values', 'modelFilterItem'];
  72. return SavedPromptsImpl;
  73. });
  74. //# sourceMappingURL=SavedPrompts.js.map