123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- define(['./VIPRConfig', '../../DynamicFileLoader', '../../widgets/livewidget/nls/StringResources', 'underscore'], function (VIPRConfig, DynamicFileLoader, StringResources, _) {
- var _class, _temp;
- var baseUrl = 'v1/visualizations';
- var _logError = function _logError(dashboardApi, error) {
- var logger = dashboardApi.getGlassCoreSvc('.Logger');
- logger.error(error);
- };
- return _temp = _class = function () {
- function VIPRBundleHelper() {
- _classCallCheck(this, VIPRBundleHelper);
- }
-
- VIPRBundleHelper._loadVIPRLibrariesClass = function _loadVIPRLibrariesClass() {
- return DynamicFileLoader.load(['dashboard-analytics/visualizations/vipr/VIPRLibraries']).then(function (modules) {
- return modules[0];
- }).catch(function (err) {
- console.log(err);
- });
- };
-
- VIPRBundleHelper._getVIPRLibraries = function _getVIPRLibraries(options) {
- return VIPRBundleHelper._loadVIPRLibrariesClass().then(function (LibrariesClass) {
- var viprLibrariesClass = new LibrariesClass({ dashboardApi: options.dashboardApi });
- return viprLibrariesClass.setVIPRLibraries();
- }).catch(function (err) {
- _logError(options.dashboardApi, err);
- });
- };
-
- VIPRBundleHelper._getOnlyEnabledSystemVisualizations = function _getOnlyEnabledSystemVisualizations(arrayOfVisDescriptions, options) {
- var aEnabledVizs = arrayOfVisDescriptions.filter(function (vis) {
- if (vis.featureFlag) {
- var featureFlag = vis.featureFlag ? vis.featureFlag.id : '';
- var valueToMatch = vis.featureFlag ? vis.featureFlag.enabledVal : 'enabled';
- return options.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', featureFlag, valueToMatch);
- } else {
- return true;
- }
- });
- return aEnabledVizs;
- };
-
- VIPRBundleHelper.getALLVIPRLibraries = function getALLVIPRLibraries() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var libraries = [];
- var promises = [VIPRBundleHelper._getVIPRLibraries(options)];
- promises.push(VIPRBundleHelper.getCustomBundleVisualizations(options));
- return Promise.all(promises).then(function (results) {
- var standardLibraries = results[0];
- var customLibraries = results[1];
-
- var enabledSystemVizs = VIPRBundleHelper._getOnlyEnabledSystemVisualizations(standardLibraries.system, options);
- libraries.push.apply(libraries, enabledSystemVizs);
- if (standardLibraries['custom'].length > 0) {
- VIPRBundleHelper._buildCustomLibVIPRConfig(standardLibraries.custom || []);
- libraries.push.apply(libraries, standardLibraries['custom']);
- }
- if (customLibraries.length > 0) {
- libraries.push.apply(libraries, customLibraries);
- }
- return libraries;
- }).catch(function (err) {
- _logError(options.dashboardApi, err);
- throw new Error(err);
- });
- };
-
- VIPRBundleHelper.getCustomBundleVisualizations = function getCustomBundleVisualizations(options) {
- var ajaxSvc = options.dashboardApi.getGlassCoreSvc('.Ajax');
- return ajaxSvc.ajax({
- url: baseUrl + '/custom',
- type: 'GET',
- contentType: 'application/json'
- }).then(function (customVisualizations) {
- return VIPRBundleHelper._buildCustomBundleVisualizationsLib(ajaxSvc, customVisualizations);
- }).catch(function (error) {
- _logError(options.dashboardApi, error);
- return Promise.resolve([]);
- });
- };
- VIPRBundleHelper._buildCustomBundleVisualizationsLib = function _buildCustomBundleVisualizationsLib(ajaxSvc) {
- var customVisualizationslib = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var customCustomVisualizationsLib = [];
- var data = customVisualizationslib.data || [];
- var promise = void 0;
- if (data.length === 0) {
- promise = Promise.resolve(customCustomVisualizationsLib);
- } else {
- _.forEach(data, function (lib) {
- customCustomVisualizationsLib.push({
- id: lib.id,
- location: lib.type === 'schematic' ? 'vizbundles/rave2schematics' : 'v1/visualizations/' + lib.id + '/content/',
- assetId: lib.storeId,
- icon: lib.icon || null,
- placeholderIcon: 'v1/visualizations/' + lib.id + '/content/',
- modificationTime: lib.modificationTime,
- name: lib.name,
- type: lib.id,
- isSchematic: lib.type === 'schematic',
- isCustomVis: lib.type !== 'schematic'
- });
- });
- promise = VIPRBundleHelper._loadIcon(ajaxSvc, customCustomVisualizationsLib);
- }
- return promise.then(VIPRBundleHelper._buildCustomLibVIPRConfig);
- };
- VIPRBundleHelper._loadIcon = function _loadIcon(ajaxSvc) {
- var customCustomVisualizationsLib = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
- var promises = [];
- customCustomVisualizationsLib.forEach(function (lib) {
- if (!lib.icon && !lib.isSchematic) {
-
-
-
- var url = baseUrl + '/id/' + lib.id;
- promises.push(ajaxSvc.ajax({
- url: url,
- type: 'GET',
- contentType: 'application/json'
- }));
- } else {
- promises.push(Promise.resolve(null));
- }
- });
- return Promise.all(promises).then(function () {
- var responses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- responses.forEach(function (response, idx) {
- if (response) {
- var data = response.data || [];
- var icon = data.find(function (fileDesc) {
- fileDesc = fileDesc || {};
- var file = fileDesc.file ? fileDesc.file.toLowerCase() : '';
- return VIPRBundleHelper.isValidIconFileExt(file);
- });
- if (icon) {
- var nameParts = icon.file.split('\\');
- customCustomVisualizationsLib[idx].icon = nameParts.join('/');
- }
- }
- });
- return customCustomVisualizationsLib;
- });
- };
- VIPRBundleHelper._buildCustomLibVIPRConfig = function _buildCustomLibVIPRConfig() {
- var customCustomVisualizationsLibs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- customCustomVisualizationsLibs.forEach(function (lib) {
- VIPRConfig.removeCustomVisConfiguration(lib.id);
- VIPRConfig.addCustomVisConfiguration(lib);
- });
- return customCustomVisualizationsLibs;
- };
-
- VIPRBundleHelper.loadCustomBundleVisualization = function loadCustomBundleVisualization(options) {
- return VIPRBundleHelper.submitAjaxAddOrUpdate(options, 'POST', baseUrl + '?maskResponses=true&updateAction=FAIL');
- };
-
-
- VIPRBundleHelper.updateCustomBundleVisualization = function updateCustomBundleVisualization() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return VIPRBundleHelper.submitAjaxAddOrUpdate(options, 'PUT', baseUrl + '/id/' + options.bundleId);
- };
-
- VIPRBundleHelper.deleteCustomBundleVisulization = function deleteCustomBundleVisulization() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var ajaxSvc = options.dashboardApi.getGlassCoreSvc('.Ajax');
- var userCapabilities = options.dashboardApi.getGlassCoreSvc('.UserProfile').capabilities;
- var hasPermission = userCapabilities.indexOf('canManageVisualizations') !== -1;
- if (hasPermission) {
- return ajaxSvc.ajax({
- url: 'v1/objects/' + encodeURIComponent(options.assetId),
- type: 'DELETE'
- }).then(function () {
- VIPRConfig.removeCustomVisConfiguration(options.id);
- });
- } else {
- return Promise.reject(new Error(StringResources.get('noPermissionToManage')));
- }
- };
- VIPRBundleHelper.submitAjaxAddOrUpdate = function submitAjaxAddOrUpdate() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var type = arguments[1];
- var url = arguments[2];
- var userCapabilities = options.dashboardApi.getGlassCoreSvc('.UserProfile').capabilities;
- var hasPermission = userCapabilities.indexOf('canManageVisualizations') !== -1;
- if (hasPermission) {
- var ajaxSvc = options.dashboardApi.getGlassCoreSvc('.Ajax');
- return ajaxSvc.ajax({
- url: url,
- type: type,
- data: options.data,
- enctype: 'multipart/form-data',
- processData: false,
- contentType: false
- }).then(function (info) {
- var data = JSON.parse(info.data);
- if (data.Status === 200 || data.Status === 201) {
- return data;
- } else if (info.jqXHR && info.jqXHR.responseJSON) {
- return Promise.reject(new Error(info.jqXHR.responseJSON.msg));
- } else if (info.jqXHR && info.jqXHR.responseText) {
- return Promise.reject(new Error(info.jqXHR.responseText));
- } else {
- return Promise.reject(new Error(data.Description));
- }
- });
- } else {
- return Promise.reject(new Error(StringResources.get('noPermissionToManage')));
- }
- };
- return VIPRBundleHelper;
- }(), _class.isValidIconFileExt = function (file) {
- var supportIconFileExts = ['.png', '.svg'];
- return file && !!supportIconFileExts.find(function (ext) {
- return file.indexOf(ext) !== -1;
- });
- }, _temp;
- });
|