Jelajahi Sumber

HUE-3215 [editor] Add a call to check the status of the queries in the history

Romain Rigaux 9 tahun lalu
induk
melakukan
b992b0e

+ 5 - 0
desktop/libs/notebook/src/notebook/api.py

@@ -113,6 +113,11 @@ def check_status(request):
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
 
+  if not snippet:
+    nb_doc = Document2.objects.get_by_uuid(user=request.user, uuid=notebook['id'])
+    notebook = Notebook(document=nb_doc).get_data()
+    snippet = notebook['snippets'][0]
+
   try:
     response['query_status'] = get_api(request, snippet).check_status(notebook, snippet)
     response['status'] = 0

+ 5 - 2
desktop/libs/notebook/src/notebook/decorators.py

@@ -43,8 +43,11 @@ def check_document_access_permission():
 
       try:
         if notebook_id:
-          document = Document2.objects.get(id=notebook_id)
-          document.can_read_or_exception(request.user)
+          if str(notebook_id).isdigit():
+            document = Document2.objects.get(id=notebook_id)
+            document.can_read_or_exception(request.user)
+          else:
+            Document2.objects.get_by_uuid(user=request.user, uuid=notebook_id)
       except Document2.DoesNotExist:
         raise PopupException(_('Document %(id)s does not exist') % {'id': notebook_id})
 

+ 19 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1342,15 +1342,32 @@
       });
     };
 
+    self.updateHistory = function () {
+      // TODO fetch list
+
+      // Update statuses
+      $.each(
+        $.grep(self.history(), function(item) { return item.status() == 'available' || item.status() == 'running' || item.status() == 'starting'; }), function(index, item) {
+          $.post("/notebook/api/check_status", {
+            notebook: ko.mapping.toJSON({id: item.uuid()}),
+          }, function (data) {
+            var status = data.status == -3 ? 'expired' : data.query_status.status;
+            if (item.status() != status) {
+              item.status(status);
+            }
+        });
+      });
+    };
+
     self._makeHistoryRecord = function(url, statement, lastExecuted, status, name, uuid) {
-      return {
+      return ko.mapping.fromJS({
           url: url,
           query: statement.substring(0, 1000) + (statement.length > 1000 ? '...' : ''),
           lastExecuted: lastExecuted,
           status: status,
           name: name,
           uuid: uuid
-      };
+      });
     };
 
     self.schedule = function() {

+ 6 - 4
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1062,8 +1062,10 @@ ${ hueIcons.symbols() }
             <!-- ko if: $parent.history().length > 0 -->
             <table class="table table-condensed margin-top-10 history-table">
               <tbody data-bind="foreach: $parent.history">
-                <tr class="pointer" data-bind="click: function() { if (getSelection().toString().length == 0) { $root.openNotebook(uuid) } }">
-                  <td style="width: 100px" class="muted" data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><span data-bind="text: moment(lastExecuted).fromNow(), attr: {title: moment(lastExecuted).format('LLL')}"></span></td>
+                <tr class="pointer" data-bind="click: function() { if (getSelection().toString().length == 0) { $root.openNotebook(uuid()) } }">
+                  <td style="width: 100px" class="muted" data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}">
+                    <span data-bind="text: moment(lastExecuted()).fromNow(), attr: {title: moment(lastExecuted()).format('LLL')}"></span>
+                  </td>
                   <td style="width: 25px" class="muted" data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}">
                     <!-- ko switch: status -->
                     <!-- ko case: 'running' -->
@@ -1080,8 +1082,8 @@ ${ hueIcons.symbols() }
                     <!-- /ko -->
                     <!-- /ko -->
                   </td>
-                  <td style="width: 25px" class="muted" data-bind="ellipsis: {data: name, length: 30}, style: {'border-top-width': $index() == 0 ? '0' : ''}"></td>
-                  <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query, flavor: $parent.type" class="history-item"></div></td>
+                  <td style="width: 25px" class="muted" data-bind="ellipsis: {data: name(), length: 30}, style: {'border-top-width': $index() == 0 ? '0' : ''}"></td>
+                  <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query(), flavor: $parent.type" class="history-item"></div></td>
                 </tr>
               </tbody>
             </table>