Browse Source

HUE-6479 [frontend] Update the top nav create button when the favourite app has changed

Johan Ahlen 8 năm trước cách đây
mục cha
commit
8b63cdf

+ 19 - 13
desktop/core/src/desktop/static/desktop/js/clusterConfig.js

@@ -21,20 +21,26 @@ function ClusterConfig (params) {
   self.clusterConfig = undefined;
   self.loading = true;
 
-  ApiHelper.getInstance().getClusterConfig(params).done(function (data) {
-    if (data.status === 0) {
+  var refreshConfig = function () {
+    ApiHelper.getInstance().getClusterConfig(params).done(function (data) {
+      if (data.status === 0) {
+        self.loading = false;
+        self.clusterConfig = data;
+        huePubSub.publish('cluster.config.set.config', self.clusterConfig);
+      } else {
+        $(document).trigger("error", data.message);
+        huePubSub.publish('cluster.config.set.config');
+      }
+    }).fail(function () {
+      huePubSub.publish('clustser.config.set.config');
+    }).always(function () {
       self.loading = false;
-      self.clusterConfig = data;
-      huePubSub.publish('cluster.config.set.config', self.clusterConfig);
-    } else {
-      $(document).trigger("error", data.message);
-      huePubSub.publish('cluster.config.set.config');
-    }
-  }).fail(function () {
-    huePubSub.publish('clustser.config.set.config');
-  }).always(function () {
-    self.loading = false;
-  });
+    });
+  };
+
+  huePubSub.subscribe('cluster.config.refresh.config', refreshConfig);
+
+  refreshConfig();
 
   huePubSub.subscribe('cluster.config.get.config', function () {
     if (! self.loading) {

+ 6 - 2
desktop/core/src/desktop/templates/hue.mako

@@ -1063,7 +1063,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           previousVisibilityValues = {
             left: self.leftAssistVisible(),
             right: self.rightAssistVisible()
-          }
+          };
           self.leftAssistVisible(false);
           self.rightAssistVisible(false);
         });
@@ -1188,6 +1188,10 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           self.hasJobBrowser(clusterConfig && clusterConfig['app_config'] && clusterConfig['app_config']['browser'] && (clusterConfig['app_config']['browser']['interpreter_names'].indexOf('yarn') != -1 || clusterConfig['app_config']['browser']['interpreter_names'].indexOf('dataeng') != -1));
         });
 
+        huePubSub.subscribe('hue.new.default.app', function () {
+          huePubSub.publish('cluster.config.refresh.config');
+        });
+
         var ClusterPanelViewModel = function() {
           var self = this;
           self.apiHelper = ApiHelper.getInstance();
@@ -1234,7 +1238,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           if (self.cluster().type() != 'dataeng') {
             self._loadInterface();
           }
-        }
+        };
         self.cluster = new ClusterPanelViewModel();
 
         self.searchAutocompleteSource = function (request, callback) {

+ 9 - 7
desktop/core/src/desktop/templates/ko_components.mako

@@ -496,25 +496,27 @@ from desktop.views import _ko
         self.app = params.app;
         self.interpreter = params.interpreter;
 
-        self.parseCurrentFavorite = function (data) {
+        self.parseCurrentFavorite = function (data, announce) {
           self.isFavorite(false);
           if (data.status === 0 && data.data && data.data.default_app) {
             try {
               var defaultApp = JSON.parse(data.data.default_app);
               self.isFavorite(defaultApp.app === self.app && ((self.app === 'editor' && defaultApp.interpreter === self.interpreter) || self.app !== 'editor'));
-            }
-            catch (e) {
+              if (announce) {
+                huePubSub.publish('hue.new.default.app', defaultApp);
+              }
+            } catch (e) {
               console.error('${ _ko("There was a problem decoding the default app setting.") }');
             }
           }
-        }
+        };
 
         self.setAsFavoriteApp = function (vm, e) {
           e.originalEvent.stopPropagation();
           e.originalEvent.stopImmediatePropagation();
           var postParams = {
             app: self.app
-          }
+          };
           if (self.interpreter !== '') {
             postParams['interpreter'] = self.interpreter;
           }
@@ -526,9 +528,9 @@ from desktop.views import _ko
             post['set'] = ko.mapping.toJSON(postParams);
           }
           $.post('/desktop/api2/user_preferences/default_app', post, function (data) {
-            self.parseCurrentFavorite(data);
+            self.parseCurrentFavorite(data, true);
           });
-        }
+        };
 
         if (self.isHue4()) {
           // Load the fav app status