Эх сурвалжийг харах

HUE-1176 [jb] Display task history in the top right corner

Romain Rigaux 9 жил өмнө
parent
commit
0a1ae28

+ 3 - 0
desktop/core/src/desktop/models.py

@@ -960,6 +960,9 @@ class Document2Manager(models.Manager, Document2QueryMixin):
   def get_history(self, user, doc_type, include_trashed=False):
     return self.documents(user, perms='owned', include_history=True, include_trashed=include_trashed).filter(type=doc_type, is_history=True)
 
+  def get_tasks_history(self, user):
+    return self.documents(user, perms='owned', include_history=True, include_trashed=False, include_managed=True).filter(is_history=True, is_managed=True).exclude(name='pig-app-hue-script')
+
   def get_home_directory(self, user):
     try:
       return self.get(owner=user, parent_directory=None, name=Document2.HOME_DIR, type='directory')

+ 74 - 6
desktop/core/src/desktop/templates/responsive.mako

@@ -203,12 +203,15 @@ ${ hueIcons.symbols() }
           <button class="btn" title="${_('Submission history')}" data-bind="toggle: historyPanelVisible"><i class="fa fa-history"></i>  <div class="jobs-badge">20</div></button>
         </div>
         <div class="jobs-panel" data-bind="visible: historyPanelVisible" style="display: none;">
-          <div style="font-size: 15px; font-weight: 300">1hours ago <i class="fa fa-fighter-jet fa-fw"></i> Extracting hdfs://.../mini-earthquake.csv.zip to /user/romain/mini-earthquake.csv</div>
-          <div style="font-size: 15px; font-weight: 300">3hours ago <i class="fa fa-fighter-jet fa-fw"></i> Executing query 'SELECT * FROM web_logs limit 500' </div>
-          <div style="font-size: 15px; font-weight: 300">3hours ago <i class="fa fa-fighter-jet fa-fw"></i> Running Schedule 'Data log usage by day' </div>
-          <div style="font-size: 15px; font-weight: 300">3hours ago <i class="fa fa-fighter-jet fa-fw"></i> Exporting query result 'SELECT * FROM sample_07 where salary is not NULL' to /user/romain/escalation</div>
-          <div style="font-size: 15px; font-weight: 300">4hours ago <i class="fa fa-check fa-fw"></i> Exporting query result 'Top 25 Hue escalations' to /user/romain/escalation</div>
-          <div style="font-size: 15px; font-weight: 300">3hours ago <i class="fa fa-check fa-fw"></i> Indexing /user/romain/mini-earthquake.csv to mini-earthquake</div>
+          <!-- ko if: editorVM.selectedNotebook() -->
+            <ul>
+              <!-- ko foreach: editorVM.selectedNotebook().history -->
+                <li style="font-size: 15px; font-weight: 300">
+                  1hours ago <i class="fa fa-fighter-jet fa-fw"></i> <span data-bind="text: $data.name"> <span data-bind="text: $data.query"></span>
+                </li>
+              <!-- /ko -->
+            </ul>
+          <!-- /ko -->
         </div>
 
         <div class="compose-action btn-group">
@@ -387,6 +390,15 @@ ${ hueIcons.symbols() }
 <script src="${ static('desktop/js/jquery.tour.js') }"></script>
 <script src="${ static('desktop/js/sqlFunctions.js') }"></script>
 
