'use strict'; 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: Dashboard *| (C) Copyright IBM Corp. 2018, 2021 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ /** * @class LiveWidgetPreview * * @classdesc Live widget preview class that is used to create and control a live widget instance without tying it to a specific dashboard canvas. * This class is used to render a visualization anywhere in the user interface and not necessarily inside of a dashboard. * Each live widget instance correspands to a rendered instance of the live widget * * @example * // Create an instance of the LiveWidgetAPI by providing : * 1 - The node where the content will render. The visualization will be maximized to fit the size of the given node. * 2 - The glass context * 3 - the live widget spec. This could be a complete or partial spec with just the data section and/or filters. * Any missing parts will be filled by the viz recommender (e.g. mappings, vizType) * * // Example #1 - the dataView contains a modelRef that is referencing an existing source in the currently opened dashboard application * let LiveWidget = new LiveWidgetAPI({ * node: document.getElementById('containerDivId'), * glassContext: this.glassContext, * spec: { * "data": { * "dataViews": [ * { * "modelRef": "model000001610f7b9e74_00000002", * "dataItems": [ * { * "itemId": "HollywoodMovies_xls.Year_", * * }, * { * "itemId": "HollywoodMovies_xls.Rotten_Tomatoes" * } * ] * } * ] * } * } * }); * * * // Example #2 - the dataView contains a model with an assetID (ContentManager id) that is referencing a module ID. * The model type is also needed. It could be either "uploadedFile", "module" or "package" * let LiveWidget = new LiveWidgetAPI({ * node: document.getElementById('containerDivId'), * glassContext: this.glassContext, * spec: { * "data": { * "dataViews": [ * { * "model":{ * "assetId": "iB3884FE9ACF64BD2B8F0879A8C34B978", * "type": "uploadedFile" * } * "dataItems": [ * { * "itemId": "HollywoodMovies_xls.Year_", * * }, * { * "itemId": "HollywoodMovies_xls.Rotten_Tomatoes" * } * ] * } * ] * } * } * }); * * * // Render the live widget instance after creation. The content will be rendered in the given node. * liveWidget.render(); * * */ define(['./error/ErrorView', 'jquery', 'underscore', '../lib/@waca/core-client/js/core-client/utils/BrowserUtils', '../widgets/livewidget/StandaloneLiveWidget'], function (ErrorView, $, _, BrowserUtils, StandaloneLiveWidget) { var STATICVIEW = { 'com.ibm.vis.rave2bundletiledmap': 'dashboard-analytics/images/placeholders/map.svg' }; var LiveWidgetPreview = function (_StandaloneLiveWidget) { _inherits(LiveWidgetPreview, _StandaloneLiveWidget); function LiveWidgetPreview(options) { _classCallCheck(this, LiveWidgetPreview); return _possibleConstructorReturn(this, _StandaloneLiveWidget.call(this, options)); } /** * Render the live widget preview instance. * @function LiveWidgetAPI#render * @return {Promise} promise that will be resolved when the render is complete or reject in the case of an error */ LiveWidgetPreview.prototype.render = function render() { this.contentNode = document.createElement('div'); this.contentNode.setAttribute('class', 'liveWidgetPreview'); this.contentNode.setAttribute('style', 'width:100%;height:100%; padding:0px'); this.contentNode.setAttribute('data-vis-id', this.spec.visId); if (this._isStaticView()) { var staticView = this._getStaticView(); this.contentNode.appendChild(staticView); this.node.appendChild(this.contentNode); return Promise.resolve(); } else { var options = { id: this.spec.id, el: this.contentNode, errorView: new ErrorView(), // Disable all extra features by default featureSet: this.featureSet || [], interactivitySettings: this.interactivitySettings, optimizeForSize: true, forceDisabledThumbnail: true, isPreview: true, isPredictPreview: this.isPredictPreview, predictData: this.predictData, managesOwnQueries: this._managesOwnQueries }; return _StandaloneLiveWidget.prototype.render.call(this, options); } }; LiveWidgetPreview.prototype._isStaticView = function _isStaticView() { if (BrowserUtils.isIE() && STATICVIEW[this.spec.visId]) { return true; } return false; }; LiveWidgetPreview.prototype._getStaticView = function _getStaticView() { var iconUrl = STATICVIEW[this.spec.visId]; if (iconUrl) { return $('
')[0]; } }; return LiveWidgetPreview; }(StandaloneLiveWidget); return LiveWidgetPreview; }); //# sourceMappingURL=LiveWidgetPreview.js.map