Jelajahi Sumber

HUE-3228 [dashboard] Integrate with Notebook result download

Romain Rigaux 8 tahun lalu
induk
melakukan
e3f0fe31ef

+ 1 - 0
apps/impala/src/impala/dashboard_api.py

@@ -112,6 +112,7 @@ class SQLApi():
         statement=sql,
         database=database,
         status='ready-execute'
+        # historify=False
     )
     return editor.execute(MockRequest(self.user))
 

+ 40 - 27
apps/search/src/search/static/search/js/search.ko.js

@@ -455,6 +455,9 @@ var Collection = function (vm, collection) {
   self.engine.subscribe(function() {
     self.name(null);
   });
+  self.queryResult = ko.observable(new QueryResult(self, {
+    type: self.engine(),
+  }));
   self.nested = ko.mapping.fromJS(collection.nested);
   self.nestedNames = ko.computed(function() {
     function flatten(values) {
@@ -679,6 +682,9 @@ var Collection = function (vm, collection) {
       });
 
       // TODO queryResult reload QueryResult
+      facet.queryResult = ko.observable(new QueryResult(self, {
+    	    type: self.engine(),
+      }));
     }
   }
 
@@ -1420,11 +1426,22 @@ var NewTemplate = function (vm, initial) {
 var QueryResult = function (vm, initial) {
   var self = this;
 
+  self.id = ko.observable(UUID());
   self.type = ko.mapping.fromJS(initial.type);
-  self.status = ko.mapping.fromJS(initial.status || 'running');
+  self.status = ko.observable('running');
   self.progress = ko.mapping.fromJS(initial.progress || 0);
+  
+  self.hasResultset = ko.observable(true);
 
   self.result = ko.mapping.fromJS(initial.result);
+  self.result.hasSomeResults = ko.computed(function () {
+    return self.hasResultset(); // && self.data().length > 0; // status() == 'available'
+  });
+  self.result.type = ko.observable('table');
+  
+  self.getContext = function() {
+	return self;
+  }
 };
 
 
@@ -1603,29 +1620,29 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
 
   self.checkStatus = function (facet) { // common?
       $.post("/notebook/api/check_status", {
-        notebook: ko.mapping.toJSON({type: facet.queryResult.type()}),
-        snippet: ko.mapping.toJSON(facet.queryResult)
+        notebook: ko.mapping.toJSON({type: facet.queryResult().type()}),
+        snippet: ko.mapping.toJSON(facet.queryResult().getContext())
       }, function (data) {
-        if (facet.queryResult.status() == 'canceled') {
+        if (facet.queryResult().status() == 'canceled') {
           // Query was canceled in the meantime, do nothing
         } else {
 
           if (data.status == 0) {
-        	  facet.queryResult.status(data.query_status.status);
+        	  facet.queryResult().status(data.query_status.status);
 
-            if (facet.queryResult.status() == 'running' || facet.queryResult.status() == 'starting') {
+            if (facet.queryResult().status() == 'running' || facet.queryResult().status() == 'starting') {
               // if (! notebook.unloaded()) { self.checkStatusTimeout = setTimeout(self.checkStatus, 1000); };
               setTimeout(function() { self.checkStatus(facet); }, 1000);
             }
-            else if (facet.queryResult.status() == 'available') {
+            else if (facet.queryResult().status() == 'available') {
               self.fetchResult(facet);
-              facet.queryResult.progress(100);
+              facet.queryResult().progress(100);
             }
-            else if (facet.queryResult.status() == 'success') {
-              facet.queryResult.progress(99);
+            else if (facet.queryResult().status() == 'success') {
+              facet.queryResult().progress(99);
             }
           } else if (data.status == -3) {
-        	  facet.queryResult.status('expired');
+        	  facet.queryResult().status('expired');
           } else {
             //self._ajaxError(data); // common?
         	$(document).trigger("error", data.message);
@@ -1633,7 +1650,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
         }
       }).fail(function (xhr, textStatus, errorThrown) {
         $(document).trigger("error", xhr.responseText || textStatus);
-        facet.queryResult.status('failed');
+        facet.queryResult().status('failed');
       });
     };
 
@@ -1649,17 +1666,17 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
            self._make_result_facet(facet);
          });
        } else {
-         facet._make_grid_result(data);
+         self._make_grid_result(data);
        }
-//       if (facet.queryResult.result['handle'].has_result_set()) {
-//         self.fetchResultSize(facet);
-//       }
+       //if (facet.queryResult().result['handle'].has_result_set()) {
+       //  self.fetchResultSize(facet);
+       //}
      });
    }
    
    self.fetchResultSize = function(facet) {
 	  $.post("/notebook/api/fetch_result_size", {
-        notebook: ko.mapping.toJSON({type: facet.queryResult.type()}),
+        notebook: ko.mapping.toJSON({type: facet.queryResult().type()}),
         snippet: ko.mapping.toJSON(facet.queryResult)
 	  }, function (data) {
 	    if (data.status == 0) {
@@ -1731,15 +1748,13 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
             collection: ko.mapping.toJSON(self.collection),
             query: ko.mapping.toJSON(self.query),
             facet: ko.mapping.toJSON(facet),
-        }, function (data) {
-        	
-            var queryResult = new QueryResult(self, {
+        }, function (data) { 
+            facet.queryResult(new QueryResult(self, {
                 type: self.collection.engine(),
                 result: data,
                 status: 'running',
                 progress: 0,
-              });
-            facet.queryResult = queryResult;
+            }));
 
           	self.checkStatus(facet);
         });
@@ -1766,15 +1781,13 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
             if (self.collection.engine() != 'impala') {
               self._make_grid_result(data, callback);
             } else {
-              var query = new QueryResult(self, {
+              self.collection.queryResult(new QueryResult(self, {
                   type: self.collection.engine(),
                   result: data,
                   status: 'running',
                   progress: 0,
-               });
-
-              self.queryResult = query;
-           	  self.checkStatus(self);
+               }));
+           	  self.checkStatus(self.collection);
             }
           }
           catch (e) {

+ 8 - 0
apps/search/src/search/templates/common_search.mako

@@ -23,6 +23,7 @@ from desktop.views import commonheader, commonfooter, _ko
 
 <%namespace name="dashboard" file="common_dashboard.mako" />
 
+
 <%def name="page_structure(is_mobile=False, is_embeddable=False)">
 
 <script type="text/javascript">
@@ -1466,6 +1467,12 @@ ${ dashboard.layout_skeleton() }
             <!-- /ko -->
           </a>
         </div>
+        
+        <!-- ko if: $root.collection.engine() != 'solr' -->
+          <div data-bind="component: { name: 'downloadSnippetResults', params: { snippet: $data.queryResult(), notebook: {getContext: function() { return {type: $data.queryResult().type(), id: 1}; }} } }" style="display:inline-block;"></div>        
+        <!-- /ko -->
+        
+        <!-- ko if: $root.collection.engine() == 'solr' -->
         <form method="POST" action="${ url('search:download') }" style="display:inline">
           ${ csrf_token(request) | n,unicode }
           <input type="hidden" name="collection" data-bind="value: ko.mapping.toJSON($root.collection)"/>
@@ -1500,6 +1507,7 @@ ${ dashboard.layout_skeleton() }
             </ul>
           </div>
         </form>
+        <!-- /ko -->
 
       </div>
     </div>

+ 5 - 1
apps/search/src/search/templates/search.mako

@@ -15,15 +15,19 @@
 ## limitations under the License.
 
 <%!
+from django.utils.translation import ugettext as _
+
 from desktop.views import commonheader, commonfooter, _ko
 from desktop import conf
-from django.utils.translation import ugettext as _
 %>
 
 <%namespace name="common_search" file="common_search.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 
 ${ commonheader(_('Search'), "search", user, request, "80px") | n,unicode }
 
+${ notebookKoComponents.downloadSnippetResults() }
+
 <div id="searchComponents">
 ${ common_search.page_structure() }
 </div>

+ 6 - 1
apps/search/src/search/templates/search_m.mako

@@ -15,15 +15,20 @@
 ## limitations under the License.
 
 <%!
+from django.utils.translation import ugettext as _
+
 from desktop.views import commonheader_m, commonfooter_m, _ko
 from desktop import conf
-from django.utils.translation import ugettext as _
 %>
 
 <%namespace name="common_search" file="common_search.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 
 ${ commonheader_m(_('Search'), "search", user, request, "80px") | n,unicode }
 
+${ notebookKoComponents.downloadSnippetResults() }
+
+
 <div id="searchComponents">
 ${ common_search.page_structure(is_mobile=True) }
 </div>

+ 0 - 0
desktop/libs/notebook/src/notebook/templates/notebook_ko_components.mako → desktop/core/src/desktop/templates/common_notebook_ko_components.mako


+ 1 - 1
desktop/libs/indexer/src/indexer/settings.py

@@ -16,7 +16,7 @@
 # limitations under the License.
 
 DJANGO_APPS = [ "indexer" ]
-NICE_NAME = "Solr Indexer"
+NICE_NAME = "Data Importer"
 REQUIRES_HADOOP = False
 MENU_INDEX = 43
 ICON = "search/art/icon_search_48.png"

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

@@ -22,7 +22,7 @@
 <%namespace name="assist" file="/assist.mako" />
 <%namespace name="configKoComponents" file="/config_ko_components.mako" />
 <%namespace name="editorComponents" file="editor_components.mako" />
-<%namespace name="notebookKoComponents" file="notebook_ko_components.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 <%namespace name="hueAceAutocompleter" file="hue_ace_autocompleter.mako" />
 
 ${ commonheader(_('Editor'), editor_type, user, request, "68px") | n,unicode }

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

@@ -22,7 +22,7 @@
 <%namespace name="assist" file="/assist.mako" />
 <%namespace name="configKoComponents" file="/config_ko_components.mako" />
 <%namespace name="editorComponents" file="editor_components.mako" />
-<%namespace name="notebookKoComponents" file="notebook_ko_components.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 <%namespace name="hueAceAutocompleter" file="hue_ace_autocompleter.mako" />
 
 <span id="editorComponents" class="editorComponents notebook">

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

@@ -22,7 +22,7 @@
 <%namespace name="assist" file="/assist.mako" />
 <%namespace name="configKoComponents" file="/config_ko_components.mako" />
 <%namespace name="editorComponents" file="editor_components.mako" />
-<%namespace name="notebookKoComponents" file="notebook_ko_components.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 <%namespace name="hueAceAutocompleter" file="hue_ace_autocompleter.mako" />
 
 ${ commonheader(_('Notebook'), app_name, user, request, "68px") | n,unicode }

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

@@ -22,7 +22,7 @@
 <%namespace name="assist" file="/assist.mako" />
 <%namespace name="configKoComponents" file="/config_ko_components.mako" />
 <%namespace name="editorComponents" file="editor_components.mako" />
-<%namespace name="notebookKoComponents" file="notebook_ko_components.mako" />
+<%namespace name="notebookKoComponents" file="/common_notebook_ko_components.mako" />
 <%namespace name="hueAceAutocompleter" file="hue_ace_autocompleter.mako" />
 
 <span id="notebookComponents" class="editorComponents notebook">