Jelajahi Sumber

HUE-6254 [jb] The widget and logs links shouldn't throw JS errors

Enrico Berti 8 tahun lalu
induk
melakukan
6b8d63aae3

+ 22 - 21
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -1902,6 +1902,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 
       self.load = function() {
         var h = window.location.hash;
+        huePubSub.publish('stop.refresh.view');
 
         h = h.indexOf('#!') === 0 ? h.substr(2) : '';
         switch (h) {
@@ -1917,7 +1918,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
             break;
           default:
             if (h.indexOf('id=') === 0 && ! self.isMini()){
-              new Job(viewModel, {id: h.substr(3)}).fetchJob();
+              new Job(self, {id: h.substr(3)}).fetchJob();
             }
             else {
               self.selectInterface('reset');
@@ -1926,30 +1927,30 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       }
     };
 
-    var viewModel;
 
-    huePubSub.subscribe('oozie.action.logs.click', function (widget) {
-      viewModel.job().id(widget.externalId());
-      viewModel.job().fetchJob();
-    });
-
-    huePubSub.subscribe('oozie.action.click', function (widget) {
-      viewModel.job().id(widget.externalId());
-      viewModel.job().fetchJob();
-    });
 
     $(document).ready(function () {
-      viewModel = new JobBrowserViewModel();
+      var jobBrowserViewModel = new JobBrowserViewModel();
       % if not is_mini:
-      ko.applyBindings(viewModel, $('#jobbrowserComponents')[0]);
+      ko.applyBindings(jobBrowserViewModel, $('#jobbrowserComponents')[0]);
+      huePubSub.subscribe('oozie.action.logs.click', function (widget) {
+        jobBrowserViewModel.job().id(widget.externalId());
+        jobBrowserViewModel.job().fetchJob();
+      });
+
+      huePubSub.subscribe('oozie.action.click', function (widget) {
+        jobBrowserViewModel.job().id(widget.externalId());
+        jobBrowserViewModel.job().fetchJob();
+      });
       % else:
-      ko.applyBindings(viewModel, $('#jobbrowserMiniComponents')[0]);
-      viewModel.isMini(true);
+      ko.applyBindings(jobBrowserViewModel, $('#jobbrowserMiniComponents')[0]);
+      jobBrowserViewModel.isMini(true);
       % endif
 
+
       var loadHash = function () {
         if (window.location.pathname.indexOf('jobbrowser') > -1) {
-          viewModel.load();
+          jobBrowserViewModel.load();
         }
       };
 
@@ -1958,7 +1959,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       }
 
       huePubSub.subscribeOnce('cluster.config.set.config', function (clusterConfig) {
-        viewModel.appConfig(clusterConfig && clusterConfig['app_config']);
+        jobBrowserViewModel.appConfig(clusterConfig && clusterConfig['app_config']);
         loadHash();
       });
 
@@ -1968,13 +1969,13 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       huePubSub.subscribe('submit.rerun.popup.return', function (data) {
         $.jHueNotify.info('${_('Rerun submitted.')}');
         $('#rerun-modal').modal('hide');
-        viewModel.job().apiStatus('RUNNING');
-        viewModel.job().updateJob();
+        jobBrowserViewModel.job().apiStatus('RUNNING');
+        jobBrowserViewModel.job().updateJob();
       }, 'jobbrowser');
       % else:
-      viewModel.selectInterface('jobs');
+      jobBrowserViewModel.selectInterface('jobs');
       huePubSub.subscribe('mini.jb.navigate', function(interface){
-        viewModel.selectInterface(interface);
+        jobBrowserViewModel.selectInterface(interface);
       });
       % endif
     });

+ 69 - 0
apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js

@@ -1251,6 +1251,75 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
     }
   };
 
