Browse Source

HUE-6176 [frontend] Integrate dynamic configuration into the left menu

Romain Rigaux 8 năm trước cách đây
mục cha
commit
2d4a9ae

+ 127 - 33
desktop/core/src/desktop/models.py

@@ -21,7 +21,6 @@ import logging
 import os
 import urllib
 import uuid
-from notebook.conf import get_ordered_interpreters
 
 try:
   from collections import OrderedDict
@@ -42,8 +41,9 @@ from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from settings import HUE_DESKTOP_VERSION
 
+from aws.conf import is_enabled as is_s3_enabled, has_s3_access
 from dashboard.conf import IS_ENABLED as IS_DASHBOARD_ENABLED
-from notebook.conf import SHOW_NOTEBOOKS
+from notebook.conf import SHOW_NOTEBOOKS, get_ordered_interpreters
 
 from desktop import appmanager
 from desktop.lib.i18n import force_unicode
@@ -1562,7 +1562,84 @@ class ClusterConfig():
           'page': '/dashboard/new_search'
         }
     else:
-      return {}
+      return None
+  
+  def _get_browser(self):
+    interpreters = []
+   
+    if 'filebrowser' in self.apps:
+      interpreters.append({
+        'type': 'hdfs',
+        'displayName': _('Files'),
+        'tooltip': _('Files'),
+        'page': '/filebrowser/'
+      })
+  
+    if is_s3_enabled() and has_s3_access(self.user):
+      interpreters.append({
+        'type': 's3',
+        'displayName': _('S3'),
+        'tooltip': _('S3'),
+        'page': '/filebrowser/view=S3A://'
+      })
+        
+    if 'metastore' in self.apps:
+      interpreters.append({
+        'type': 'tables',
+        'displayName': _('Tables'),
+        'tooltip': _('Tables'),
+        'page': '/metastore/tables'
+      })
+
+    if 'search' in self.apps:
+      interpreters.append({
+        'type': 'indexes',
+        'displayName': _('Indexes'),
+        'tooltip': _('Indexes'),
+        'page': '/indexer/'
+      })
+
+    if 'jobbrowser' in self.apps:
+      interpreters.append({
+        'type': 'jobs',
+        'displayName': _('Jobs'),
+        'tooltip': _('Jobs'),
+        'page': '/jobbrowser/'
+      })
+
+    if 'hbase' in self.apps:
+      interpreters.append({
+        'type': 'hbase',
+        'displayName': _('HBase'),
+        'tooltip': _('HBase'),
+        'page': '/hbase/'
+      })
+
+    if 'security' in self.apps:
+      interpreters.append({
+        'type': 'security',
+        'displayName': _('Security'),
+        'tooltip': _('Security'),
+        'page': '/security/hive'
+      })
+
+    if 'sqoop' in self.apps:
+      interpreters.append({
+        'type': 'sqoop',
+        'displayName': _('Sqoop'),
+        'tooltip': _('Sqoop'),
+        'page': '/sqoop'
+      })
+
+    if interpreters:
+      return {
+          'name': 'browser',
+          'displayName': _('Browsers'),
+          'interpreters': interpreters,
+        }
+    else:
+      return None
+  
   
   def _get_scheduler(self):
     interpreters = [{
@@ -1590,42 +1667,41 @@ class ClusterConfig():
           'interpreters': interpreters,
         }
     else:
-      return {}  
+      return None  
+
+
+  def _get_sdk_apps(self):
+    current_app, other_apps, apps_list = _get_apps(self.user)  
+
+    interpreters = []
+    
+    for other in other_apps:
+      interpreters.push({
+        'type': other.nice_name,
+        'displayName': other.nice_name,
+        'tooltip': other.nice_name,
+        'page': '/%s' % other.nice_name
+      })
+
+    if interpreters:
+      return {
+          'name': 'other',
+          'displayName': _('Other Apps'),
+          'interpreters': interpreters,
+        }
+    else:
+      return None
+  
   
   def get_apps(self):
     apps = OrderedDict([      
       ('editor', self._get_editor()),
       ('dashboard', self._get_dashboard()),
-      ('browser', {
-          'name': 'browser',
-          'displayName': _('Browsers'),
-        'interpreters': [{
-            'type': 'hdfs',
-            'displayName': _('Jobs'),
-            'page': '/jobbrowser/',
-          }, {
-            'type': 'metastore',
-            'displayName': _('Jobs'),
-            'page': '/jobbrowser/',
-          }, {
-            'type': 's3',
-            'displayName': _('Jobs'),
-            'page': '/jobbrowser/',
-          }, {
-            'type': 'jobbrowser',
-            'displayName': _('Jobs'),
-            'page': '/jobbrowser/',
-            'interpreters': [
-              'yarn',
-              'oozie',
-              'dataeng'
-            ]
-          }
-        ]
-      }),
-      ('scheduler', self._get_scheduler())
+      ('browser', self._get_browser()),
+      ('scheduler', self._get_scheduler()),
+      ('sdkapps', self._get_sdk_apps()),
     ])
-    
+
     # Default action
     # If not in user setting, first interpreter in apps
 #     default_app = None    
@@ -1650,6 +1726,24 @@ class ClusterConfig():
     return apps
 
 
+def _get_apps(user, section=None):
+  current_app = None
+  other_apps = []
+  if user.is_authenticated():
+    apps = appmanager.get_apps(user)
+    apps_list = appmanager.get_apps_dict(user)
+    for app in apps:
+      if app.display_name not in [
+          'beeswax', 'impala', 'pig', 'jobsub', 'jobbrowser', 'metastore', 'hbase', 'sqoop', 'oozie', 'filebrowser',
+          'useradmin', 'search', 'help', 'about', 'zookeeper', 'proxy', 'rdbms', 'spark', 'indexer', 'security', 'notebook'] and app.menu_index != -1:
+        other_apps.append(app)
+      if section == app.display_name:
+        current_app = app
+  else:
+    apps_list = []
+    
+  return current_app, other_apps, apps_list
+
 
 def get_data_link(meta):
   link = None

+ 87 - 136
desktop/core/src/desktop/templates/hue.mako

@@ -949,16 +949,19 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
         self.config = ko.observable();
         
-        $.post("/desktop/api2/get_config/", {
-          cluster: ko.mapping.toJSON('default'),
-        }, function (data) {
-          if (data.status == 0) {
-            self.config(data);
-          } else {
-            $(document).trigger("error", data.message);
-          }
-        });
+        self.getConfig = function() {
+          $.post("/desktop/api2/get_config/", {
+            cluster: ko.mapping.toJSON('default'),
+          }, function (data) {
+            if (data.status == 0) {
+              self.config(data);
+            } else {
+              $(document).trigger("error", data.message);
+            }
+          });
+        };
 
+        self.getConfig();
 
         self.mainQuickCreateAction = ko.computed(function() {          
           if (self.config()) {
@@ -1112,138 +1115,86 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
 
     (function (onePageViewModel, topNavViewModel) {
       function SideBarViewModel () {
-        self.items = [];
-
-        self.leftNavVisible = topNavViewModel.leftNavVisible;
-        self.onePageViewModel = onePageViewModel;
-
-        self.items.push({
-          displayName: '${ _('Documents') }',
-          click: function () {
-            page('/home')
-          }
-        });
-
-        var appsItems = [];
-
-        % if interpreters:
-          appsItems.push({
-            displayName: '${ _('Editor') }',
-            click: function () {
-              page('/editor?type=hive');
-            }
-          });
-        % endif
-        % if IS_DASHBOARD_ENABLED.get():
-          appsItems.push({
-            displayName: '${ _('Dashboard') }',
-            click: function () {
-              page('/dashboard/new_search');
-            }
-          });
-        % endif
-        % if 'oozie' in apps:
-          appsItems.push({
-            displayName: '${ _('Scheduler') }',
-            click: function () {
-              page('/oozie/editor/workflow/new/')
-            }
-          });
-        % endif
-
-        if (appsItems.length > 0) {
-          self.items.push({
-            isCategory: true,
-            displayName: '${ _('Apps') }',
-            children: appsItems
-          })
-        }
-
-        var browserItems = [];
-
-        % if 'filebrowser' in apps:
-          browserItems.push({
-            displayName: '${ _('Files') }',
-            click: function () {
-              page('/filebrowser/')
-            }
-          });
-        % endif
-        % if is_s3_enabled:
-          browserItems.push({
-            displayName: '${ _('S3') }',
-            click: function () {
-              page('/filebrowser/view=S3A://')
-            }
-          });
-        % endif
-        % if 'metastore' in apps:
-          browserItems.push({
-            displayName: '${ _('Tables') }',
-            click: function () {
-              page('/metastore/tables/')
-            }
-          });
-        % endif
-        % if 'search' in apps:
-          browserItems.push({
-            displayName: '${ _('Indexes') }',
-            click: function () {
-              page('/indexer/')
-            }
-          });
-        % endif
-        % if 'jobbrowser' in apps:
-          browserItems.push({
-            displayName: '${ _('Jobs') }',
-            click: function () {
-              page('/jobbrowser/')
-            }
-          });
-        % endif
-        % if 'hbase' in apps:
-          browserItems.push({
-            displayName: '${ _('HBase') }',
-            click: function () {
-              page('/hbase/')
-            }
-          });
-        % endif
-        % if 'security' in apps:
-          browserItems.push({
-            displayName: '${ _('Security') }',
+        //self.items = [];
+        
+        self.items = ko.computed(function() {
+          var items = [];
+          
+          items.push({
+            displayName: '${ _('Documents') }',
             click: function () {
-              page('/security/hive')
+              page('/home')
             }
           });
-        % endif
-        % if 'sqoop' in apps:
-          browserItems.push({
-            displayName: '${ _('Sqoop') }',
-            click: function () {
-              page('/sqoop')
-            }
+          
+          var appConfig = hueDebug.viewModel($('.top-nav')[0]).config() && hueDebug.viewModel($('.top-nav')[0]).config()['app_config'];
+          
+          if (! appConfig) {
+            return items;
+          }
+                                              
+          var appsItems = [];
+          $.each(['editor', 'dashboard', 'scheduler'], function(index, appName) {
+            if (appConfig[appName]) {
+              appsItems.push({
+                displayName: appConfig[appName]['displayName'],
+                click: function () {
+                  page(appConfig[appName]['page']);
+                }
+              });
+            };
           });
-        % endif
-
-        if (browserItems.length > 0) {
-          self.items.push({
-            isCategory: true,
-            displayName: '${ _('Browsers') }',
-            children: browserItems
-          })
-        }
+          if (appsItems.length > 0) {
+            items.push({
+              isCategory: true,
+              displayName: '${ _('Apps') }',
+              children: appsItems
+            })
+          }
+          
+          var browserItems = [];
+          if (appConfig['browser']) {
+            $.each(appConfig['browser']['interpreters'], function(index, browser) {
+              browserItems.push({
+                displayName: browser['displayName'],
+                click: function () {
+                  page(browser['page'])
+                }
+              });
+            });
+          }
+          if (browserItems.length > 0) {
+            items.push({
+              isCategory: true,
+              displayName: '${ _('Browsers') }',
+              children: browserItems
+            })
+          }
+                     
+          var sdkItems = [];
+          if (appConfig['sdkapps']) {
+            $.each(appConfig['sdkapps']['interpreters'], function(index, browser) {
+              sdkItems.push({
+                displayName: browser['displayName'],
+                click: function () {
+                  page(browser['page'])
+                }
+              });
+            });
+          }
+          if (sdkItems.length > 0) {
+            items.push({
+              isCategory: true,
+              displayName: appConfig['sdkapps']['displayName'],
+              children: sdkItems
+            })
+          }
+          
+          return items;
+        });
 
-        % if other_apps:
-        % for other in other_apps:
-          appsItems.push({
-            displayName: '${ other.nice_name }',
-            click: function () {
-              window.location('/${ other.nice_name }')
-            }
-          });
-        % endfor
-        % endif
+        self.leftNavVisible = topNavViewModel.leftNavVisible;
+        self.onePageViewModel = onePageViewModel;
       }
 
       var sidebarViewModel = new SideBarViewModel();

+ 3 - 16
desktop/core/src/desktop/views.py

@@ -44,6 +44,7 @@ from notebook.conf import get_ordered_interpreters
 import desktop.conf
 import desktop.log.log_buffer
 
+from desktop import appmanager
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json, _get_docs
 
 from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER, HTTP_PORT
@@ -55,8 +56,7 @@ from desktop.lib.paths import get_desktop_root
 from desktop.lib.thread_util import dump_traceback
 from desktop.log.access import access_log_level, access_warn
 from desktop.log import set_all_debug as _set_all_debug, reset_all_debug as _reset_all_debug, get_all_debug as _get_all_debug
-from desktop.models import UserPreferences, Settings, hue_version, ClusterConfig
-from desktop import appmanager
+from desktop.models import UserPreferences, Settings, hue_version, ClusterConfig, _get_apps
 
 
 LOG = logging.getLogger(__name__)
@@ -438,20 +438,7 @@ def commonheader(title, section, user, request=None, padding="90px", skip_topbar
   """
   Returns the rendered common header
   """
-  current_app = None
-  other_apps = []
-  if user.is_authenticated():
-    apps = appmanager.get_apps(user)
-    apps_list = appmanager.get_apps_dict(user)
-    for app in apps:
-      if app.display_name not in [
-          'beeswax', 'impala', 'pig', 'jobsub', 'jobbrowser', 'metastore', 'hbase', 'sqoop', 'oozie', 'filebrowser',
-          'useradmin', 'search', 'help', 'about', 'zookeeper', 'proxy', 'rdbms', 'spark', 'indexer', 'security', 'notebook'] and app.menu_index != -1:
-        other_apps.append(app)
-      if section == app.display_name:
-        current_app = app
-  else:
-    apps_list = []
+  current_app, other_apps, apps_list = _get_apps(user, section)
 
   template = 'common_header.mako'
   if is_mobile: