瀏覽代碼

[metastore] Added changeURL to HueUtils and enabled history pushState

Enrico Berti 10 年之前
父節點
當前提交
5a957f80b3

+ 1 - 3
apps/beeswax/src/beeswax/static/beeswax/js/beeswax.vm.js

@@ -552,9 +552,7 @@ function BeeswaxViewModel(server, assistHelper) {
         self.design.errors.removeAll();
         self.design.watch.errors.removeAll();
         if (data.status == 0) {
-          if (typeof history.pushState != 'undefined') {
-            history.pushState(null, null, '/' + self.server() + '/execute/query/' + data.id + '#query/logs');
-          }
+          hueUtils.changeURL('/' + self.server() + '/execute/query/' + data.id + '#query/logs');
           self.design.results.url('/' + self.server() + '/results/' + data.id + '/0?format=json');
           self.design.watch.url(data.watch_url);
           self.design.statement(data.statement);

+ 18 - 2
apps/metastore/src/metastore/templates/describe_table.mako

@@ -65,11 +65,11 @@ ${ assist.assistPanel() }
       <i class="fa fa-th muted"></i>
     </li>
     <li>
-      <a href="javascript:void(0);" data-bind="click: function() { database(null) }">${_('Databases')}</a><span class="divider">&gt;</span>
+      <a href="javascript:void(0);" data-bind="click: function() { database(null); huePubSub.publish('metastore.url.change'); }">${_('Databases')}</a><span class="divider">&gt;</span>
     </li>
     <!-- ko with: database -->
     <li>
-      <a href="javascript:void(0);" data-bind="text: name, click: function() { $root.database().table(null) }"></a><span class="divider">&gt;</span>
+      <a href="javascript:void(0);" data-bind="text: name, click: function() { $root.database().table(null); huePubSub.publish('metastore.url.change'); }"></a><span class="divider">&gt;</span>
     </li>
     <!-- ko with: table -->
     <li>
@@ -734,6 +734,7 @@ ${ assist.assistPanel() }
       if (! metastoreTable.loaded()) {
         metastoreTable.load();
       }
+      huePubSub.publish('metastore.url.change');
     }
 
     /**
@@ -983,6 +984,7 @@ ${ assist.assistPanel() }
 
       var setDatabaseByName = function (databaseName) {
         if (self.database() && self.database().name == databaseName) {
+          huePubSub.publish('metastore.url.change');
           return;
         }
         var foundDatabases = $.grep(self.databases(), function (database) {
@@ -997,6 +999,7 @@ ${ assist.assistPanel() }
         setDatabaseByName(tableDef.database);
         if (self.database()) {
           if (self.database().table() && self.database().table().name == tableDef.name) {
+            huePubSub.publish('metastore.url.change');
             return;
           }
 
@@ -1028,6 +1031,18 @@ ${ assist.assistPanel() }
         $.totalStorage('spark_left_panel_visible', newValue);
       });
 
+      huePubSub.subscribe('metastore.url.change', function () {
+        if (self.database() && self.database().table()) {
+          hueUtils.changeURL('/metastore/table/' + self.database().name + '/' + self.database().table().name);
+        }
+        else if (self.database()){
+          hueUtils.changeURL('/metastore/tables/' + self.database().name);
+        }
+        else {
+          hueUtils.changeURL('metastore/databases');
+        }
+      });
+
       // TODO: Move queries into MetastoreTable
       self.loadingQueries = ko.observable(false);
       self.queries = ko.observableArray([]);
@@ -1040,6 +1055,7 @@ ${ assist.assistPanel() }
       if (! metastoreDatabase.loaded()) {
         metastoreDatabase.load();
       }
+      huePubSub.publish('metastore.url.change');
     }
 
     $(document).ready(function () {

+ 6 - 6
apps/search/src/search/static/search/js/search.ko.js

@@ -629,8 +629,8 @@ var Collection = function (vm, collection) {
 
     vm.selectedQDefinition(qdefinition);
     if (window.location.hash.indexOf("collection") == -1) {
-      if (typeof history.pushState != "undefined" && location.getParameter("collection") != "") {
-        history.pushState(null, null, "?collection=" + location.getParameter("collection") + "&qd=" + qdef.uuid());
+      if (location.getParameter("collection") != "") {
+        hueUtils.changeURL("?collection=" + location.getParameter("collection") + "&qd=" + qdef.uuid());
       }
       else {
         window.location.hash = "qd=" + qdef.uuid();
@@ -667,8 +667,8 @@ var Collection = function (vm, collection) {
     vm.query.start(0);
     vm.query.selectedMultiq([]);
     if (window.location.hash.indexOf("collection") == -1) {
-      if (typeof history.pushState != "undefined" && location.getParameter("collection") != "") {
-        history.pushState(null, null, "?collection=" + location.getParameter("collection"));
+      if (location.getParameter("collection") != "") {
+        hueUtils.changeURL("?collection=" + location.getParameter("collection"));
       }
       else {
         window.location.hash = "";
@@ -1335,9 +1335,9 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
         self.selectedQDefinition().hasChanged(true);
       }
     }
-    else if (typeof history.pushState != "undefined" && location.getParameter("collection") != "") {
+    else if (location.getParameter("collection") != "") {
       var firstQuery = self.query.qs()[0].q();
-      history.pushState(null, null, "?collection=" + location.getParameter("collection") + (firstQuery ? "&q=" + firstQuery : ""));
+      hueUtils.changeURL("?collection=" + location.getParameter("collection") + (firstQuery ? "&q=" + firstQuery : ""));
     }
 
     // Multi queries

+ 4 - 0
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -145,6 +145,10 @@ Array.prototype.diff = function (a) {
     }
   }
 
+  hueUtils.changeURL = function (newURL) {
+    window.history.pushState(null, null, newURL);
+  }
+
 }(hueUtils = window.hueUtils || {}));
 
 if (!Object.keys) {

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

@@ -465,7 +465,7 @@
             notebook: ko.mapping.toJSON(notebook, SPARK_MAPPING)
           }, function(data){
             if (vm.editorMode && data && data.status == 0 && data.id){
-              history.pushState(null, null, '/notebook/editor?editor=' + data.id);
+              hueUtils.changeURL('/notebook/editor?editor=' + data.id);
             }
           });
         }
@@ -926,10 +926,10 @@
           self.id(data.id);
           $(document).trigger("info", data.message);
           if (vm.editorMode){
-            history.pushState(null, null, '/notebook/editor?editor=' + data.id);
+            hueUtils.changeURL('/notebook/editor?editor=' + data.id);
           }
           else {
-            history.pushState(null, null, '/notebook/notebook?notebook=' + data.id);
+            hueUtils.changeURL('/notebook/notebook?notebook=' + data.id);
           }
         }
         else {

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

@@ -422,7 +422,7 @@ ${ require.config() }
           </tr>
         </thead>
         <tbody data-bind="foreach: $parent.history">
-          <tr class="pointer" data-bind="click: function() { if (getSelection().toString().length == 0) { history.pushState(null, null, url); location.href=url; } }">
+          <tr class="pointer" data-bind="click: function() { if (getSelection().toString().length == 0) { location.href=url; } }">
             <td><code data-bind="text: query" style="white-space: normal"></code></td>
             <td style="width: 200px" class="muted"><span data-bind="text: moment(lastExecuted).format('LLL')"></span></td>
           </tr>