+
+  self.drawArrows = function () {
+
+    function linkWidgets(fromId, toId) {
+      var _from = $("#wdg_" + (typeof fromId == "function" ? fromId() : fromId));
+      var _to = $("#wdg_" + (typeof toId == "function" ? toId() : toId));
+      if (_from.length > 0 && _to.length > 0) {
+        var $painter = $(document.body);
+
+        if ($('.oozie_workflowComponents').length > 0) {
+          $painter = $('.oozie_workflowComponents');
+        }
+
+        var _fromCenter = {
+          x: _from.position().left + _from.outerWidth() / 2,
+          y: _from.position().top + _from.outerHeight() + 3
+        }
+
+        var _toCenter = {
+          x: _to.position().left + _to.outerWidth() / 2,
+          y: _to.position().top - 5
+        }
+
+        var _curveCoords = {};
+
+        if (_fromCenter.x == _toCenter.x) {
+          _curveCoords.x = _fromCenter.x;
+          _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
+        } else {
+          if (_fromCenter.x > _toCenter.x) {
+            _fromCenter.x = _fromCenter.x - 5;
+            _toCenter.x = _toCenter.x + 5;
+          } else {
+            _fromCenter.x = _fromCenter.x + 5;
+            _toCenter.x = _toCenter.x - 5;
+          }
+          _curveCoords.x = _fromCenter.x - (_fromCenter.x - _toCenter.x) / 4;
+          _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
+        }
+
+        $painter.curvedArrow({
+          p0x: _fromCenter.x,
+          p0y: _fromCenter.y,
+          p1x: _curveCoords.x,
+          p1y: _curveCoords.y,
+          p2x: _toCenter.x,
+          p2y: _toCenter.y,
+          lineWidth: 2,
+          size: 10,
+          strokeStyle: self.isEditing() ? '#e5e5e5' : '#dddddd'
+        });
+      }
+    }
+
+    $("canvas").remove();
+    if (self.oozieColumns()[0].rows().length > 3) {
+      var _links = self.workflow.linkMapping();
+      Object.keys(_links).forEach(function (id) {
+        if (_links[id].length > 0) {
+          _links[id].forEach(function (nextId) {
+            linkWidgets(id, nextId);
+          });
+        }
+      });
+    }
+  }
+
+  huePubSub.subscribe('draw.graph.arrows', self.drawArrows);
+
   function bareWidgetBuilder(name, type) {
     return new ExtendedWidget({
       size: 12,

+ 0 - 67
apps/oozie/src/oozie/static/oozie/js/workflow-editor.utils.js

@@ -14,73 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-function linkWidgets(fromId, toId) {
-  var _from = $("#wdg_" + (typeof fromId == "function" ? fromId() : fromId));
-  var _to = $("#wdg_" + (typeof toId == "function" ? toId() : toId));
-  if (_from.length > 0 && _to.length > 0) {
-    var $painter = $(document.body);
-
-    if ($('.oozie_workflowComponents').length > 0){
-      $painter = $('.oozie_workflowComponents');
-    }
-
-    var _fromCenter = {
-      x: _from.position().left + _from.outerWidth() / 2,
-      y: _from.position().top + _from.outerHeight() + 3
-    }
-
-    var _toCenter = {
-      x: _to.position().left + _to.outerWidth() / 2,
-      y: _to.position().top - 5
-    }
-
-    var _curveCoords = {};
-
-    if (_fromCenter.x == _toCenter.x) {
-      _curveCoords.x = _fromCenter.x;
-      _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
-    } else {
-      if (_fromCenter.x > _toCenter.x) {
-        _fromCenter.x = _fromCenter.x - 5;
-        _toCenter.x = _toCenter.x + 5;
-      } else {
-        _fromCenter.x = _fromCenter.x + 5;
-        _toCenter.x = _toCenter.x - 5;
-      }
-      _curveCoords.x = _fromCenter.x - (_fromCenter.x - _toCenter.x) / 4;
-      _curveCoords.y = _fromCenter.y + (_toCenter.y - _fromCenter.y) / 2;
-    }
-
-    $painter.curvedArrow({
-      p0x: _fromCenter.x,
-      p0y: _fromCenter.y,
-      p1x: _curveCoords.x,
-      p1y: _curveCoords.y,
-      p2x: _toCenter.x,
-      p2y: _toCenter.y,
-      lineWidth: 2,
-      size: 10,
-      strokeStyle: viewModel.isEditing() ? '#e5e5e5' : '#dddddd'
-    });
-  }
-}
-
-function drawArrows() {
-  $("canvas").remove();
-  if (viewModel.oozieColumns()[0].rows().length > 3) {
-    var _links = viewModel.workflow.linkMapping();
-    Object.keys(_links).forEach(function (id) {
-      if (_links[id].length > 0) {
-        _links[id].forEach(function (nextId) {
-          linkWidgets(id, nextId);
-        });
-      }
-    });
-  }
-}
-
-huePubSub.subscribe('draw.graph.arrows', drawArrows);
-
 function toggleProperties(widget) {
   if (widget.oozieMovable()) {
     var _el = $("#wdg_" + widget.id());

+ 3 - 3
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflow.mako

@@ -488,7 +488,7 @@ ${ dashboard.import_layout() }
 
   $(document).ready(function() {
     % if layout_json != '':
-    drawArrows();
+    viewModel.drawArrows();
     %endif
 
     var CURRENT_ZOOM = 1;
@@ -551,7 +551,7 @@ ${ dashboard.import_layout() }
     $("a[data-toggle='tab']").on("shown", function (e) {
       if ($(e.target).attr("href") == "#graph") {
         % if layout_json != '':
-        drawArrows();
+        viewModel.drawArrows();
         %endif
       }
       else {
@@ -742,7 +742,7 @@ ${ dashboard.import_layout() }
         resizeLogs();
         if ($("#graph").is(":visible")){
           % if layout_json != '':
-          drawArrows();
+          viewModel.drawArrows();
           %endif
         }
       }, 200);

+ 83 - 67
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflow_graph.mako

@@ -49,75 +49,91 @@ ${ dashboard.import_layout() }
 
   ${ utils.slaGlobal() }
 
-  % if layout_json != '':
-  var viewModel = new WorkflowEditorViewModel(${ layout_json | n,unicode }, ${ workflow_json | n,unicode }, ${ credentials_json | n,unicode }, ${ workflow_properties_json | n,unicode }, ${ subworkflows_json | n,unicode }, ${ can_edit_json | n,unicode });
-  ko.cleanNode($("#${graph_element_id}")[0]);
-  ko.applyBindings(viewModel, $("#${graph_element_id}")[0]);
-  viewModel.isViewer = ko.observable(true);
-  viewModel.isEmbeddable = ko.observable(true);
-  viewModel.init();
-  fullLayout(viewModel);
-
-  var globalFilechooserOptions = {
-    skipInitialPathIfEmpty: true,
-    showExtraHome: true,
-    uploadFile: true,
-    createFolder: true,
-    extraHomeProperties: {
-      label: '${ _('Workspace') }',
-      icon: 'fa-folder-open',
-      path: viewModel.workflow.properties.deployment_dir()
-    },
-    deploymentDir: viewModel.workflow.properties.deployment_dir()
-  }
-
-  function refreshView() {
-      $.getJSON("${ oozie_workflow.get_absolute_url(format='json') }", function (data) {
-
-        if (data.actions){
-          % if layout_json != '':
-          ko.utils.arrayForEach(data.actions, function(action) {
-            var _w, actionId = action.id.substr(action.id.length - 4);
-            if (actionId === '@End'){
-              _w = viewModel.getWidgetById('33430f0f-ebfa-c3ec-f237-3e77efa03d0a');
-            }
-            else {
-              _w = viewModel.getWidgetById($("[id^=wdg_" + actionId.toLowerCase() + "]").attr("id").substr(4));
-            }
-            if (_w != null) {
-              if (['SUCCEEDED', 'OK', 'DONE'].indexOf(action.status) > -1) {
-                _w.status("success");
-                _w.progress(100);
-              }
-              else if (['RUNNING', 'READY', 'PREP', 'WAITING', 'SUSPENDED', 'PREPSUSPENDED', 'PREPPAUSED', 'PAUSED', 'SUBMITTED', 'SUSPENDEDWITHERROR', 'PAUSEDWITHERROR'].indexOf(action.status) > -1) {
-                _w.status("running");
-                _w.progress(50);
-              }
-              else {
-                _w.status("failed");
-                _w.progress(100);
-              }
-              _w.actionURL(action.url);
-              _w.logsURL(action.log);
-              _w.externalIdUrl(action.externalIdUrl);
-              _w.externalId(action.id);
-            }
-          });
-          %endif
-        }
-        if (data.status != "RUNNING" && data.status != "PREP"){
-          return;
-        }
-        window.setTimeout(refreshView, 1000);
-      });
-    }
+  var globalFilechooserOptions;
 
-  %endif
+  (function () {
 
-  $(document).ready(function() {
     % if layout_json != '':
-    drawArrows();
-    refreshView();
+      var viewModel = new WorkflowEditorViewModel(${ layout_json | n,unicode }, ${ workflow_json | n,unicode }, ${ credentials_json | n,unicode }, ${ workflow_properties_json | n,unicode }, ${ subworkflows_json | n,unicode }, ${ can_edit_json | n,unicode });
+      ko.cleanNode($("#${graph_element_id}")[0]);
+      ko.applyBindings(viewModel, $("#${graph_element_id}")[0]);
+      viewModel.isViewer = ko.observable(true);
+      viewModel.isEmbeddable = ko.observable(true);
+      viewModel.init();
+      fullLayout(viewModel);
+
+      globalFilechooserOptions = {
+        skipInitialPathIfEmpty: true,
+        showExtraHome: true,
+        uploadFile: true,
+        createFolder: true,
+        extraHomeProperties: {
+          label: '${ _('Workspace') }',
+          icon: 'fa-folder-open',
+          path: viewModel.workflow.properties.deployment_dir()
+        },
+        deploymentDir: viewModel.workflow.properties.deployment_dir()
+      }
+
+      var refreshViewTimeout = -1;
+
+      function refreshView() {
+        $.getJSON("${ oozie_workflow.get_absolute_url(format='json') }", function (data) {
+
+          if (data.actions) {
+            % if layout_json != '':
+              ko.utils.arrayForEach(data.actions, function (action) {
+                var _w, actionId = action.id.substr(action.id.length - 4);
+                if (actionId === '@End') {
+                  _w = viewModel.getWidgetById('33430f0f-ebfa-c3ec-f237-3e77efa03d0a');
+                }
+                else {
+                  if ($("[id^=wdg_" + actionId.toLowerCase() + "]").length > 0) {
+                    _w = viewModel.getWidgetById($("[id^=wdg_" + actionId.toLowerCase() + "]").attr("id").substr(4));
+                  }
+                  else {
+                    _w = viewModel.getWidgetById('33430f0f-ebfa-c3ec-f237-3e77efa03d0a');
+                  }
+                }
+                if (_w != null) {
+                  if (['SUCCEEDED', 'OK', 'DONE'].indexOf(action.status) > -1) {
+                    _w.status("success");
+                    _w.progress(100);
+                  }
+                  else if (['RUNNING', 'READY', 'PREP', 'WAITING', 'SUSPENDED', 'PREPSUSPENDED', 'PREPPAUSED', 'PAUSED', 'SUBMITTED', 'SUSPENDEDWITHERROR', 'PAUSEDWITHERROR'].indexOf(action.status) > -1) {
+                    _w.status("running");
+                    _w.progress(50);
+                  }
+                  else {
+                    _w.status("failed");
+                    _w.progress(100);
+                  }
+                  _w.actionURL(action.url);
+                  _w.logsURL(action.log);
+                  _w.externalIdUrl(action.externalIdUrl);
+                  _w.externalId(action.id);
+                }
+              });
+            %endif
+          }
+          if (data.status != "RUNNING" && data.status != "PREP") {
+            return;
+          }
+          refreshViewTimeout = window.setTimeout(refreshView, 1000);
+        });
+      }
+
+      huePubSub.subscribe('stop.refresh.view', function(){
+        window.clearTimeout(refreshViewTimeout);
+      });
+
     %endif
-  });
+
+    $(document).ready(function () {
+      % if layout_json != '':
+        viewModel.drawArrows();
+        refreshView();
+      %endif
+    });
+  })();
 </script>

+ 1 - 1
apps/oozie/src/oozie/templates/editor2/workflow_editor.mako

@@ -719,7 +719,7 @@ ${ dashboard.import_bindings() }
   function renderChangeables() {
     resizeDrops();
     if (viewModel.workflow.properties.show_arrows()){
-      drawArrows();
+      viewModel.drawArrows();
     }
     $(".widget-main-section").removeClass("zoom-in");
     $(".widget-main-section").each(function(){