Layout.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore', '../../lib/@waca/dashboard-common/dist/core/APIFactory', '../LayoutAPI', '../deprecated/LayoutAPI'], function (Class, _, APIFactory, LayoutAPI, DeprecatedLayoutAPI) {
  8. var LayoutAPIImpl = Class.extend({
  9. model: null,
  10. controller: null,
  11. /**
  12. * Constructor
  13. *
  14. * @param {LayoutController} controller - layout controller
  15. */
  16. init: function init(controller) {
  17. this.model = controller.model;
  18. this.controller = controller;
  19. this.layoutController = controller.layoutController;
  20. },
  21. destroy: function destroy() {
  22. this.model = null;
  23. this.controller = null;
  24. this.layoutController = null;
  25. },
  26. /**
  27. * Layout id getter
  28. * @return {string} layout id
  29. */
  30. getId: function getId() {
  31. return this.model.id;
  32. },
  33. /**
  34. * Get layout children
  35. *
  36. * @return {LayoutAPI[]} array of children layout APIs
  37. */
  38. getChildren: function getChildren() {
  39. var _this = this;
  40. return this.model.items.map(function (_ref) {
  41. var id = _ref.id;
  42. var layout = _this.layoutController.getView(id);
  43. if (layout && layout.view && layout.view.getAPI) {
  44. return layout.view.getAPI();
  45. }
  46. }).filter(function (item) {
  47. return !!item;
  48. });
  49. },
  50. /**
  51. * Show layout
  52. *
  53. * @param {object} options - Rendering Options
  54. * Supported options:
  55. * isBackgroundRun:true|false // Indicate that the rendering is non-interactive (for use by thumbnails)
  56. *
  57. */
  58. render: function render(options) {
  59. this.controller.render(options);
  60. },
  61. /**
  62. * Get layout ratio from parent layout
  63. * @return {Object} ratio; has properties `width` and `height` with the appropriate ratios
  64. */
  65. getSelfRatio: function getSelfRatio() {
  66. return this.controller.getSelfRatio();
  67. },
  68. /**
  69. * Get parent layout API
  70. *
  71. * @return {Object}
  72. */
  73. getParentLayout: function getParentLayout() {
  74. return this.controller.getParentLayout();
  75. },
  76. /**
  77. * Get widget API
  78. *
  79. * @return {WidgetAPI} widget API
  80. */
  81. getWidgetAPI: function getWidgetAPI() {
  82. return this.controller.widgetAPI;
  83. },
  84. getAPI: function getAPI() {
  85. return APIFactory.createAPI(this, [LayoutAPI, DeprecatedLayoutAPI]);
  86. },
  87. getChildrenList: function getChildrenList() {
  88. return this.getChildren();
  89. },
  90. getWidget: function getWidget() {
  91. return this.getWidgetAPI();
  92. }
  93. });
  94. return LayoutAPIImpl;
  95. });
  96. //# sourceMappingURL=Layout.js.map