Browse Source

HUE-6122 [core] Aggregate task history snippets into a single task that gets updated

Romain Rigaux 8 years ago
parent
commit
2cb6a67

+ 1 - 1
desktop/core/src/desktop/templates/ko_components.mako

@@ -346,7 +346,7 @@ from desktop.views import _ko
                 notebook._makeHistoryRecord(
                     notebook.onSuccessUrl(),
                     notebook.description(),
-                    notebook.snippets()[0].lastExecuted(),
+                    (new Date()).getTime(),
                     notebook.snippets()[0].status(),
                     notebook.name(),
                     notebook.uuid()

+ 20 - 14
desktop/libs/notebook/src/notebook/api.py

@@ -348,6 +348,7 @@ def _save_notebook(notebook, user):
 
   return notebook_doc, save_as
 
+
 @api_error_handler
 @require_POST
 @check_document_modify_permission()
@@ -369,14 +370,18 @@ def save_notebook(request):
 def _historify(notebook, user):
   query_type = notebook['type']
   name = notebook['name'] if (notebook['name'] and notebook['name'].strip() != '') else DEFAULT_HISTORY_NAME
+  is_managed = notebook.get('isManaged') == True  # Prevents None
 
-  history_doc = Document2.objects.create(
-    name=name,
-    type=query_type,
-    owner=user,
-    is_history=True,
-    is_managed=notebook.get('isManaged') == True # No None
-  )
+  if is_managed and Document2.objects.filter(uuid=notebook['uuid']).exists():
+    history_doc = Document2.objects.get(uuid=notebook['uuid'])
+  else:
+    history_doc = Document2.objects.create(
+      name=name,
+      type=query_type,
+      owner=user,
+      is_history=True,
+      is_managed=is_managed
+    )
 
   # Link history of saved query
   if notebook['isSaved']:
@@ -384,13 +389,14 @@ def _historify(notebook, user):
     notebook['parentSavedQueryUuid'] = parent_doc.uuid
     history_doc.dependencies.add(parent_doc)
 
-  Document.objects.link(
-    history_doc,
-    name=history_doc.name,
-    owner=history_doc.owner,
-    description=history_doc.description,
-    extra=query_type
-  )
+  if not is_managed:
+    Document.objects.link(
+      history_doc,
+      name=history_doc.name,
+      owner=history_doc.owner,
+      description=history_doc.description,
+      extra=query_type
+    )
 
   notebook['uuid'] = history_doc.uuid
   history_doc.update_data(notebook)

+ 25 - 16
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1071,12 +1071,14 @@ var EditorViewModel = (function() {
         self.statusForButtons('executed');
         stopLongOperationTimeout();
 
-        if (vm.editorMode() && data.history_id && ! vm.isNotificationManager()) {
-          var url = '/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.history_id;
-          if (vm.isHue4()){
-            url = vm.URLS.hue4 + '?editor=' + data.history_id;
+        if (vm.editorMode() && data.history_id) {
+          if (! vm.isNotificationManager()) {
+            var url = '/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.history_id;
+            if (vm.isHue4()){
+              url = vm.URLS.hue4 + '?editor=' + data.history_id;
+            }
+            vm.changeURL(url);
           }
-          vm.changeURL(url);
           notebook.id(data.history_id);
           notebook.uuid(data.history_uuid);
           notebook.isHistory(true);
@@ -1101,16 +1103,23 @@ var EditorViewModel = (function() {
 
         if (data.handle) {
           if (vm.editorMode()) {
-            notebook.history.unshift(
-              notebook._makeHistoryRecord(
-                url,
-                vm.isNotificationManager() ? notebook.description() : data.handle.statement,
-                self.lastExecuted(),
-                self.status(),
-                notebook.name(),
-                notebook.uuid()
-              )
-            );
+            if (vm.isNotificationManager()) { // Update task status
+              var tasks = $.grep(notebook.history(), function(row) { return row.uuid() == notebook.uuid()});
+              if (tasks.length == 1) {
+                tasks[0].status(self.status()); console.log(tasks[0].uuid());
+              }
+            } else {
+              notebook.history.unshift(
+                notebook._makeHistoryRecord(
+                  url,
+                  data.handle.statement,
+                  self.lastExecuted(),
+                  self.status(),
+                  notebook.name(),
+                  notebook.uuid()
+                )
+              );
+            }
           }
 
           if (data.handle.statements_count != null) {
@@ -1432,7 +1441,7 @@ var EditorViewModel = (function() {
                 }
               }
               if (! self.result.handle().has_more_statements && vm.successUrl()) {
-                window.location.href = vm.successUrl(); // Not used anymore in Hue 4 
+                window.location.href = vm.successUrl(); // Not used anymore in Hue 4
               }
             }
             else if (self.status() == 'success') {