Ver Fonte

Revert "HUE4907 [editor] Provide a default value to parameters"

This reverts commit 30143b66ec240a993c072bd8b335f7d4bed71943.
jdesjean há 8 anos atrás
pai
commit
2fc039a

+ 17 - 35
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -592,11 +592,7 @@ var EditorViewModel = (function() {
         }
       }, 100);
     });
-    if (snippet && snippet.variable) {
-      snippet.variables.forEach(function (variable) {
-        variable.defaultValue = variable.defaultValue || '';
-      });
-    }
+
     self.variables = ko.mapping.fromJS(typeof snippet.variables != "undefined" && snippet.variables != null ? snippet.variables : []);
     self.variables.subscribe(function (newValue) {
       $(document).trigger("updateResultHeaders", self);
@@ -662,67 +658,53 @@ var EditorViewModel = (function() {
 
       return params;
     };
-    self.updated = ko.observable(true);
     self.variableNames = ko.computed(function () {
       if (self.type() == 'pig') {
         return Object.keys(self.getPigParameters());
       } else {
-        var re = /(?:^|\W)\${(\w*\=?\w*)(?!\w)}/g;
+        var re = /(?:^|\W)\${(\w+)(?!\w)}/g;
 
-        var match, matches = {};
+        var match, matches = [];
         while (match = re.exec(self.statement_raw())) {
-          if (match[1].indexOf('=') > -1) {
-              var splittedName = match[1].split('=');
-              matches[splittedName[0]] = matches[splittedName[0]] || splittedName[1];
-            }
-            else {
-              matches[match[1]] = '';
-            }
+          if (matches.indexOf(match[1]) == -1) {
+            matches.push(match[1]);
+          }
         }
-        return Object.keys(matches).map(function(match){
-          return {name:match, defaultValue:matches[match]};
-        });
+        return matches;
       }
     });
     self.variableNames.extend({ rateLimit: 150 });
     self.variableNames.subscribe(function (newVal) {
       var toDelete = [];
       var toAdd = [];
-      var toUpdate = [];
+
       if (newVal.length == self.variables().length) { // Just rename one of the variable
         $.each(newVal, function(i, item) {
-          self.variables()[i].name(item.name);
-          self.variables()[i].defaultValue(item.defaultValue);
+          self.variables()[i].name(newVal[i]);
         });
       } else {
-        $.each(newVal, function (key, item) {
-          var name = item.name;
+        $.each(newVal, function (key, name) {
           var match = ko.utils.arrayFirst(self.variables(), function (_var) {
             return _var.name() == name;
           });
           if (! match) {
-            toAdd.push(item);
-          } else {
-            toUpdate.push(item);
+            toAdd.push(name);
           }
         });
         $.each(self.variables(), function (key, _var) {
-          var match = ko.utils.arrayFirst(newVal, function (item) {
-            return _var.name() == item.name;
+          var match = ko.utils.arrayFirst(newVal, function (name) {
+            return _var.name() == name;
           });
           if (! match) {
             toDelete.push(_var);
           }
         });
-        $.each(toUpdate, function (i, item) {
-          self.variables()[i].name(item.name);
-          self.variables()[i].defaultValue(item.defaultValue);
-        });
+
         $.each(toDelete, function (index, item) {
-          self.variables.remove(item.name);
+          self.variables.remove(item);
         });
         $.each(toAdd, function (index, item) {
-          self.variables.push(ko.mapping.fromJS({'name': item.name, 'value': '', defaultValue: item.defaultValue}));
+          self.variables.push(ko.mapping.fromJS({'name': item, 'value': ''}));
         });
       }
 
@@ -737,7 +719,7 @@ var EditorViewModel = (function() {
     self.statement = ko.computed(function () {
       var statement = self.isSqlDialect() ? (self.selectedStatement() ? self.selectedStatement() : (self.positionStatement() !== null ? self.positionStatement().statement : self.statement_raw())) : self.statement_raw();
       $.each(self.variables(), function (index, variable) {
-        statement = statement.replace(RegExp("([^\\\\])?\\${" + variable.name() + "(=[^}]*)?}", "g"), "$1" + (variable.value() || variable.defaultValue()));
+        statement = statement.replace(RegExp("([^\\\\])?\\$" + (self.hasCurlyBracketParameters() ? "{" : "") + variable.name() + (self.hasCurlyBracketParameters() ? "}" : ""), "g"), "$1" + variable.value());
       });
       return statement;
     });

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1129,7 +1129,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       <li>
         <div class="input-prepend margin-top-10">
           <span class="muted add-on" data-bind="text: name"></span>
-          <input class="input-medium" type="text" data-bind="value: value, attr: { placeholder: defaultValue() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keypress': function (context, e){ if (e.ctrlKey && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }">
+          <input class="input-medium" type="text" placeholder="${ _("Variable value") }" data-bind="value: value, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keypress': function (context, e){ if (e.ctrlKey && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }">
         </div>
       </li>
     </ul>