Daniel@0: "use strict";
Daniel@0:
Daniel@0: App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
Daniel@0:
Daniel@0: RepresentationModule.addInitializer(function(options){
Daniel@0:
Daniel@0: RepresentationModule.registerMaster({
Daniel@0: id: "view._",
Daniel@0: inherit: "_",
Daniel@0:
Daniel@0: options: {
Daniel@0: canHaveBase: false,
Daniel@0: canHaveOverlay: false,
Daniel@0: canHaveTemp: false,
Daniel@0:
Daniel@0: visInstanceContentHeightMin: 20,
Daniel@0: visInstanceContentHeightMax: 20,
Daniel@0: visInstanceContentPaddingTop: 5,
Daniel@0: visInstanceContentPaddingBottom: 5,
Daniel@0:
Daniel@0: visInstanceSupportedComparisonModes: [],
Daniel@0:
Daniel@0: auxiliaryAssetsTimeout: 2000,
Daniel@0: auxiliaryAssetsCheckInterval: 500
Daniel@0: },
Daniel@0:
Daniel@0: defaultConfigParameterValues: {
Daniel@0: widthToHeightRatio: 2
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // housekeeping
Daniel@0:
Daniel@0: initialize: function() {
Daniel@0: this.obtainAuxiliaryData();
Daniel@0: this.obtainAuxiliaryAssets();
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: setAuxiliaryDataStatus: function(status) {
Daniel@0: this.auxiliaryDataStatus = status;
Daniel@0: this.trigger("change:auxiliaryResourcesStatus");
Daniel@0: },
Daniel@0:
Daniel@0: setAuxiliaryAssetsStatus: function(status) {
Daniel@0: this.auxiliaryAssetsStatus = status;
Daniel@0: this.trigger("change:auxiliaryResourcesStatus");
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: getAuxiliaryResourcesStatus: function() {
Daniel@0: if (this.auxiliaryDataStatus == "fail" || this.auxiliaryAssetsStatus == "fail") {
Daniel@0: return "fail";
Daniel@0: }
Daniel@0: if (this.auxiliaryDataStatus == "pending" || this.auxiliaryAssetsStatus == "pending") {
Daniel@0: return "pending";
Daniel@0: }
Daniel@0: return "";
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: obtainAuxiliaryAssets: function() {
Daniel@0: if (!this.options.auxiliaryAssets || !this.options.auxiliaryAssets.length) {
Daniel@0: return;
Daniel@0: }
Daniel@0:
Daniel@0: if (this.auxiliaryAssetsStatus) {
Daniel@0: return
Daniel@0: }
Daniel@0:
Daniel@0: this.setAuxiliaryAssetsStatus("pending");
Daniel@0:
Daniel@0: var $body = $("body");
Daniel@0: _.each(this.options.auxiliaryAssets, function(assetURL) {
Daniel@0: $body.append("")
Daniel@0: .attr("script", "text/javascript")
Daniel@0: .attr("src", assetURL);
Daniel@0: });
Daniel@0:
Daniel@0: this.auxiliaryAssetsIntervalCount = 0;
Daniel@0: this.auxiliaryAssetsInterval = setInterval($.proxy(this.auxiliaryAssetsInvervalFunction, this), this.options.auxiliaryAssetsCheckInterval);
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: auxiliaryAssetsInvervalFunction: function() {
Daniel@0: ++ this.auxiliaryAssetsIntervalCount;
Daniel@0: if (this.auxiliaryAssetsIntervalCount * this.options.auxiliaryAssetsCheckInterval > this.options.auxiliaryAssetsTimeout) {
Daniel@0: clearInterval(this.auxiliaryAssetsInterval);
Daniel@0: this.setAuxiliaryAssetsStatus("fail");
Daniel@0: return;
Daniel@0: }
Daniel@0: if (this.checkIfAuxiliaryAssetsAreReady()) {
Daniel@0: clearInterval(this.auxiliaryAssetsInterval);
Daniel@0: this.setAuxiliaryAssetsStatus("success");
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0: checkIfAuxiliaryAssetsAreReady: function() {
Daniel@0: return true;
Daniel@0: },
Daniel@0:
Daniel@0: obtainAuxiliaryData: function() {
Daniel@0: if (!this.options.auxiliaryData) {
Daniel@0: return;
Daniel@0: }
Daniel@0:
Daniel@0: if (this.auxiliaryDataStatus) {
Daniel@0: return;
Daniel@0: }
Daniel@0:
Daniel@0: this.setAuxiliaryDataStatus("pending");
Daniel@0:
Daniel@0: var arrayOfDeferred = [];
Daniel@0: var keys = [];
Daniel@0:
Daniel@0: _.each(this.options.auxiliaryData, function(definition, key) {
Daniel@0: keys.push(key);
Daniel@0: arrayOfDeferred.push($.ajax(App.generateAssetURL(definition)));
Daniel@0: // if (_.isFunction(definition)) {
Daniel@0: // } else if (_.isString(definition)) {
Daniel@0: // }
Daniel@0: });
Daniel@0: var _this = this;
Daniel@0: $.when.apply(null, arrayOfDeferred)
Daniel@0: .then(function() {
Daniel@0: var auxiliaryData = {};
Daniel@0: _.each(arguments, function(argument, i) {
Daniel@0: auxiliaryData[keys[i]] = argument[0];
Daniel@0: });
Daniel@0: _this.auxiliaryData = auxiliaryData;
Daniel@0: _this.setAuxiliaryDataStatus("ready");
Daniel@0: },
Daniel@0: function() {
Daniel@0: _this.setAuxiliaryDataStatus("fail");
Daniel@0: }
Daniel@0: );
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: verifyAuxiliaryResources: function() {
Daniel@0: var status = this.getAuxiliaryResourcesStatus();
Daniel@0: if (status == "pending" || status == "fail") {
Daniel@0: throw new RepresentationModule.Error({type: "auxiliary-resources_" + status, derivedDataToUpdate: "base"});
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: getViewName: function(viewConfig) {
Daniel@0: // the names are obtained from the templates that contain feature pickers
Daniel@0: if (!App._cachedViewNamesByViewMasterId) {
Daniel@0: var master = this;
Daniel@0: App._cachedViewNamesByViewMasterId = {};
Daniel@0: _.each(["collection", "recording"], function(configGridType) {
Daniel@0: var $featureSelector = $(Marionette.TemplateCache.get("#cgpma_" + configGridType + "_view__feature-selector")());
Daniel@0: var autocompleteSuggestions = master.parseAutocompleteSuggestions($featureSelector.find("[data-autocomplete-suggestions]").data("autocomplete-suggestions"));
Daniel@0: _.each(autocompleteSuggestions, function(kindName, kind) {
Daniel@0: var masterIdPart = kind;
Daniel@0: if (!masterIdPart) {
Daniel@0: masterIdPart = "default";
Daniel@0: }
Daniel@0: App._cachedViewNamesByViewMasterId["view." + configGridType + "." + masterIdPart] = kindName;
Daniel@0: });
Daniel@0: });
Daniel@0: }
Daniel@0: var viewName = App._cachedViewNamesByViewMasterId[this.id];
Daniel@0:
Daniel@0: if (!viewName) {
Daniel@0: viewName = _.str.trim(viewConfig.getParameterValue("kind")) || "an empty view";
Daniel@0: if (viewName.length >= 4 && viewName.substring(0, 2) == "__" && viewName.substring(viewName.length - 2) == "__") {
Daniel@0: viewName = viewName.substring(2, viewName.length - 2);
Daniel@0: }
Daniel@0: viewName = _.str.trim(viewName);
Daniel@0: }
Daniel@0:
Daniel@0: return viewName;
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // config grid panel
Daniel@0:
Daniel@0:
Daniel@0: // FIXME Bug:
Daniel@0: // When a user changes the view kind, then modifies some parameters
Daniel@0: // and then returns back to the original view kind, there are still
Daniel@0: // pending changes, but no fields are "grey"
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // config grid panel - prepare
Daniel@0:
Daniel@0:
Daniel@0: prepareConfigGridPanelMainArea: function(configGridPanelView) {
Daniel@0:
Daniel@0: // feature selector
Daniel@0: if (!App._cached$viewPanelFeatureSelectorsByConfigGridType) {
Daniel@0: App._cached$viewPanelFeatureSelectorsByConfigGridType = {};
Daniel@0: _.each(["collection", "recording"], function(configGridType) {
Daniel@0: var $featureSelector = $(Marionette.TemplateCache.get("#cgpma_" + configGridType + "_view__feature-selector")());
Daniel@0: App._cached$viewPanelFeatureSelectorsByConfigGridType[configGridType] = $featureSelector;
Daniel@0: });
Daniel@0: };
Daniel@0:
Daniel@0: var $featureSelector = App._cached$viewPanelFeatureSelectorsByConfigGridType[configGridPanelView.options.configGrid.getType()];
Daniel@0: configGridPanelView._$mainArea.data("$featureSelector", $featureSelector);
Daniel@0: configGridPanelView._$mainArea.prepend($featureSelector);
Daniel@0: var $inputForKind = $featureSelector.find("[data-parameter-name=kind]");
Daniel@0: if ($inputForKind.data("cgpma-textfield") && $featureSelector.data("savedTextRange")) {
Daniel@0: $inputForKind.textfield("setTextRange", $featureSelector.data("savedTextRange"));
Daniel@0: $featureSelector.removeData("savedTextRange");
Daniel@0: }
Daniel@0:
Daniel@0: // Parent master's behaviour
Daniel@0: RepresentationModule.getMasterById("_").prepareConfigGridPanelMainArea.apply(this, arguments);
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // config grid panel - sync
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // config grid panel - destroy
Daniel@0:
Daniel@0: destroyConfigGridPanelMainArea: function(configGridPanelView) {
Daniel@0: // save the feature selector
Daniel@0: var $featureSelector = configGridPanelView._$mainArea.data("$featureSelector");
Daniel@0: if ($featureSelector) {
Daniel@0: var $inputForKind = configGridPanelView._$mainArea.find("[data-parameter-name=kind]");
Daniel@0: if ($inputForKind.textfield("isFocused")) {
Daniel@0: $featureSelector.data("savedTextRange", $inputForKind.textfield("getTextRange"));
Daniel@0: }
Daniel@0: $featureSelector.detach();
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // config grid header
Daniel@0:
Daniel@0: _doRenderHeaderContentRelatedToOwnData: function(headerView, instant) {
Daniel@0: if (!headerView._$label) {
Daniel@0: headerView._$label = $.bem.generateElement("config-grid-cells", "view-header-label").appendTo(headerView.$el);
Daniel@0: }
Daniel@0: headerView._$label.html(this._generateHeaderLabel(headerView));
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _generateHeaderLabel: function(headerView) {
Daniel@0: var labelCore = this.getViewName(headerView.options.config) + this._generateHeaderLabelSuffix(headerView);
Daniel@0: if (headerView.options.config.hasPlannedParameterUpdates()) {
Daniel@0: return " – being modified";
Daniel@0: } else {
Daniel@0: return labelCore;
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0: _generateHeaderLabelSuffix: function(headerView) {
Daniel@0: return "";
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // dynamic derived config data
Daniel@0:
Daniel@0: __upateMethodOfDynamicDerivedConfigData: function() {
Daniel@0: var viewConfig = this.options.viewConfig;
Daniel@0: var viewMaster = this.options.viewMaster;
Daniel@0: this.set({
Daniel@0: basePerspectiveRequestParams: viewMaster.generateBasePerspectiveRequestParams(viewConfig),
Daniel@0: overlayPerspectiveRequestParams: viewMaster.generateOverlayPerspectiveRequestParams(viewConfig)
Daniel@0: });
Daniel@0: },
Daniel@0:
Daniel@0: generateDynamicDerivedConfigData: function(config, configGrid) {
Daniel@0: var dynamicDerivedConfigData = new RepresentationModule.DynamicDerivedConfigData({
Daniel@0: basePerspectiveRequestParams: null,
Daniel@0: overlayPerspectiveRequestParams: null
Daniel@0: }, {
Daniel@0: viewConfig: config,
Daniel@0: viewMaster: RepresentationModule.getMasterForConfig(config),
Daniel@0: });
Daniel@0:
Daniel@0: dynamicDerivedConfigData.update = this.__upateMethodOfDynamicDerivedConfigData;
Daniel@0: dynamicDerivedConfigData.listenTo(config, "change", dynamicDerivedConfigData.update);
Daniel@0: dynamicDerivedConfigData.update();
Daniel@0:
Daniel@0: return dynamicDerivedConfigData;
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // dynamic derived vis instance data
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // dynamic derived vis instance data - base
Daniel@0:
Daniel@0: generateBasePerspectiveRequestParams: function(viewConfig) {
Daniel@0: var viewConfigKind = _.str.trim(viewConfig.getParameterValue("kind"));
Daniel@0: if (!_.isString(viewConfigKind) || this.getSupportedKind() != viewConfigKind) {
Daniel@0: return null;
Daniel@0: }
Daniel@0: var result = this._generateCustomParamsForBasePerspectiveRequestParams(viewConfig);
Daniel@0: if (!result) {
Daniel@0: return null;
Daniel@0: }
Daniel@0: if (!result.pid) {
Daniel@0: result.pid = viewConfigKind.replace(/-/g, "_");
Daniel@0: }
Daniel@0: return result;
Daniel@0: },
Daniel@0:
Daniel@0: _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) {
Daniel@0: return {};
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // dynamic derived vis instance data - overlay
Daniel@0:
Daniel@0: generateOverlayPerspectiveRequestParams: function(viewConfig) {
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // =================================================================
Daniel@0: // vis instance rendering
Daniel@0:
Daniel@0:
Daniel@0: _groupDataForGraphicsRendering: function(visInstanceView, layer) {
Daniel@0: if (layer == "base") {
Daniel@0: return {
Daniel@0: self: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponse,
Daniel@0: left: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponseOnTheLeft,
Daniel@0: right: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponseOnTheRight
Daniel@0: };
Daniel@0: } else {
Daniel@0: return null;
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0: _getVisInstanceViewComparisonMode: function(visInstanceView) {
Daniel@0: var comparisonMode = undefined;
Daniel@0: var kind = visInstanceView.options.entityConfig.getParameterValue("kind");
Daniel@0: if (kind === "pair") {
Daniel@0: comparisonMode = RepresentationModule.getMasterById("entity.collection.pair").getConfigParameterValueOrDefaultValue(visInstanceView.options.entityConfig, "comparisonMode");
Daniel@0: }
Daniel@0: return comparisonMode;
Daniel@0: },
Daniel@0:
Daniel@0: calculateVisInstanceContentHeight: function(viewConfig, entityWidth) {
Daniel@0: var height = 0;
Daniel@0:
Daniel@0: var widthToHeightRatio = 1 * this.getConfigParameterValueOrDefaultValue(viewConfig, "widthToHeightRatio");
Daniel@0: if (widthToHeightRatio) {
Daniel@0: height = Math.round(entityWidth / widthToHeightRatio);
Daniel@0: }
Daniel@0: if (height < this.options.visInstanceContentHeightMin) {
Daniel@0: height = this.options.visInstanceContentHeightMin;
Daniel@0: }
Daniel@0: if (height > this.options.visInstanceContentHeightMax) {
Daniel@0: height = this.options.visInstanceContentHeightMax;
Daniel@0: }
Daniel@0: return height + this.options.visInstanceContentPaddingTop + this.options.visInstanceContentPaddingBottom;
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: __domEventHandlerToSelectAllTextInTheField: function(event) {
Daniel@0: if (!event.shiftKey) {
Daniel@0: return;
Daniel@0: }
Daniel@0: var $cover = $(this);
Daniel@0: var visInstanceView = $cover.data("visInstanceView");
Daniel@0: var attachedError = $cover.data("attachedError");
Daniel@0: RepresentationModule.logger.warn(_.str.sprintf("An error behind the clicked vis instance (id %s):", visInstanceView.cid), attachedError);
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: renderVisInstance: function(visInstanceView, deep, instant) {
Daniel@0: if (deep) {
Daniel@0: visInstanceView._cachedRenderingHashForBase = undefined;
Daniel@0: visInstanceView._cachedRenderingHashForOverlay = undefined;
Daniel@0: visInstanceView._cachedRenderingHashForTemp = undefined;
Daniel@0: }
Daniel@0:
Daniel@0: var newRenderingHashForBase = /*!this.options.canHaveBase ||*/ this._calculateVisInstanceRenderingHashForBase(visInstanceView);
Daniel@0: var newRenderingHashForOverlay = !this.options.canHaveOverlay || this._calculateVisInstanceRenderingHashForOverlay(visInstanceView);
Daniel@0: var newRenderingHashForTemp = !this.options.canHaveTemp || this._calculateVisInstanceRenderingHashForTemp(visInstanceView);
Daniel@0:
Daniel@0: var baseHasChanged = /*this.options.canHaveBase && */ newRenderingHashForBase !== visInstanceView._cachedRenderingHashForBase;
Daniel@0: var overlayHasChanged = /*this.options.canHaveOverlay && */ newRenderingHashForOverlay !== visInstanceView._cachedRenderingHashForOverlay;
Daniel@0: var tempHasChanged = /*this.options.hasTemp && */ newRenderingHashForTemp !== visInstanceView._cachedRenderingHashForTemp;
Daniel@0:
Daniel@0: var debugMode = App.options.debugAPI;
Daniel@0:
Daniel@0: if (!(baseHasChanged || overlayHasChanged || tempHasChanged)) {
Daniel@0: return;
Daniel@0: }
Daniel@0:
Daniel@0: try {
Daniel@0: if (baseHasChanged) {
Daniel@0: try {
Daniel@0: if (debugMode) {
Daniel@0: this._prepareRenderingVisInstanceViewInDebugModeIfNeeded(visInstanceView);
Daniel@0: this._doRenderVisInstanceViewInDebugMode(visInstanceView, "base");
Daniel@0: } else {
Daniel@0: visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
Daniel@0: visInstanceView._cachedViewMaster.verifyAuxiliaryResources();
Daniel@0: this._prepareRenderingVisInstanceViewIfNeeded(visInstanceView);
Daniel@0: this._doRenderVisInstanceViewBase(visInstanceView);
Daniel@0: }
Daniel@0:
Daniel@0: } catch (e) {
Daniel@0: visInstanceView._cachedRenderingHashForOverlay = undefined;
Daniel@0: visInstanceView._cachedRenderingHashForTemp = undefined;
Daniel@0: overlayHasChanged = true;
Daniel@0: tempHasChanged = true;
Daniel@0: throw e;
Daniel@0: }
Daniel@0: }
Daniel@0: if (overlayHasChanged) {
Daniel@0: try {
Daniel@0: if (debugMode) {
Daniel@0: this._doRenderVisInstanceViewInDebugMode(visInstanceView, "overlay");
Daniel@0: } else {
Daniel@0: if (!baseHasChanged) {
Daniel@0: visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
Daniel@0: }
Daniel@0: visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceOverlay(visInstanceView);
Daniel@0: this._doRenderVisInstanceViewOverlay(visInstanceView);
Daniel@0: }
Daniel@0: } catch (e) {
Daniel@0: visInstanceView._cachedRenderingHashForTemp = undefined;
Daniel@0: tempHasChanged = true;
Daniel@0: throw e;
Daniel@0: }
Daniel@0: }
Daniel@0: if (tempHasChanged) {
Daniel@0: if (debugMode) {
Daniel@0: this._doRenderVisInstanceViewInDebugMode(visInstanceView, "temp");
Daniel@0: } else {
Daniel@0: if (!baseHasChanged) {
Daniel@0: visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
Daniel@0: }
Daniel@0: if (!overlayHasChanged) {
Daniel@0: visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceOverlay(visInstanceView);
Daniel@0: }
Daniel@0: this._doRenderVisInstanceViewTemp(visInstanceView);
Daniel@0: }
Daniel@0: }
Daniel@0: if (visInstanceView.$cover.hasClass("vis-instance__cover_visible")) {
Daniel@0: visInstanceView.$cover.removeClass("vis-instance__cover_visible");
Daniel@0: };
Daniel@0: } catch (e) {
Daniel@0: var errorType = (e instanceof RepresentationModule.Error) ? e.options.type : "unknown";
Daniel@0: var coverTapAction = (e instanceof RepresentationModule.Error) ? e.options.coverTapAction : null;
Daniel@0:
Daniel@0: var coverContentTemplate = null;
Daniel@0: try {
Daniel@0: coverContentTemplate = Marionette.TemplateCache.get("#vicc__" + errorType + "__" + visInstanceView._cachedEntityMaster.id.replace(/\./g, "-"));
Daniel@0: } catch (e) {
Daniel@0: coverContentTemplate = Marionette.TemplateCache.get("#vicc__" + errorType);
Daniel@0: }
Daniel@0: var coverContent = coverContentTemplate(e.options);
Daniel@0:
Daniel@0: var coverCategory = coverContent.slice(0, coverContent.indexOf("|"));
Daniel@0: var coverMessage = coverContent.slice(coverCategory.length + 1);
Daniel@0:
Daniel@0: if (!(e instanceof RepresentationModule.Error) || e.needToEmptyContent()) {
Daniel@0: visInstanceView.$content.empty();
Daniel@0: };
Daniel@0:
Daniel@0: visInstanceView.$coverMessage.html(coverMessage);
Daniel@0: visInstanceView.$cover
Daniel@0: .addClass("vis-instance__cover_visible")
Daniel@0: .unbind("click")
Daniel@0: .bind("click", coverTapAction)
Daniel@0: .bind("click", this.__domEventHandlerToSelectAllTextInTheField)
Daniel@0: .setMod("vis-instance", "cover", "category", coverCategory)
Daniel@0: .data("attachedError", e)
Daniel@0: .data("visInstanceView", visInstanceView);
Daniel@0: }
Daniel@0: if (baseHasChanged) {visInstanceView._cachedRenderingHashForBase = newRenderingHashForBase;}
Daniel@0: if (overlayHasChanged) {visInstanceView._cachedRenderingHashForOverlay = newRenderingHashForBase;}
Daniel@0: if (tempHasChanged) {visInstanceView._cachedRenderingHashForTemp = newRenderingHashForBase;}
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: cancelVisInstancePointerHighlights: function(visInstanceView) {
Daniel@0: var vegaHoveredItem = visInstanceView.$content.children(0).data("vegaHoveredItem");
Daniel@0: if (vegaHoveredItem) {
Daniel@0: App.TooltipModule.tooltipView.update();
Daniel@0: var vegaObj = visInstanceView.$content.children(0).data("vegaObj");
Daniel@0: vegaObj.update({items: vegaHoveredItem})
Daniel@0: }
Daniel@0:
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // vis instance rendering - base
Daniel@0:
Daniel@0: _calculateVisInstanceRenderingHashForBase: function(visInstanceView) {
Daniel@0: if (visInstanceView.options.configGrid.getType() == "collection") {
Daniel@0: if (this._getVisInstanceViewComparisonMode(visInstanceView)) {
Daniel@0: var result = this.getAuxiliaryResourcesStatus()
Daniel@0: + visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.entityConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
Daniel@0: //console.log(result);
Daniel@0: return result;
Daniel@0: } else {
Daniel@0: return this.getAuxiliaryResourcesStatus()
Daniel@0: + visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.attributes.dynamicDefinitionForCollection.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
Daniel@0: }
Daniel@0: } else {
Daniel@0: if (this._getVisInstanceViewComparisonMode(visInstanceView)) {
Daniel@0: var result = this.getAuxiliaryResourcesStatus()
Daniel@0: + visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.entityConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
Daniel@0: //console.log(result);
Daniel@0: return result;
Daniel@0: } else {
Daniel@0: return this.getAuxiliaryResourcesStatus()
Daniel@0: + visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.attributes.dynamicDefinitionForRecording.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
Daniel@0: }
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _prepareRenderingVisInstanceViewIfNeeded: function(visInstanceView) {},
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewBase: function(visInstanceView) {
Daniel@0: this._doRenderVisInstanceViewBaseWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // vis instance rendering - overlay
Daniel@0:
Daniel@0: _calculateVisInstanceRenderingHashForOverlay: function(visInstanceView) {
Daniel@0: return visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForOverlay.getHash();
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewOverlay: function(visInstanceView) {
Daniel@0: this._doRenderVisInstanceViewOverlayWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewOverlayWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // vis instance rendering - temp
Daniel@0:
Daniel@0: _calculateVisInstanceRenderingHashForTemp: function(visInstanceView) {
Daniel@0: return visInstanceView._cachedSizeHash
Daniel@0: + visInstanceView.options.viewConfig.getHashForParameters()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
Daniel@0: + visInstanceView.dynamicDerivedConfigDataForView.getHash()
Daniel@0: + visInstanceView.dynamicDerivedVisInstanceDataForTemp.getHash();
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewTemp: function(visInstanceView) {
Daniel@0: this._doRenderVisInstanceViewTempWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewTempWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
Daniel@0:
Daniel@0:
Daniel@0: // -----------------------------------------------------------------
Daniel@0: // vis instance rendering - debug mode
Daniel@0:
Daniel@0: _selectAllInDebugTextFieldIfNeeded: function() {
Daniel@0: $(this).select();
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _prepareRenderingVisInstanceViewInDebugModeIfNeeded: function(visInstanceView) {
Daniel@0: if (!visInstanceView.$content.children(0).hasClass("vic-api-debug")) {
Daniel@0: visInstanceView.$content.empty();
Daniel@0: var $apiDebug = $.bem.generateBlock("vic-api-debug");
Daniel@0: var mappings = visInstanceView._cachedEntityMaster._mapDerivedVisInstanceDataAttributesToDebugAPIQueryBoxes(this);
Daniel@0: for (var i = 0; i < mappings.length; i++) {
Daniel@0: var $queryBox = $.bem.generateElement("vic-api-debug", "query-box", ["alignment_" + mappings[i][0]]);
Daniel@0:
Daniel@0: var $queryURIWrapper = $.bem.generateElement("vic-api-debug", "query-uri-wrapper");
Daniel@0: var $queryResponseWrapper = $.bem.generateElement("vic-api-debug", "query-response-wrapper");
Daniel@0:
Daniel@0: var $queryURI = $.bem.generateElement("input", "vic-api-debug", "query-uri").attr("type", "text")
Daniel@0: .mouseup(this._avoidDeselectInDebugTextField)
Daniel@0: .focus(this._selectAllInDebugTextFieldIfNeeded)
Daniel@0: .attr("readonly", true);
Daniel@0: var $queryResponse = $.bem.generateElement("textarea", "vic-api-debug", "query-response")
Daniel@0: .attr("readonly", true);
Daniel@0:
Daniel@0: $queryURIWrapper.append($queryURI);
Daniel@0: $queryResponseWrapper.append($queryResponse);
Daniel@0: $queryBox.append($queryURIWrapper, $queryResponseWrapper);
Daniel@0: $apiDebug.append($queryBox);
Daniel@0: }
Daniel@0: $apiDebug.data("mappings", mappings);
Daniel@0: visInstanceView.$content.append($apiDebug);
Daniel@0: }
Daniel@0: },
Daniel@0:
Daniel@0:
Daniel@0: _doRenderVisInstanceViewInDebugMode: function(visInstanceView, layer) {
Daniel@0: var $apiDebug = visInstanceView.$content.children(0);
Daniel@0: var mappings = $apiDebug.data("mappings");
Daniel@0: for (var i = 0; i < mappings.length; i++) {
Daniel@0: var mapping = mappings[i];
Daniel@0: if (layer != mapping[1]) {
Daniel@0: return;
Daniel@0: }
Daniel@0: var currentDynamicDerivedVisInstanceData = null;
Daniel@0: switch (layer) {
Daniel@0: case "base":
Daniel@0: currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForBase;
Daniel@0: break;
Daniel@0: case "overlay":
Daniel@0: currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForOverlay;
Daniel@0: break;
Daniel@0: case "temp":
Daniel@0: currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForTemp;
Daniel@0: break;
Daniel@0: }
Daniel@0:
Daniel@0: var $queryBox = $apiDebug.children().eq(i);
Daniel@0: var $queryURI = $queryBox.children().eq(0).children();
Daniel@0: var $queryResponse = $queryBox.children().eq(1).children();
Daniel@0:
Daniel@0: var queryURI = currentDynamicDerivedVisInstanceData.attributes[mapping[2]];
Daniel@0: var queryResponse = currentDynamicDerivedVisInstanceData.attributes[mapping[3]];
Daniel@0:
Daniel@0: var queryURIText = queryURI;
Daniel@0: if (_.isString(queryURI) && queryURI.indexOf("//") === 0) {
Daniel@0: var protocol = window.location.href.slice(0, window.location.href.indexOf(":"));
Daniel@0: queryURIText = protocol + ":" + queryURIText;
Daniel@0: }
Daniel@0:
Daniel@0: var queryResponseText = "";
Daniel@0: if (_.isObject(queryResponse)) {
Daniel@0: queryResponseText = JSON.stringify(queryResponse, false, " ");
Daniel@0: } else if (queryResponse === null) {
Daniel@0: queryResponseText = "obtaining...";
Daniel@0: } else {
Daniel@0: //queryResponseText =
Daniel@0: //no request is being made
Daniel@0: }
Daniel@0: var status = "ok";
Daniel@0: if (queryResponse && queryResponse.errors) {
Daniel@0: status = "has-errors";
Daniel@0: }
Daniel@0:
Daniel@0:
Daniel@0: $queryURI.val(queryURIText);
Daniel@0: $queryResponse.val(queryResponseText);
Daniel@0: $queryBox.setMod("vic-api-debug", "query-box", "status", status);
Daniel@0: }
Daniel@0: },
Daniel@0: });
Daniel@0: });
Daniel@0: }, Logger);