|
@@ -66,60 +66,62 @@ var Snippet = function (notebook, snippet) {
|
|
|
self.type = ko.observable(typeof snippet.type != "undefined" && snippet.type != null ? snippet.type : "hive");
|
|
self.type = ko.observable(typeof snippet.type != "undefined" && snippet.type != null ? snippet.type : "hive");
|
|
|
self.editorMode = ko.observable(TYPE_EDITOR_MAP[self.type()]);
|
|
self.editorMode = ko.observable(TYPE_EDITOR_MAP[self.type()]);
|
|
|
self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
|
|
self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
|
|
|
|
|
+ self.statement_raw.extend({ rateLimit: 150 });
|
|
|
self.status = ko.observable(typeof snippet.status != "undefined" && snippet.status != null ? snippet.status : 'loading');
|
|
self.status = ko.observable(typeof snippet.status != "undefined" && snippet.status != null ? snippet.status : 'loading');
|
|
|
self.settings = ko.mapping.fromJS(typeof snippet.settings != "undefined" && snippet.settings != null ? snippet.settings : {});
|
|
self.settings = ko.mapping.fromJS(typeof snippet.settings != "undefined" && snippet.settings != null ? snippet.settings : {});
|
|
|
self.variables = ko.observableArray([]);
|
|
self.variables = ko.observableArray([]);
|
|
|
- self.variableNames = ko.computed(function() {
|
|
|
|
|
- var matches = [];
|
|
|
|
|
- var myRegexp = /(?:[^\\]\$)([^\d'" ]\w*)/g;
|
|
|
|
|
- var match = myRegexp.exec(self.statement_raw());
|
|
|
|
|
-
|
|
|
|
|
- while (match != null) {
|
|
|
|
|
- matches.push(match[1]);
|
|
|
|
|
- match = myRegexp.exec(self.statement());
|
|
|
|
|
- }
|
|
|
|
|
- return matches;
|
|
|
|
|
|
|
+ self.variableNames = ko.computed(function () {
|
|
|
|
|
+ var matches = [];
|
|
|
|
|
+ var myRegexp = /(?:[^\\]\$)([^\d'" ]\w*)/g;
|
|
|
|
|
+ var match = myRegexp.exec(self.statement_raw());
|
|
|
|
|
+
|
|
|
|
|
+ while (match != null) {
|
|
|
|
|
+ matches.push(match[1]);
|
|
|
|
|
+ match = myRegexp.exec(self.statement());
|
|
|
|
|
+ }
|
|
|
|
|
+ return matches;
|
|
|
});
|
|
});
|
|
|
- self.variableNames.subscribe(function(newVal){
|
|
|
|
|
- var toDelete = [];
|
|
|
|
|
- var toAdd = [];
|
|
|
|
|
-
|
|
|
|
|
- $.each(newVal, function(key, name) {
|
|
|
|
|
- var match = ko.utils.arrayFirst(self.variables(), function(_var) {
|
|
|
|
|
- return _var.name() == name;
|
|
|
|
|
- });
|
|
|
|
|
- if (! match) {
|
|
|
|
|
- toAdd.push(name);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- $.each(self.variables(), function(key, _var) {
|
|
|
|
|
- var match = ko.utils.arrayFirst(newVal, function(name) {
|
|
|
|
|
- return _var.name() == name;
|
|
|
|
|
- });
|
|
|
|
|
- if (! match) {
|
|
|
|
|
- toDelete.push(_var);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- $.each(toDelete, function(index, item) {
|
|
|
|
|
|
|
+ self.variableNames.extend({ rateLimit: 150 });
|
|
|
|
|
+ self.variableNames.subscribe(function (newVal) {
|
|
|
|
|
+ var toDelete = [];
|
|
|
|
|
+ var toAdd = [];
|
|
|
|
|
+
|
|
|
|
|
+ $.each(newVal, function (key, name) {
|
|
|
|
|
+ var match = ko.utils.arrayFirst(self.variables(), function (_var) {
|
|
|
|
|
+ return _var.name() == name;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!match) {
|
|
|
|
|
+ toAdd.push(name);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ $.each(self.variables(), function (key, _var) {
|
|
|
|
|
+ var match = ko.utils.arrayFirst(newVal, function (name) {
|
|
|
|
|
+ return _var.name() == name;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!match) {
|
|
|
|
|
+ toDelete.push(_var);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $.each(toDelete, function (index, item) {
|
|
|
self.variables.remove(item);
|
|
self.variables.remove(item);
|
|
|
- });
|
|
|
|
|
- $.each(toAdd, function(index, item) {
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ $.each(toAdd, function (index, item) {
|
|
|
self.variables.push(ko.mapping.fromJS({'name': item, 'value': ''}));
|
|
self.variables.push(ko.mapping.fromJS({'name': item, 'value': ''}));
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- self.variables.sort(function(left, right) {
|
|
|
|
|
- var leftIndex = newVal.indexOf(left.name());
|
|
|
|
|
- var rightIndex = newVal.indexOf(right.name());
|
|
|
|
|
- return leftIndex == rightIndex ? 0 : (leftIndex < rightIndex ? -1 : 1);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ self.variables.sort(function (left, right) {
|
|
|
|
|
+ var leftIndex = newVal.indexOf(left.name());
|
|
|
|
|
+ var rightIndex = newVal.indexOf(right.name());
|
|
|
|
|
+ return leftIndex == rightIndex ? 0 : (leftIndex < rightIndex ? -1 : 1);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- self.statement = ko.computed(function() {
|
|
|
|
|
|
|
+ self.statement = ko.computed(function () {
|
|
|
var statement = self.statement_raw();
|
|
var statement = self.statement_raw();
|
|
|
- $.each(self.variables(), function(index, variable) {
|
|
|
|
|
- statement = statement.replace(RegExp("([^\\\\])\\$" + variable.name(), "g"), "$1" + variable.value());
|
|
|
|
|
- });
|
|
|
|
|
- return statement;
|
|
|
|
|
|
|
+ $.each(self.variables(), function (index, variable) {
|
|
|
|
|
+ statement = statement.replace(RegExp("([^\\\\])\\$" + variable.name(), "g"), "$1" + variable.value());
|
|
|
|
|
+ });
|
|
|
|
|
+ return statement;
|
|
|
});
|
|
});
|
|
|
self.result = new Result(snippet, snippet.result);
|
|
self.result = new Result(snippet, snippet.result);
|
|
|
self.showGrid = ko.observable(typeof snippet.showGrid != "undefined" && snippet.showGrid != null ? snippet.showGrid : true);
|
|
self.showGrid = ko.observable(typeof snippet.showGrid != "undefined" && snippet.showGrid != null ? snippet.showGrid : true);
|