Browse Source

HUE-8330 [assist] Add a refresh action to namespace assist listing

Johan Ahlen 7 years ago
parent
commit
cb2cbbcbd4

+ 26 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -117,7 +117,32 @@ var AssistDbSource = (function () {
   };
 
   AssistDbSource.prototype.triggerRefresh = function (data, event) {
-    // TODO: Refresh namespaces
+    var self = this;
+    self.loading(true);
+    ContextCatalog.getNamespaces({ sourceType: self.sourceType, clearCache: true }).done(function (namespaces) {
+      var newNamespaces = [];
+      var existingNamespaceIndex = {};
+      self.namespaces().forEach(function (assistNamespace) {
+        existingNamespaceIndex[assistNamespace.namespace.id] = assistNamespace;
+      });
+      namespaces.forEach(function(newNamespace) {
+        if (existingNamespaceIndex[newNamespace.id]) {
+          existingNamespaceIndex[newNamespace.id].namespace = newNamespace;
+          existingNamespaceIndex[newNamespace.id].name = newNamespace.name;
+          newNamespaces.push(existingNamespaceIndex[newNamespace.id]);
+        } else {
+          newNamespaces.push(new AssistDbNamespace({
+            sourceType: self.sourceType,
+            namespace: namespace,
+            i18n: self.i18n,
+            navigationSettings: self.navigationSettings
+          }));
+        }
+      });
+      self.namespaces(newNamespaces);
+    }).always(function () {
+      self.loading(false);
+    })
   };
 
   return AssistDbSource;

+ 11 - 4
desktop/core/src/desktop/static/desktop/js/contextCatalog.js

@@ -40,12 +40,18 @@ var ContextCatalog = (function () {
     /**
      * @param {Object} options
      * @param {string} options.sourceType
-     * @param {boolean} [options.silenceErrors]
+     * @param {boolean} [options.clearCache] - Default False
+     * @param {boolean} [options.silenceErrors] - Default False
      * @return {Promise}
      */
     ContextCatalog.prototype.getNamespaces = function (options) {
       var self = this;
 
+      if (options.clearCache) {
+        self.namespacePromises[options.sourceType] = undefined;
+        self.namespaces[options.sourceType] = undefined;
+      }
+
       if (self.namespacePromises[options.sourceType]) {
         return self.namespacePromises[options.sourceType];
       }
@@ -79,7 +85,7 @@ var ContextCatalog = (function () {
     /**
      * @param {Object} options
      * @param {string} options.sourceType
-     * @param {boolean} [options.silenceErrors]
+     * @param {boolean} [options.silenceErrors] - Default False
      * @return {Promise}
      */
     ContextCatalog.prototype.getComputes = function (options) {
@@ -125,7 +131,8 @@ var ContextCatalog = (function () {
       /**
        * @param {Object} options
        * @param {string} options.sourceType
-       * @param {boolean} [options.silenceErrors]
+       * @param {boolean} [options.clearCache] - Default False
+       * @param {boolean} [options.silenceErrors] - Default False
        * @return {Promise}
        */
       getNamespaces: function (options) {
@@ -134,7 +141,7 @@ var ContextCatalog = (function () {
       /**
        * @param {Object} options
        * @param {string} options.sourceType
-       * @param {boolean} [options.silenceErrors]
+       * @param {boolean} [options.silenceErrors] - Default False
        * @return {Promise}
        */
       getComputes: function (options) {

+ 13 - 0
desktop/core/src/desktop/templates/assist.mako

@@ -764,6 +764,18 @@ from desktop.views import _ko
     <div style="width: 100%; display: inline-block; margin-top: 5px;"><button class="pull-right btn btn-primary" data-bind="css: { 'btn-primary': invalidateOnRefresh() !== 'invalidateAndFlush', 'btn-danger': invalidateOnRefresh() === 'invalidateAndFlush' }, click: function (data, event) { huePubSub.publish('close.popover'); triggerRefresh(data, event); }, clickBubble: false">${ _('Refresh') }</button></div>
   </script>
 
+  <script type="text/html" id="assist-namespace-header-actions">
+    <div class="assist-db-header-actions">
+      <!-- ko ifnot: loading -->
+      <span class="assist-tables-counter">(<span data-bind="text: filteredNamespaces().length"></span>)</span>
+      <a class="inactive-action" href="javascript:void(0)" data-bind="click: triggerRefresh"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Refresh')}"></i></a>
+      <!-- /ko -->
+      <!-- ko if: loading -->
+      <i class="fa fa-refresh fa-spin blue" title="${_('Refresh')}"></i>
+      <!-- /ko -->
+    </div>
+  </script>
+
   <script type="text/html" id="assist-db-header-actions">
     <div class="assist-db-header-actions">
       <!-- ko ifnot: loading -->
@@ -819,6 +831,7 @@ from desktop.views import _ko
     <div class="assist-flex-header">
       <div class="assist-inner-header">
         ${_('Namespaces')}
+        <!-- ko template: 'assist-namespace-header-actions' --><!-- /ko -->
       </div>
     </div>
     <div class="assist-flex-search" data-bind="visible: hasNamespaces() && !hasErrors()">