'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 Business 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(['./nls/StringResources'], function (ServiceabilityStringResources) { var ServiceabilityDataSource = function () { function ServiceabilityDataSource(visualizationAPI) { _classCallCheck(this, ServiceabilityDataSource); this._visualizationAPI = visualizationAPI; this._dataSource = this._visualizationAPI.getDataSource(); this._initializeInfo(); } /** * @returns {object} The result of this result should be an object which will * be stringfied later. * @description this method will fetch the data source info of a live widget * through the APIs. */ ServiceabilityDataSource.prototype.toJSON = function toJSON() { this._dataSource = this._visualizationAPI.getDataSource(); this._updateInfo(); return this._json; }; /** * @description this method will fetch the data mapping info and construct a UI spec which defined * how the Data Mapping section will be displayed * @returns {object} The UI spec which will be consumed by ContentInfoAPI */ ServiceabilityDataSource.prototype.toUIJSON = function toUIJSON() { var json = this.toJSON(); return [{ fieldName: ServiceabilityStringResources.get('dataSourceName'), fieldValue: json.dataSourceInfo.name }, { fieldName: ServiceabilityStringResources.get('dataSourceId'), fieldValue: json.dataSourceInfo.id }, { fieldName: ServiceabilityStringResources.get('dataSourcePath'), fieldValue: json.dataSourceInfo.path }, { fieldName: ServiceabilityStringResources.get('dataSourceType'), fieldValue: json.dataSourceInfo.type }]; }; ServiceabilityDataSource.prototype._initializeInfo = function _initializeInfo() { this._resetInfo(); this._updateInfo(); }; ServiceabilityDataSource.prototype._resetInfo = function _resetInfo() { this._json = { dataSourceInfo: { name: ServiceabilityStringResources.get('infoNotAvailable'), id: ServiceabilityStringResources.get('infoNotAvailable'), path: ServiceabilityStringResources.get('infoNotAvailable'), type: ServiceabilityStringResources.get('infoNotAvailable') } }; }; ServiceabilityDataSource.prototype._updateInfo = function _updateInfo() { if (this._dataSource) { if (this._dataSource.getAssetId() !== this._json.dataSourceInfo.id) { this._fetchAttributes(); } } else { this._resetInfo(); } }; /** * Fetch async values that we want to show in the serviceability panel * Note: These will be populated when available. If not available and user opens * the serviceability panel, they will see blank value */ ServiceabilityDataSource.prototype._fetchAttributes = function _fetchAttributes() { var _this = this; this._json.dataSourceInfo.id = this._dataSource.getAssetId(); this._json.dataSourceInfo.type = this._dataSource.getType(); this._dataSource.getLocalizedName().then(function (name) { _this._json.dataSourceInfo.name = name; }); this._dataSource.getSearchPath().then(function (path) { _this._json.dataSourceInfo.path = path; }); }; return ServiceabilityDataSource; }(); return ServiceabilityDataSource; }); //# sourceMappingURL=ServiceabilityDataSource.js.map