浏览代码

HUE-7743 [frontend] Allow any URL base path in embedded mode

Johan Ahlen 8 年之前
父节点
当前提交
87ffd05
共有 2 个文件被更改,包括 25 次插入8 次删除
  1. 11 1
      desktop/core/src/desktop/static/desktop/ext/js/page.js
  2. 14 7
      desktop/core/src/desktop/templates/hue.mako

+ 11 - 1
desktop/core/src/desktop/static/desktop/ext/js/page.js

@@ -43,6 +43,9 @@
       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 + '',
@@ -420,6 +423,9 @@
 
     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;
@@ -453,7 +459,11 @@
       return path;
     }
 
-    var adaptedPath = location.pathname + '?app=' + path.replace(base, '').replace('//', '/').replace('?', '&');
+    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;
     }

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

@@ -1043,7 +1043,11 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           $(this).attr('href', link);
         });
 
-        page.base(typeof HUE_EMBEDDED_BASE_URL !== 'undefined' ? HUE_EMBEDDED_BASE_URL : '/hue');
+        % if IS_EMBEDDED.get():
+        page.base(window.location.pathname + '');
+        % else:
+        page.base('/hue');
+        % endif
 
         self.lastContext = null;
 
@@ -1248,13 +1252,16 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
         huePubSub.subscribe('open.link', function (href) {
           if (href) {
-            if (href.startsWith('/') && !href.startsWith('/hue')){
-              page('/hue' + href);
-            } else {
+            % if not IS_EMBEDDED.get():
+              if (href.startsWith('/') && !href.startsWith('/hue')){
+                page('/hue' + href);
+              } else {
+                page(href);
+              }
+            % else:
               page(href);
-            }
-          }
-          else {
+            % endif
+          } else {
             console.warn('Received an open.link without href.')
           }
         });