Procházet zdrojové kódy

HUE-7254 [editor] Update the Schedule tab when saving a new query without requiring a page refresh

Save as logic was reversed
Romain Rigaux před 8 roky
rodič
revize
70bca46

+ 13 - 15
desktop/core/src/desktop/templates/assist.mako

@@ -2352,30 +2352,28 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, get_ord
   <script type="text/html" id="schedule-panel-template">
     <div class="assist-inner-panel">
       <div class="assist-flex-panel">
-        <div class="assist-flex-header"><div class="assist-inner-header">${ _('Schedule') }</div></div>
         <!-- ko if: selectedNotebook() && selectedNotebook().isBatchable() -->
         <!-- ko with: selectedNotebook() -->
         <div class="tab-pane" id="scheduleTab">
+          <!-- ko ifnot: isSaved() && ! isHistory() -->
+          ${ _('Query needs to be saved.') }
+          <!-- /ko -->
           <!-- ko if: isSaved() && ! isHistory() -->
-          <!-- ko if: schedulerViewModelIsLoaded() && schedulerViewModel.coordinator.isDirty() -->
-          <a data-bind="click: save" href="javascript: void(0);">${ _('Save changes') }</a>
+            <!-- ko if: schedulerViewModelIsLoaded() && schedulerViewModel.coordinator.isDirty() -->
+            <a data-bind="click: saveScheduler" href="javascript: void(0);">${ _('Save changes') }</a>
+            <!-- /ko -->
+            <!-- ko if: schedulerViewModelIsLoaded() && ! schedulerViewModel.coordinator.isDirty() && ! viewSchedulerId()-->
+            <a data-bind="click: showSubmitPopup" href="javascript: void(0);">${ _('Start') }</a>
+            <!-- /ko -->
+            <!-- ko if: schedulerViewModelIsLoaded() && viewSchedulerId()-->
+            <a data-bind="click: function() { huePubSub.publish('show.jobs.panel', viewSchedulerId()) }, clickBubble: false" href="javascript: void(0);">
+              ${ _('View') }
+            </a>
           <!-- /ko -->
-          <!-- ko if: schedulerViewModelIsLoaded() && ! schedulerViewModel.coordinator.isDirty() && ! viewSchedulerId()-->
-          <a data-bind="click: showSubmitPopup" href="javascript: void(0);">${ _('Start') }</a>
-          <!-- /ko -->
-          <!-- ko if: schedulerViewModelIsLoaded() && viewSchedulerId()-->
-          <a data-bind="click: function() { huePubSub.publish('show.jobs.panel', viewSchedulerId()) }, clickBubble: false" href="javascript: void(0);">
-            ${ _('View') }
-          </a>
           <!-- /ko -->
           <br>
           <br>
           <div id="schedulerEditor"></div>
-          <!-- /ko -->
-
-          <!-- ko ifnot: isSaved() && ! isHistory() -->
-          ${ _('Query needs to be saved first.') }
-          <!-- /ko -->
         </div>
         <!-- /ko -->
         <!-- /ko -->

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

@@ -311,7 +311,7 @@ def get_logs(request):
 
 def _save_notebook(notebook, user):
   notebook_type = notebook.get('type', 'notebook')
-  save_as = True
+  save_as = False
 
   if notebook.get('parentSavedQueryUuid'): # We save into the original saved query, not into the query history
     notebook_doc = Document2.objects.get_by_uuid(user=user, uuid=notebook['parentSavedQueryUuid'])
@@ -320,7 +320,7 @@ def _save_notebook(notebook, user):
   else:
     notebook_doc = Document2.objects.create(name=notebook['name'], uuid=notebook['uuid'], type=notebook_type, owner=user)
     Document.objects.link(notebook_doc, owner=notebook_doc.owner, name=notebook_doc.name, description=notebook_doc.description, extra=notebook_type)
-    save_as = False
+    save_as = True
 
     if notebook.get('directoryUuid'):
       notebook_doc.parent_directory = Document2.objects.get_by_uuid(user=user, uuid=notebook.get('directoryUuid'), perm_type='write')

+ 13 - 8
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2020,14 +2020,14 @@ var EditorViewModel = (function() {
         }).length == self.snippets().length;
     });
 
-    self.isExecutingAll = ko.observable(typeof notebook.isExecutingAll != "undefined" && notebook.isExecutingAll != null ? notebook.isExecutingAll : false);
+    self.isExecutingAll = ko.observable(!! notebook.isExecutingAll);
     self.cancelExecutingAll = function() {
       var index = self.executingAllIndex();
       if (self.isExecutingAll() && self.snippets()[index]) {
         self.snippets()[index].cancel();
       }
     };
-    self.executingAllIndex = ko.observable(typeof notebook.executingAllIndex != "undefined" && notebook.executingAllIndex != null ? notebook.executingAllIndex : 0);
+    self.executingAllIndex = ko.observable(notebook.executingAllIndex || 0);
 
     self.retryModalConfirm = null;
     self.retryModalCancel = null;
@@ -2257,10 +2257,11 @@ var EditorViewModel = (function() {
         if (data.status == 0) {
           self.id(data.id);
           self.isSaved(true);
+          var wasHistory = self.isHistory();
           self.isHistory(false);
           $(document).trigger("info", data.message);
           if (vm.editorMode()) {
-            if (data.save_as) {
+            if (! data.save_as) {
               var existingQuery = self.snippets()[0].queries().filter(function (item) {
                 return item.uuid() === data.uuid
               });
@@ -2277,6 +2278,9 @@ var EditorViewModel = (function() {
               self.saveScheduler();
               self.schedulerViewModel.coordinator.refreshParameters();
             }
+            if (wasHistory || data.save_as) {
+              self.loadScheduler();
+            }
 
             if (vm.isHue4()){
               vm.changeURL(vm.URLS.hue4 + '?editor=' + data.id);
@@ -2290,7 +2294,7 @@ var EditorViewModel = (function() {
               vm.changeURL('/notebook/notebook?notebook=' + data.id);
             }
           }
-          if (callback) {
+          if (typeof callback == "function") {
             callback();
           }
         } else {
@@ -2540,9 +2544,7 @@ var EditorViewModel = (function() {
                   self.schedulerViewModelIsLoaded(true);
 
                   if (_action == 'new') {
-                    self.coordinatorUuid(UUID());
-                    self.schedulerViewModel.coordinator.uuid(self.coordinatorUuid());
-                    self.schedulerViewModel.coordinator.properties.document(self.uuid());
+                    self.schedulerViewModel.coordinator.properties.document(self.uuid()); // Expected for triggering the display
                   }
                 }
               });
@@ -2570,7 +2572,10 @@ var EditorViewModel = (function() {
         self.schedulerViewModel.coordinator.isManaged(true);
         self.schedulerViewModel.coordinator.properties.document(self.uuid());
         self.schedulerViewModel.save(function(data) {
-          self.coordinatorUuid(data.uuid);
+          if (! self.coordinatorUuid()) {
+            self.coordinatorUuid(data.uuid);
+            self.save();
+          }
         });
       }
     };