'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: Content Explorer *| (C) Copyright IBM Corp. 2016, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['../../lib/@waca/core-client/js/core-client/ui/core/View', 'text!./templates/Metadata.html', '../../lib/@waca/core-client/js/core-client/utils/BidiUtil', '../../lib/@waca/loading-indicator/src/js/LoadingIndicatorView', '../../lib/@waca/core-client/js/core-client/ui/KeyCodes', '../nls/StringResources', '../utils/ShapingUIUtils', '../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/unknown-warning_128', 'react-dom', 'react'], function (View, DataSourceTitleTemplate, BidiUtil, LoadingIndicator, KeyCodes, StringResources, ShapingUIUtils, em_unknown_warning, ReactDOM, React) { return function (_View) { _inherits(Metadata, _View); function Metadata() { _classCallCheck(this, Metadata); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _possibleConstructorReturn(this, _View.call.apply(_View, [this].concat(args))); } Metadata.prototype.init = function init() { var _View$prototype$init, _this2 = this; for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } var options = args[0]; this.id = options.id; //Require to set this.templateString before call the parent class this.templateString = DataSourceTitleTemplate; (_View$prototype$init = _View.prototype.init).call.apply(_View$prototype$init, [this].concat(args)); this.isVisible = true; this.dashboardApi = options.dashboardApi; this.dataSource = options.dataSource; this.panelController = options.panelController; //Workaround for now to make sure DataSource is initialized when Metadata is loaded this.dashboardApi.getFeature('DataSources').getDataSource(this.id); //handle the change of state(ready, loading) by showing or hiding //the loading icon this.changeStateHandler = this.dataSource.on('change:state', this.onSourceChangeState.bind(this)); this.removeHandler = this.dataSource.on('remove', this.onSourceRemoved.bind(this)); // Add dataSource title division var sHTML = this.dotTemplate({}); this.$el.append(sHTML); var loadingIndicator = new LoadingIndicator(); loadingIndicator.render().then(function ($el) { _this2.$el.find('.loading-indicator').append($el); }); this.$el.on('keydown.metadatatreeKeydown', this.onKeyDown.bind(this)); this.logger = this.dashboardApi.getGlassCoreSvc('.Logger'); }; Metadata.prototype.onKeyDown = function onKeyDown(event) { //CTRL+C to copy selection tree items if (event.keyCode === 67 && event.ctrlKey) { this._copySelectedTreeItems(); return false; } }; Metadata.prototype._copySelectedTreeItems = function _copySelectedTreeItems() { return this.dataSource.getModule().then(function (module) { ShapingUIUtils.copySelectedTreeItems(module); }.bind(this)); }; Metadata.prototype.show = function show(options) { this.isVisible = true; this.render(options); }; Metadata.prototype.render = function render(options) { this.dashboardApi.getFeature('DataSources').setActiveDataSourceId(this.dataSource.getId()); if (!this.isRendered || options && options.forceRefreshMetadata) { //TODO: Hook up forceRefreshMetadata where necessary, and have it actually force a refresh this.isRendered = true; } this.panelController.clearIcons(); this.panelController.renderDataSourcePaneButtons('com.ibm.bi.dashboard.dataSourcePanel.metadata.buttons').then(function () { if (this.isVisible && options && options.setFocus) { var firstButton = this.panelController.$el.find('.buttons .ds_btn'); if (firstButton.length) { firstButton[0].focus(); } } }.bind(this)); return this._renderTree(); }; Metadata.prototype._renderTree = function _renderTree() { if (!this._module) { return this.dataSource.getModule().then(function (module) { this._module = module; // It's possible we got a module back but we're still in an error case. // For example, if we have an empty dataset if (this.dataSource.getState() === 'error') { this.showError(StringResources.get('errorLoadingDataTree')); return Promise.resolve(); } else { this._treeContainer = this.$el.find('.metadataContainer')[0]; return ShapingUIUtils.renderTree(module, this.dashboardApi, this._treeContainer, this.addDataItemsOrAddWidget.bind(this)); } }.bind(this), function (err) { this.showError(StringResources.get('errorLoadingDataTree')); throw err; }.bind(this)); } else { return ShapingUIUtils.renderTree(this._module, this.dashboardApi, this._treeContainer, this.addDataItemsOrAddWidget.bind(this)); } }; Metadata.prototype.showError = function showError(error) { var $container = this.$el.find('.metadataContainer'); var errorSourcesLabel = StringResources.get('errorSourcesTitle'); this.reactDomNode = $container[0]; ReactDOM.render(React.createElement( 'div', { className: 'metadataTreeErrorContentWrapper' }, React.createElement( 'div', { className: 'metadataTreeErrorImage ba-theme-waca' }, React.createElement( 'svg', { viewBox: em_unknown_warning.default.viewBox, focusable: 'false' }, React.createElement('use', { className: 'ba-graphics-themable', xlinkHref: '#' + em_unknown_warning.default.id, fill: '#8ee9d4' }) ) ), React.createElement( 'div', { className: 'metadataTreeErrorText line1', role: 'option', title: errorSourcesLabel, 'aria-label': errorSourcesLabel }, errorSourcesLabel ), React.createElement( 'div', { className: 'metadataTreeErrorText line2', role: 'option', title: error, 'aria-label': error }, error ) ), this.reactDomNode); }; Metadata.prototype.searchTypeDelay = function searchTypeDelay(evt, searchTerm) { this._renderTree(searchTerm); }; Metadata.prototype.addDataItemsOrAddWidget = function addDataItemsOrAddWidget(payload, key) { if (key.shiftKey && key.keyCode === KeyCodes.RIGHT_ARROW) { this.addToCanvas(payload); } else if (key.shiftKey && key.altKey && key.keyCode === KeyCodes.F) { this.addToFilter(payload, true); } else if (key.shiftKey && key.keyCode === KeyCodes.F) { this.addToFilter(payload, false); } }; Metadata.prototype.addToCanvas = function addToCanvas(payload) { if (payload.data && payload.data.utils && payload.data.utils.isValid()) { this.dashboardApi.addContentToCanvas(payload); } }; Metadata.prototype.addToFilter = function addToFilter(payload, globalScope) { var _this3 = this; var selectedColumns = payload.data.columns; var options = { scope: null, openViewOnLoad: selectedColumns.length > 1 ? false : true }; var canvas = this.dashboardApi.getCanvas(); return canvas.getFeature('filterDock').then(function (filterDock) { if (globalScope && filterDock.isGlobalDockShown === false) { // if user is trying to add filter to global tab, ensure to see if // global tab is enabled or not. If not then don't do anything return; } else if (!globalScope) { // if user is trying to add filter to current tab, then use // the correct scope options.scope = filterDock.currentScope(); } // loop through selected items and create filter for each for (var _iterator = selectedColumns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var column = _ref; var metadataColumn = column.metadataColumn; if (_this3._getPageContextType(metadataColumn.getDataType(), metadataColumn.getType()) === 'range') { options.condition = {}; } else { options.values = []; } canvas.getFilters().addFilter({ sourceId: metadataColumn.getSourceId(), itemId: metadataColumn.getId() }, options); } }); }; Metadata.prototype._getPageContextType = function _getPageContextType(dataType, usage) { if (usage === 'fact') { return 'range'; } // usage is attribute: non numeric, tree, or date time filter var isDateType = dataType === 'date' || dataType === 'time' || dataType === 'datetime' || dataType === 'timestamp'; return isDateType ? 'range' : 'tupleset'; }; Metadata.prototype.onSourceChangeState = function onSourceChangeState() { if (this.isVisible) { this.panelController.setTypeIcon(this.dataSource); } }; Metadata.prototype.onSourceRemoved = function onSourceRemoved(event) { if (this.isVisible) { // If the source is removed by UndoRedoController, we don't want to render the dataSourceList after going back. // This is already taken care by DataSourceList.dataSourceCollection's 'on remove' handler. var preventRender = event && event.sender === 'UndoRedoController' ? true : false; this.panelController.goBack(preventRender); } }; Metadata.prototype.detach = function detach() { this.$el.detach(); this.isVisible = false; }; Metadata.prototype.hide = function hide() { this.$el.hide(); this.isVisible = false; }; Metadata.prototype.remove = function remove() { this.changeStateHandler.remove(); this.removeHandler.remove(); this.changeStateHandler = null; this.removeHandler = null; this._module = null; this.dashboardApi = null; this.dataSource = null; this.panelController = null; this.logger = null; if (this._treeContainer) { ReactDOM.unmountComponentAtNode(this._treeContainer); } Metadata.inherited('remove', this, arguments); }; return Metadata; }(View); }); //# sourceMappingURL=Metadata.js.map