Преглед на файлове

HUE-5493 [responsive] Create URL entry points for loading specific apps at startup

Enrico Berti преди 9 години
родител
ревизия
aa7a04a

+ 5 - 2
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -198,7 +198,7 @@ if (!String.prototype.includes) {
 
   hueUtils.changeURLParameter = function (param, value) {
     var newSearch = '';
-    if (window.location.getParameter(param) !== '') {
+    if (window.location.getParameter(param, true) !== null) {
       newSearch += '?';
       window.location.search.replace(/\?/gi, '').split('&').forEach(function (p) {
         if (p.split('=')[0] !== param) {
@@ -425,10 +425,13 @@ String.prototype.hashCode = function() {
 };
 
 if (!('getParameter' in window.location)) {
-  window.location.getParameter = function (name) {
+  window.location.getParameter = function (name, returnNull) {
     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
         results = regex.exec(window.location.search);
+    if (returnNull && results === null){
+      return null;
+    }
     return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
   };
 }

+ 20 - 12
desktop/core/src/desktop/templates/responsive.mako

@@ -501,33 +501,36 @@ ${ assist.assistPanel() }
           self.currentApp('fileviewer');
         });
 
-        self.currentApp.subscribe(function(newVal){
+        self.currentApp.subscribe(function (newVal) {
+          hueUtils.changeURLParameter('app', newVal);
           self.isLoadingEmbeddable(true);
-          if (typeof self.embeddable_cache[newVal] === 'undefined'){
+          if (typeof self.embeddable_cache[newVal] === 'undefined') {
             $.ajax({
               url: self.EMBEDDABLE_PAGE_URLS[newVal] + self.extraEmbeddableURLParams(),
-              beforeSend:function (xhr) {
+              beforeSend: function (xhr) {
                 xhr.setRequestHeader('X-Requested-With', 'Hue');
               },
-              dataType:'html',
-              success:function (response) {
+              dataType: 'html',
+              success: function (response) {
                 self.extraEmbeddableURLParams('');
                 // TODO: remove the next lines
                 // hack to avoid css caching for development
                 var r = $(response);
-                r.find('link').each(function(){ $(this).attr('href', $(this).attr('href') + '?' + Math.random()) });
+                r.find('link').each(function () {
+                  $(this).attr('href', $(this).attr('href') + '?' + Math.random())
+                });
                 // load just CSS and JS files that are not loaded before
-                r.find('script[src]').each(function(){
+                r.find('script[src]').each(function () {
                   var jsFile = $(this).attr('src').split('?')[0];
-                  if (LOADED_JS.indexOf(jsFile) === -1){
+                  if (LOADED_JS.indexOf(jsFile) === -1) {
                     LOADED_JS.push(jsFile);
                     $(this).clone().appendTo($('head'));
                     $(this).remove();
                   }
                 });
-                r.find('link[href]').each(function(){
+                r.find('link[href]').each(function () {
                   var cssFile = $(this).attr('href').split('?')[0];
-                  if (LOADED_CSS.indexOf(cssFile) === -1){
+                  if (LOADED_CSS.indexOf(cssFile) === -1) {
                     LOADED_CSS.push(cssFile);
                     $(this).clone().appendTo($('head'));
                     $(this).remove();
@@ -547,15 +550,20 @@ ${ assist.assistPanel() }
           $('#embeddable_' + newVal).show();
         });
 
-        if (window.location.getParameter('editor') !== '' || window.location.getParameter('type') !== ''){
+        if (window.location.getParameter('app') !== '' && self.EMBEDDABLE_PAGE_URLS[window.location.getParameter('app')]){
+          self.currentApp(window.location.getParameter('app'));
+        }
+        else if (window.location.getParameter('editor') !== '' || window.location.getParameter('type') !== ''){
           self.currentApp('editor');
         }
+        else {
+          self.currentApp('home');
+        }
 
         huePubSub.subscribe('switch.app', function (name) {
           self.currentApp(name);
         });
 
-        self.currentApp('editor');
       };
 
       var onePageViewModel = new OnePageViewModel();

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

@@ -969,7 +969,7 @@ var EditorViewModel = (function() {
         if (vm.editorMode() && data.history_id) {
           var url = '/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.history_id;
           if (vm.isResponsive()){
-            url = vm.URLS.responsive + '?editor=' + data.history_id;
+            url = vm.URLS.responsive + '&editor=' + data.history_id;
           }
           hueUtils.changeURL(url);
           notebook.id(data.history_id);
@@ -1810,7 +1810,7 @@ var EditorViewModel = (function() {
             }
 
             if (vm.isResponsive()){
-              hueUtils.changeURL(vm.URLS.responsive + '?editor=' + data.id);
+              hueUtils.changeURL(vm.URLS.responsive + '&editor=' + data.id);
             }
             else {
               hueUtils.changeURL('/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.id);
@@ -1818,7 +1818,7 @@ var EditorViewModel = (function() {
           }
           else {
             if (vm.isResponsive()){
-              hueUtils.changeURL(vm.URLS.responsive + '?notebook=' + data.id);
+              hueUtils.changeURL(vm.URLS.responsive + '&notebook=' + data.id);
             }
             else {
               hueUtils.changeURL('/notebook/notebook?notebook=' + data.id);
@@ -1999,7 +1999,7 @@ var EditorViewModel = (function() {
           self.id(null);
           self.uuid(UUID());
           if (vm.isResponsive()) {
-            hueUtils.changeURL(vm.URLS.responsive + '?type=' + vm.editorType());
+            hueUtils.changeURL(vm.URLS.responsive + '&type=' + vm.editorType());
           }
           else {
             hueUtils.changeURL('/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?type=' + vm.editorType());
@@ -2149,7 +2149,7 @@ var EditorViewModel = (function() {
       editor: '/notebook/editor',
       editorMobile: '/notebook/editor_m',
       notebook: '/notebook/notebook',
-      responsive: '/responsive'
+      responsive: '/responsive?app=editor'
     }
 
     self.user = options.user;
@@ -2394,7 +2394,7 @@ var EditorViewModel = (function() {
           if (typeof skipUrlChange === 'undefined'){
             if (self.editorMode()) {
               if (self.isResponsive()){
-                hueUtils.changeURL(self.URLS.responsive + '?editor=' + data.document.id);
+                hueUtils.changeURL(self.URLS.responsive + '&editor=' + data.document.id);
               }
               else {
                 hueUtils.changeURL((self.isMobile() ? self.URLS.editorMobile : self.URLS.editor) + '?editor=' + data.document.id);
@@ -2402,10 +2402,10 @@ var EditorViewModel = (function() {
             }
             else {
               if (self.isResponsive()){
-                hueUtils.changeURL(self.URLS.responsive + '?notebook=' + data.document.id);
+                hueUtils.changeURL(self.URLS.responsive + '&notebook=' + data.document.id);
               }
               else {
-                hueUtils.changeURL(self.URLS.notebook + '?notebook=' + data.document.id);
+                hueUtils.changeURL(self.URLS.notebook + '&notebook=' + data.document.id);
               }
             }
           }
@@ -2435,14 +2435,14 @@ var EditorViewModel = (function() {
           }
           if (window.location.getParameter('type')) {
             if (self.isResponsive()){
-              hueUtils.changeURL(self.URLS.responsive + '?type=' + window.location.getParameter('type'));
+              hueUtils.changeURL(self.URLS.responsive + '&type=' + window.location.getParameter('type'));
             }
             else {
               hueUtils.changeURL((self.isMobile() ? self.URLS.editorMobile : self.URLS.editor) + '?type=' + window.location.getParameter('type'));
             }
           } else {
             if (self.isResponsive()){
-              hueUtils.changeURL(self.URLS.responsive + '?type=' + self.editorType());
+              hueUtils.changeURL(self.URLS.responsive + '&type=' + self.editorType());
             }
             else {
               hueUtils.changeURL((self.isMobile() ? self.URLS.editorMobile : self.URLS.editor) + '?type=' + self.editorType());