浏览代码

HUE-6291 [frontend] Remove multiple loading of scheduler files

Enrico Berti 8 年之前
父节点
当前提交
35a00dc

+ 12 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -593,6 +593,18 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           loadedCss.push($(this).attr('href'));
           loadedCss.push($(this).attr('href'));
         });
         });
 
 
+        huePubSub.subscribe('hue4.add.global.js', function(path){
+          loadedJs.push(path);
+        });
+
+        huePubSub.subscribe('hue4.add.global.css', function(path){
+          loadedCss.push(path);
+        });
+
+        huePubSub.subscribe('hue4.get.globals', function(callback){
+          callback(loadedJs, loadedCss);
+        });
+
         // Only load CSS and JS files that are not loaded before
         // Only load CSS and JS files that are not loaded before
         self.processHeaders = function(response){
         self.processHeaders = function(response){
           var r = $('<span>').html(response);
           var r = $('<span>').html(response);

+ 63 - 23
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2286,36 +2286,76 @@ var EditorViewModel = (function() {
         }
         }
         hueAnalytics.log('notebook', 'schedule/' + _action);
         hueAnalytics.log('notebook', 'schedule/' + _action);
 
 
-        $.get('/oozie/editor/coordinator/' + _action + '/', {
-          format: 'json',
-          document: self.uuid(),
-          coordinator: self.coordinatorUuid()
-        }, function (data) {
-          if ($("#schedulerEditor").length > 0) {
-            $("#schedulerEditor").html(data.layout);
+        function getCoordinator(loadedJs, loadedCss) {
+          $.get('/oozie/editor/coordinator/' + _action + '/', {
+            format: 'json',
+            document: self.uuid(),
+            coordinator: self.coordinatorUuid()
+          }, function (data) {
+            if ($("#schedulerEditor").length > 0) {
+              var response = data.layout;
+              var r = $('<span>').html(response);
+              r.find('link').each(function () {
+                $(this).attr('href', $(this).attr('href') + '?' + Math.random())
+              });
+              r.find('script[src]').each(function () {
+                var jsFile = $(this).attr('src').split('?')[0];
+                if (loadedJs.indexOf(jsFile) === -1) {
+                  loadedJs.push(jsFile);
+                  $(this).clone().appendTo($('head'));
+                }
+                $(this).remove();
+              });
+              r.find('link[href]').each(function () {
+                var cssFile = $(this).attr('href').split('?')[0];
+                if (loadedCss.indexOf(cssFile) === -1) {
+                  loadedCss.push(cssFile);
+                  $(this).clone().appendTo($('head'));
+                }
+                $(this).remove();
+              });
+              r.find('a[href]').each(function () {
+                var link = $(this).attr('href');
+                if (link.startsWith('/') && !link.startsWith('/hue')){
+                  link = '/hue' + link;
+                }
+                $(this).attr('href', link);
+              });
+              r.unwrap('<span>');
 
 
-            self.schedulerViewModel = new vm.CoordinatorEditorViewModel(data.coordinator, data.credentials, data.workflows, data.can_edit);
+              $("#schedulerEditor").html(r);
 
 
-            ko.cleanNode($("#schedulerEditor")[0]);
-            ko.applyBindings(self.schedulerViewModel, $("#schedulerEditor")[0]);
+              self.schedulerViewModel = new vm.CoordinatorEditorViewModel(data.coordinator, data.credentials, data.workflows, data.can_edit);
 
 
-            huePubSub.publish('render.jqcron');
+              ko.cleanNode($("#schedulerEditor")[0]);
+              ko.applyBindings(self.schedulerViewModel, $("#schedulerEditor")[0]);
 
 
-            self.schedulerViewModel.coordinator.properties.cron_advanced.valueHasMutated(); // Update jsCron enabled status
-            self.schedulerViewModel.coordinator.tracker().markCurrentStateAsClean();
-            self.schedulerViewModel.isEditing(true);
+              huePubSub.publish('render.jqcron');
 
 
-            self.schedulerViewModelIsLoaded(true);
+              self.schedulerViewModel.coordinator.properties.cron_advanced.valueHasMutated(); // Update jsCron enabled status
+              self.schedulerViewModel.coordinator.tracker().markCurrentStateAsClean();
+              self.schedulerViewModel.isEditing(true);
 
 
-            if (_action == 'new') {
-              self.coordinatorUuid(UUID());
-              self.schedulerViewModel.coordinator.uuid(self.coordinatorUuid());
-              self.schedulerViewModel.coordinator.properties.document(self.uuid());
+              self.schedulerViewModelIsLoaded(true);
+
+              if (_action == 'new') {
+                self.coordinatorUuid(UUID());
+                self.schedulerViewModel.coordinator.uuid(self.coordinatorUuid());
+                self.schedulerViewModel.coordinator.properties.document(self.uuid());
+              }
             }
             }
-          }
-        }).fail(function (xhr) {
-          $(document).trigger("error", xhr.responseText);
-        });
+          }).fail(function (xhr) {
+            $(document).trigger("error", xhr.responseText);
+          });
+        }
+
+        if (IS_HUE_4){
+          huePubSub.publish('hue4.get.globals', getCoordinator);
+        }
+        else {
+          getCoordinator([], []);
+        }
+
       }
       }
     };
     };