Selaa lähdekoodia

HUE-4391 [editor] Blacklisting oozie should not break the editor

Enrico Berti 9 vuotta sitten
vanhempi
commit
2e7180f

+ 46 - 41
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -20,15 +20,13 @@
       'knockout',
       'desktop/js/apiHelper',
       'desktop/js/autocompleter',
-      'oozie/js/coordinator-editor.ko',
-      'oozie/js/list-oozie-coordinator.ko',
       'knockout-mapping',
       'ko.charts'
     ], factory);
   } else {
     root.EditorViewModel = factory(ko, ApiHelper, Autocompleter);
   }
-}(this, function (ko, ApiHelper, Autocompleter, CoordinatorEditorViewModel, RunningCoordinatorModel) {
+}(this, function (ko, ApiHelper, Autocompleter) {
 
   var NOTEBOOK_MAPPING = {
     ignore: [
@@ -1697,37 +1695,39 @@
     };
 
     self.loadScheduler = function () {
-      var _action;
-      if (self.coordinatorUuid()) {
-        _action = 'edit';
-      } else {
-        _action = 'new';
-      }
-      logGA('schedule/' + _action);
+      if (typeof vm.CoordinatorEditorViewModel !== 'undefined') {
+        var _action;
+        if (self.coordinatorUuid()) {
+          _action = 'edit';
+        } else {
+          _action = 'new';
+        }
+        logGA('schedule/' + _action);
 
-      $.get('/oozie/editor/coordinator/' + _action + '/', {
-        format: 'json',
-        document: self.uuid(),
-        coordinator: self.coordinatorUuid()
-      }, function (data) {
-        $("#schedulerEditor").html(data.layout);
-        self.schedulerViewModel = new CoordinatorEditorViewModel(data.coordinator, data.credentials, data.workflows, data.can_edit);
+        $.get('/oozie/editor/coordinator/' + _action + '/', {
+          format: 'json',
+          document: self.uuid(),
+          coordinator: self.coordinatorUuid()
+        }, function (data) {
+          $("#schedulerEditor").html(data.layout);
+          self.schedulerViewModel = new vm.CoordinatorEditorViewModel(data.coordinator, data.credentials, data.workflows, data.can_edit);
 
-        ko.cleanNode($("#schedulerEditor")[0]);
-        ko.applyBindings(self.schedulerViewModel, $("#schedulerEditor")[0]);
+          ko.cleanNode($("#schedulerEditor")[0]);
+          ko.applyBindings(self.schedulerViewModel, $("#schedulerEditor")[0]);
 
-        huePubSub.publish('render.jqcron');
+          huePubSub.publish('render.jqcron');
 
-        self.schedulerViewModel.coordinator.properties.cron_advanced.valueHasMutated(); // Update jsCron enabled status
-        self.schedulerViewModel.coordinator.tracker().markCurrentStateAsClean();
-        self.schedulerViewModel.isEditing(true);
+          self.schedulerViewModel.coordinator.properties.cron_advanced.valueHasMutated(); // Update jsCron enabled status
+          self.schedulerViewModel.coordinator.tracker().markCurrentStateAsClean();
+          self.schedulerViewModel.isEditing(true);
 
-        if (_action == 'new') {
-          self.saveScheduler();
-        }
-      }).fail(function (xhr) {
-        $(document).trigger("error", xhr.responseText);
-      });
+          if (_action == 'new') {
+            self.saveScheduler();
+          }
+        }).fail(function (xhr) {
+          $(document).trigger("error", xhr.responseText);
+        });
+      }
     };
 
     self.refreshSchedulerParameters = function() {
@@ -1767,17 +1767,19 @@
     self.viewSchedulerId = ko.observable('0000025-160525025600562-oozie-oozi-C');
     self.loadingScheduler = ko.observable(false);
     self.viewScheduler = function() {
-      logGA('schedule/view');
-      self.loadingScheduler(true);
-      $.get("/oozie/list_oozie_coordinator/" + self.viewSchedulerId(), {
-        format: 'json'
-      }, function (data) {
-        self.schedulerViewerViewModel(new RunningCoordinatorModel(data.actions));
-      }).fail(function (xhr) {
-        $(document).trigger("error", xhr.responseText);
-      }).always(function(){
-        self.loadingScheduler(false);
-      });
+      if (typeof vm.RunningCoordinatorModel !== 'undefined') {
+        logGA('schedule/view');
+        self.loadingScheduler(true);
+        $.get("/oozie/list_oozie_coordinator/" + self.viewSchedulerId(), {
+          format: 'json'
+        }, function (data) {
+          self.schedulerViewerViewModel(new vm.RunningCoordinatorModel(data.actions));
+        }).fail(function (xhr) {
+          $(document).trigger("error", xhr.responseText);
+        }).always(function () {
+          self.loadingScheduler(false);
+        });
+      }
     };
 
     self.exportJupyterNotebook = function () {
@@ -1841,7 +1843,7 @@
   };
 
 
-  function EditorViewModel(editor_id, notebooks, options, i18n) {
+  function EditorViewModel(editor_id, notebooks, options, i18n, CoordinatorEditorViewModel, RunningCoordinatorModel) {
     var self = this;
     self.i18n = i18n;
     self.user = options.user;
@@ -1861,6 +1863,9 @@
     self.isOptimizerEnabled = ko.observable(options.is_optimizer_enabled);
     self.isNavigatorEnabled = ko.observable(options.is_navigator_enabled);
 
+    self.CoordinatorEditorViewModel = CoordinatorEditorViewModel;
+    self.RunningCoordinatorModel = RunningCoordinatorModel;
+
     self.canSave = ko.computed(function() {
       // Saved query or history but history coming from a saved query
       return self.selectedNotebook() && self.selectedNotebook().canWrite() && (

+ 29 - 23
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -46,7 +46,10 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <script src="${ static('desktop/ext/js/markdown.min.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.hotkeys.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.mousewheel.min.js') }"></script>
+
+%if 'oozie' in apps:
 <script src="${ static('oozie/js/dashboard-utils.js') }" type="text/javascript" charset="utf-8"></script>
+% endif
 
 %if ENABLE_QUERY_BUILDER.get():
 <!-- For query builder -->
@@ -86,7 +89,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
 </script>
 <!-- End query builder imports -->
-%endif
+% endif
 
 <script src="${ static('desktop/ext/js/bootstrap-editable.min.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/chosen/chosen.jquery.min.js') }" type="text/javascript" charset="utf-8"></script>
@@ -155,20 +158,14 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
 <script src="${ static('desktop/ext/js/download.min.js') }"></script>
 
-## Scheduler
-## ChangeTracker
 <%namespace name="dashboard" file="/common_dashboard.mako" />
-## ${ dashboard.import_layout() }
-## <link href="${ static('desktop/css/jqCron.css') }" rel="stylesheet" type="text/css" />
-## <script src="${ static('desktop/js/jqCron.js') }" type="text/javascript"></script>
 <script src="${ static('desktop/ext/js/moment-timezone-with-data.min.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/tzdetect.js') }" type="text/javascript" charset="utf-8"></script>
 
 <script src="${ static('desktop/js/ko.common-dashboard.js') }" type="text/javascript" charset="utf-8"></script>
-## <script src="${ static('oozie/js/coordinator-editor.ko.js') }" type="text/javascript" charset="utf-8"></script>
-## <script src="${ static('oozie/js/editor2-utils.js') }" type="text/javascript" charset="utf-8"></script>
-## submit popup
+% if 'oozie' in apps:
 <script src="${ static('oozie/js/editor2-utils.js') }" type="text/javascript" charset="utf-8"></script>
+% endif
 
 ${ require.config() }
 
@@ -292,10 +289,12 @@ ${ hueIcons.symbols() }
                 <img src="${ static('rdbms/art/icon_rdbms_48.png') }" class="app-icon" />
                 DB Query
               <!-- /ko -->
+              % if 'pig' in apps:
               <!-- ko if: editorType() == 'pig' -->
                 <img src="${ static('pig/art/icon_pig_48.png') }" class="app-icon" />
                 Pig
               <!-- /ko -->
+              % endif
               <!-- ko if: editorType() == 'beeswax' || editorType() == 'hive' -->
                 <img src="${ static('beeswax/art/icon_beeswax_48.png') }" class="app-icon" />
                 Hive
@@ -885,7 +884,7 @@ ${ hueIcons.symbols() }
   </div>
 </div>
 
-%if ENABLE_QUERY_BUILDER.get():
+% if ENABLE_QUERY_BUILDER.get():
 <div id="invalidQueryBuilder" class="modal hide">
   <div class="modal-header">
     <a href="#" class="close" data-dismiss="modal">&times;</a>
@@ -898,7 +897,7 @@ ${ hueIcons.symbols() }
     <a class="btn" data-dismiss="modal">${_('Close')}</a>
   </div>
 </div>
-%endif
+% endif
 
 <a title="${_('Toggle Assist')}" class="pointer show-assist" data-bind="visible: !$root.isLeftPanelVisible() && $root.assistAvailable(), click: function() { $root.isLeftPanelVisible(true); huePubSub.publish('assist.set.manual.visibility'); }">
   <i class="fa fa-chevron-right"></i>
@@ -984,9 +983,9 @@ ${ hueIcons.symbols() }
           }
         }">
       </div>
-      %if hasattr(caller, "addSnippetHTML"):
+      % if hasattr(caller, "addSnippetHTML"):
         ${ caller.addSnippetHTML() }
-      %endif
+      % endif
     </div>
   </div>
 
@@ -994,7 +993,7 @@ ${ hueIcons.symbols() }
   <div class="context-panel" data-bind="css: {'visible': isContextPanelVisible}">
     <ul class="nav nav-tabs">
       <li class="active"><a href="#sessionsTab" data-toggle="tab">${_('Sessions')}</a></li>
-      % if ENABLE_QUERY_SCHEDULING.get():
+      % if ENABLE_QUERY_SCHEDULING.get() and 'oozie' in apps:
       <li><a href="#scheduleTab" data-toggle="tab">${_('Schedule')}</a></li>
       <li><a href="#scheduledJobsTab" data-toggle="tab">${_('Jobs')}</a></li>
       % endif
@@ -1185,9 +1184,9 @@ ${ hueIcons.symbols() }
             <input class="input-small history-filter" type="text" data-bind="visible: queriesFilterVisible, blurHide: queriesFilterVisible, clearable: queriesFilter, valueUpdate:'afterkeydown'" placeholder="${ _('Search...') }">
           </a>
         </li>
-        %if ENABLE_QUERY_BUILDER.get():
+        % if ENABLE_QUERY_BUILDER.get():
         <li data-bind="click: function(){ currentQueryTab('queryBuilderTab'); }, css: {'active': currentQueryTab() == 'queryBuilderTab'}"><a class="inactive-action" href="#queryBuilderTab" data-toggle="tab">${_('Query Builder')}</a></li>
-        %endif
+        % endif
         <!-- ko if: result.hasSomeResults -->
         <li data-bind="click: function(){ currentQueryTab('queryResults'); }, css: {'active': currentQueryTab() == 'queryResults'}">
           <a class="inactive-action" href="#queryResults" data-toggle="tab">${_('Results')}
@@ -1294,7 +1293,7 @@ ${ hueIcons.symbols() }
           </div>
         </div>
 
-        %if ENABLE_QUERY_BUILDER.get():
+        % if ENABLE_QUERY_BUILDER.get():
         <div class="tab-pane margin-top-10" id="queryBuilderTab" data-bind="css: {'active': currentQueryTab() == 'queryBuilderTab'}">
           <div id="queryBuilderAlert" style="display: none" class="alert">${ _('There are currently no rules defined. To get started, right click on any table column in the SQL Assist panel.') }</div>
           <table id="queryBuilder" class="table table-condensed">
@@ -1311,7 +1310,7 @@ ${ hueIcons.symbols() }
             <button class="btn btn-primary disable-feedback" data-bind="click: generateQuery">${_('Build query')}</button>
           </div>
         </div>
-        %endif
+        % endif
 
         <div class="tab-pane" id="queryResults" data-bind="css: {'active': currentQueryTab() == 'queryResults'}">
           <!-- ko template: { if: ['text', 'jar', 'py', 'markdown'].indexOf(type()) == -1, name: 'snippet-results' } --><!-- /ko -->
@@ -2600,14 +2599,17 @@ ${ hueIcons.symbols() }
     "knockout",
     "ko.charts",
     "notebook/js/notebook.ko",
+    % if 'oozie' in apps:
     "oozie/js/coordinator-editor.ko",
+    "oozie/js/list-oozie-coordinator.ko",
+    % endif
     "assistPanel",
     "knockout-mapping",
     "knockout-sortable",
     "ko.editable",
     "ko.hue-bindings",
     "ko.switch-case"
-  ], function (ko, charts, EditorViewModel, CoordinatorEditorViewModel) {
+  ], function (ko, charts, EditorViewModel, CoordinatorEditorViewModel, RunningCoordinatorModel) {
 
     ko.options.deferUpdates = true;
 
@@ -2615,9 +2617,9 @@ ${ hueIcons.symbols() }
       user: '${ user.username }',
       userId: ${ user.id },
       assistAvailable: true,
-      %if conf.USE_NEW_AUTOCOMPLETER.get():
+      % if conf.USE_NEW_AUTOCOMPLETER.get():
       useNewAutocompleter: true,
-      %endif
+      % endif
       autocompleteTimeout: ${ conf.EDITOR_AUTOCOMPLETE_TIMEOUT.get() },
       snippetViewSettings: {
         default: {
@@ -2995,7 +2997,11 @@ ${ hueIcons.symbols() }
       var i18n = {
         errorLoadingDatabases: "${ _('There was a problem loading the databases') }"
       }
+      % if 'oozie' in apps:
+      viewModel = new EditorViewModel(${ editor_id or 'null' }, ${ notebooks_json | n,unicode }, VIEW_MODEL_OPTIONS, i18n, CoordinatorEditorViewModel, RunningCoordinatorModel);
+      % else:
       viewModel = new EditorViewModel(${ editor_id or 'null' }, ${ notebooks_json | n,unicode }, VIEW_MODEL_OPTIONS, i18n);
+      % endif
       ko.applyBindings(viewModel);
       viewModel.init();
 
@@ -3037,9 +3043,9 @@ ${ hueIcons.symbols() }
           $(".add-snippet").show();
           % if conf.CUSTOM.BANNER_TOP_HTML.get():
           $(".main-content").css("top", "112px");
-          %else:
+          % else:
           $(".main-content").css("top", "82px");
-          %endif
+          % endif
           redrawFixedHeaders(200);
           $(window).unbind("keydown", exitPlayerMode);
         }

+ 3 - 0
desktop/libs/notebook/src/notebook/views.py

@@ -21,6 +21,7 @@ import logging
 from django.db.models import Q
 from django.utils.translation import ugettext as _
 
+from desktop import appmanager
 from desktop.conf import USE_NEW_EDITOR
 from desktop.lib.django_util import render, JsonResponse
 from desktop.lib.exceptions_renderable import PopupException
@@ -74,6 +75,7 @@ def notebook(request):
   return render('notebook.mako', request, {
       'editor_id': notebook_id or None,
       'notebooks_json': '{}',
+      'apps': appmanager.get_apps_dict(request.user).keys(),
       'options_json': json.dumps({
           'languages': get_interpreters(request.user),
           'session_properties': SparkApi.get_properties(),
@@ -97,6 +99,7 @@ def editor(request):
   return render('editor.mako', request, {
       'editor_id': editor_id or None,
       'notebooks_json': '{}',
+      'apps': appmanager.get_apps_dict(request.user).keys(),
       'options_json': json.dumps({
           'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
           'mode': 'editor',