Răsfoiți Sursa

HUE-4855 [notebook] Notebook or editor gets the list of all available snippets

Will simplify the merging of notebook and editor together.
Romain Rigaux 9 ani în urmă
părinte
comite
fb340ed

+ 33 - 20
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -252,6 +252,11 @@
     self.name = ko.observable(typeof snippet.name != "undefined" && snippet.name != null ? snippet.name : '');
     self.type = ko.observable(typeof snippet.type != "undefined" && snippet.type != null ? snippet.type : 'hive');
 
+    self.isBatchable = ko.computed(function() {
+      return self.type() == 'hive'
+    	  || $.grep(vm.availableLanguages, function(language) { return language.type == self.type() && language.interface == 'oozie'; }).length > 0;
+    });
+
     // Ace stuff
     self.ace = ko.observable(null);
     self.errors = ko.observableArray([]);
@@ -278,7 +283,6 @@
     };
 
     self.database = ko.observable(typeof snippet.database != "undefined" && snippet.database != null ? snippet.database : null);
-
     self.availableDatabases = ko.observableArray();
 
     var updateDatabases = function () {
@@ -301,7 +305,6 @@
 
     // History is currently in Notebook, same with saved queries by snippets, might be better in assist
     self.currentQueryTab = ko.observable(typeof snippet.currentQueryTab != "undefined" && snippet.currentQueryTab != null ? snippet.currentQueryTab : 'queryHistory');
-
     self.pinnedContextTabs = ko.observableArray(typeof snippet.pinnedContextTabs != "undefined" && snippet.pinnedContextTabs != null ? snippet.pinnedContextTabs : []);
 
     huePubSub.subscribe('sql.context.pin', function (contextData) {
@@ -1369,9 +1372,10 @@
     self.schedulerViewModel = null;
     self.schedulerViewerViewModel = ko.observable();
     self.isBatchable = ko.computed(function() {
-      return $.grep(self.snippets(), function (snippet) {
-        return snippet.type() == 'hive' || snippet.interface() == 'oozie';
-      }).length == self.snippets().length;
+      return self.snippets().length > 0
+        && $.each(self.snippets(), function (index, snippet) {
+          return snippet.isBatchable();
+        }).length == self.snippets().length;
     });
 
     self.retryModalConfirm = null;
@@ -1792,7 +1796,7 @@
     };
 
     self.loadScheduler = function () {
-      if (typeof vm.CoordinatorEditorViewModel !== 'undefined') {
+      if (typeof vm.CoordinatorEditorViewModel !== 'undefined' && self.isBatchable()) {
         var _action;
         if (self.coordinatorUuid()) {
           _action = 'edit';
@@ -1830,21 +1834,23 @@
     };
 
     self.refreshSchedulerParameters = function() {
-      $.post("/oozie/editor/workflow/action/refresh_parameters/", {
-        uuid: self.coordinatorUuid()
-      }, function(data) {
-        if (data.status == 0) {
-          if (data.changed) {
-            self.schedulerViewModel.coordinator.refreshParameters()
+      if (self.isBatchable()) {
+        $.post("/oozie/editor/workflow/action/refresh_parameters/", {
+          uuid: self.coordinatorUuid()
+        }, function(data) {
+          if (data.status == 0) {
+            if (data.changed) {
+              self.schedulerViewModel.coordinator.refreshParameters()
+            }
+          } else {
+            $(document).trigger("error", data.message);
           }
-        } else {
-          $(document).trigger("error", data.message);
-        }
-      });
+        });
+      }
     }
 
     self.saveScheduler = function() {
-      if (! self.coordinatorUuid() || self.schedulerViewModel.coordinator.isDirty()) {
+      if (self.isBatchable() && (! self.coordinatorUuid() || self.schedulerViewModel.coordinator.isDirty())) {
         self.schedulerViewModel.coordinator.isManaged(true);
         self.schedulerViewModel.save(function(data) {
           self.coordinatorUuid(data.uuid);
@@ -1979,9 +1985,15 @@
     });
 
     self.sqlSourceTypes = [];
+    self.availableLanguages = [];
 
     if (options.languages && options.snippetViewSettings) {
       $.each(options.languages, function (idx, language) {
+    	self.availableLanguages.push({
+          type: language.type,
+          name: language.name,
+          interface: language.interface,
+    	});
         var viewSettings = options.snippetViewSettings[language.type];
         if (viewSettings && viewSettings.sqlDialect) {
           self.sqlSourceTypes.push({
@@ -1992,8 +2004,9 @@
       });
     }
 
-    if (self.sqlSourceTypes.length > 0) {
-      self.activeSqlSourceType = self.sqlSourceTypes[0].type;
+    var sqlSourceTypes = $.grep(self.sqlSourceTypes, function(language) { return language.type == self.editorType(); });
+    if (sqlSourceTypes.length > 0) {
+      self.activeSqlSourceType = sqlSourceTypes[0].type;
     } else {
       self.activeSqlSourceType = null;
     }
@@ -2200,7 +2213,7 @@
       }, function (data) {
         self.loadNotebook(data.notebook);
         if (self.editorMode()) {
-          self.selectedNotebook().newSnippet();
+          self.selectedNotebook().newSnippet(self.editorType());
           huePubSub.publish('detach.scrolls', self.selectedNotebook().snippets()[0]);
           if (window.location.getParameter('new') == '') {
             self.selectedNotebook().snippets()[0].statement_raw($.totalStorage('hue.notebook.lastWrittenSnippet.' + self.user + '.' + window.location.getParameter('type')));

+ 7 - 5
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1046,8 +1046,10 @@ ${ hueIcons.symbols() }
     <ul class="nav nav-tabs">
       <li class="active"><a href="#sessionsTab" data-toggle="tab">${_('Sessions')}</a></li>
       % if ENABLE_QUERY_SCHEDULING.get():
-      <li><a href="#scheduleTab" data-toggle="tab">${_('Schedule')}</a></li>
-      <li><a href="#scheduledJobsTab" data-toggle="tab">${_('Instances')}</a></li>
+      <!-- ko if: $root.selectedNotebook() && $root.selectedNotebook().isBatchable() -->
+        <li><a href="#scheduleTab" data-toggle="tab">${_('Schedule')}</a></li>
+        <li><a href="#scheduledJobsTab" data-toggle="tab">${_('Instances')}</a></li>
+      <!-- /ko -->
       % endif
     </ul>
 
@@ -1970,18 +1972,18 @@ ${ hueIcons.symbols() }
     </a>
 
     <div class="inactive-action dropdown hover-actions pointer" data-bind="css: {'disabled': statement() === '' || status() === 'running' || status() === 'loading' }">
-      <!-- ko if: $parent.isBatchable() && wasBatchExecuted() -->
+      <!-- ko if: isBatchable() && wasBatchExecuted() -->
       <a class="snippet-side-btn" style="padding-right:0; padding-left: 2px" href="javascript: void(0)" title="${ _('Submit all the queries as a background batch job.') }" data-bind="click: function() { wasBatchExecuted(true); execute(); }, visible: status() != 'running' && status() != 'loading', css: {'blue': $parent.history().length == 0 || $root.editorMode(), 'disabled': statement() === '' }">
         <i class="fa fa-fw fa-send"></i>
       </a>
       <!-- /ko -->
-      <!-- ko if: ! $parent.isBatchable() || ! wasBatchExecuted() -->
+      <!-- ko if: ! isBatchable() || ! wasBatchExecuted() -->
       <a class="snippet-side-btn" style="padding-right:0" href="javascript: void(0)" data-bind="attr: {'title': $root.editorMode() && result.statements_count() > 1 ? '${ _ko('Execute next statement')}' : '${ _ko('Execute or CTRL + ENTER') }'}, click: function() { wasBatchExecuted(false); execute(); }, visible: status() != 'running' && status() != 'loading', css: {'blue': $parent.history().length == 0 || $root.editorMode(), 'disabled': ! isReady() }, style: {'padding-left': $parent.isBatchable() ? '2px' : '0' }">
         <i class="fa fa-fw fa-play" data-bind="css: { 'snippet-side-single' : ! $parent.isBatchable() }"></i>
       </a>
       <!-- /ko -->
       % if ENABLE_BATCH_EXECUTE.get():
-      <!-- ko if: $parent.isBatchable() && status() != 'running' && status() != 'loading' -->
+      <!-- ko if: isBatchable() && status() != 'running' && status() != 'loading' -->
         <a class="dropdown-toggle snippet-side-btn" style="padding:0" data-toggle="dropdown" href="javascript: void(0)" data-bind="css: {'disabled': statement() === '', 'blue': currentQueryTab() == 'queryExplain' }">
           <i class="fa fa-caret-down"></i>
         </a>

+ 2 - 2
desktop/libs/notebook/src/notebook/views.py

@@ -100,7 +100,7 @@ def editor(request):
       'editor_id': editor_id or None,
       'notebooks_json': '{}',
       'options_json': json.dumps({
-          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
+          'languages': get_interpreters(request.user),
           'mode': 'editor',
           'is_optimizer_enabled': has_optimizer(),
           'is_navigator_enabled': has_navigator(),
@@ -124,7 +124,7 @@ def browse(request, database, table):
   return render('editor.mako', request, {
       'notebooks_json': json.dumps([editor.get_data()]),
       'options_json': json.dumps({
-          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
+          'languages': get_interpreters(request.user),
           'mode': 'editor',
           'editor_type': editor_type
       }),