Browse Source

[spark] Configure the list of available languages

Romain Rigaux 10 years ago
parent
commit
7d7191bc74

+ 17 - 0
apps/spark/src/spark/conf.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import json
 import sys
 
 from django.utils.translation import ugettext_lazy as _t, ugettext as _
@@ -23,12 +24,28 @@ from desktop.lib.conf import Config
 from spark.settings import NICE_NAME
 
 
+def coerce_json(j):
+  return json.loads(j)
+
+
 JOB_SERVER_URL = Config(
   key="server_url",
   help=_t("URL of the Spark Job Server."),
   default="http://localhost:8080/"
 )
 
+LANGUAGES = Config(
+  key="languages",
+  help=_t("List of available types of snippets."),
+  type=coerce_json,
+  default="""[
+      {"name": "Scala", "type": "scala"},
+      {"name": "Python", "type": "python"},
+      {"name": "Impala SQL", "type": "impala"},
+      {"name": "Hive SQL", "type": "hive"},
+      {"name": "Text", "type": "text"}
+  ]"""
+)
 
 
 def get_spark_status(user):

+ 6 - 5
apps/spark/src/spark/templates/editor.mako

@@ -68,7 +68,7 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
 <script src="/static/js/hue.utils.js"></script>
 <script src="/static/js/ko.hue-bindings.js" type="text/javascript" charset="utf-8"></script>
 <script src="/spark/static/js/assist.js" type="text/javascript" charset="utf-8"></script>
-<script src="/spark/static/js/spark.vm.js" type="text/javascript" charset="utf-8"></script>
+<script src="/spark/static/js/spark.ko.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/chosen/chosen.jquery.min.js" type="text/javascript" charset="utf-8"></script>
 
 
@@ -243,7 +243,7 @@ ${_('Example: SELECT * FROM tablename, or press CTRL + space')}
 
         </textarea>
         <div class="overlay">
-          <select data-bind="options: availableSnippets, value: selectedSnippet, optionsText: 'name', optionsValue: 'type'"></select>
+          <select data-bind="options: $root.availableSnippets, value: selectedSnippet, optionsText: 'name', optionsValue: 'type'"></select>
           <i class="fa fa-plus-circle" data-bind="click: newSnippet" title="${ _('Add a new snippet') }"></i>
         </div>
       </div>
@@ -944,11 +944,12 @@ ${_('Example: SELECT * FROM tablename, or press CTRL + space')}
     }
   };
 
-  var _opts = {
+  var options = ${ options_json | n,unicode };
+  $.extend(options, {
     assistVisible: $.totalStorage("sparkAssistVisible") != null ? $.totalStorage("sparkAssistVisible") : true
-  }
+  });
 
-  viewModel = new EditorViewModel(${ notebooks_json | n,unicode }, _opts);
+  viewModel = new EditorViewModel(${ notebooks_json | n,unicode }, options);
   viewModel.assistContent(assist);
   ko.applyBindings(viewModel);
   viewModel.init();

+ 3 - 1
apps/spark/src/spark/views.py

@@ -21,6 +21,7 @@ import logging
 from desktop.lib.django_util import render
 from desktop.models import Document2
 
+from spark.conf import LANGUAGES
 from spark.models import Notebook, get_api
 
 LOG = logging.getLogger(__name__)
@@ -35,7 +36,8 @@ def editor(request):
     notebook = Notebook()
     
   return render('editor.mako', request, {
-      'notebooks_json': json.dumps([notebook.get_data()])
+      'notebooks_json': json.dumps([notebook.get_data()]),
+      'options_json': json.dumps({'languages': LANGUAGES.get()})
   })
 
 

+ 3 - 10
apps/spark/static/js/spark.vm.js → apps/spark/static/js/spark.ko.js

@@ -422,15 +422,7 @@ var Notebook = function (vm, notebook) {
   self.uuid = ko.observable(typeof notebook.uuid != "undefined" && notebook.uuid != null ? notebook.uuid : UUID());
   self.name = ko.observable(typeof notebook.name != "undefined" && notebook.name != null ? notebook.name : 'My Notebook');
   self.snippets = ko.observableArray();
-  self.selectedSnippet = ko.observable("scala");
-  self.availableSnippets = ko.observableArray([
-      {"name": "Scala", "type": "scala"},
-      {"name": "Python", "type": "python"},
-      {"name": "Impala SQL", "type": "impala"},
-      {"name": "Hive SQL", "type": "hive"},
-      {"name": "Text", "type": "text"},
-      {"name": "Pig", "type": "pig"}
-  ]); // presto, mysql, oracle, sqlite, postgres, phoenix
+  self.selectedSnippet = ko.observable("scala");  
   self.sessions = ko.mapping.fromJS(typeof notebook.sessions != "undefined" && notebook.sessions != null ? notebook.sessions : []); 
 
   self.getSession = function(session_type) {
@@ -528,6 +520,8 @@ function EditorViewModel(notebooks, options) {
 
   self.assistContent = ko.observable();
 
+  self.availableSnippets = ko.mapping.fromJS(options.languages);
+  
   self.init = function() {
     $.each(notebooks, function(index, notebook) {
       self.loadNotebook(notebook);
@@ -553,7 +547,6 @@ function EditorViewModel(notebooks, options) {
   self.saveNotebook = function() {
     self.selectedNotebook().save();
   };
-
 }
 
 

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -972,6 +972,9 @@
   # URL of the REST Spark Job Server.
   ## server_url=http://localhost:8090/
 
+  # List of available types of snippets
+  ## languages='[{"name": "Scala", "type": "scala"},{"name": "Python", "type": "python"},{"name": "Impala SQL", "type": "impala"},{"name": "Hive SQL", "type": "hive"},{"name": "Text", "type": "text"}]'
+
 
 ###########################################################################
 # Settings for the User Admin application

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -979,6 +979,9 @@
   # URL of the REST Spark Job Server.
   ## server_url=http://localhost:8090/
 
+  # List of available types of snippets
+  ## languages='[{"name": "Scala", "type": "scala"},{"name": "Python", "type": "python"},{"name": "Impala SQL", "type": "impala"},{"name": "Hive SQL", "type": "hive"},{"name": "Text", "type": "text"}]'
+
 
 ###########################################################################
 # Settings for the User Admin application