Răsfoiți Sursa

HUE-5564 [responsive] The home new document links should open in the same window

Enrico Berti 9 ani în urmă
părinte
comite
55ae1d0c15

+ 10 - 0
desktop/core/src/desktop/static/desktop/js/document/hueFileEntry.js

@@ -503,6 +503,16 @@ var HueFileEntry = (function () {
     }
   };
 
+  HueFileEntry.prototype.openExternalLink = function (entry, event) {
+    event.preventDefault();
+    location.href = $(event.target).attr('href');
+  };
+
+  HueFileEntry.prototype.openResponsiveLink = function (entry, event) {
+    event.preventDefault();
+    huePubSub.publish('open.link', $(event.target).attr('href'));
+  };
+
   HueFileEntry.prototype.showDeleteConfirmation = function () {
     var self = this;
     if (self.selectedEntries().length > 0 && (self.superuser || !self.sharedWithMeSelected())) {

+ 11 - 7
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -277,6 +277,16 @@ if (!String.prototype.includes) {
     return width;
   }
 
+  hueUtils.getSearchParameter = function (search, name, returnNull) {
+    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
+        results = regex.exec(search);
+    if (returnNull && results === null){
+      return null;
+    }
+    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+  }
+
 
 }(hueUtils = window.hueUtils || {}));
 
@@ -527,13 +537,7 @@ String.prototype.hashCode = function() {
 
 if (!('getParameter' in window.location)) {
   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, " "));
+    return hueUtils.getSearchParameter(window.location.search, name, returnNull);
   };
 }
 

+ 2 - 2
desktop/core/src/desktop/templates/common_home.mako

@@ -21,7 +21,7 @@
 
 <%namespace name="docBrowser" file="/document_browser.mako" />
 
-<%def name="homeJSModels()">
+<%def name="homeJSModels(is_embeddable=False)">
   <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.custom.min.js') }"></script>
   <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
   <script src="${ static('desktop/js/apiHelper.js') }"></script>
@@ -33,7 +33,7 @@
   <script src="${ static('desktop/ext/js/jquery.mCustomScrollbar.concat.min.js') }"></script>
   <script src="${ static('desktop/js/home2.vm.js') }"></script>
 
-  ${ docBrowser.docBrowser() }
+  ${ docBrowser.docBrowser(is_embeddable) }
 </%def>
 
 

+ 9 - 9
desktop/core/src/desktop/templates/document_browser.mako

@@ -21,7 +21,7 @@ from django.utils.translation import ugettext as _
 from desktop.views import _ko
 %>
 
-<%def name="docBrowser()">
+<%def name="docBrowser(is_embeddable=False)">
 
   <script src="/static/desktop/ext/js/bootstrap-fileupload.js" type="text/javascript" charset="utf-8"></script>
   <link rel="stylesheet" href="/static/desktop/ext/css/bootstrap-fileupload.css">
@@ -619,27 +619,27 @@ from desktop.views import _ko
               <a class="inactive-action doc-browser-action" title="${_('New document')}" data-toggle="dropdown" data-bind="tooltip: { placement: 'bottom', delay: 750 }, css: { 'disabled': isTrash() || isTrashed() }" href="javascript:void(0);"><span class="fa-stack fa-fw" style="width: 1.28571429em"><i class="fa fa-file-o fa-stack-1x"></i><i class="fa fa-plus-circle fa-stack-1x" style="font-size: 14px; margin-left: 6px; margin-top: 6px;"></i></span></a>
               <ul class="dropdown-menu less-padding document-types" style="margin-top:10px; width: 175px;" role="menu">
                 % if 'beeswax' in apps:
-                  <li><a title="${_('Hive Query')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=hive') }"><img src="${ static(apps['beeswax'].icon_path) }" class="app-icon"/> ${_('Hive Query')}</a></li>
+                  <li><a title="${_('Hive Query')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=hive') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static(apps['beeswax'].icon_path) }" class="app-icon"/> ${_('Hive Query')}</a></li>
                 % endif
                 % if 'impala' in apps:
-                  <li><a title="${_('Impala Query')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=impala') }"><img src="${ static(apps['impala'].icon_path) }" class="app-icon"/> ${_('Impala Query')}</a></li>
+                  <li><a title="${_('Impala Query')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=impala') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static(apps['impala'].icon_path) }" class="app-icon"/> ${_('Impala Query')}</a></li>
                 % endif
                 % if 'pig' in apps:
-                  <li><a title="${_('Pig Script')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('pig:index') }') }"><img src="${ static(apps['pig'].icon_path) }" class="app-icon"/> ${_('Pig Script')}</a></li>
+                  <li><a title="${_('Pig Script')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('pig:index') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static(apps['pig'].icon_path) }" class="app-icon"/> ${_('Pig Script')}</a></li>
                 % endif
                 <%
                 from notebook.conf import SHOW_NOTEBOOKS
                 %>
                 % if SHOW_NOTEBOOKS.get():
