123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- 'use strict';
- define(['../AnalyticsBaseWidget', 'underscore', 'jquery', '../../prompts/PromptManager', '../../DynamicFileLoader', '../../lib/@waca/core-client/js/core-client/utils/Deferred'], function (WidgetBase, _, $, PromptManager, DynamicFileLoader, Deferred) {
- 'use strict';
-
- var DeprecateWidgetBase = WidgetBase.extend({
- isMaximizeSupported: true,
- customPalettePrefix: '__CM__',
-
- init: function init(params) {
- DeprecateWidgetBase.inherited('init', this, arguments);
-
- this.readyDfd = new Deferred();
- this.visualizationDfd = new Deferred();
-
- this._isDashboardActive = true;
- this.logger = this.dashboardApi.getGlassCoreSvc('.Logger');
- this._useNewQueryApi = params.useNewQueryApi;
- this.visModelManager = null;
- this.dataSet = null;
- this.transactionApi = this.dashboardApi.getFeature('Transaction');
- this.visualizationFeature = this.content.getFeature('Visualization');
- this.colorsService.on('palette:deleted', this.onPaletteDeleted, this);
- this.colorsService.on('palette:updated', this.onPaletteUpdated, this);
- },
- destroy: function destroy() {
- DeprecateWidgetBase.inherited('destroy', this, arguments);
- this.clearRefreshTimer();
- this.dataSet = null;
- if (this.model) {
- this.model.off('change:queryRefresh', this.registerRefreshTimer, this);
- this.model = null;
- }
- this._removeShapingModelEvents();
- this.readyDfd = null;
- this.visualizationDfd = null;
- this.logger = null;
- this.boardModel = null;
- },
- reRender: function reRender(extraInfo) {
- return this.visAPI.reRender(extraInfo);
- },
- registerEvents: function registerEvents() {
- DeprecateWidgetBase.inherited('registerEvents', this, arguments);
- this.dashboardApi.on('widget:toolbar:show:before', this.onToolbarShowBefore, this);
- this.dashboardApi.on('widget:toolbar:hide:after', this.onToolbarHideAfter, this);
- this.dashboardApi.on('dashboard:show', this.onDashboardShow, this);
- this.dashboardApi.on('dashboard:deactivate', this.onDashboardDeactivate, this);
- },
- unregisterEvents: function unregisterEvents() {
- DeprecateWidgetBase.inherited('unregisterEvents', this, arguments);
- this.dashboardApi.off('widget:toolbar:show:before', this.onToolbarShowBefore, this);
- this.dashboardApi.off('widget:toolbar:show:after', this.onToolbarShowAfter, this);
- this.dashboardApi.off('widget:toolbar:show:after', this.onToolbarShowAfter, this);
- this.dashboardApi.off('widget:toolbar:hide:after', this.onToolbarHideAfter, this);
- this.dashboardApi.off('dashboard:show', this.onDashboardShow, this);
- this.dashboardApi.off('dashboard:deactivate', this.onDashboardDeactivate, this);
- this.colorsService.off('palette:deleted', this.onPaletteDeleted, this);
- this.colorsService.off('palette:updated', this.onPaletteUpdated, this);
- },
- getCurrentVis: function getCurrentVis() {
- return this._currVis;
- },
- onStartMove: function onStartMove() /*payload*/{
- if (this._currVis && this._currVis.onStartMove) {
- this._currVis.onStartMove();
- }
- },
- onStopMove: function onStopMove() /*payload*/{
- if (this._currVis && this._currVis.onStopMove) {
- this._currVis.onStopMove();
- }
- },
- onToolbarHideAfter: function onToolbarHideAfter(payload) {
- if (this._currVis) {
- var selector = this._currVis.getCurrentViewSelector();
- if (selector && selector.setPopoverClosed) {
- selector.setPopoverClosed(payload);
- }
- }
- },
- onToolbarShowBefore: function onToolbarShowBefore(payload) {
- if (this._currVis) {
- var selector = this._currVis.getCurrentViewSelector();
- if (selector && selector.setPopoverOpened) {
- selector.setPopoverOpened(payload);
- }
- }
- },
-
- onDashboardShow: function onDashboardShow() {
-
- this._isTimerActive = true;
- this._isDashboardActive = true;
- },
-
- onDashboardDeactivate: function onDashboardDeactivate() {
-
- this._isTimerActive = false;
- this._isDashboardActive = false;
- },
-
- updateThemeMapping: function updateThemeMapping(themeMapping) {
- this.colorsService.updateThemeMapping(themeMapping);
- },
-
- onContainerReady: function onContainerReady(containerContext) {
- var _this = this;
- console.debug('onContainerReady');
- DeprecateWidgetBase.inherited('onContainerReady', this, arguments);
- this.model = containerContext.model;
- if (this.model) {
- this.model.on('change:queryRefresh', this.registerRefreshTimer, this);
- }
-
-
- this.addWhiteListAttrs('titleHtml', 'name', 'type', 'localFilters', 'visId', 'showTitle', 'properties', 'maintainAxisScales', 'colorPalette', 'showItemLabel', 'titleType', 'titleMode', 'truncateTitle', 'hideLegend', 'hideAxisTitleLabels', 'legendPosition', 'lineColor', 'interpolation', 'elementColor', 'symbolShape', 'symbolFill', 'heatScalePalette', 'heatScaleColorOrder', 'hideRadialTitle', 'hideRadialValue', 'archetype', 'expandOnRender', 'hideLabel', 'hideValue', 'hideTreeMapLeafLabels', 'pieAsDonut', 'hideGridLines', 'hideSymbols', 'hideDataLines', 'conditions', 'queryRefresh', 'transpose', 'labelLocation', 'interpolate', 'condColorPalette', 'condColorOrder', 'hideSummaries', 'legend.position', 'donutRadius', 'labelLocation', 'lineWithPoints.symbol', 'itemLabel.display', 'tiledmap.style', 'fillDirection', 'savedPrompts', 'labels.visible', 'label.format', 'defaultPaletteIndex', 'actions', 'showInsights', 'lineWithPoints.symbol');
- var getContentRef = function getContentRef(propName) {
- var value = _this.visAPI.getPropertyValue(propName);
-
- if (value && value.indexOf(_this.customPalettePrefix) === 0) {
- return value.split(_this.customPalettePrefix)[1];
- }
- return null;
- };
- var contentReferences = [];
- ['colorPalette', 'contColorPalette', 'condColorPalette'].forEach(function (propName) {
- contentReferences.push({
- type: 'palette',
- get: function get() {
- return getContentRef(propName);
- }
- });
- });
- this.addContentReferences(contentReferences);
- this.registerRefreshTimer();
- },
-
- resizeToPreferredSize: function resizeToPreferredSize() {
- this.setPreferredSize(this.visAPI.getPreferredSize());
- },
-
- placeAt: function placeAt(visualization, domElement) {
- if (!domElement) {
- domElement = this.el;
- }
- if (this._currVis) {
- this._currVis.remove( false);
- }
- this._currVis = visualization;
- this._currVis.predictData = this.predictData;
- this.visualizationDfd.resolve(visualization);
- this.setLayoutProperties({
- pannable: this._currVis.isPannable,
- mobilePannable: this._currVis.isMobilePannable,
- noRotate: this._currVis.noRotate,
- maximizable: this._currVis.isMaximizable
- });
- $(domElement).children('.dataview').detach();
- if (visualization.placeAt) {
- visualization.placeAt(domElement, 0);
- } else {
- $(visualization.el).appendTo(domElement);
- }
- },
-
- getDataSet: function getDataSet() {
- return this.dataSet;
- },
- _refreshWidgets: function _refreshWidgets(event) {
-
- if (event.sender.widget !== this && this.visAPI && (!event.sender.refreshedWidgets || event.sender.refreshedWidgets.indexOf(this) === -1)) {
-
- if (event.dataItemId && !this.visAPI.isDataItemMapped(event.dataItemId)) {
- return;
- }
- var sender = event.sender;
- if (!sender) {
- sender = {};
- }
- if (!sender.refreshedWidgets) {
- sender.refreshedWidgets = [];
- }
- sender.refreshedWidgets.push(this);
- this.reRender({
- sender: sender
- });
- if (this.visExpandMode) {
- this.visExpandMode.renderSlotsView();
- }
- }
- },
-
- onMenuAction: function onMenuAction() {},
- _applyingExternalFilter: {},
- _createEventTransactionToken: function _createEventTransactionToken(event) {
- var transactionToken = void 0;
- if (event && event.data) {
- if (event.data.transactionToken && this.transactionApi.isValidTransaction(event.data.transactionToken)) {
-
- transactionToken = this.transactionApi.startTransaction(event.data.transactionToken);
- } else {
- if (event.data.undoRedoTransactionId) {
-
- transactionToken = this.transactionApi.startTransactionById(event.data.undoRedoTransactionId);
- } else {
-
- transactionToken = this.transactionApi.startTransaction();
- }
- event.data.transactionToken = transactionToken;
- }
- } else {
- transactionToken = this.transactionApi.startTransaction();
- event.data = {
- transactionToken: transactionToken
- };
- }
- return transactionToken;
- },
-
- _onModelChange: function _onModelChange(event) {
- var _this2 = this,
- _arguments = arguments;
- if (event.data && event.data.saveOnly) {
- return;
- }
-
-
- if (['properties', 'localFilters', 'searchFilters', 'visId'].indexOf(event.name) !== -1) {
- return;
- }
- var transactionToken = this._createEventTransactionToken(event);
-
- if (this.visAPI) {
- this.visAPI.clearModelInvalid();
- }
- this.readyDfd.promise.then(function () {
-
- DeprecateWidgetBase.inherited('_onModelChange', _this2, _arguments);
- }).finally(function () {
- _this2.trigger('dwChange:' + event.name, event, _this2);
- _this2.transactionApi.endTransaction(transactionToken);
- });
-
- DeprecateWidgetBase.inherited('_onModelChange', this, arguments);
- },
- getUnavailableLocalFilter: function getUnavailableLocalFilter() {
- return this.visModelManager.filterSupport.getUnavailableLocalFilter();
- },
- updateMissingFilters: function updateMissingFilters() {
- this.visModelManager.filterSupport.updateMissingFilters();
- },
- resize: function resize(options) {
- if (!this.visAPI || !this.el) {
- return;
- }
- this.visAPI.resize(this.$el.innerWidth(), this.$el.innerHeight(), options);
- },
-
- isAnOverridableVisProperty: function isAnOverridableVisProperty(property) {
-
- var asOverride = ['fillDirection', 'legendPosition', 'lineColor', 'maintainAxisScales', 'showItemLabel', 'colorPalette', 'symbolShape', 'symbolFill', 'hideLegend', 'elementColor', 'interpolation', 'shortNumbers', 'hideAxisTitleLabels', 'heatScalePalette', 'contColorPalette', 'hideRadialTitle', 'hideRadialValue', 'valueColor', 'hideLabel', 'hideValue', 'hideTreeMapLeafLabels', 'pieAsDonut', 'hideGridLines', 'hideSymbols', 'hideDataLines', 'transpose', 'rangeSlider', 'labelLocation', 'condColorPalette', 'condColorOrder', 'hideSummaries', 'legend.position', 'donutRadius', 'labelLocation', 'lineWithPoints.symbol', 'itemLabel.display', 'tiledmap.style', 'labels.visible', 'label.format'];
- return asOverride.indexOf(property) !== -1;
- },
-
- getConditionalPalette: function getConditionalPalette(paletteName) {
- return this.colorsService.getPalette({
- paletteId: paletteName,
- type: 'ConditionalPalette',
- defaultIfNotFound: true
- });
- },
-
- _reverseColorPointAt: function _reverseColorPointAt(palette) {
-
- var newPalette = _.map(palette, _.clone);
- var count = newPalette.length;
- _.each(newPalette, function (item, idx) {
- var reverseIdx = count - idx - 1;
- var newAt = palette[reverseIdx].at;
- item.at = newAt;
- });
- return newPalette;
- },
-
- onHeatScalePaletteChanged: function onHeatScalePaletteChanged(info) {
-
-
- this.onPropertyUpdate(info);
- },
- onPaletteDeleted: function onPaletteDeleted(_ref) {
- var paletteId = _ref.paletteId;
- this.onCustomPaletteChanged(paletteId, 'delete');
- },
- onPaletteUpdated: function onPaletteUpdated(_ref2) {
- var paletteId = _ref2.paletteId;
- this.onCustomPaletteChanged(paletteId, 'update');
- },
- onCustomPaletteChanged: function onCustomPaletteChanged() {
-
- },
- onColorPaletteChanged: function onColorPaletteChanged(info) {
- this.onPropertyUpdate(info);
- },
- _reMapBundle: function _reMapBundle(bundleDefinition, visDefinitions) {
- var def = visDefinitions.find(function (visDefinition) {
- return visDefinition.id === bundleDefinition.id;
- });
- if (!def) {
-
- def = visDefinitions.find(function (visDefinition) {
- return visDefinition.id === bundleDefinition.minimalVisId;
- });
- }
- return def;
- },
-
- updateVisProperties: function updateVisProperties(updatedProperties) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var extendedOptions = _.extend({}, options, this.boardModel.getLanguageModelOptions(true));
-
- this.model.properties.set(updatedProperties, _.extend({
- merge: true,
- remove: false
- }, extendedOptions));
- },
- _getInteractionConfig: function _getInteractionConfig() {
- return this.dashboardApi.getAppConfig('interactions') || {};
- },
-
- _isInteractionEnabled: function _isInteractionEnabled(name) {
- var config = this._getInteractionConfig();
- if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) {
- return false;
- }
- return true;
- },
- doesWidgetSupportContextualGrid: function doesWidgetSupportContextualGrid() {
- var visualization = this._currVis;
- if (!visualization) {
- return false;
- } else if (visualization.doesVisPropertyMatchExpected('isMultilayersWidget', true)) {
- return false;
- } else if (visualization.doesVisPropertyMatchExpected('noDataQuery', true)) {
- return false;
- }
- return true;
- },
- suppressAnimations: function suppressAnimations(suppress) {
- if (this.visModelManager) {
- this.visModelManager.setSuppressViewAnimations(suppress);
- }
- },
- _getRefreshValueInUnits: function _getRefreshValueInUnits(value, timeUnit) {
- var maxIntervalForUnits = this._getMaxRefreshValuesForUnits(timeUnit);
- return Math.min(maxIntervalForUnits, value);
- },
- onPropertyUpdate: function onPropertyUpdate(info) {
- DeprecateWidgetBase.inherited('onPropertyUpdate', this, arguments);
- if (info.category === 'queryRefresh' && info.item) {
- var value = info.item.value ? this._getRefreshValueInUnits(info.item.value, info.item.unit) : null;
- this.model.set({
- 'queryRefresh': $.extend(info.item, {
- value: value
- })
- });
- }
- },
- validateInput: function validateInput(options) {
- var interval = options.value;
- var isValid = interval && $.isNumeric(interval);
- if (isValid) {
- interval = Math.ceil(interval);
- isValid = this._getTimeIntervalInSeconds(interval, options.unit) >= 5;
- }
- return isValid;
- },
-
- _getMaxRefreshValuesForUnits: function _getMaxRefreshValuesForUnits(timeUnit) {
-
- var maxIntervalInSeconds = (Math.pow(2, 31) - 1) / 1000;
- var maxForTimeUnit;
- var maxTime;
- switch (timeUnit) {
- case 'minutes':
- maxForTimeUnit = maxIntervalInSeconds / 60;
- maxTime = Math.ceil(maxForTimeUnit - 1);
- break;
- case 'hours':
- maxForTimeUnit = maxIntervalInSeconds / 3600;
- maxTime = Math.ceil(maxForTimeUnit - 1);
- break;
- default:
-
- maxTime = Math.ceil(maxIntervalInSeconds - 1);
- }
- return maxTime;
- },
- _getTimeIntervalInSeconds: function _getTimeIntervalInSeconds(timeIntervalInSeconds, timeUnit) {
- var result = null;
- if ($.isNumeric(timeIntervalInSeconds)) {
-
- var maxIntervalInSeconds = this._getMaxRefreshValuesForUnits(timeUnit);
- switch (timeUnit) {
- case 'minutes':
- result = Math.min(maxIntervalInSeconds, timeIntervalInSeconds *= 60);
- break;
- case 'hours':
- result = Math.min(maxIntervalInSeconds, timeIntervalInSeconds *= 3600);
- break;
- default:
-
- result = Math.min(maxIntervalInSeconds, timeIntervalInSeconds);
- }
- }
- return result;
- },
- registerRefreshTimer: function registerRefreshTimer() {
- this.clearRefreshTimer();
- var queryRefreshInfo = this.get('queryRefresh');
- if (queryRefreshInfo) {
- this._startRefreshTimer(queryRefreshInfo);
- this.trigger('dwChange:refreshTimerIndicator', {
- autoRefresh: queryRefreshInfo.autoRefresh
- });
- }
- },
- _startRefreshTimer: function _startRefreshTimer(queryRefreshInfo) {
- if (!queryRefreshInfo || !queryRefreshInfo.autoRefresh || !queryRefreshInfo.value) {
- return;
- }
- this.visibilityHandler = function () {
- if (this._isDashboardActive === true) {
- if (document.hidden || !document.visibilityState) {
- this._isTimerActive = false;
- } else {
- this._isTimerActive = true;
- }
- }
- }.bind(this);
- this._isTimerActive = true;
- this._queryRefreshFinished = true;
- this._setLastRefreshedTime();
- this._refreshTimer = setInterval(function () {
- if (this._isTimerActive && this._queryRefreshFinished) {
- $(document).on('visibilitychange', this.visibilityHandler);
- this._autoRefresh();
- }
- }.bind(this), this._getTimeIntervalInSeconds(queryRefreshInfo.value, queryRefreshInfo.unit) * 1000);
- },
- _autoRefresh: function _autoRefresh() {
- if (!this.visAPI) {
- return;
- }
- this._queryRefreshFinished = false;
- if (this._currVis) {
- this._currVis.animationType = this._currVis.ANIMATION_TYPES.TRANSITION;
- }
- return this.reRender( {
- sender: 'realtimeRefresh',
- queryRefresh: this.model.queryRefresh
- }).then(function () {
- this._queryRefreshFinished = true;
- this._setLastRefreshedTime();
- }.bind(this), function (e) {
-
-
- if (!window.dashboardErrorDetailsEnabled) {
- this._queryRefreshFinished = true;
- }
- throw e;
- }.bind(this));
- },
- _setLastRefreshedTime: function _setLastRefreshedTime() {
- this.model.set({
- 'queryRefresh': $.extend(this.get('queryRefresh'), {
- lastRefreshed: new Date().getTime()
- })
- }, {
- silent: true
- });
- },
- clearRefreshTimer: function clearRefreshTimer() {
- if (this._refreshTimer) {
- clearInterval(this._refreshTimer);
- this._refreshTimer = null;
- if (this.visibilityHandler) {
- $(document).off('visibilitychange', this.visibilityHandler);
- this.visibilityHandler = null;
- }
- }
- },
-
- _rebuildVis: function _rebuildVis() /* widget, undoRedo, forceRerender */{},
-
- savePromptSpec: function savePromptSpec(promptSpec) {
- var oSavedPrompts = this.get('savedPrompts') || {};
- oSavedPrompts[promptSpec.name] = promptSpec;
- this.model.set({
- 'savedPrompts': oSavedPrompts
- });
- this._updateFilterIndicator();
- },
-
- getSavedPrompts: function getSavedPrompts() {
- return this.get('savedPrompts') || {};
- },
-
- setPromptSpecs: function setPromptSpecs(promptSpecs) {
- this.model.set({
- 'savedPrompts': promptSpecs
- });
- this._updateFilterIndicator();
- },
-
- _updateFilterIndicator: function _updateFilterIndicator() {
- if (this._currVis && this._currVis.filterIndicator) {
- this._currVis.filterIndicator.update();
- }
- },
-
- getPromptSpec: function getPromptSpec(promptName) {
- var oSavedPrompts = this.get('savedPrompts');
- if (!promptName) {
- return oSavedPrompts;
- }
- return oSavedPrompts ? oSavedPrompts[promptName] : null;
- },
-
- useNewQueryApi: function useNewQueryApi() {
- if (this._useNewQueryApi !== undefined) {
- return this._useNewQueryApi;
- }
- if (['kpi', 'summary', 'crosstab', 'JQGrid'].indexOf(this.visAPI.getDefinition().id) !== -1) {
- return true;
- }
- return !this.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'queryApi', 'disabled');
- },
- rePrompt: function rePrompt(sPromptName) {
- var _this3 = this;
- if (!sPromptName) {
- this.logger.error('Could not find prompt info to rePrompt', sPromptName, this);
- return Promise.resolve();
- }
- var savedPromptSpec = this.getPromptSpec(sPromptName);
- if (!savedPromptSpec) {
- this.logger.error('Could not find prompt info for ' + sPromptName, this);
- return Promise.resolve();
- }
-
- if (this.useNewQueryApi()) {
- var openSpec = _.extend({}, savedPromptSpec);
- openSpec.rePrompt = true;
- var prompts = this.dashboardApi.getFeature('Prompts');
- var visualization = this.dashboardApi.getCanvas().getContent(this.getId()).getFeature('Visualization.internal');
- var savedPrompts = visualization.getSavedPrompts();
- return prompts.openPromptView([openSpec], visualization).then(function (oNewPromptSpec) {
- savedPrompts.save(oNewPromptSpec[0]);
- });
- } else {
- var oOptions = {
- promptSpec: [savedPromptSpec],
- id: this.visModelManager.getModuleId(),
- 'preferences': this.dashboardApi.getGlassCoreSvc('.UserProfile').preferences
- };
- _.extend(oOptions, this.visAPI.getQueryExecution().getPromptQueries());
- return PromptManager.openPromptView(oOptions).then(function (oNewPromptSpec) {
- _this3.savePromptSpec(oNewPromptSpec[0]);
- _this3.reRender();
- });
- }
- },
-
- onCancelPromptDialog: function onCancelPromptDialog() {
- if (this.isAuthoringMode) {
- this.dashboardApi.undo();
- }
- },
- onUnSupportedPrompt: function onUnSupportedPrompt(message) {
- DynamicFileLoader.load(['dashboard-analytics/lib/@waca/core-client/js/core-client/ui/dialogs/ConfirmationDialog']).then(function (modules) {
- var dlg = new modules[0]('warning', '', message);
- dlg.confirm(function () {
- this.onCancelPromptDialog();
- }.bind(this));
- dlg._cancelCallback = function () {
- this.onCancelPromptDialog();
- }.bind(this);
- }.bind(this));
- }
- });
- return DeprecateWidgetBase;
- });
|