Ver Fonte

HUE-7743 [frontend] Detect hash changes and abort page.js routing in embedded mode

Johan Ahlen há 8 anos atrás
pai
commit
6a2fd64

+ 13 - 5
desktop/core/src/desktop/static/desktop/ext/js/page.js

@@ -31,11 +31,7 @@
   // Hue specific
   var winLoc = function (href) {
     if (href) {
-      if (!paramBased) {
-        location.href = href;
-      }
-      // TODO: When is this called?
-      // console.log('setting: ' + href);
+      location.href = href;
     } else if (!paramBased) {
       return location;
     } else {
@@ -79,6 +75,9 @@
 
   var base = '';
 
+  // Hue specific
+  var baseHash = '';
+
   /**
    * Running flag.
    */
@@ -179,6 +178,11 @@
     base = path;
   };
 
+  page.baseHash = function (hash) {
+    if (0 === arguments.length) return baseHash;
+    baseHash = decodeURLEncodedURIComponent(hash);
+  };
+
   /**
    * Bind with the given `options`.
    *
@@ -330,6 +334,10 @@
 
     prevContext = ctx;
 
+    if (prev && prev.hash && prev.hash !== baseHash) {
+      return unhandled(ctx);
+    }
+
     function nextExit() {
       var fn = page.exits[j++];
       if (!fn) return nextEnter();

+ 1 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -1045,6 +1045,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
         % if IS_EMBEDDED.get():
         page.base(window.location.pathname + '');
+        page.baseHash(window.location.hash.replace(/\/*$/, '').substring(1));
         % else:
         page.base('/hue');
         % endif