WidgetUpgradeUtils.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: BI Dashboard
  7. *| (C) Copyright IBM Corp. 2018
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['underscore'], function (_) {
  14. var WidgetUpgradeUtils = function () {
  15. function WidgetUpgradeUtils() {
  16. _classCallCheck(this, WidgetUpgradeUtils);
  17. }
  18. WidgetUpgradeUtils.prototype.findProperty = function findProperty(id, properties) {
  19. return _.find(properties, function (property) {
  20. return property.id === id;
  21. });
  22. };
  23. WidgetUpgradeUtils.prototype.findLayout = function findLayout() {
  24. var layouts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  25. var widgetId = arguments[1];
  26. var match = null;
  27. for (var i = 0; i < layouts.length; i++) {
  28. if (layouts[i].id === widgetId) {
  29. match = layouts[i];
  30. }
  31. if (!match && layouts[i].items) {
  32. match = this.findLayout(layouts[i].items, widgetId);
  33. }
  34. if (match) {
  35. break;
  36. }
  37. }
  38. return match;
  39. };
  40. WidgetUpgradeUtils.prototype.specHasWidgets = function specHasWidgets(spec) {
  41. return spec && spec.widgets && !_.isEmpty(spec.widgets);
  42. };
  43. WidgetUpgradeUtils.prototype.isLiveWidgetModel = function isLiveWidgetModel(model) {
  44. return model && model.type && model.type === 'live';
  45. };
  46. WidgetUpgradeUtils.prototype.setDefaultProperty = function setDefaultProperty(model, propertyName, defaultValue) {
  47. var oldProp = this.findProperty(propertyName, model.properties);
  48. if (!oldProp) {
  49. if (!model.properties) {
  50. model.properties = [];
  51. }
  52. model.properties.push({
  53. id: propertyName,
  54. value: defaultValue
  55. });
  56. }
  57. };
  58. return WidgetUpgradeUtils;
  59. }();
  60. return new WidgetUpgradeUtils();
  61. });
  62. //# sourceMappingURL=WidgetUpgradeUtils.js.map