Browse Source

HUE-3727 [home] Create new editor document from home directory in responsive

Romain Rigaux 8 years ago
parent
commit
bf538c2

+ 10 - 14
desktop/conf.dist/hue.ini

@@ -1613,35 +1613,31 @@
 ###########################################################################
 
 [metadata]
-  # For metadata tagging and enhancement features
 
   [[optimizer]]
     # Cache timeout in milliseconds for the Optimizer metadata used in assist, autocomplete, etc.
     # defaults to 432000000 (5 days), set to 0 to disable caching
     # cacheable_ttl=432000000
 
-    # For SQL query and table analysis
     # Base URL to Optimizer API.
-    ## api_url=https://alpha.optimizer.cloudera.com
-    # The name of the product or group which will have API access to the emails associated with it.
-    ## product_name=hue
-    # A secret passphrase associated with the productName
-    ## product_secret=hue
-    # Execute this script to produce the product secret. This will be used when 'product_secret' is not set.
-    ## product_secret_script=
+    ## api_url=https://optimizer.cloudera.com
+
+    # Aka workload or tenant id, keep commented and it will be guessed from the email.
+    ## product_name=e0819f3a-1e6f-4904-be69-5b704bacd1244
+
+    # A secret passphrase associated with the account.
+    ## product_secret=e0819f3a-1e6f-4904-be69-5b704bacd1245
+
+    # A secret key passphrase associated with the account.
+    ## product_auth_secret='-----BEGIN PRIVATE KEY....'
 
     # The email of the Optimizer account you want to associate with the Product.
     ## email=hue@gethue.com
-    # The password associated with the Optimizer account you to associate with the Product.
-    ## email_password=hue
-    # Execute this script to produce the email password. This will be used when 'email_password' is not set.
-    ## password_script=
 
     # In secure mode (HTTPS), if Optimizer SSL certificates have to be verified against certificate authority.
     ## ssl_cert_ca_verify=True
 
   [[navigator]]
-    # For tagging tables, files and getting lineage of data.
     # Navigator API URL (without version suffix).
     ## api_url=http://localhost:7187/api
 

+ 10 - 14
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1617,35 +1617,31 @@
 ###########################################################################
 
 [metadata]
-  # For metadata tagging and enhancement features
 
   [[optimizer]]
     # Cache timeout in milliseconds for the Optimizer metadata used in assist, autocomplete, etc.
     # defaults to 432000000 (5 days), set to 0 to disable caching
     # cacheable_ttl=432000000
 
-    # For SQL query and table analysis
     # Base URL to Optimizer API.
-    ## api_url=https://alpha.optimizer.cloudera.com
-    # The name of the product or group which will have API access to the emails associated with it.
-    ## product_name=hue
-    # A secret passphrase associated with the productName
-    ## product_secret=hue
-    # Execute this script to produce the product secret. This will be used when 'product_secret' is not set.
-    ## product_secret_script=
+    ## api_url=https://optimizer.cloudera.com
+
+    # Aka workload or tenant id, keep commented and it will be guessed from the email.
+    ## product_name=e0819f3a-1e6f-4904-be69-5b704bacd1244
+
+    # A secret passphrase associated with the account.
+    ## product_secret=e0819f3a-1e6f-4904-be69-5b704bacd1245
+
+    # A secret key passphrase associated with the account.
+    ## product_auth_secret='-----BEGIN PRIVATE KEY....'
 
     # The email of the Optimizer account you want to associate with the Product.
     ## email=hue@gethue.com
-    # The password associated with the Optimizer account you to associate with the Product.
-    ## email_password=hue
-    # Execute this script to produce the email password. This will be used when 'email_password' is not set.
-    ## password_script=
 
     # In secure mode (HTTPS), if Optimizer SSL certificates have to be verified against certificate authority.
     ## ssl_cert_ca_verify=True
 
   [[navigator]]
-    # For tagging tables, files and getting lineage of data.
     # Navigator API URL (without version suffix).
     ## api_url=http://localhost:7187/api
 

+ 19 - 3
desktop/core/src/desktop/static/desktop/js/document/hueFileEntry.js