+# Task History
+<script src="${ static('desktop/js/autocomplete/sql.js') }"></script>
+<script src="${ static('desktop/js/sqlAutocompleter.js') }"></script>
+<script src="${ static('desktop/js/sqlAutocompleter2.js') }"></script>
+<script src="${ static('desktop/js/hdfsAutocompleter.js') }"></script>
+<script src="${ static('desktop/js/autocompleter.js') }"></script>
+<script src="${ static('desktop/js/hue.json.js') }"></script>
+<script src="${ static('notebook/js/notebook.ko.js') }"></script>
+
 <script type="text/javascript" charset="utf-8">
 (function () {
     var proxiedKORegister = ko.components.register;
@@ -781,6 +793,62 @@ ${ assist.assistPanel() }
       TopNavViewModel.prototype.performSearch = function () {
       };
 
+
+      self.editorVM = new EditorViewModel(null, '', {
+        user: '${ user.username }',
+        userId: ${ user.id },
+        languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
+        is_history: true,
+        snippetViewSettings: {
+          java : {
+            snippetIcon: 'fa-file-archive-o '
+          },
+          hive: {
+            placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
+            aceMode: 'ace/mode/hive',
+            snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
+            sqlDialect: true
+          },
+          impala: {
+            placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
+            aceMode: 'ace/mode/impala',
+            snippetImage: '${ static("impala/art/icon_impala_48.png") }',
+            sqlDialect: true
+          }
+        }
+      });
+      self.editorVM.editorMode(true);
+      self.editorVM.newNotebook();
+
+/**
+          topNavViewModel.editorVM.openNotebook(resp.history_uuid, null, true, function(){
+          topNavViewModel.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
+              if (val == 100){
+                //self.indexingStarted(false);
+                //self.isIndexing(false);
+                //self.indexingSuccess(true);
+              }
+            });
+            self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
+              if (val == 'failed'){
+                self.isIndexing(false);
+                self.indexingStarted(false);
+                self.indexingError(true);
+              } else if (val == 'available') {
+                var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
+                if (! snippet.result.handle().has_more_statements) {
+                  if (self.editorVM.selectedNotebook().onSuccessUrl()) {
+                    window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
+                  }
+                } else { // Perform last DROP statement execute
+                  snippet.execute();
+                }
+              }
+            });
+            topNavViewModel.editorVM.selectedNotebook().snippets()[0].checkStatus();
+          });
+*/
+
       var topNavViewModel = new TopNavViewModel();
       ko.applyBindings(topNavViewModel, $('.top-nav')[0]);
       ko.applyBindings(topNavViewModel, $('.left-nav')[0]);

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

@@ -420,8 +420,12 @@ def get_history(request):
   doc_type = request.GET.get('doc_type')
   doc_text = request.GET.get('doc_text')
   limit = min(request.GET.get('len', 50), 100)
+  is_history = request.GET.get('is_history', 'false') == 'true'
 
-  docs = Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user)
+  if is_history:
+    docs = Document2.objects.get_tasks_history(user=request.user)
+  else:
+    docs = Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user)
 
   if doc_text:
     docs = docs.filter(Q(name__icontains=doc_text) | Q(description__icontains=doc_text) | Q(search__icontains=doc_text))

+ 4 - 3
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1569,6 +1569,7 @@ var EditorViewModel = (function() {
     self.historyFilter.subscribe(function(val){
       self.fetchHistory();
     });
+    self.loadingHistory = ko.observable(self.history().length == 0);
 
     self.schedulerViewModel = null;
     self.schedulerViewModelIsLoaded = ko.observable(false);
@@ -1585,8 +1586,6 @@ var EditorViewModel = (function() {
 
     self.avoidClosing = false;
 
-    self.loadingHistory = ko.observable(self.history().length == 0);
-    // TODO: Move fetchHistory and clearHistory into the Snippet and drop self.selectedSnippet. Actually, history should go in the assist in Hue 4.
     self.getSession = function (session_type) {
       var _s = null;
       $.each(self.sessions(), function (index, s) {
@@ -1920,7 +1919,8 @@ var EditorViewModel = (function() {
       $.get("/notebook/api/get_history", {
         doc_type: self.selectedSnippet(),
         limit: 50,
-        doc_text: self.historyFilter()
+        doc_text: self.historyFilter(),
+        is_history: vm.isHistory()
       }, function(data) {
         var parsedHistory = [];
         if (data && data.history){
@@ -2170,6 +2170,7 @@ var EditorViewModel = (function() {
     self.userId = options.userId;
     self.isMobile = ko.observable(options.mobile);
     self.isResponsive = ko.observable(options.responsive);
+    self.isHistory = ko.observable(options.is_history || false);
     self.editorType = ko.observable(options.editor_type);
     self.editorType.subscribe(function(newVal) {
       self.editorMode(newVal != 'notebook');