123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- 'use strict';
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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; }
- 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; }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Conversion service
- *| (C) Copyright IBM Corp. 2018, 2021
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', './ConversionService'], function (_, ConversionService) {
- var conversionServiceInstance = new ConversionService();
- var ConverterInterface = conversionServiceInstance.getInterface();
- var ExploreToDashboardConverter = function (_ConverterInterface) {
- _inherits(ExploreToDashboardConverter, _ConverterInterface);
- function ExploreToDashboardConverter(definition) {
- _classCallCheck(this, ExploreToDashboardConverter);
- return _possibleConstructorReturn(this, (ExploreToDashboardConverter.__proto__ || Object.getPrototypeOf(ExploreToDashboardConverter)).call(this, Object.assign({
- src: 'EXPLORE',
- target: 'DASHBOARD'
- }, definition)));
- }
- _createClass(ExploreToDashboardConverter, [{
- key: 'convert',
- value: function convert(src, target, spec) {
- var _this2 = this;
- return new Promise(function (resolve, reject) {
- var specJson = JSON.parse(spec);
- if (!_this2.validate(specJson)) {
- reject(new Error('Invalid incoming spec'));
- }
- _this2.filterOutEmptyWidgets(specJson);
- resolve(JSON.stringify(_this2._doConvert(specJson)));
- });
- }
- }, {
- key: 'validate',
- value: function validate(spec) {
- return !_.isEmpty(spec) && !_.isEmpty(this._getFilteredWidgets(spec));
- }
- }, {
- key: 'filterOutEmptyWidgets',
- value: function filterOutEmptyWidgets(spec) {
- var filteredWidgets = this._getFilteredWidgets(spec);
- var filteredLayoutItems = this._getFilteredLayoutItems(spec.layout.items, filteredWidgets);
- spec.layout.items = filteredLayoutItems;
- spec.widgets = filteredWidgets;
- }
- }, {
- key: '_getFilteredWidgets',
- value: function _getFilteredWidgets() {
- var spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var filteredWidgets = {};
- var widgets = [];
- if (spec.widgets) {
- widgets = Object.values(spec.widgets);
- } else if (spec.layout && spec.layout.items) {
- widgets = this._findWidgets(spec.layout.items);
- }
- widgets.forEach(function (widget) {
- if (widget.type === 'live') {
- filteredWidgets[widget.id] = widget;
- }
- });
- return filteredWidgets;
- }
- }, {
- key: '_findWidgets',
- value: function _findWidgets() {
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var widgets = [];
- for (var i = 0; i < items.length; i++) {
- var item = items[i];
- if (item.items) {
- widgets = widgets.concat(this._findWidgets(item.items));
- } else if (item.features) {
- widgets.push(item.features['Models_internal']);
- }
- }
- return widgets;
- }
- }, {
- key: '_getFilteredLayoutItems',
- value: function _getFilteredLayoutItems(layoutItems, filteredWidgets) {
- return layoutItems.filter(function (item) {
- if (item.subType === 'compare') {
- var firstWidgetId = item.items[0].id;
- var secondWidgetId = item.items[1].id;
- var hasLiveWidgets = filteredWidgets[firstWidgetId] || filteredWidgets[secondWidgetId];
- // Should only keep live widgets in comparison card layouts
- item.items = item.items.filter(function (widget) {
- return filteredWidgets[widget.id];
- });
- return hasLiveWidgets;
- } else {
- var widgetId = item.items[0].id;
- return filteredWidgets[widgetId];
- }
- });
- }
- }, {
- key: '_doConvert',
- value: function _doConvert(exploreSpec) {
- var fragmentSpec = {
- dataSources: exploreSpec.dataSources,
- widgets: this._cleanWidgets(_.values(exploreSpec.widgets))
- };
- var convertedCards = this._convertCards(exploreSpec.layout.items);
- fragmentSpec.layout = convertedCards.layout;
- fragmentSpec.widgetToCardMap = convertedCards.widgetToCardMap;
- return fragmentSpec;
- }
- }, {
- key: '_cleanWidgets',
- value: function _cleanWidgets(widgets) {
- return widgets.map(function (widget) {
- return _.omit(widget, 'thumbnailId');
- });
- }
- }, {
- key: '_convertCards',
- value: function _convertCards(cards) {
- var _this3 = this;
- return cards.reduce(function (acc, card) {
- return _this3._convertCard(acc, card);
- }, {
- layout: [],
- widgetToCardMap: {}
- });
- }
- }, {
- key: '_convertCard',
- value: function _convertCard(acc, card) {
- var widgets = this._getWidgets(card); //in order
- if (widgets.length === 1) {
- acc.layout.push(this._getGroupedItems(widgets)[0]);
- acc.widgetToCardMap[widgets[0].id] = card.id;
- } else {
- var groupId = _.uniqueId('group');
- acc.layout.push({
- id: groupId,
- type: 'group',
- relatedLayouts: '',
- items: this._getGroupedItems(widgets),
- style: {
- top: '0%',
- left: '0%',
- height: '50%',
- width: '50%'
- }
- });
- acc.widgetToCardMap[groupId] = card.id;
- }
- return acc;
- }
- }, {
- key: '_getWidgets',
- value: function _getWidgets(card) {
- var widgets = [];
- card.items.forEach(function (item) {
- if (item.type === 'widget') {
- widgets.push(item);
- }
- });
- return widgets;
- }
- }, {
- key: '_trimPercent',
- value: function _trimPercent(percent) {
- return +percent.toFixed(2);
- }
- }, {
- key: '_getGroupedItems',
- value: function _getGroupedItems(widgets) {
- var _this4 = this;
- var percentage = widgets.length > 1 ? 100 : 50;
- var width = this._trimPercent(1 / widgets.length * percentage) + '%';
- return widgets.map(function (widget, index) {
- var widgetSpec = {
- id: widget.id,
- type: 'widget',
- relatedLayouts: '',
- style: {
- top: '0%',
- left: _this4._trimPercent(index / widgets.length * 100) + '%',
- height: percentage + '%',
- width: width
- },
- content: widget.content
- };
- if (widget.properties) {
- //explore widget properties should be persisted after conversion.please find defect explore-2966
- widgetSpec.properties = widget.properties;
- }
- return widgetSpec;
- });
- }
- }]);
- return ExploreToDashboardConverter;
- }(ConverterInterface);
- return ExploreToDashboardConverter;
- });
- //# sourceMappingURL=ExploreToDashboardConverter.js.map
|