瀏覽代碼

HUE-6245 [cluster] Display list of cluster dynamically in the top menu

Romain Rigaux 8 年之前
父節點
當前提交
9a2a6bb
共有 3 個文件被更改,包括 45 次插入35 次删除
  1. 2 9
      desktop/core/src/desktop/api2.py
  2. 11 0
      desktop/core/src/desktop/models.py
  3. 32 26
      desktop/core/src/desktop/templates/hue.mako

+ 2 - 9
desktop/core/src/desktop/api2.py

@@ -43,7 +43,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.export_csvxls import make_response
 from desktop.lib.i18n import smart_str, force_unicode
 from desktop.models import Document2, Document, Directory, FilesystemException, uuid_default, ClusterConfig,\
-  UserPreferences
+  UserPreferences, get_user_preferences
 
 
 LOG = logging.getLogger(__name__)
@@ -586,14 +586,7 @@ def user_preferences(request, key=None):
   response = {'status': 0, 'data': {}}
 
   if request.method != "POST":
-    if key is not None:
-      try:
-        x = UserPreferences.objects.get(user=request.user, key=key)
-        response['data'] = {key: x.value}
-      except UserPreferences.DoesNotExist:
-        response['data'] = None
-    else:
-      response['data'] = dict((x.key, x.value) for x in UserPreferences.objects.filter(user=request.user))
+    response['data'] = get_user_preferences(request.user, key)
   else:
     if "set" in request.POST:
       try:

+ 11 - 0
desktop/core/src/desktop/models.py

@@ -1788,6 +1788,17 @@ def _get_apps(user, section=None):
   return current_app, other_apps, apps_list
 
 
+def get_user_preferences(user, key=None):
+  if key is None:
+    try:
+      x = UserPreferences.objects.get(user=user, key=key)
+      return {key: x.value}
+    except UserPreferences.DoesNotExist:
+      return None
+  else:
+    return dict((x.key, x.value) for x in UserPreferences.objects.filter(user=user))
+
+
 def get_data_link(meta):
   link = None
 

+ 32 - 26
desktop/core/src/desktop/templates/hue.mako

@@ -162,32 +162,38 @@ ${ hueIcons.symbols() }
           </button>
 
           <ul class="dropdown-menu">
-            <li class="dropdown-submenu">
-              <a data-rel="navigator-tooltip" href="javascript: void(0)" data-bind="click: function(){ page('/editor'); onePageViewModel.changeEditorType('hive', true); }">
-                <i class="fa fa-fw fa-th-large inline-block"></i> ${ _('Data Eng') }
-              </a>
-              <ul class="dropdown-menu">
-               <li><a data-rel="navigator-tooltip" href="#"><span class="dropdown-no-icon"><i class="fa fa-fw fa-plus inline-block"></i></span></a></li>
-                <!-- ko foreach: cluster.clusters()[3]['clusters'] -->
-                  <li>
-                    <a href="javascript: void(0)" data-bind="click: function() { $parent.cluster.cluster($data) }">
-                      <span class="dropdown-no-icon" data-bind="text: name"></span>
-                    </a>
+            <!-- ko foreach: cluster.clusters -->
+              <li>
+              <!-- ko switch: type -->
+                <!-- ko case: 'dataeng' -->
+                <li class="dropdown-submenu">
+                  <a data-rel="navigator-tooltip" href="javascript: void(0)">
+                    <i class="fa fa-fw fa-th-large inline-block"></i> <span data-bind="text: name"></span>
+                  </a>
+                  <ul class="dropdown-menu">
+                    <li>
+                      <a data-rel="navigator-tooltip" href="#">
+                        <span class="dropdown-no-icon"><i class="fa fa-fw fa-plus inline-block"></i></span>
+                      </a>
+                    </li>
+                    <!-- ko foreach: $data['clusters'] -->
+                      <li>
+                        <a href="javascript: void(0)" data-bind="click: function() { $root.cluster.cluster($data) }">
+                          <span class="dropdown-no-icon" data-bind="text: name"></span>
+                        </a>
+                      </li>
+                    <!-- /ko -->
+                  </ul>
+                </li>
+                <!-- /ko -->
+                <!-- ko case: $default -->
+                  <li><a href="javascript: void(0)" data-bind="click: function(){  $root.cluster.cluster($data) }">
+                    <i class="fa fa-fw fa-square"></i> <span data-bind="text: name"></span></a>
                   </li>
                 <!-- /ko -->
-              </ul>
-            </li>
-            <li><a href="javascript: void(0)" data-bind="click: function(){ page('/dashboard/new_search') }"><i class="fa fa-fw fa-th-large"></i> ${ _('Team') }</a></li>
-            <li><a href="javascript: void(0)" data-bind="click: function(){ page('/dashboard/new_search') }"><i class="fa fa-fw fa-square"></i> ${ _('Athena') }</a></li>
-            <li class="dropdown-submenu">
-              <a data-rel="navigator-tooltip" href="javascript: void(0)" data-bind="click: function(){ page('/editor'); onePageViewModel.changeEditorType('hive', true); }">
-                <i class="fa fa-fw fa-th-large inline-block"></i> ${ _('Nightly') }
-              </a>
-              <ul class="dropdown-menu">
-              <li><a  href="javascript: void(0)"><span class="dropdown-no-icon">Cluster 1</span></a></li>
-              <li><a  href="javascript: void(0)"><span class="dropdown-no-icon">Cluster 2</span></a></li>
-              </ul>
-            </li>
+              <!-- /ko -->
+              </li>
+            <!-- /ko -->
           </ul>
         </div>
 
@@ -1183,8 +1189,8 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
             {'name': 'Athena', 'type': 'athena'}
           ]);
           self.cluster = ko.observable(self.clusters()[0]);
-          self.cluster.subscribe(function() {
-            new ClusterConfig(ko.mapping.toJS(self.cluster));
+          self.cluster.subscribe(function(newValue) {
+            new ClusterConfig(ko.mapping.toJS(newValue));
           });
 
           self.contextPanelVisible = ko.observable(false);