Browse Source

HUE-2892 [notebook] Disable $ variables for R

Added ${var} support to all the snippets
Restyled variables input
Fixed regex to detect variables and replace them
Added variable showing at page load
Enrico Berti 10 years ago
parent
commit
c5346fa

BIN
apps/spark/java/-version


+ 8 - 7
apps/spark/src/spark/static/spark/js/spark.ko.js

@@ -111,7 +111,7 @@ var TYPE_ACE_EDITOR_MAP = {
   'pyspark': 'ace/mode/python',
   'pyspark': 'ace/mode/python',
   'spark': 'ace/mode/scala',
   'spark': 'ace/mode/scala',
   'pig': 'ace/mode/pig',
   'pig': 'ace/mode/pig',
-  'r': 'ace/mode/r',
+  'r': 'ace/mode/r'
 };
 };
 
 
 var getDefaultSnippetProperties = function (snippetType) {
 var getDefaultSnippetProperties = function (snippetType) {
@@ -186,13 +186,11 @@ var Snippet = function (vm, notebook, snippet) {
 
 
   self.variables = ko.observableArray([]);
   self.variables = ko.observableArray([]);
   self.variableNames = ko.computed(function () {
   self.variableNames = ko.computed(function () {
-    var matches = [];
-    var myRegexp = /(?:[^\\]\$)([^\d'" ]\w*)/g;
-    var match = myRegexp.exec(self.statement_raw());
+    var re = /(?:^|\W)\${(\w+)(?!\w)}/g;
 
 
-    while (match != null) {
+    var match, matches = [];
+    while (match = re.exec(self.statement_raw())) {
       matches.push(match[1]);
       matches.push(match[1]);
-      match = myRegexp.exec(self.statement());
     }
     }
     return matches;
     return matches;
   });
   });
@@ -234,7 +232,7 @@ var Snippet = function (vm, notebook, snippet) {
   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) {
     $.each(self.variables(), function (index, variable) {
-      statement = statement.replace(RegExp("([^\\\\])\\$" + variable.name(), "g"), "$1" + variable.value());
+      statement = statement.replace(RegExp("([^\\\\])?\\${" + variable.name() + "}", "g"), "$1" + variable.value());
     });
     });
     return statement;
     return statement;
   });
   });
@@ -905,6 +903,9 @@ function EditorViewModel(notebooks, options) {
     self.notebooks.push(_n);
     self.notebooks.push(_n);
     if (_n.snippets().length > 0) {
     if (_n.snippets().length > 0) {
       _n.selectedSnippet(_n.snippets()[_n.snippets().length - 1].type());
       _n.selectedSnippet(_n.snippets()[_n.snippets().length - 1].type());
+      _n.snippets().forEach(function(snippet){
+        snippet.statement_raw.valueHasMutated();
+      });
     }
     }
   };
   };
 
 

+ 11 - 7
apps/spark/src/spark/templates/editor_components.mako

@@ -448,14 +448,8 @@ from django.utils.translation import ugettext as _
 </script>
 </script>
 
 
 <script type="text/html" id="code-editor-snippet-body">
 <script type="text/html" id="code-editor-snippet-body">
-  <div class="row-fluid">
+  <div class="row-fluid" style="margin-bottom: 5px">
     <div class="editor span12" data-bind="verticalSlide: codeVisible">
     <div class="editor span12" data-bind="verticalSlide: codeVisible">
-      <div data-bind="foreach: variables">
-        <div>
-          <span data-bind="text: name"></span>
-          <input type="text" data-bind="value: value" />
-        </div>
-      </div>
       <div class="ace-editor" data-bind="attr: { id: id() }, aceEditor: {
       <div class="ace-editor" data-bind="attr: { id: id() }, aceEditor: {
           value: statement_raw,
           value: statement_raw,
           onExecute: execute,
           onExecute: execute,
@@ -467,7 +461,17 @@ from django.utils.translation import ugettext as _
           openIt: '${ _("Double click to open it") }',
           openIt: '${ _("Double click to open it") }',
           placeholder: $root.snippetPlaceholders[type()] }"></div>
           placeholder: $root.snippetPlaceholders[type()] }"></div>
       </div>
       </div>
+    <div class="clearfix"></div>
+    <ul data-bind="foreach: variables" class="unstyled inline">
+        <li>
+          <div class="input-prepend margin-top-10">
+            <span class="muted add-on" data-bind="text: name"></span>
+            <input class="input-medium" type="text" placeholder="${ _("Variable value") }" data-bind="value: value">
+          </div>
+        </li>
+      </ul>
   </div>
   </div>
+  <div class="clearfix"></div>
 
 
   <!-- ko template: 'snippet-footer-actions' --><!-- /ko -->
   <!-- ko template: 'snippet-footer-actions' --><!-- /ko -->
   <!-- ko template: 'snippet-results' --><!-- /ko -->
   <!-- ko template: 'snippet-results' --><!-- /ko -->