Serializer.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Business Analytics (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../dashboard/serializer/SerializerAPI', '../../../dashboard/model/ModelUtils'], function (APIFactory, SerializerAPI, ModelUtils) {
  9. /**
  10. * @implements {SerializerAPI}
  11. */
  12. var Serializer = function () {
  13. /**
  14. * @param {Object} options
  15. * @param {Object} options.features An object of the defined dependencies from the feature contribution json
  16. */
  17. function Serializer(_ref) {
  18. var layoutModel = _ref.layoutModel,
  19. content = _ref.content,
  20. logger = _ref.logger;
  21. _classCallCheck(this, Serializer);
  22. this._layoutModel = layoutModel;
  23. this._content = content;
  24. this._logger = logger;
  25. this._api = APIFactory.createAPI(this, [SerializerAPI]);
  26. }
  27. Serializer.prototype.getAPI = function getAPI() {
  28. return this._api;
  29. };
  30. Serializer.prototype.destroy = function destroy() {
  31. delete this._layoutModel;
  32. delete this._content;
  33. delete this._api;
  34. };
  35. Serializer.prototype.toJSON = function toJSON() {
  36. var _this = this;
  37. var json = this._layoutModel.toJSON(null, ['items']);
  38. var children = this._layoutModel.items;
  39. if (children) {
  40. json.items = [];
  41. children.forEach(function (child) {
  42. var childContent = _this._content.getContent(child.id);
  43. if (childContent) {
  44. json.items.push(childContent.getFeature('Serializer').toJSON());
  45. } else {
  46. _this._logger.log('Cannot get the child content');
  47. }
  48. });
  49. }
  50. ModelUtils.pullPropertiesFromContentModelSpec(json);
  51. return json;
  52. };
  53. return Serializer;
  54. }();
  55. return Serializer;
  56. });
  57. //# sourceMappingURL=Serializer.js.map