12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Watson Analytics (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore'], function ($, _) {
- var SDK_REQUIRE_CONTEXT = 'Dashboard.VidaSdkUtil';
- // eslint-disable-next-line no-undef
- var rjs = requirejs;
- /**
- * Deletes the new requirejs context and cleans up any new <script/> tags Require created
- */
- var cleanupRequireContext = function cleanupRequireContext() {
- delete rjs.s.contexts[SDK_REQUIRE_CONTEXT];
- $('[data-requirecontext="' + SDK_REQUIRE_CONTEXT + '"]').remove();
- };
- return function () {
- function VidaSdkUtil() {
- _classCallCheck(this, VidaSdkUtil);
- }
- VidaSdkUtil.isSDKActive = function isSDKActive(dashboardApi) {
- var visDefinitions = dashboardApi.getFeature('VisDefinitions');
- var visPreview = visDefinitions.getById('visualizationPreview');
- var visualizationPreviewHasBeenLoaded = visPreview && !visPreview.getState().getError();
- var promise = void 0;
- if (visualizationPreviewHasBeenLoaded) {
- // The SDK bundle is currently loaded... but the server may not be running any more.
- // This code reloads the manifest.xml to verify the servier is active... or not.
- promise = new Promise(function (resolve, reject) {
- require(['com/ibm/vida/control/vida'], function (vida) {
- // We need a fresh requirejs context here...
- // so we don't go undefining things in the global scope
- var globalRequireConifg = JSON.parse(JSON.stringify(rjs.s.contexts._.config));
- var minimalRequireConfig = {
- context: SDK_REQUIRE_CONTEXT,
- baseUrl: globalRequireConifg.baseUrl,
- urlArgs: 'v=' + Date.now(),
- paths: _.pick(globalRequireConifg.paths, 'text', vida.sdk.bundleLocation)
- };
- var req = require.config(minimalRequireConfig);
- var manifestPath = 'text!' + vida.sdk.bundleLocation + '/manifest.xml';
- // Require the manifest, and use resolve/reject as success/failure handlers
- req([manifestPath], function () {
- cleanupRequireContext();
- resolve();
- }, function (err) {
- cleanupRequireContext();
- reject(err);
- });
- }, reject);
- });
- } else {
- // The bundle is currently not loaded, attempt to load it.
- promise = Promise.race([
- // Note: This will fail to resolve on IE due to a Mixed/Content error, unless the user has accepted
- // the browser warning and refreshed the page...
- visDefinitions.loadById('visualizationPreview'),
- // Lets give IE 15 seconds?
- new Promise(function (resolve, reject) {
- setTimeout(function () {
- reject(new Error('Failed to load test visualization'));
- }, 15000);
- })]);
- }
- return promise.then(function () {
- return true;
- }).catch(function () {
- return false;
- });
- };
- return VidaSdkUtil;
- }();
- });
- //# sourceMappingURL=VidaSdkUtil.js.map
|