Browse Source

HUE-8330 [metastore] Enable context switching in the Table Browser

Johan Ahlen 7 years ago
parent
commit
0473951715

+ 9 - 6
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -326,13 +326,16 @@ var MetastoreViewModel = (function () {
       }
       }
     };
     };
 
 
-    if (self.loadingDatabases() && self.lastLoadDatabasesPromise !== null) {
-      self.lastLoadDatabasesPromise.done(function () {
+    window.setTimeout(function () {
+      if (self.loadingDatabases() && self.lastLoadDatabasesPromise !== null) {
+        self.lastLoadDatabasesPromise.done(function () {
+          whenLoaded(true);
+        });
+      } else {
         whenLoaded(true);
         whenLoaded(true);
-      });
-    } else {
-      whenLoaded(true);
-    }
+      }
+
+    }, 0);
   };
   };
 
 
   MetastoreViewModel.prototype.loadURL = function () {
   MetastoreViewModel.prototype.loadURL = function () {

+ 11 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -984,6 +984,17 @@ ${ components.menubar(is_embeddable) }
           <!-- ko ifnot: loading -->
           <!-- ko ifnot: loading -->
           <h1>
           <h1>
             <div class="inline-block pull-right">
             <div class="inline-block pull-right">
+              <!-- ko component: {
+                name: 'hue-drop-down',
+                params: {
+                  icon: 'fa-crosshairs',
+                  value: activeSourceContext,
+                  entries: sourceContexts,
+                  searchable: true,
+                  labelAttribute: 'name',
+                  linkTitle: 'Active context'
+                 }
+               } --><!-- /ko -->
               <!-- ko with: database -->
               <!-- ko with: database -->
               <!-- ko with: table -->
               <!-- ko with: table -->
               % if USE_NEW_EDITOR.get():
               % if USE_NEW_EDITOR.get():
@@ -1005,7 +1016,6 @@ ${ components.menubar(is_embeddable) }
               <a href="javascript: void(0);" class="btn btn-default" data-bind="click: reload" title="${_('Refresh the table')}"><i class="fa fa-refresh" data-bind="css: { 'fa-spin blue' : refreshing }"></i> ${_('Refresh')}</a>
               <a href="javascript: void(0);" class="btn btn-default" data-bind="click: reload" title="${_('Refresh the table')}"><i class="fa fa-refresh" data-bind="css: { 'fa-spin blue' : refreshing }"></i> ${_('Refresh')}</a>
               <!-- /ko -->
               <!-- /ko -->
               <!-- ko if: !table() -->
               <!-- ko if: !table() -->
-              <select data-bind="selectize: $parent.sourceContexts, value: $parent.sourceContext" class="input-medium"></select>
               <a href="javascript: void(0);" class="btn btn-default" data-bind="click: reload" title="${_('Refresh the database')}"><i class="fa fa-refresh" data-bind="css: { 'fa-spin blue' : refreshing }"></i> ${_('Refresh')}</a>
               <a href="javascript: void(0);" class="btn btn-default" data-bind="click: reload" title="${_('Refresh the database')}"><i class="fa fa-refresh" data-bind="css: { 'fa-spin blue' : refreshing }"></i> ${_('Refresh')}</a>
               <!-- /ko -->
               <!-- /ko -->
               <!-- /ko -->
               <!-- /ko -->

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1296,7 +1296,7 @@ var ApiHelper = (function () {
           type: sourceType,
           type: sourceType,
           source: isQuery ? 'query' : 'data',
           source: isQuery ? 'query' : 'data',
         }),
         }),
