Преглед изворни кода

HUE-3629 [editor] Add executed query to the history

Romain Rigaux пре 9 година
родитељ
комит
40019f8

+ 32 - 9
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -380,7 +380,7 @@
     }
 
     self.result = new Result(snippet, snippet.result);
-    if (!self.result.hasSomeResults()) {
+    if (! self.result.hasSomeResults()) {
       self.currentQueryTab('queryHistory');
     }
     self.showGrid = ko.observable(typeof snippet.showGrid != "undefined" && snippet.showGrid != null ? snippet.showGrid : true);
@@ -591,9 +591,20 @@
         self.currentQueryTab('queryResults');
         self.statusForButtons('executed');
         if (vm.editorMode && data.history_id) {
-          hueUtils.changeURL('/notebook/editor?editor=' + data.history_id);
+          var url = '/notebook/editor?editor=' + data.history_id;
+          hueUtils.changeURL(url);
           notebook.id(data.history_id);
           notebook.uuid(data.history_uuid);
+
+          notebook.history.push( // TODO append to beginning
+            self._makeHistoryRecord(
+                url,
+                self.statement_raw(),
+                self.lastExecuted(),
+                self.status(),
+                notebook.uuid()
+            )
+          );
         }
         if (data.status == 0) {
           self.result.handle(data.handle);
@@ -1263,19 +1274,31 @@
         var parsedHistory = [];
         if (data && data.history){
           data.history.forEach(function(nbk){
-            parsedHistory.push({
-              url: nbk.absoluteUrl,
-              query: nbk.data.snippets[0].statement_raw.substring(0, 1000) + (nbk.data.snippets[0].statement_raw.length > 1000 ? '...' : ''),
-              lastExecuted: nbk.data.snippets[0].lastExecuted,
-              status: nbk.data.snippets[0].status,
-              uuid: nbk.uuid
-            });
+            parsedHistory.push(
+              self._makeHistoryRecord(
+                nbk.absoluteUrl,
+                nbk.data.snippets[0].statement_raw,
+                nbk.data.snippets[0].lastExecuted,
+                nbk.data.snippets[0].status,
+                nbk.uuid
+              )
+            );
           });
         }
         self.history(parsedHistory);
       });
     };
 
+    self._makeHistoryRecord = function(url, statement, lastExecuted, status, uuid) {
+      return {
+          url: url,
+          query: statement.substring(0, 1000) + (statement.length > 1000 ? '...' : ''),
+          lastExecuted: lastExecuted,
+          status: status,
+          uuid: uuid
+      };
+    };
+
     self.schedule = function() {
       logGA('schedule');
       $.post("/oozie/editor/document/schedule/", {

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

@@ -1030,24 +1030,24 @@ ${ hueIcons.symbols() }
           <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>
-                <td style="width: 25px" class="muted" data-bind="style:{'border-top-width': $index()==0 ? '0' : ''}">
+                <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' -->
-                  <div class="history-status" data-bind="tooltip : { title: '${ _("Query running") }', placement: 'bottom' }"><i class="fa fa-fighter-jet fa-fw"></i></div>
+                  <div class="history-status" data-bind="tooltip: { title: '${ _("Query running") }', placement: 'bottom' }"><i class="fa fa-fighter-jet fa-fw"></i></div>
                   <!-- /ko -->
                   <!-- ko case: 'failed' -->
-                  <div class="history-status" data-bind="tooltip : { title: '${ _("Query failed") }', placement: 'bottom' }"><i class="fa fa-exclamation fa-fw"></i></div>
+                  <div class="history-status" data-bind="tooltip: { title: '${ _("Query failed") }', placement: 'bottom' }"><i class="fa fa-exclamation fa-fw"></i></div>
                   <!-- /ko -->
                   <!-- ko case: 'available' -->
-                  <div class="history-status" data-bind="tooltip : { title: '${ _("Result available") }', placement: 'bottom' }"><i class="fa fa-check fa-fw"></i></div>
+                  <div class="history-status" data-bind="tooltip: { title: '${ _("Result available") }', placement: 'bottom' }"><i class="fa fa-check fa-fw"></i></div>
                   <!-- /ko -->
                   <!-- ko case: 'expired' -->
-                  <div class="history-status" data-bind="tooltip : { title: '${ _("Result expired") }', placement: 'bottom' }"><i class="fa fa-unlink fa-fw"></i></div>
+                  <div class="history-status" data-bind="tooltip: { title: '${ _("Result expired") }', placement: 'bottom' }"><i class="fa fa-unlink fa-fw"></i></div>
                   <!-- /ko -->
                   <!-- /ko -->
                 </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 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>