Forráskód Böngészése

HUE-7743 [frontend] Revert param-based page routing in embedded mode

Johan Ahlen 7 éve
szülő
commit
e7f99d4

+ 8 - 22
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -137,22 +137,17 @@ var MetastoreViewModel = (function () {
 
     huePubSub.subscribe('metastore.url.change', function () {
       var prefix = '/metastore/';
-      if (self.isHue4() && !IS_EMBEDDED){
+      if (self.isHue4()){
         prefix = '/hue' + prefix;
       }
-      var newUrl;
       if (self.database() && self.database().table()) {
-        newUrl = prefix + 'table/' + self.database().name + '/' + self.database().table().name;
-      } else if (self.database()) {
-        newUrl = prefix + 'tables/' + self.database().name;
-      } else {
-        newUrl = prefix + 'databases';
+        hueUtils.changeURL(prefix + 'table/' + self.database().name + '/' + self.database().table().name);
       }
-
-      if (IS_EMBEDDED) {
-        hueUtils.changeURLParameter('app', newUrl);
-      } else {
-        hueUtils.changeURL(newUrl);
+      else if (self.database()) {
+        hueUtils.changeURL(prefix + 'tables/' + self.database().name);
+      }
+      else {
+        hueUtils.changeURL(prefix + 'databases');
       }
     });
 
@@ -301,16 +296,7 @@ var MetastoreViewModel = (function () {
   MetastoreViewModel.prototype.loadURL = function () {
     var self = this;
 
-    var path;
-
-    if (IS_EMBEDDED) {
-      var appMatch = location.search.match(/app=\/?([^&#]+)/);
-      if (appMatch) {
-        path = '/' + appMatch[1];
-      }
-    } else {
-      path = (IS_HUE_4 ? window.location.pathname.substr(4) : window.location.pathname);
-    }
+    var path = (IS_HUE_4 ? window.location.pathname.substr(4) : window.location.pathname);
     if (!path) {
       path = '/metastore/tables';
     }

+ 10 - 89
desktop/core/src/desktop/static/desktop/ext/js/page.js

@@ -28,34 +28,6 @@
 
   var location = ('undefined' !== typeof window) && (window.history.location || window.location);
 
-  // Hue specific
-  var winLoc = function (href) {
-    if (href) {
-      location.href = href;
-    } else if (!paramBased) {
-      return location;
-    } else {
-      var hueMatch = location.search.match(/app=\/?([^&#]+)/);
-      var pathname = location.pathname + (hueMatch ? hueMatch[1] : '');
-      var search = hueMatch ? location.search.replace(hueMatch[0], '') : location.search + '';
-      search = search.replace('?&', '?');
-      if (pathname[0] !== '/') {
-        pathname = '/' + pathname;
-      }
-
-      var adaptedLocation = {
-        hash: location.hash + '',
-        search: search === '?' ? '' : search,
-        pathname: pathname,
-        protocol: location.protocol + '',
-        port: location.port + '',
-        hostname: location.hostname + ''
-      };
-
-      return adaptedLocation;
-    }
-  }
-
   /**
    * Perform initial dispatch.
    */
@@ -75,9 +47,6 @@
 
   var base = '';
 
-  // Hue specific
-  var baseHash = '';
-
   /**
    * Running flag.
    */
@@ -90,12 +59,6 @@
 
   var hashbang = false;
 
-  /**
-   * paramBased option
-   */
-
-  var paramBased = true; // Hue specific
-
   /**
    * Previous context, for capturing
    * page exit events.
@@ -178,11 +141,6 @@
     base = path;
   };
 
-  page.baseHash = function (hash) {
-    if (0 === arguments.length) return baseHash;
-    baseHash = decodeURLEncodedURIComponent(hash);
-  };
-
   /**
    * Bind with the given `options`.
    *
@@ -208,8 +166,7 @@
     }
     if (true === options.hashbang) hashbang = true;
     if (!dispatch) return;
-    var loc = winLoc();
-    var url = (hashbang && ~loc.hash.indexOf('#!')) ? loc.hash.substr(2) + loc.search : loc.pathname + loc.search + loc.hash;
+    var url = (hashbang && ~location.hash.indexOf('#!')) ? location.hash.substr(2) + location.search : location.pathname + location.search + location.hash;
     page.replace(url, null, true, dispatch);
   };
 
@@ -334,10 +291,6 @@
 
     prevContext = ctx;
 
-    if (prev && prev.hash && prev.hash !== baseHash) {
-      return unhandled(ctx);
-    }
-
     function nextExit() {
       var fn = page.exits[j++];
       if (!fn) return nextEnter();
@@ -375,15 +328,15 @@
     var current;
 
     if (hashbang) {
-      current = base + winLoc().hash.replace('#!', '');
+      current = base + location.hash.replace('#!', '');
     } else {
-      current = winLoc().pathname + winLoc().search;
+      current = location.pathname + location.search;
     }
 
     if (current === ctx.canonicalPath) return;
     page.stop();
     ctx.handled = false;
-    winLoc(ctx.canonicalPath);
+    location.href = ctx.canonicalPath;
   }
 
   /**
@@ -431,9 +384,6 @@
 
     this.canonicalPath = path;
     this.path = path.replace(base, '') || '/';
-    if (this.path[0] !== '/') {
-      this.path = '/' + this.path;
-    }
     if (hashbang) this.path = this.path.replace('#!', '') || '/';
 
     this.title = document.title;
@@ -460,34 +410,6 @@
 
   page.Context = Context;
 
-
-  // Hue specific
-  Context.prototype.adaptPath = function (path) {
-    if (!paramBased || ~path.indexOf('app=')) {
-      return path;
-    }
-
-    var appPath = path.replace(base, '').replace('//', '/').replace('?', '&');
-    if (appPath[0] !== '/') {
-      appPath = appPath + '/';
-    }
-    var adaptedPath = location.pathname + '?app=' + appPath;
-    if (!~path.indexOf('#') && location.hash) {
-      adaptedPath += location.hash;
-    }
-    return adaptedPath;
-  };
-
-  // Hue specific
-  Context.prototype.adaptedState = function () {
-    if (paramBased && this.state && this.state.path) {
-      return {
-        path: this.adaptPath(this.state.path)
-      }
-    }
-    return this.state;
-  };
-
   /**
    * Push state.
    *
@@ -496,7 +418,7 @@
 
   Context.prototype.pushState = function() {
     page.len++;
-    history.pushState(this.adaptedState(), this.title, this.adaptPath(hashbang && this.path !== '/' ? '#!' + this.path : this.canonicalPath));
+    history.pushState(this.state, this.title, hashbang && this.path !== '/' ? '#!' + this.path : this.canonicalPath);
   };
 
   /**
@@ -506,7 +428,7 @@
    */
 
   Context.prototype.save = function() {
-    history.replaceState(this.adaptedState(), this.title, this.adaptPath(hashbang && this.path !== '/' ? '#!' + this.path : this.canonicalPath));
+    history.replaceState(this.state, this.title, hashbang && this.path !== '/' ? '#!' + this.path : this.canonicalPath);
   };
 
   /**
@@ -610,7 +532,7 @@
         var path = e.state.path;
         page.replace(path, e.state);
       } else {
-        page.show(winLoc().pathname + winLoc().hash, undefined, undefined, false);
+        page.show(location.pathname + location.hash, undefined, undefined, false);
       }
     };
   })();
@@ -642,7 +564,7 @@
 
     // ensure non-hash for the same path
     var link = el.getAttribute('href');
-    if (!hashbang && el.pathname === winLoc().pathname && (el.hash || '#' === link)) return;
+    if (!hashbang && el.pathname === location.pathname && (el.hash || '#' === link)) return;
 
 
 
@@ -694,9 +616,8 @@
    */
 
   function sameOrigin(href) {
-    var loc = winLoc();
-    var origin = loc.protocol + '//' + loc.hostname;
-    if (loc.port) origin += ':' + loc.port;
+    var origin = location.protocol + '//' + location.hostname;
+    if (location.port) origin += ':' + location.port;
     return (href && (0 === href.indexOf(origin)));
   }
 

+ 0 - 2
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -157,8 +157,6 @@
 
   window.HUE_VERSION = '${ hue_version() }';
 
-  window.IS_EMBEDDED = '${ IS_EMBEDDED.get() }' === 'True';
-
   %if hasattr(ENABLE_NEW_INDEXER, 'get') and ENABLE_NEW_INDEXER.get():
     window.IS_NEW_INDEXER_ENABLED = true;
   %else:

+ 6 - 14
desktop/core/src/desktop/templates/hue.mako

@@ -1057,12 +1057,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           $(this).attr('href', link);
         });
 
-        % if IS_EMBEDDED.get():
-        page.base(window.location.pathname + '');
-        page.baseHash(window.location.hash.replace(/\/*$/, '').substring(1));
-        % else:
-        page.base('/hue');
-        % endif
+        page.base(typeof HUE_EMBEDDED_BASE_URL !== 'undefined' ? HUE_EMBEDDED_BASE_URL : '/hue');
 
         self.lastContext = null;
 
@@ -1277,15 +1272,12 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
         huePubSub.subscribe('open.link', function (href) {
           if (href) {
-            % if not IS_EMBEDDED.get():
-              if (href.startsWith('/') && !href.startsWith('/hue')){
-                page('/hue' + href);
-              } else {
-                page(href);
-              }
-            % else:
+            var prefix = typeof HUE_EMBEDDED_BASE_URL !== 'undefined' ? HUE_EMBEDDED_BASE_URL : '/hue';
+            if (href.startsWith('/') && !href.startsWith(prefix)){
+              page(prefix + href);
+            } else {
               page(href);
-            % endif
+            }
           } else {
             console.warn('Received an open.link without href.')
           }