-        cluster: options.sourceContext.id
+        cluster: '"' + options.sourceContext.id + '"'
       },
       },
       timeout: options.timeout
       timeout: options.timeout
     }).success(function (data) {
     }).success(function (data) {

+ 6 - 5
desktop/core/src/desktop/templates/ko_components/ko_drop_down.mako

@@ -29,7 +29,7 @@ from desktop.views import _ko
     <a class="inactive-action hue-drop-down-active" href="javascript:void(0)" data-bind="toggle: dropDownVisible, css: { 'blue': dropDownVisible }">
     <a class="inactive-action hue-drop-down-active" href="javascript:void(0)" data-bind="toggle: dropDownVisible, css: { 'blue': dropDownVisible }">
       <!-- ko if: icon --><i class="fa" data-bind="css: icon"></i><!-- /ko -->
       <!-- ko if: icon --><i class="fa" data-bind="css: icon"></i><!-- /ko -->
       <!-- ko if: !noLabel && value -->
       <!-- ko if: !noLabel && value -->
-      <span data-bind="text: typeof value().label !== 'undefined' ? value().label : value(), visible: ! dropDownVisible() || !searchable, attr: { 'title': linkTitle }" ></span>
+      <span data-bind="text: typeof value()[labelAttribute] !== 'undefined' ? value()[labelAttribute] : value(), visible: ! dropDownVisible() || !searchable, attr: { 'title': linkTitle }" ></span>
       <!-- /ko -->
       <!-- /ko -->
       <i class="fa fa-caret-down"></i>
       <i class="fa fa-caret-down"></i>
     </a>
     </a>
@@ -46,7 +46,7 @@ from desktop.views import _ko
           <li class="divider"></li>
           <li class="divider"></li>
           <!-- /ko -->
           <!-- /ko -->
           <!-- ko if: typeof $data.divider === 'undefined' || !$data.divider -->
           <!-- ko if: typeof $data.divider === 'undefined' || !$data.divider -->
-          <li><a href="javascript:void(0)" data-bind="text: typeof $data.label !== 'undefined' ? $data.label : $data, click: function () { $parent.value($data); }"></a></li>
+          <li><a href="javascript:void(0)" data-bind="text: typeof $data[$parent.labelAttribute] !== 'undefined' ? $data[$parent.labelAttribute] : $data, click: function () { $parent.value($data); }"></a></li>
           <!-- /ko -->
           <!-- /ko -->
         </ul>
         </ul>
         <!-- /ko -->
         <!-- /ko -->
@@ -56,7 +56,7 @@ from desktop.views import _ko
           <li class="divider"></li>
           <li class="divider"></li>
           <!-- /ko -->
           <!-- /ko -->
           <!-- ko if: typeof $data.divider === 'undefined' || !$data.divider -->
           <!-- ko if: typeof $data.divider === 'undefined' || !$data.divider -->
-          <li><a href="javascript:void(0)" data-bind="text: typeof $data.label !== 'undefined' ? $data.label : $data, click: function () { $parent.value($data); }"></a></li>
+          <li><a href="javascript:void(0)" data-bind="text: typeof $data[$parent.labelAttribute] !== 'undefined' ? $data[$parent.labelAttribute] : $data, click: function () { $parent.value($data); }"></a></li>
           <!-- /ko -->
           <!-- /ko -->
         </ul>
         </ul>
         <!-- /ko -->
         <!-- /ko -->
@@ -158,6 +158,7 @@ from desktop.views import _ko
         self.dropDownVisible = ko.observable(!!params.showOnInit);
         self.dropDownVisible = ko.observable(!!params.showOnInit);
         self.menuOnly = !!params.menuOnly;
         self.menuOnly = !!params.menuOnly;
         self.noLabel = !!params.noLabel;
         self.noLabel = !!params.noLabel;
+        self.labelAttribute = params.labelAttribute || 'label';
         self.icon = params.icon;
         self.icon = params.icon;
         self.value = params.value;
         self.value = params.value;
         self.entries = params.entries;
         self.entries = params.entries;
@@ -167,7 +168,7 @@ from desktop.views import _ko
         self.fixedPosition = !!params.fixedPosition;
         self.fixedPosition = !!params.fixedPosition;
 
 
         self.inputPlaceHolder = ko.pureComputed(function () {
         self.inputPlaceHolder = ko.pureComputed(function () {
-          return typeof self.value() === 'object' ? self.value().label : self.value();
+          return typeof self.value() === 'object' ? self.value()[self.labelAttribute] : self.value();
         });
         });
 
 
         var closeOnOutsideClick = function (e) {
         var closeOnOutsideClick = function (e) {
@@ -220,7 +221,7 @@ from desktop.views import _ko
             var lowerFilter = self.filter().toLowerCase();
             var lowerFilter = self.filter().toLowerCase();
             return ko.unwrap(self.entries).filter(function (entry) {
             return ko.unwrap(self.entries).filter(function (entry) {
               if (typeof entry === 'object') {
               if (typeof entry === 'object') {
-                return entry.label.toLowerCase().indexOf(lowerFilter) !== -1;
+                return entry[self.labelAttribute].toLowerCase().indexOf(lowerFilter) !== -1;
               }
               }
               return entry.toLowerCase().indexOf(lowerFilter) !== -1;
               return entry.toLowerCase().indexOf(lowerFilter) !== -1;
             });
             });