Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
|
Daniel@0
|
4
|
Daniel@0
|
5 RepresentationModule.addInitializer(function(options){
|
Daniel@0
|
6
|
Daniel@0
|
7 RepresentationModule.registerMaster({
|
Daniel@0
|
8 id: "view._",
|
Daniel@0
|
9 inherit: "_",
|
Daniel@0
|
10
|
Daniel@0
|
11 options: {
|
Daniel@0
|
12 canHaveBase: false,
|
Daniel@0
|
13 canHaveOverlay: false,
|
Daniel@0
|
14 canHaveTemp: false,
|
Daniel@0
|
15
|
Daniel@0
|
16 visInstanceContentHeightMin: 20,
|
Daniel@0
|
17 visInstanceContentHeightMax: 20,
|
Daniel@0
|
18 visInstanceContentPaddingTop: 5,
|
Daniel@0
|
19 visInstanceContentPaddingBottom: 5,
|
Daniel@0
|
20
|
Daniel@0
|
21 visInstanceSupportedComparisonModes: [],
|
Daniel@0
|
22
|
Daniel@0
|
23 auxiliaryAssetsTimeout: 2000,
|
Daniel@0
|
24 auxiliaryAssetsCheckInterval: 500
|
Daniel@0
|
25 },
|
Daniel@0
|
26
|
Daniel@0
|
27 defaultConfigParameterValues: {
|
Daniel@0
|
28 widthToHeightRatio: 2
|
Daniel@0
|
29 },
|
Daniel@0
|
30
|
Daniel@0
|
31
|
Daniel@0
|
32 // =================================================================
|
Daniel@0
|
33 // housekeeping
|
Daniel@0
|
34
|
Daniel@0
|
35 initialize: function() {
|
Daniel@0
|
36 this.obtainAuxiliaryData();
|
Daniel@0
|
37 this.obtainAuxiliaryAssets();
|
Daniel@0
|
38 },
|
Daniel@0
|
39
|
Daniel@0
|
40
|
Daniel@0
|
41 setAuxiliaryDataStatus: function(status) {
|
Daniel@0
|
42 this.auxiliaryDataStatus = status;
|
Daniel@0
|
43 this.trigger("change:auxiliaryResourcesStatus");
|
Daniel@0
|
44 },
|
Daniel@0
|
45
|
Daniel@0
|
46 setAuxiliaryAssetsStatus: function(status) {
|
Daniel@0
|
47 this.auxiliaryAssetsStatus = status;
|
Daniel@0
|
48 this.trigger("change:auxiliaryResourcesStatus");
|
Daniel@0
|
49 },
|
Daniel@0
|
50
|
Daniel@0
|
51
|
Daniel@0
|
52 getAuxiliaryResourcesStatus: function() {
|
Daniel@0
|
53 if (this.auxiliaryDataStatus == "fail" || this.auxiliaryAssetsStatus == "fail") {
|
Daniel@0
|
54 return "fail";
|
Daniel@0
|
55 }
|
Daniel@0
|
56 if (this.auxiliaryDataStatus == "pending" || this.auxiliaryAssetsStatus == "pending") {
|
Daniel@0
|
57 return "pending";
|
Daniel@0
|
58 }
|
Daniel@0
|
59 return "";
|
Daniel@0
|
60 },
|
Daniel@0
|
61
|
Daniel@0
|
62
|
Daniel@0
|
63 obtainAuxiliaryAssets: function() {
|
Daniel@0
|
64 if (!this.options.auxiliaryAssets || !this.options.auxiliaryAssets.length) {
|
Daniel@0
|
65 return;
|
Daniel@0
|
66 }
|
Daniel@0
|
67
|
Daniel@0
|
68 if (this.auxiliaryAssetsStatus) {
|
Daniel@0
|
69 return
|
Daniel@0
|
70 }
|
Daniel@0
|
71
|
Daniel@0
|
72 this.setAuxiliaryAssetsStatus("pending");
|
Daniel@0
|
73
|
Daniel@0
|
74 var $body = $("body");
|
Daniel@0
|
75 _.each(this.options.auxiliaryAssets, function(assetURL) {
|
Daniel@0
|
76 $body.append("<script/>")
|
Daniel@0
|
77 .attr("script", "text/javascript")
|
Daniel@0
|
78 .attr("src", assetURL);
|
Daniel@0
|
79 });
|
Daniel@0
|
80
|
Daniel@0
|
81 this.auxiliaryAssetsIntervalCount = 0;
|
Daniel@0
|
82 this.auxiliaryAssetsInterval = setInterval($.proxy(this.auxiliaryAssetsInvervalFunction, this), this.options.auxiliaryAssetsCheckInterval);
|
Daniel@0
|
83 },
|
Daniel@0
|
84
|
Daniel@0
|
85
|
Daniel@0
|
86 auxiliaryAssetsInvervalFunction: function() {
|
Daniel@0
|
87 ++ this.auxiliaryAssetsIntervalCount;
|
Daniel@0
|
88 if (this.auxiliaryAssetsIntervalCount * this.options.auxiliaryAssetsCheckInterval > this.options.auxiliaryAssetsTimeout) {
|
Daniel@0
|
89 clearInterval(this.auxiliaryAssetsInterval);
|
Daniel@0
|
90 this.setAuxiliaryAssetsStatus("fail");
|
Daniel@0
|
91 return;
|
Daniel@0
|
92 }
|
Daniel@0
|
93 if (this.checkIfAuxiliaryAssetsAreReady()) {
|
Daniel@0
|
94 clearInterval(this.auxiliaryAssetsInterval);
|
Daniel@0
|
95 this.setAuxiliaryAssetsStatus("success");
|
Daniel@0
|
96 }
|
Daniel@0
|
97 },
|
Daniel@0
|
98
|
Daniel@0
|
99 checkIfAuxiliaryAssetsAreReady: function() {
|
Daniel@0
|
100 return true;
|
Daniel@0
|
101 },
|
Daniel@0
|
102
|
Daniel@0
|
103 obtainAuxiliaryData: function() {
|
Daniel@0
|
104 if (!this.options.auxiliaryData) {
|
Daniel@0
|
105 return;
|
Daniel@0
|
106 }
|
Daniel@0
|
107
|
Daniel@0
|
108 if (this.auxiliaryDataStatus) {
|
Daniel@0
|
109 return;
|
Daniel@0
|
110 }
|
Daniel@0
|
111
|
Daniel@0
|
112 this.setAuxiliaryDataStatus("pending");
|
Daniel@0
|
113
|
Daniel@0
|
114 var arrayOfDeferred = [];
|
Daniel@0
|
115 var keys = [];
|
Daniel@0
|
116
|
Daniel@0
|
117 _.each(this.options.auxiliaryData, function(definition, key) {
|
Daniel@0
|
118 keys.push(key);
|
Daniel@0
|
119 arrayOfDeferred.push($.ajax(App.generateAssetURL(definition)));
|
Daniel@0
|
120 // if (_.isFunction(definition)) {
|
Daniel@0
|
121 // } else if (_.isString(definition)) {
|
Daniel@0
|
122 // }
|
Daniel@0
|
123 });
|
Daniel@0
|
124 var _this = this;
|
Daniel@0
|
125 $.when.apply(null, arrayOfDeferred)
|
Daniel@0
|
126 .then(function() {
|
Daniel@0
|
127 var auxiliaryData = {};
|
Daniel@0
|
128 _.each(arguments, function(argument, i) {
|
Daniel@0
|
129 auxiliaryData[keys[i]] = argument[0];
|
Daniel@0
|
130 });
|
Daniel@0
|
131 _this.auxiliaryData = auxiliaryData;
|
Daniel@0
|
132 _this.setAuxiliaryDataStatus("ready");
|
Daniel@0
|
133 },
|
Daniel@0
|
134 function() {
|
Daniel@0
|
135 _this.setAuxiliaryDataStatus("fail");
|
Daniel@0
|
136 }
|
Daniel@0
|
137 );
|
Daniel@0
|
138 },
|
Daniel@0
|
139
|
Daniel@0
|
140
|
Daniel@0
|
141 verifyAuxiliaryResources: function() {
|
Daniel@0
|
142 var status = this.getAuxiliaryResourcesStatus();
|
Daniel@0
|
143 if (status == "pending" || status == "fail") {
|
Daniel@0
|
144 throw new RepresentationModule.Error({type: "auxiliary-resources_" + status, derivedDataToUpdate: "base"});
|
Daniel@0
|
145 }
|
Daniel@0
|
146 },
|
Daniel@0
|
147
|
Daniel@0
|
148
|
Daniel@0
|
149 getViewName: function(viewConfig) {
|
Daniel@0
|
150 // the names are obtained from the templates that contain feature pickers
|
Daniel@0
|
151 if (!App._cachedViewNamesByViewMasterId) {
|
Daniel@0
|
152 var master = this;
|
Daniel@0
|
153 App._cachedViewNamesByViewMasterId = {};
|
Daniel@0
|
154 _.each(["collection", "recording"], function(configGridType) {
|
Daniel@0
|
155 var $featureSelector = $(Marionette.TemplateCache.get("#cgpma_" + configGridType + "_view__feature-selector")());
|
Daniel@0
|
156 var autocompleteSuggestions = master.parseAutocompleteSuggestions($featureSelector.find("[data-autocomplete-suggestions]").data("autocomplete-suggestions"));
|
Daniel@0
|
157 _.each(autocompleteSuggestions, function(kindName, kind) {
|
Daniel@0
|
158 var masterIdPart = kind;
|
Daniel@0
|
159 if (!masterIdPart) {
|
Daniel@0
|
160 masterIdPart = "default";
|
Daniel@0
|
161 }
|
Daniel@0
|
162 App._cachedViewNamesByViewMasterId["view." + configGridType + "." + masterIdPart] = kindName;
|
Daniel@0
|
163 });
|
Daniel@0
|
164 });
|
Daniel@0
|
165 }
|
Daniel@0
|
166 var viewName = App._cachedViewNamesByViewMasterId[this.id];
|
Daniel@0
|
167
|
Daniel@0
|
168 if (!viewName) {
|
Daniel@0
|
169 viewName = _.str.trim(viewConfig.getParameterValue("kind")) || "an empty view";
|
Daniel@0
|
170 if (viewName.length >= 4 && viewName.substring(0, 2) == "__" && viewName.substring(viewName.length - 2) == "__") {
|
Daniel@0
|
171 viewName = viewName.substring(2, viewName.length - 2);
|
Daniel@0
|
172 }
|
Daniel@0
|
173 viewName = _.str.trim(viewName);
|
Daniel@0
|
174 }
|
Daniel@0
|
175
|
Daniel@0
|
176 return viewName;
|
Daniel@0
|
177 },
|
Daniel@0
|
178
|
Daniel@0
|
179
|
Daniel@0
|
180 // =================================================================
|
Daniel@0
|
181 // config grid panel
|
Daniel@0
|
182
|
Daniel@0
|
183
|
Daniel@0
|
184 // FIXME Bug:
|
Daniel@0
|
185 // When a user changes the view kind, then modifies some parameters
|
Daniel@0
|
186 // and then returns back to the original view kind, there are still
|
Daniel@0
|
187 // pending changes, but no fields are "grey"
|
Daniel@0
|
188
|
Daniel@0
|
189
|
Daniel@0
|
190 // -----------------------------------------------------------------
|
Daniel@0
|
191 // config grid panel - prepare
|
Daniel@0
|
192
|
Daniel@0
|
193
|
Daniel@0
|
194 prepareConfigGridPanelMainArea: function(configGridPanelView) {
|
Daniel@0
|
195
|
Daniel@0
|
196 // feature selector
|
Daniel@0
|
197 if (!App._cached$viewPanelFeatureSelectorsByConfigGridType) {
|
Daniel@0
|
198 App._cached$viewPanelFeatureSelectorsByConfigGridType = {};
|
Daniel@0
|
199 _.each(["collection", "recording"], function(configGridType) {
|
Daniel@0
|
200 var $featureSelector = $(Marionette.TemplateCache.get("#cgpma_" + configGridType + "_view__feature-selector")());
|
Daniel@0
|
201 App._cached$viewPanelFeatureSelectorsByConfigGridType[configGridType] = $featureSelector;
|
Daniel@0
|
202 });
|
Daniel@0
|
203 };
|
Daniel@0
|
204
|
Daniel@0
|
205 var $featureSelector = App._cached$viewPanelFeatureSelectorsByConfigGridType[configGridPanelView.options.configGrid.getType()];
|
Daniel@0
|
206 configGridPanelView._$mainArea.data("$featureSelector", $featureSelector);
|
Daniel@0
|
207 configGridPanelView._$mainArea.prepend($featureSelector);
|
Daniel@0
|
208 var $inputForKind = $featureSelector.find("[data-parameter-name=kind]");
|
Daniel@0
|
209 if ($inputForKind.data("cgpma-textfield") && $featureSelector.data("savedTextRange")) {
|
Daniel@0
|
210 $inputForKind.textfield("setTextRange", $featureSelector.data("savedTextRange"));
|
Daniel@0
|
211 $featureSelector.removeData("savedTextRange");
|
Daniel@0
|
212 }
|
Daniel@0
|
213
|
Daniel@0
|
214 // Parent master's behaviour
|
Daniel@0
|
215 RepresentationModule.getMasterById("_").prepareConfigGridPanelMainArea.apply(this, arguments);
|
Daniel@0
|
216 },
|
Daniel@0
|
217
|
Daniel@0
|
218
|
Daniel@0
|
219 // -----------------------------------------------------------------
|
Daniel@0
|
220 // config grid panel - sync
|
Daniel@0
|
221
|
Daniel@0
|
222
|
Daniel@0
|
223 // -----------------------------------------------------------------
|
Daniel@0
|
224 // config grid panel - destroy
|
Daniel@0
|
225
|
Daniel@0
|
226 destroyConfigGridPanelMainArea: function(configGridPanelView) {
|
Daniel@0
|
227 // save the feature selector
|
Daniel@0
|
228 var $featureSelector = configGridPanelView._$mainArea.data("$featureSelector");
|
Daniel@0
|
229 if ($featureSelector) {
|
Daniel@0
|
230 var $inputForKind = configGridPanelView._$mainArea.find("[data-parameter-name=kind]");
|
Daniel@0
|
231 if ($inputForKind.textfield("isFocused")) {
|
Daniel@0
|
232 $featureSelector.data("savedTextRange", $inputForKind.textfield("getTextRange"));
|
Daniel@0
|
233 }
|
Daniel@0
|
234 $featureSelector.detach();
|
Daniel@0
|
235 }
|
Daniel@0
|
236 },
|
Daniel@0
|
237
|
Daniel@0
|
238
|
Daniel@0
|
239 // =================================================================
|
Daniel@0
|
240 // config grid header
|
Daniel@0
|
241
|
Daniel@0
|
242 _doRenderHeaderContentRelatedToOwnData: function(headerView, instant) {
|
Daniel@0
|
243 if (!headerView._$label) {
|
Daniel@0
|
244 headerView._$label = $.bem.generateElement("config-grid-cells", "view-header-label").appendTo(headerView.$el);
|
Daniel@0
|
245 }
|
Daniel@0
|
246 headerView._$label.html(this._generateHeaderLabel(headerView));
|
Daniel@0
|
247 },
|
Daniel@0
|
248
|
Daniel@0
|
249
|
Daniel@0
|
250 _generateHeaderLabel: function(headerView) {
|
Daniel@0
|
251 var labelCore = this.getViewName(headerView.options.config) + this._generateHeaderLabelSuffix(headerView);
|
Daniel@0
|
252 if (headerView.options.config.hasPlannedParameterUpdates()) {
|
Daniel@0
|
253 return "<span class=\"config-grid-cells__view-header-label-part_modified\">" + labelCore + "</span> – being modified";
|
Daniel@0
|
254 } else {
|
Daniel@0
|
255 return labelCore;
|
Daniel@0
|
256 }
|
Daniel@0
|
257 },
|
Daniel@0
|
258
|
Daniel@0
|
259 _generateHeaderLabelSuffix: function(headerView) {
|
Daniel@0
|
260 return "";
|
Daniel@0
|
261 },
|
Daniel@0
|
262
|
Daniel@0
|
263
|
Daniel@0
|
264
|
Daniel@0
|
265
|
Daniel@0
|
266 // =================================================================
|
Daniel@0
|
267 // dynamic derived config data
|
Daniel@0
|
268
|
Daniel@0
|
269 __upateMethodOfDynamicDerivedConfigData: function() {
|
Daniel@0
|
270 var viewConfig = this.options.viewConfig;
|
Daniel@0
|
271 var viewMaster = this.options.viewMaster;
|
Daniel@0
|
272 this.set({
|
Daniel@0
|
273 basePerspectiveRequestParams: viewMaster.generateBasePerspectiveRequestParams(viewConfig),
|
Daniel@0
|
274 overlayPerspectiveRequestParams: viewMaster.generateOverlayPerspectiveRequestParams(viewConfig)
|
Daniel@0
|
275 });
|
Daniel@0
|
276 },
|
Daniel@0
|
277
|
Daniel@0
|
278 generateDynamicDerivedConfigData: function(config, configGrid) {
|
Daniel@0
|
279 var dynamicDerivedConfigData = new RepresentationModule.DynamicDerivedConfigData({
|
Daniel@0
|
280 basePerspectiveRequestParams: null,
|
Daniel@0
|
281 overlayPerspectiveRequestParams: null
|
Daniel@0
|
282 }, {
|
Daniel@0
|
283 viewConfig: config,
|
Daniel@0
|
284 viewMaster: RepresentationModule.getMasterForConfig(config),
|
Daniel@0
|
285 });
|
Daniel@0
|
286
|
Daniel@0
|
287 dynamicDerivedConfigData.update = this.__upateMethodOfDynamicDerivedConfigData;
|
Daniel@0
|
288 dynamicDerivedConfigData.listenTo(config, "change", dynamicDerivedConfigData.update);
|
Daniel@0
|
289 dynamicDerivedConfigData.update();
|
Daniel@0
|
290
|
Daniel@0
|
291 return dynamicDerivedConfigData;
|
Daniel@0
|
292 },
|
Daniel@0
|
293
|
Daniel@0
|
294
|
Daniel@0
|
295 // =================================================================
|
Daniel@0
|
296 // dynamic derived vis instance data
|
Daniel@0
|
297
|
Daniel@0
|
298
|
Daniel@0
|
299 // -----------------------------------------------------------------
|
Daniel@0
|
300 // dynamic derived vis instance data - base
|
Daniel@0
|
301
|
Daniel@0
|
302 generateBasePerspectiveRequestParams: function(viewConfig) {
|
Daniel@0
|
303 var viewConfigKind = _.str.trim(viewConfig.getParameterValue("kind"));
|
Daniel@0
|
304 if (!_.isString(viewConfigKind) || this.getSupportedKind() != viewConfigKind) {
|
Daniel@0
|
305 return null;
|
Daniel@0
|
306 }
|
Daniel@0
|
307 var result = this._generateCustomParamsForBasePerspectiveRequestParams(viewConfig);
|
Daniel@0
|
308 if (!result) {
|
Daniel@0
|
309 return null;
|
Daniel@0
|
310 }
|
Daniel@0
|
311 if (!result.pid) {
|
Daniel@0
|
312 result.pid = viewConfigKind.replace(/-/g, "_");
|
Daniel@0
|
313 }
|
Daniel@0
|
314 return result;
|
Daniel@0
|
315 },
|
Daniel@0
|
316
|
Daniel@0
|
317 _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) {
|
Daniel@0
|
318 return {};
|
Daniel@0
|
319 },
|
Daniel@0
|
320
|
Daniel@0
|
321
|
Daniel@0
|
322 // -----------------------------------------------------------------
|
Daniel@0
|
323 // dynamic derived vis instance data - overlay
|
Daniel@0
|
324
|
Daniel@0
|
325 generateOverlayPerspectiveRequestParams: function(viewConfig) {
|
Daniel@0
|
326 },
|
Daniel@0
|
327
|
Daniel@0
|
328
|
Daniel@0
|
329 // =================================================================
|
Daniel@0
|
330 // vis instance rendering
|
Daniel@0
|
331
|
Daniel@0
|
332
|
Daniel@0
|
333 _groupDataForGraphicsRendering: function(visInstanceView, layer) {
|
Daniel@0
|
334 if (layer == "base") {
|
Daniel@0
|
335 return {
|
Daniel@0
|
336 self: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponse,
|
Daniel@0
|
337 left: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponseOnTheLeft,
|
Daniel@0
|
338 right: visInstanceView.dynamicDerivedVisInstanceDataForBase.attributes.apiResponseOnTheRight
|
Daniel@0
|
339 };
|
Daniel@0
|
340 } else {
|
Daniel@0
|
341 return null;
|
Daniel@0
|
342 }
|
Daniel@0
|
343 },
|
Daniel@0
|
344
|
Daniel@0
|
345 _getVisInstanceViewComparisonMode: function(visInstanceView) {
|
Daniel@0
|
346 var comparisonMode = undefined;
|
Daniel@0
|
347 var kind = visInstanceView.options.entityConfig.getParameterValue("kind");
|
Daniel@0
|
348 if (kind === "pair") {
|
Daniel@0
|
349 comparisonMode = RepresentationModule.getMasterById("entity.collection.pair").getConfigParameterValueOrDefaultValue(visInstanceView.options.entityConfig, "comparisonMode");
|
Daniel@0
|
350 }
|
Daniel@0
|
351 return comparisonMode;
|
Daniel@0
|
352 },
|
Daniel@0
|
353
|
Daniel@0
|
354 calculateVisInstanceContentHeight: function(viewConfig, entityWidth) {
|
Daniel@0
|
355 var height = 0;
|
Daniel@0
|
356
|
Daniel@0
|
357 var widthToHeightRatio = 1 * this.getConfigParameterValueOrDefaultValue(viewConfig, "widthToHeightRatio");
|
Daniel@0
|
358 if (widthToHeightRatio) {
|
Daniel@0
|
359 height = Math.round(entityWidth / widthToHeightRatio);
|
Daniel@0
|
360 }
|
Daniel@0
|
361 if (height < this.options.visInstanceContentHeightMin) {
|
Daniel@0
|
362 height = this.options.visInstanceContentHeightMin;
|
Daniel@0
|
363 }
|
Daniel@0
|
364 if (height > this.options.visInstanceContentHeightMax) {
|
Daniel@0
|
365 height = this.options.visInstanceContentHeightMax;
|
Daniel@0
|
366 }
|
Daniel@0
|
367 return height + this.options.visInstanceContentPaddingTop + this.options.visInstanceContentPaddingBottom;
|
Daniel@0
|
368 },
|
Daniel@0
|
369
|
Daniel@0
|
370
|
Daniel@0
|
371 __domEventHandlerToSelectAllTextInTheField: function(event) {
|
Daniel@0
|
372 if (!event.shiftKey) {
|
Daniel@0
|
373 return;
|
Daniel@0
|
374 }
|
Daniel@0
|
375 var $cover = $(this);
|
Daniel@0
|
376 var visInstanceView = $cover.data("visInstanceView");
|
Daniel@0
|
377 var attachedError = $cover.data("attachedError");
|
Daniel@0
|
378 RepresentationModule.logger.warn(_.str.sprintf("An error behind the clicked vis instance (id %s):", visInstanceView.cid), attachedError);
|
Daniel@0
|
379 },
|
Daniel@0
|
380
|
Daniel@0
|
381
|
Daniel@0
|
382 renderVisInstance: function(visInstanceView, deep, instant) {
|
Daniel@0
|
383 if (deep) {
|
Daniel@0
|
384 visInstanceView._cachedRenderingHashForBase = undefined;
|
Daniel@0
|
385 visInstanceView._cachedRenderingHashForOverlay = undefined;
|
Daniel@0
|
386 visInstanceView._cachedRenderingHashForTemp = undefined;
|
Daniel@0
|
387 }
|
Daniel@0
|
388
|
Daniel@0
|
389 var newRenderingHashForBase = /*!this.options.canHaveBase ||*/ this._calculateVisInstanceRenderingHashForBase(visInstanceView);
|
Daniel@0
|
390 var newRenderingHashForOverlay = !this.options.canHaveOverlay || this._calculateVisInstanceRenderingHashForOverlay(visInstanceView);
|
Daniel@0
|
391 var newRenderingHashForTemp = !this.options.canHaveTemp || this._calculateVisInstanceRenderingHashForTemp(visInstanceView);
|
Daniel@0
|
392
|
Daniel@0
|
393 var baseHasChanged = /*this.options.canHaveBase && */ newRenderingHashForBase !== visInstanceView._cachedRenderingHashForBase;
|
Daniel@0
|
394 var overlayHasChanged = /*this.options.canHaveOverlay && */ newRenderingHashForOverlay !== visInstanceView._cachedRenderingHashForOverlay;
|
Daniel@0
|
395 var tempHasChanged = /*this.options.hasTemp && */ newRenderingHashForTemp !== visInstanceView._cachedRenderingHashForTemp;
|
Daniel@0
|
396
|
Daniel@0
|
397 var debugMode = App.options.debugAPI;
|
Daniel@0
|
398
|
Daniel@0
|
399 if (!(baseHasChanged || overlayHasChanged || tempHasChanged)) {
|
Daniel@0
|
400 return;
|
Daniel@0
|
401 }
|
Daniel@0
|
402
|
Daniel@0
|
403 try {
|
Daniel@0
|
404 if (baseHasChanged) {
|
Daniel@0
|
405 try {
|
Daniel@0
|
406 if (debugMode) {
|
Daniel@0
|
407 this._prepareRenderingVisInstanceViewInDebugModeIfNeeded(visInstanceView);
|
Daniel@0
|
408 this._doRenderVisInstanceViewInDebugMode(visInstanceView, "base");
|
Daniel@0
|
409 } else {
|
Daniel@0
|
410 visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
|
Daniel@0
|
411 visInstanceView._cachedViewMaster.verifyAuxiliaryResources();
|
Daniel@0
|
412 this._prepareRenderingVisInstanceViewIfNeeded(visInstanceView);
|
Daniel@0
|
413 this._doRenderVisInstanceViewBase(visInstanceView);
|
Daniel@0
|
414 }
|
Daniel@0
|
415
|
Daniel@0
|
416 } catch (e) {
|
Daniel@0
|
417 visInstanceView._cachedRenderingHashForOverlay = undefined;
|
Daniel@0
|
418 visInstanceView._cachedRenderingHashForTemp = undefined;
|
Daniel@0
|
419 overlayHasChanged = true;
|
Daniel@0
|
420 tempHasChanged = true;
|
Daniel@0
|
421 throw e;
|
Daniel@0
|
422 }
|
Daniel@0
|
423 }
|
Daniel@0
|
424 if (overlayHasChanged) {
|
Daniel@0
|
425 try {
|
Daniel@0
|
426 if (debugMode) {
|
Daniel@0
|
427 this._doRenderVisInstanceViewInDebugMode(visInstanceView, "overlay");
|
Daniel@0
|
428 } else {
|
Daniel@0
|
429 if (!baseHasChanged) {
|
Daniel@0
|
430 visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
|
Daniel@0
|
431 }
|
Daniel@0
|
432 visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceOverlay(visInstanceView);
|
Daniel@0
|
433 this._doRenderVisInstanceViewOverlay(visInstanceView);
|
Daniel@0
|
434 }
|
Daniel@0
|
435 } catch (e) {
|
Daniel@0
|
436 visInstanceView._cachedRenderingHashForTemp = undefined;
|
Daniel@0
|
437 tempHasChanged = true;
|
Daniel@0
|
438 throw e;
|
Daniel@0
|
439 }
|
Daniel@0
|
440 }
|
Daniel@0
|
441 if (tempHasChanged) {
|
Daniel@0
|
442 if (debugMode) {
|
Daniel@0
|
443 this._doRenderVisInstanceViewInDebugMode(visInstanceView, "temp");
|
Daniel@0
|
444 } else {
|
Daniel@0
|
445 if (!baseHasChanged) {
|
Daniel@0
|
446 visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceBase(visInstanceView);
|
Daniel@0
|
447 }
|
Daniel@0
|
448 if (!overlayHasChanged) {
|
Daniel@0
|
449 visInstanceView._cachedEntityMaster.verifyAllDataForVisInstanceOverlay(visInstanceView);
|
Daniel@0
|
450 }
|
Daniel@0
|
451 this._doRenderVisInstanceViewTemp(visInstanceView);
|
Daniel@0
|
452 }
|
Daniel@0
|
453 }
|
Daniel@0
|
454 if (visInstanceView.$cover.hasClass("vis-instance__cover_visible")) {
|
Daniel@0
|
455 visInstanceView.$cover.removeClass("vis-instance__cover_visible");
|
Daniel@0
|
456 };
|
Daniel@0
|
457 } catch (e) {
|
Daniel@0
|
458 var errorType = (e instanceof RepresentationModule.Error) ? e.options.type : "unknown";
|
Daniel@0
|
459 var coverTapAction = (e instanceof RepresentationModule.Error) ? e.options.coverTapAction : null;
|
Daniel@0
|
460
|
Daniel@0
|
461 var coverContentTemplate = null;
|
Daniel@0
|
462 try {
|
Daniel@0
|
463 coverContentTemplate = Marionette.TemplateCache.get("#vicc__" + errorType + "__" + visInstanceView._cachedEntityMaster.id.replace(/\./g, "-"));
|
Daniel@0
|
464 } catch (e) {
|
Daniel@0
|
465 coverContentTemplate = Marionette.TemplateCache.get("#vicc__" + errorType);
|
Daniel@0
|
466 }
|
Daniel@0
|
467 var coverContent = coverContentTemplate(e.options);
|
Daniel@0
|
468
|
Daniel@0
|
469 var coverCategory = coverContent.slice(0, coverContent.indexOf("|"));
|
Daniel@0
|
470 var coverMessage = coverContent.slice(coverCategory.length + 1);
|
Daniel@0
|
471
|
Daniel@0
|
472 if (!(e instanceof RepresentationModule.Error) || e.needToEmptyContent()) {
|
Daniel@0
|
473 visInstanceView.$content.empty();
|
Daniel@0
|
474 };
|
Daniel@0
|
475
|
Daniel@0
|
476 visInstanceView.$coverMessage.html(coverMessage);
|
Daniel@0
|
477 visInstanceView.$cover
|
Daniel@0
|
478 .addClass("vis-instance__cover_visible")
|
Daniel@0
|
479 .unbind("click")
|
Daniel@0
|
480 .bind("click", coverTapAction)
|
Daniel@0
|
481 .bind("click", this.__domEventHandlerToSelectAllTextInTheField)
|
Daniel@0
|
482 .setMod("vis-instance", "cover", "category", coverCategory)
|
Daniel@0
|
483 .data("attachedError", e)
|
Daniel@0
|
484 .data("visInstanceView", visInstanceView);
|
Daniel@0
|
485 }
|
Daniel@0
|
486 if (baseHasChanged) {visInstanceView._cachedRenderingHashForBase = newRenderingHashForBase;}
|
Daniel@0
|
487 if (overlayHasChanged) {visInstanceView._cachedRenderingHashForOverlay = newRenderingHashForBase;}
|
Daniel@0
|
488 if (tempHasChanged) {visInstanceView._cachedRenderingHashForTemp = newRenderingHashForBase;}
|
Daniel@0
|
489 },
|
Daniel@0
|
490
|
Daniel@0
|
491
|
Daniel@0
|
492 cancelVisInstancePointerHighlights: function(visInstanceView) {
|
Daniel@0
|
493 var vegaHoveredItem = visInstanceView.$content.children(0).data("vegaHoveredItem");
|
Daniel@0
|
494 if (vegaHoveredItem) {
|
Daniel@0
|
495 App.TooltipModule.tooltipView.update();
|
Daniel@0
|
496 var vegaObj = visInstanceView.$content.children(0).data("vegaObj");
|
Daniel@0
|
497 vegaObj.update({items: vegaHoveredItem})
|
Daniel@0
|
498 }
|
Daniel@0
|
499
|
Daniel@0
|
500 },
|
Daniel@0
|
501
|
Daniel@0
|
502
|
Daniel@0
|
503 // -----------------------------------------------------------------
|
Daniel@0
|
504 // vis instance rendering - base
|
Daniel@0
|
505
|
Daniel@0
|
506 _calculateVisInstanceRenderingHashForBase: function(visInstanceView) {
|
Daniel@0
|
507 if (visInstanceView.options.configGrid.getType() == "collection") {
|
Daniel@0
|
508 if (this._getVisInstanceViewComparisonMode(visInstanceView)) {
|
Daniel@0
|
509 var result = this.getAuxiliaryResourcesStatus()
|
Daniel@0
|
510 + visInstanceView._cachedSizeHash
|
Daniel@0
|
511 + visInstanceView.options.entityConfig.getHashForTrimmedParameters()
|
Daniel@0
|
512 + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
|
Daniel@0
|
513 + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
|
Daniel@0
|
514 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
515 + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
|
Daniel@0
|
516 //console.log(result);
|
Daniel@0
|
517 return result;
|
Daniel@0
|
518 } else {
|
Daniel@0
|
519 return this.getAuxiliaryResourcesStatus()
|
Daniel@0
|
520 + visInstanceView._cachedSizeHash
|
Daniel@0
|
521 + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
|
Daniel@0
|
522 + visInstanceView.dynamicDerivedConfigDataForEntity.attributes.dynamicDefinitionForCollection.getHash()
|
Daniel@0
|
523 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
524 + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
|
Daniel@0
|
525 }
|
Daniel@0
|
526 } else {
|
Daniel@0
|
527 if (this._getVisInstanceViewComparisonMode(visInstanceView)) {
|
Daniel@0
|
528 var result = this.getAuxiliaryResourcesStatus()
|
Daniel@0
|
529 + visInstanceView._cachedSizeHash
|
Daniel@0
|
530 + visInstanceView.options.entityConfig.getHashForTrimmedParameters()
|
Daniel@0
|
531 + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
|
Daniel@0
|
532 + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
|
Daniel@0
|
533 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
534 + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
|
Daniel@0
|
535 //console.log(result);
|
Daniel@0
|
536 return result;
|
Daniel@0
|
537 } else {
|
Daniel@0
|
538 return this.getAuxiliaryResourcesStatus()
|
Daniel@0
|
539 + visInstanceView._cachedSizeHash
|
Daniel@0
|
540 + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
|
Daniel@0
|
541 + visInstanceView.dynamicDerivedConfigDataForEntity.attributes.dynamicDefinitionForRecording.getHash()
|
Daniel@0
|
542 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
543 + visInstanceView.dynamicDerivedVisInstanceDataForBase.getHash();
|
Daniel@0
|
544 }
|
Daniel@0
|
545 }
|
Daniel@0
|
546 },
|
Daniel@0
|
547
|
Daniel@0
|
548
|
Daniel@0
|
549 _prepareRenderingVisInstanceViewIfNeeded: function(visInstanceView) {},
|
Daniel@0
|
550
|
Daniel@0
|
551
|
Daniel@0
|
552 _doRenderVisInstanceViewBase: function(visInstanceView) {
|
Daniel@0
|
553 this._doRenderVisInstanceViewBaseWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
|
Daniel@0
|
554 },
|
Daniel@0
|
555
|
Daniel@0
|
556
|
Daniel@0
|
557 _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
|
Daniel@0
|
558
|
Daniel@0
|
559
|
Daniel@0
|
560 // -----------------------------------------------------------------
|
Daniel@0
|
561 // vis instance rendering - overlay
|
Daniel@0
|
562
|
Daniel@0
|
563 _calculateVisInstanceRenderingHashForOverlay: function(visInstanceView) {
|
Daniel@0
|
564 return visInstanceView._cachedSizeHash
|
Daniel@0
|
565 + visInstanceView.options.viewConfig.getHashForTrimmedParameters()
|
Daniel@0
|
566 + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
|
Daniel@0
|
567 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
568 + visInstanceView.dynamicDerivedVisInstanceDataForOverlay.getHash();
|
Daniel@0
|
569 },
|
Daniel@0
|
570
|
Daniel@0
|
571
|
Daniel@0
|
572 _doRenderVisInstanceViewOverlay: function(visInstanceView) {
|
Daniel@0
|
573 this._doRenderVisInstanceViewOverlayWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
|
Daniel@0
|
574 },
|
Daniel@0
|
575
|
Daniel@0
|
576
|
Daniel@0
|
577 _doRenderVisInstanceViewOverlayWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
|
Daniel@0
|
578
|
Daniel@0
|
579
|
Daniel@0
|
580 // -----------------------------------------------------------------
|
Daniel@0
|
581 // vis instance rendering - temp
|
Daniel@0
|
582
|
Daniel@0
|
583 _calculateVisInstanceRenderingHashForTemp: function(visInstanceView) {
|
Daniel@0
|
584 return visInstanceView._cachedSizeHash
|
Daniel@0
|
585 + visInstanceView.options.viewConfig.getHashForParameters()
|
Daniel@0
|
586 + visInstanceView.dynamicDerivedConfigDataForEntity.getHash()
|
Daniel@0
|
587 + visInstanceView.dynamicDerivedConfigDataForView.getHash()
|
Daniel@0
|
588 + visInstanceView.dynamicDerivedVisInstanceDataForTemp.getHash();
|
Daniel@0
|
589 },
|
Daniel@0
|
590
|
Daniel@0
|
591
|
Daniel@0
|
592 _doRenderVisInstanceViewTemp: function(visInstanceView) {
|
Daniel@0
|
593 this._doRenderVisInstanceViewTempWithKnownComparisonMode(visInstanceView, this._getVisInstanceViewComparisonMode(visInstanceView));
|
Daniel@0
|
594 },
|
Daniel@0
|
595
|
Daniel@0
|
596
|
Daniel@0
|
597 _doRenderVisInstanceViewTempWithKnownComparisonMode: function(visInstanceView, comparisonMode) {},
|
Daniel@0
|
598
|
Daniel@0
|
599
|
Daniel@0
|
600 // -----------------------------------------------------------------
|
Daniel@0
|
601 // vis instance rendering - debug mode
|
Daniel@0
|
602
|
Daniel@0
|
603 _selectAllInDebugTextFieldIfNeeded: function() {
|
Daniel@0
|
604 $(this).select();
|
Daniel@0
|
605 },
|
Daniel@0
|
606
|
Daniel@0
|
607
|
Daniel@0
|
608 _prepareRenderingVisInstanceViewInDebugModeIfNeeded: function(visInstanceView) {
|
Daniel@0
|
609 if (!visInstanceView.$content.children(0).hasClass("vic-api-debug")) {
|
Daniel@0
|
610 visInstanceView.$content.empty();
|
Daniel@0
|
611 var $apiDebug = $.bem.generateBlock("vic-api-debug");
|
Daniel@0
|
612 var mappings = visInstanceView._cachedEntityMaster._mapDerivedVisInstanceDataAttributesToDebugAPIQueryBoxes(this);
|
Daniel@0
|
613 for (var i = 0; i < mappings.length; i++) {
|
Daniel@0
|
614 var $queryBox = $.bem.generateElement("vic-api-debug", "query-box", ["alignment_" + mappings[i][0]]);
|
Daniel@0
|
615
|
Daniel@0
|
616 var $queryURIWrapper = $.bem.generateElement("vic-api-debug", "query-uri-wrapper");
|
Daniel@0
|
617 var $queryResponseWrapper = $.bem.generateElement("vic-api-debug", "query-response-wrapper");
|
Daniel@0
|
618
|
Daniel@0
|
619 var $queryURI = $.bem.generateElement("input", "vic-api-debug", "query-uri").attr("type", "text")
|
Daniel@0
|
620 .mouseup(this._avoidDeselectInDebugTextField)
|
Daniel@0
|
621 .focus(this._selectAllInDebugTextFieldIfNeeded)
|
Daniel@0
|
622 .attr("readonly", true);
|
Daniel@0
|
623 var $queryResponse = $.bem.generateElement("textarea", "vic-api-debug", "query-response")
|
Daniel@0
|
624 .attr("readonly", true);
|
Daniel@0
|
625
|
Daniel@0
|
626 $queryURIWrapper.append($queryURI);
|
Daniel@0
|
627 $queryResponseWrapper.append($queryResponse);
|
Daniel@0
|
628 $queryBox.append($queryURIWrapper, $queryResponseWrapper);
|
Daniel@0
|
629 $apiDebug.append($queryBox);
|
Daniel@0
|
630 }
|
Daniel@0
|
631 $apiDebug.data("mappings", mappings);
|
Daniel@0
|
632 visInstanceView.$content.append($apiDebug);
|
Daniel@0
|
633 }
|
Daniel@0
|
634 },
|
Daniel@0
|
635
|
Daniel@0
|
636
|
Daniel@0
|
637 _doRenderVisInstanceViewInDebugMode: function(visInstanceView, layer) {
|
Daniel@0
|
638 var $apiDebug = visInstanceView.$content.children(0);
|
Daniel@0
|
639 var mappings = $apiDebug.data("mappings");
|
Daniel@0
|
640 for (var i = 0; i < mappings.length; i++) {
|
Daniel@0
|
641 var mapping = mappings[i];
|
Daniel@0
|
642 if (layer != mapping[1]) {
|
Daniel@0
|
643 return;
|
Daniel@0
|
644 }
|
Daniel@0
|
645 var currentDynamicDerivedVisInstanceData = null;
|
Daniel@0
|
646 switch (layer) {
|
Daniel@0
|
647 case "base":
|
Daniel@0
|
648 currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForBase;
|
Daniel@0
|
649 break;
|
Daniel@0
|
650 case "overlay":
|
Daniel@0
|
651 currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForOverlay;
|
Daniel@0
|
652 break;
|
Daniel@0
|
653 case "temp":
|
Daniel@0
|
654 currentDynamicDerivedVisInstanceData = visInstanceView.dynamicDerivedVisInstanceDataForTemp;
|
Daniel@0
|
655 break;
|
Daniel@0
|
656 }
|
Daniel@0
|
657
|
Daniel@0
|
658 var $queryBox = $apiDebug.children().eq(i);
|
Daniel@0
|
659 var $queryURI = $queryBox.children().eq(0).children();
|
Daniel@0
|
660 var $queryResponse = $queryBox.children().eq(1).children();
|
Daniel@0
|
661
|
Daniel@0
|
662 var queryURI = currentDynamicDerivedVisInstanceData.attributes[mapping[2]];
|
Daniel@0
|
663 var queryResponse = currentDynamicDerivedVisInstanceData.attributes[mapping[3]];
|
Daniel@0
|
664
|
Daniel@0
|
665 var queryURIText = queryURI;
|
Daniel@0
|
666 if (_.isString(queryURI) && queryURI.indexOf("//") === 0) {
|
Daniel@0
|
667 var protocol = window.location.href.slice(0, window.location.href.indexOf(":"));
|
Daniel@0
|
668 queryURIText = protocol + ":" + queryURIText;
|
Daniel@0
|
669 }
|
Daniel@0
|
670
|
Daniel@0
|
671 var queryResponseText = "";
|
Daniel@0
|
672 if (_.isObject(queryResponse)) {
|
Daniel@0
|
673 queryResponseText = JSON.stringify(queryResponse, false, " ");
|
Daniel@0
|
674 } else if (queryResponse === null) {
|
Daniel@0
|
675 queryResponseText = "obtaining...";
|
Daniel@0
|
676 } else {
|
Daniel@0
|
677 //queryResponseText =
|
Daniel@0
|
678 //no request is being made
|
Daniel@0
|
679 }
|
Daniel@0
|
680 var status = "ok";
|
Daniel@0
|
681 if (queryResponse && queryResponse.errors) {
|
Daniel@0
|
682 status = "has-errors";
|
Daniel@0
|
683 }
|
Daniel@0
|
684
|
Daniel@0
|
685
|
Daniel@0
|
686 $queryURI.val(queryURIText);
|
Daniel@0
|
687 $queryResponse.val(queryResponseText);
|
Daniel@0
|
688 $queryBox.setMod("vic-api-debug", "query-box", "status", status);
|
Daniel@0
|
689 }
|
Daniel@0
|
690 },
|
Daniel@0
|
691 });
|
Daniel@0
|
692 });
|
Daniel@0
|
693 }, Logger);
|