Browse Source

HUE-3493 [editor] Load queries without refreshing the page

Romain Rigaux 9 years ago
parent
commit
8374d15

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

@@ -298,6 +298,7 @@ def get_history(request):
   response['history'] = [{
       'name': doc.name,
       'id': doc.id,
+      'uuid': doc.uuid,
       'data': Notebook(document=doc).get_data(),
       'absoluteUrl': doc.get_absolute_url()
       } for doc in Document2.objects.get_history(doc_type='query-%s' % doc_type, user=request.user).order_by('-last_modified')[:25]]

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

@@ -689,7 +689,7 @@
         targetPlatform: 'impala'
       }, function(data) {
         if (data.status == 0) {
-         self.suggestion(ko.mapping.fromJS(data.query_compatibility.platformCompilationStatus.Impala));	
+         self.suggestion(ko.mapping.fromJS(data.query_compatibility.platformCompilationStatus.Impala));  
          self.hasSuggestion(true);
         } else {
           $(document).trigger("error", data.message);
@@ -1252,7 +1252,8 @@
               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
+              status: nbk.data.snippets[0].status,
+              uuid: nbk.uuid
             });
           });
         }
@@ -1489,6 +1490,18 @@
       }
     };
 
+    self.openNotebook = function (uuid) {
+      $.get('/desktop/api2/doc/', {
+        uuid: uuid,
+        data: true
+   	  }, function(data) {
+   		self.notebooks.removeAll();
+   	    self.loadNotebook(data.data);
+   	    self.selectedNotebook(self.notebooks()[0]);
+   	    hueUtils.changeURL('/notebook/editor?editor=' + data.document.id);
+      });  
+    };
+
     self.newNotebook = function () {
       var notebook = new Notebook(self, {});
       self.notebooks.push(notebook);

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

@@ -461,7 +461,7 @@ ${ 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) { location.href=url; } }">
+              <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' : ''}">
                   <i class="fa fa-fw fa-bolt inactive-action" data-bind="css: {'fa-fighter-jet': status == 'running', 'fa-cloud-download': status == 'available'}, attr: {'title': status}"></i>