|
@@ -274,7 +274,16 @@ var EditorViewModel = (function() {
|
|
|
// Ace stuff
|
|
// Ace stuff
|
|
|
self.ace = ko.observable(null);
|
|
self.ace = ko.observable(null);
|
|
|
self.errors = ko.observableArray([]);
|
|
self.errors = ko.observableArray([]);
|
|
|
- self.warnings = ko.observableArray([]);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ self.aceErrorsHolder = ko.observableArray([]);
|
|
|
|
|
+ self.aceWarningsHolder = ko.observableArray([]);
|
|
|
|
|
+
|
|
|
|
|
+ self.aceErrors = ko.pureComputed(function(){
|
|
|
|
|
+ return self.showOptimizer() ? self.aceErrorsHolder() : [];
|
|
|
|
|
+ });
|
|
|
|
|
+ self.aceWarnings = ko.pureComputed(function(){
|
|
|
|
|
+ return self.showOptimizer() ? self.aceWarningsHolder() : [];
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
self.availableSnippets = vm.availableSnippets();
|
|
self.availableSnippets = vm.availableSnippets();
|
|
|
self.inFocus = ko.observable(false);
|
|
self.inFocus = ko.observable(false);
|
|
@@ -809,26 +818,28 @@ var EditorViewModel = (function() {
|
|
|
self.complexityCheckActive = ko.observable(true);
|
|
self.complexityCheckActive = ko.observable(true);
|
|
|
self.compatibilityCheckActive = ko.observable(true);
|
|
self.compatibilityCheckActive = ko.observable(true);
|
|
|
|
|
|
|
|
|
|
+ self.showOptimizer = ko.observable(false);
|
|
|
|
|
+
|
|
|
self.isOptimizing = ko.observable(false);
|
|
self.isOptimizing = ko.observable(false);
|
|
|
|
|
|
|
|
if (HAS_OPTIMIZER) {
|
|
if (HAS_OPTIMIZER) {
|
|
|
- var lastRequest;
|
|
|
|
|
- var lastCheckedStatement;
|
|
|
|
|
|
|
+ var lastComplexityRequest;
|
|
|
|
|
+ var lastCheckedComplexityStatement;
|
|
|
|
|
|
|
|
- self.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 3000 } });
|
|
|
|
|
|
|
+ self.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 2000 } });
|
|
|
|
|
|
|
|
self.checkComplexity = function () {
|
|
self.checkComplexity = function () {
|
|
|
- if (lastCheckedStatement === self.statement_raw()) {
|
|
|
|
|
|
|
+ if (lastCheckedComplexityStatement === self.statement_raw()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (lastRequest && lastRequest.readyState < 4) {
|
|
|
|
|
- lastRequest.abort();
|
|
|
|
|
|
|
+ if (lastComplexityRequest && lastComplexityRequest.readyState < 4) {
|
|
|
|
|
+ lastComplexityRequest.abort();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
logGA('get_query_risk');
|
|
logGA('get_query_risk');
|
|
|
self.isOptimizing(true);
|
|
self.isOptimizing(true);
|
|
|
- lastRequest = $.ajax({
|
|
|
|
|
|
|
+ lastComplexityRequest = $.ajax({
|
|
|
type: 'POST',
|
|
type: 'POST',
|
|
|
url: '/notebook/api/optimizer/statement/risk',
|
|
url: '/notebook/api/optimizer/statement/risk',
|
|
|
timeout: 10000, // 10 seconds
|
|
timeout: 10000, // 10 seconds
|
|
@@ -843,7 +854,7 @@ var EditorViewModel = (function() {
|
|
|
// TODO: Silence errors
|
|
// TODO: Silence errors
|
|
|
$(document).trigger('error', data.message);
|
|
$(document).trigger('error', data.message);
|
|
|
}
|
|
}
|
|
|
- lastCheckedStatement = self.statement_raw();
|
|
|
|
|
|
|
+ lastCheckedComplexityStatement = self.statement_raw();
|
|
|
self.isOptimizing(false);
|
|
self.isOptimizing(false);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -1151,7 +1162,13 @@ var EditorViewModel = (function() {
|
|
|
|
|
|
|
|
self.compatibilityTarget = ko.observable('');
|
|
self.compatibilityTarget = ko.observable('');
|
|
|
|
|
|
|
|
|
|
+ var lastCompatibilityRequest;
|
|
|
|
|
+
|
|
|
self.queryCompatibility = function (targetPlatform) {
|
|
self.queryCompatibility = function (targetPlatform) {
|
|
|
|
|
+ if (lastCompatibilityRequest && lastCompatibilityRequest.readyState < 4) {
|
|
|
|
|
+ lastCompatibilityRequest.abort();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
logGA('compatibility');
|
|
logGA('compatibility');
|
|
|
self.isOptimizing(true);
|
|
self.isOptimizing(true);
|
|
|
|
|
|
|
@@ -1161,17 +1178,19 @@ var EditorViewModel = (function() {
|
|
|
|
|
|
|
|
self.compatibilityTarget(targetPlatform);
|
|
self.compatibilityTarget(targetPlatform);
|
|
|
|
|
|
|
|
- $.post("/notebook/api/optimizer/statement/compatibility", {
|
|
|
|
|
|
|
+ lastCompatibilityRequest = $.post("/notebook/api/optimizer/statement/compatibility", {
|
|
|
notebook: ko.mapping.toJSON(notebook.getContext()),
|
|
notebook: ko.mapping.toJSON(notebook.getContext()),
|
|
|
snippet: ko.mapping.toJSON(self.getContext()),
|
|
snippet: ko.mapping.toJSON(self.getContext()),
|
|
|
sourcePlatform: self.type(),
|
|
sourcePlatform: self.type(),
|
|
|
targetPlatform: targetPlatform
|
|
targetPlatform: targetPlatform
|
|
|
}, function (data) {
|
|
}, function (data) {
|
|
|
if (data.status == 0) {
|
|
if (data.status == 0) {
|
|
|
|
|
+ self.aceErrorsHolder([]);
|
|
|
|
|
+ self.aceWarningsHolder([]);
|
|
|
self.suggestion(ko.mapping.fromJS(data.query_compatibility));
|
|
self.suggestion(ko.mapping.fromJS(data.query_compatibility));
|
|
|
if (self.suggestion().queryError.errorString()) {
|
|
if (self.suggestion().queryError.errorString()) {
|
|
|
var match = ERROR_REGEX.exec(self.suggestion().queryError.errorString());
|
|
var match = ERROR_REGEX.exec(self.suggestion().queryError.errorString());
|
|
|
- self.warnings.push({
|
|
|
|
|
|
|
+ self.aceWarningsHolder.push({
|
|
|
message: self.suggestion().queryError.errorString(),
|
|
message: self.suggestion().queryError.errorString(),
|
|
|
line: match === null ? null : parseInt(match[1]) - 1,
|
|
line: match === null ? null : parseInt(match[1]) - 1,
|
|
|
col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
|
|
col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
|
|
@@ -1179,13 +1198,12 @@ var EditorViewModel = (function() {
|
|
|
}
|
|
}
|
|
|
if (self.suggestion().parseError()) {
|
|
if (self.suggestion().parseError()) {
|
|
|
var match = ERROR_REGEX.exec(self.suggestion().parseError());
|
|
var match = ERROR_REGEX.exec(self.suggestion().parseError());
|
|
|
- self.errors.push({
|
|
|
|
|
|
|
+ self.aceErrorsHolder.push({
|
|
|
message: self.suggestion().parseError(),
|
|
message: self.suggestion().parseError(),
|
|
|
line: match === null ? null : parseInt(match[1]) - 1,
|
|
line: match === null ? null : parseInt(match[1]) - 1,
|
|
|
col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
|
|
col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
self.hasSuggestion(true);
|
|
self.hasSuggestion(true);
|
|
|
} else {
|
|
} else {
|
|
|
$(document).trigger("error", data.message);
|
|
$(document).trigger("error", data.message);
|