-                  <li><a title="${_('Notebook')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:index') }') }"><i style="font-size: 24px; line-height: 24px; vertical-align: middle; color: #338BB8;" class="fa app-icon fa-fw fa-file-text-o"></i> ${_('Notebook')}</a></li>
+                  <li><a title="${_('Notebook')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:index') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><i style="font-size: 24px; line-height: 24px; vertical-align: middle; color: #338BB8;" class="fa app-icon fa-fw fa-file-text-o"></i> ${_('Notebook')}</a></li>
                 % endif
                 % if 'oozie' in apps:
-                  <li><a title="${_('Oozie Workflow')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_workflow') }') }"><img src="${ static('oozie/art/icon_oozie_workflow_48.png') }" class="app-icon"/> ${_('Oozie Workflow')}</a></li>
-                  <li><a title="${_('Oozie Coordinator')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_coordinator') }') }"><img src="${ static('oozie/art/icon_oozie_coordinator_48.png') }" class="app-icon"/> ${_('Oozie Coordinator')}</a></li>
-                  <li><a title="${_('Oozie Bundle')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_bundle') }') }"><img src="${ static('oozie/art/icon_oozie_bundle_48.png') }" class="app-icon"/> ${_('Oozie Bundle')}</a></li>
+                  <li><a title="${_('Oozie Workflow')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_workflow') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_workflow_48.png') }" class="app-icon"/> ${_('Oozie Workflow')}</a></li>
+                  <li><a title="${_('Oozie Coordinator')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_coordinator') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_coordinator_48.png') }" class="app-icon"/> ${_('Oozie Coordinator')}</a></li>
+                  <li><a title="${_('Oozie Bundle')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_bundle') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_bundle_48.png') }" class="app-icon"/> ${_('Oozie Bundle')}</a></li>
                 % endif
                 % if 'search' in apps:
-                  <li><a title="${_('Solr Search')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('search:index') }') }"><img src="${ static('search/art/icon_search_48.png') }" class="app-icon"/> ${_('Search Dashboard')}</a></li>
+                  <li><a title="${_('Solr Search')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('search:index') }') }, click: ${ is_embeddable and 'openResponsiveLink' or 'openExternalLink' }"><img src="${ static('search/art/icon_search_48.png') }" class="app-icon"/> ${_('Search Dashboard')}</a></li>
                 % endif
               </ul>
             </span>

+ 1 - 1
desktop/core/src/desktop/templates/home_embeddable.mako

@@ -21,7 +21,7 @@
 
 <%namespace name="common_home" file="/common_home.mako" />
 
-${ common_home.homeJSModels() }
+${ common_home.homeJSModels(True) }
 
 <style type="text/css">
 

+ 39 - 1
desktop/core/src/desktop/templates/responsive.mako

@@ -541,11 +541,49 @@ ${ assist.assistPanel() }
           }, 100);
         }
 
-        huePubSub.subscribe('open.fb.file', function(path){
+        huePubSub.subscribe('open.fb.file', function (path) {
           self.extraEmbeddableURLParams(path + '?is_embeddable=true');
           self.currentApp('fileviewer');
         });
 
+        huePubSub.subscribe('open.link', function (href) {
+          if (href.startsWith('/notebook/editor')){
+            if (location.getParameter('type') !== ''){
+              if (hueUtils.getSearchParameter(href, 'type') !== '' && hueUtils.getSearchParameter(href, 'type') !== location.getParameter('type')) {
+                self.changeEditorType(hueUtils.getSearchParameter(href, 'type'));
+              }
+            }
+            else {
+              if (hueUtils.getSearchParameter(href, 'type') !== ''){
+                self.changeEditorType(hueUtils.getSearchParameter(href, 'type'));
+              }
+              else {
+                self.changeEditorType('hive');
+              }
+              self.currentApp('editor')
+            }
+          }
+          else if (href.startsWith('/notebook')){
+            self.currentApp('notebook');
+          }
+          else if (href.startsWith('/pig')){
+            self.changeEditorType('pig');
+            self.currentApp('editor');
+          }
+          else if (href.startsWith('/search')){
+            self.currentApp('search');
+          }
+          else if (href.startsWith('/oozie/editor/workflow/new')){
+            self.currentApp('oozie_workflow');
+          }
+          else if (href.startsWith('/oozie/editor/coordinator/new')){
+            self.currentApp('oozie_coordinator');
+          }
+          else if (href.startsWith('/oozie/editor/bundle/new')){
+            self.currentApp('oozie_bundle');
+          }
+        });
+
         self.currentApp.subscribe(function (newVal) {
           hueUtils.changeURLParameter('app', newVal);
           if (newVal !== 'editor') {