DashboardSpecUtil.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: Dashboard
  6. * (C) Copyright IBM Corp. 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore'], function (_) {
  10. /**
  11. * Most of Dashboard references the board and widget specs using APIs - but processing on the raw specs before they are deserialized into APIs don't have this advantage.
  12. * This utility encapsulates operations which one may be tempted to hand craft, allowing for them to updated in one place, as a poor man's alternative to an API.
  13. */
  14. var DashboardSpecUtil = function () {
  15. function DashboardSpecUtil() {
  16. _classCallCheck(this, DashboardSpecUtil);
  17. }
  18. /**
  19. * @param {object} layout - a layout from a board spec
  20. * @return {object[]} the widget models in the given layout
  21. */
  22. DashboardSpecUtil.getWidgetModelList = function getWidgetModelList(layout) {
  23. //extract widget models from widget layouts
  24. return DashboardSpecUtil._getWidgetList(layout).map(function (widget) {
  25. return widget && widget.features && widget.features.Models_internal;
  26. }).filter(function (widgetModel) {
  27. return !!widgetModel;
  28. });
  29. };
  30. DashboardSpecUtil._getWidgetList = function _getWidgetList(layout) {
  31. var layouts = [];
  32. if (layout.type === 'widget') {
  33. //This layout is a widget - return it
  34. layouts.push(layout);
  35. }
  36. if (layout.items) {
  37. //Recursively search for widget layouts
  38. layouts = _.flatten([layouts, layout.items.map(function (item) {
  39. return DashboardSpecUtil._getWidgetList(item);
  40. })]);
  41. }
  42. return layouts;
  43. };
  44. return DashboardSpecUtil;
  45. }();
  46. return DashboardSpecUtil;
  47. });
  48. //# sourceMappingURL=DashboardSpecUtil.js.map