@@ -210,15 +210,31 @@ var HueFileEntry = (function () {
     });
   }
 
-  HueFileEntry.prototype.addDirectoryParamToUrl = function (url) {
+  HueFileEntry.prototype.getDirectory = function () {
     var self = this;
+
     if (! self.definition() || self.isRoot()) {
+      return null;
+    }
+    else {
+      return self.definition().uuid;
+    }
+  };
+
+  HueFileEntry.prototype.addDirectoryParamToUrl = function (url) {
+    var self = this;
+
+    var directoryId = self.getDirectory();
+
+    if (! directoryId) {
       return url;
     }
-    if (url.indexOf('?') !== -1) {
+    else if (url.indexOf('?') !== -1) {
       return url + '&directory_uuid=' + self.definition().uuid;
     }
-    return url + '?directory_uuid=' + self.definition().uuid;
+    else {
+      return url + '?directory_uuid=' + self.definition().uuid;
+    }
   };
 
   HueFileEntry.prototype.beforeContextOpen = function () {

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/home2.vm.js

@@ -61,7 +61,7 @@ var HomeViewModel = (function () {
     var self = this;
     var entry = self.activeEntry().createNewEntry({
       definition: {
-        uuid: location.getParameter('uuid'),
+        uuid: uuid || location.getParameter('uuid'),
         name: 'unknown',
         type: 'directory',
         path: '/unknown'

+ 54 - 10
desktop/core/src/desktop/templates/document_browser.mako

@@ -645,27 +645,71 @@ 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') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static(apps['beeswax'].icon_path) }" class="app-icon" alt="${ _('Hive icon') }"/> ${_('Hive Query')}</a></li>
+                  <li>
+                    <a title="${_('Hive Query')}"
+                    % if is_embeddable:
+                      data-bind="click: function() { huePubSub.publish('open.editor.new.query', {type: 'hive', 'directoryUuid': getDirectory()}); }" href="javascript:void(0);"
+                    % else:
+                      data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=hive')}"
+                    % endif
+                    >
+                      <img src="${ static(apps['beeswax'].icon_path) }" class="app-icon" alt="${ _('Hive 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') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static(apps['impala'].icon_path) }" class="app-icon" alt="${ _('Impala icon') }"/> ${_('Impala Query')}</a></li>
-                % endif
-                % if 'pig' in apps:
-                  <li><a title="${_('Pig Script')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('pig:index') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static(apps['pig'].icon_path) }" class="app-icon" alt="${ _('Pig icon') }"/> ${_('Pig Script')}</a></li>
+                  <li>
+                    <a title="${_('Impala Query')}"
+                    % if is_embeddable:
+                      data-bind="click: function() { huePubSub.publish('open.editor.new.query', {type: 'impala', 'directoryUuid': getDirectory()}); }" href="javascript:void(0);"
+                    else:
+                      data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:editor') }?type=impala') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"
+                    % endif
+                    >
+                      <img src="${ static(apps['impala'].icon_path) }" class="app-icon" alt="${ _('Impala icon') }"/> ${_('Impala Query')}
+                    </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') }') }, click: ${ is_embeddable and 'openHue4Link' 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>
+                  <li>
+                    <a title="${_('Notebook')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('notebook:index') }') }, click: ${ is_embeddable and 'openHue4Link' 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 'pig' in apps:
+                  <li>
+                    <a title="${_('Pig Script')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('pig:index') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }">
+                      <img src="${ static(apps['pig'].icon_path) }" class="app-icon" alt="${ _('Pig icon') }"/> ${_('Pig Script')}
+                    </a>
+                  </li>
                 % endif
                 % if 'oozie' in apps:
-                  <li><a title="${_('Oozie Workflow')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_workflow') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_workflow_48.png') }" class="app-icon" alt="${ _('Oozie workflow icon') }"/> ${_('Oozie Workflow')}</a></li>
-                  <li><a title="${_('Oozie Coordinator')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_coordinator') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_coordinator_48.png') }" class="app-icon" alt="${ _('Oozie coordinator icon') }"/> ${_('Oozie Coordinator')}</a></li>
-                  <li><a title="${_('Oozie Bundle')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_bundle') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static('oozie/art/icon_oozie_bundle_48.png') }" class="app-icon" alt="${ _('Oozie bundle icon') }"/> ${_('Oozie Bundle')}</a></li>
+                  <li>
+                    <a title="${_('Oozie Workflow')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_workflow') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }">
+                      <img src="${ static('oozie/art/icon_oozie_workflow_48.png') }" class="app-icon" alt="${ _('Oozie workflow icon') }"/> ${_('Oozie Workflow')}
+                    </a>
+                  </li>
+                  <li>
+                    <a title="${_('Oozie Coordinator')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_coordinator') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }">
+                      <img src="${ static('oozie/art/icon_oozie_coordinator_48.png') }" class="app-icon" alt="${ _('Oozie coordinator icon') }"/> ${_('Oozie Coordinator')}
+                    </a>
+                  </li>
+                  <li>
+                    <a title="${_('Oozie Bundle')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('oozie:new_bundle') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }">
+                      <img src="${ static('oozie/art/icon_oozie_bundle_48.png') }" class="app-icon" alt="${ _('Oozie bundle icon') }"/> ${_('Oozie Bundle')}
+                    </a>
+                  </li>
                 % endif
                 % if 'search' in apps:
-                  <li><a title="${_('Solr Search')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('search:index') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }"><img src="${ static('search/art/icon_search_48.png') }" class="app-icon" alt="${ _('Search icon') }"/> ${_('Search Dashboard')}</a></li>
+                  <li>
+                    <a title="${_('Solr Search')}" data-bind="attr: { href: addDirectoryParamToUrl('${ url('search:index') }') }, click: ${ is_embeddable and 'openHue4Link' or 'openExternalLink' }">
+                      <img src="${ static('search/art/icon_search_48.png') }" class="app-icon" alt="${ _('Search icon') }"/> ${_('Search Dashboard')}
+                    </a>
+                  </li>
                 % endif
               </ul>
             </span>

+ 19 - 8
desktop/core/src/desktop/templates/hue.mako

@@ -13,6 +13,7 @@
 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
+
 <%!
   from django.utils.translation import ugettext as _
 
@@ -230,17 +231,15 @@ ${ hueIcons.symbols() }
   <div class="content-wrapper">
     <div class="left-nav" data-bind="css: { 'left-nav-visible': leftNavVisible }, niceScroll">
       <ul class="left-nav-menu">
-        <li class="header" style="padding-left: 4px; border-bottom: 1px solid #DDD; padding-bottom: 3px;">${ _('Analyse') }</li>
         <li data-bind="click: function () { onePageViewModel.currentApp('home') }"><a href="javascript: void(0);">Home</a></li>
+        <li class="header">&nbsp;</li>
+        <li class="header" style="padding-left: 4px; border-bottom: 1px solid #DDD; padding-bottom: 3px;">${ _('Analyse') }</li>
         % if interpreters:
         <li data-bind="click: function () { onePageViewModel.changeEditorType('hive'); onePageViewModel.currentApp('editor') }"><a href="javascript: void(0);">Editor</a></li>
         % endif
         % if IS_DASHBOARD_ENABLED.get():
         <li data-bind="click: function () { onePageViewModel.currentApp('dashboard') }"><a href="javascript: void(0);">Dashboard</a></li>
         % endif
-        % if SHOW_NOTEBOOKS.get():
-        <li data-bind="click: function () { onePageViewModel.currentApp('notebook') }"><a href="javascript: void(0);">Notebook</a></li>
-        % endif
         % if 'oozie' in apps:
         <li data-bind="click: function () { onePageViewModel.currentApp('oozie_workflow') }"><a href="javascript: void(0);">Workflows</a></li>
         % endif
@@ -616,12 +615,19 @@ ${ assist.assistPanel() }
           })
         });
 
-        huePubSub.subscribe('open.editor.query.external', function (statementOptions) {
+        huePubSub.subscribe('open.editor.new.query', function (statementOptions) {
           self.currentApp('editor');
+
           self.getActiveAppViewModel(function (viewModel) {
-            viewModel.newNotebook(function() { // Uses default type of Editor
-              viewModel.selectedNotebook().snippets()[0].statementType(statementOptions['statementType']);
-              viewModel.selectedNotebook().snippets()[0].statementPath(statementOptions['statementPath']);
+            var editorType = statementOptions['type'] || 'hive'; // Next: use file extensions and default type of Editor for SQL
+            viewModel.newNotebook(editorType, function() {
+              if (statementOptions['statementType']) {
+                viewModel.selectedNotebook().snippets()[0].statementType(statementOptions['statementType']);
+                viewModel.selectedNotebook().snippets()[0].statementPath(statementOptions['statementPath']);
+              }
+              if (statementOptions['directoryUuid']) {
+                viewModel.selectedNotebook().directoryUuid(statementOptions['directoryUuid']);
+              }
             });
           })
         });
@@ -670,6 +676,11 @@ ${ assist.assistPanel() }
             self.currentApp('editor');
           } else if (href.startsWith('/indexer')){
             self.currentApp('indexes');
+          } else if (href.startsWith('/home')){
+            self.currentApp('home');
+            self.getActiveAppViewModel(function (viewModel) {
+              viewModel.openUuid(hueUtils.getSearchParameter(href, 'uuid'));
+            });
           } else if (href.startsWith('/dashboard/embeddable') || href.startsWith('/dashboard/new_search')){
             self.currentApp('dashboard');
           } else if (href.startsWith('/dashboard/admin/collections')){

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

@@ -2603,9 +2603,9 @@ var EditorViewModel = (function() {
       });
     };
 
-    self.newNotebook = function (callback) {
+    self.newNotebook = function (editorType, callback) {
       $.post("/notebook/api/create_notebook", {
-        type: options.editor_type,
+        type: options.editor_type || editorType || 'hive',
         directory_uuid: window.location.getParameter('directory_uuid')
       }, function (data) {
         self.loadNotebook(data.notebook);

+ 11 - 2
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -354,7 +354,16 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
             <a title="${ _('This is a history query') }"><i class="fa fa-fw fa-history"></i></a>
           </li>
           <li data-bind="visible: directoryUuid" style="display: none" class="no-horiz-padding muted">
-            <a title="${ _('Open directory of this query') }" data-bind="attr: { 'href': '/home?uuid=' + directoryUuid() }" class="pointer inactive-action"><i class="fa fa-fw fa-folder-o"></i></a>
+            <!-- ko if: IS_HUE_4 -->
+              <a title="${ _('Open directory of this query') }" data-bind="click: function() { huePubSub.publish('open.link', '/home?uuid=' + directoryUuid()) }"
+                class="pointer inactive-action" href="javascript:void(0)"><i class="fa fa-fw fa-folder-o"></i>
+              </a>
+            <!-- /ko -->
+            <!-- ko if: ! IS_HUE_4 -->
+              <a title="${ _('Open directory of this query') }" data-bind="attr: { 'href': '/home?uuid=' + directoryUuid() }"
+                class="pointer inactive-action"><i class="fa fa-fw fa-folder-o"></i>
+              </a>
+            <!-- /ko -->
           </li>
           <li data-bind="visible: parentSavedQueryUuid" style="display: none" class="no-horiz-padding muted">
             <a title="${ _('Click to open original saved query') }" data-bind="click: function() { $root.openNotebook(parentSavedQueryUuid()) }" class="pointer inactive-action">
@@ -601,7 +610,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
           <a data-bind="click: $root.saveNotebook">${ _('Save changes') }</a>
         <!-- /ko -->
         <!-- ko if: schedulerViewModelIsLoaded() && ! schedulerViewModel.coordinator.isDirty() && ! viewSchedulerId()-->
-          <a data-bind="click: showSubmitPopup">${ _('Start') }</a>
+          <a data-bind="click: showSubmitPopup" href="javascript: void(0);">${ _('Start') }</a>
         <!-- /ko -->
         <!-- ko if: schedulerViewModelIsLoaded() && viewSchedulerId()-->
           <a data-bind="click: showSubmitPopup">${ _('View') }</a>