Ver código fonte

HUE-1215 [pig] Log window should occupy all the available space

Fixed log resizing
The logs are now loaded when you open a specific script logs page
Enrico Berti 12 anos atrás
pai
commit
35675e4
2 arquivos alterados com 37 adições e 7 exclusões
  1. 34 7
      apps/pig/src/pig/templates/app.mako
  2. 3 0
      apps/pig/static/js/pig.ko.js

+ 34 - 7
apps/pig/src/pig/templates/app.mako

@@ -678,14 +678,20 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
       if (viewModel.currentScript().watchUrl() != "") {
         $.getJSON(viewModel.currentScript().watchUrl(), function (data) {
           if (data.logs.pig) {
-            $("#withoutLogs").addClass("hide");
-            $("#withLogs").removeClass("hide");
+            if ($("#withLogs").is(":hidden")) {
+              $("#withoutLogs").addClass("hide");
+              $("#withLogs").removeClass("hide");
+              resizeLogs();
+            }
             var _logsEl = $("#withLogs");
             var newLines = data.logs.pig.split("\n").slice(_logsEl.text().split("\n").length);
             _logsEl.text(_logsEl.text() + newLines.join("\n"));
-            if (logsAtEnd) {
-              _logsEl.scrollTop(_logsEl[0].scrollHeight - _logsEl.height());
-            }
+            window.setTimeout(function () {
+              resizeLogs();
+              if (logsAtEnd) {
+                _logsEl.scrollTop(_logsEl[0].scrollHeight - _logsEl.height());
+              }
+            }, 100);
           }
           if (data.workflow && data.workflow.isRunning) {
             viewModel.currentScript().actions(data.workflow.actions);
@@ -746,6 +752,8 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
       $("li[data-section='" + section + "']").addClass("active");
     }
 
+    var dashboardLoadedInterval = -1;
+
     routie({
       "editor": function () {
         showMainSection("editor");
@@ -782,8 +790,27 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
       },
       "logs/:scriptId": function (scriptId) {
         if (scriptId !== "undefined" && scriptId != viewModel.currentScript().id()) {
-          viewModel.loadScript(scriptId);
-          $(document).trigger("loadEditor");
+          dashboardLoadedInterval = window.setInterval(function () {
+            if (viewModel.isDashboardLoaded) {
+              window.clearInterval(dashboardLoadedInterval);
+              viewModel.loadScript(scriptId);
+              if (viewModel.currentScript().id() == -1) {
+                viewModel.newScript();
+              }
+              else {
+                viewModel.currentScript().isRunning(true);
+                var _foundLastRun = null;
+                $.each(viewModel.completedScripts(), function (cnt, pastScript) {
+                  if (pastScript.scriptId == scriptId && _foundLastRun == null) {
+                    _foundLastRun = pastScript;
+                  }
+                });
+                viewModel.currentScript().watchUrl(_foundLastRun.watchUrl);
+                $(document).trigger("startLogsRefresh");
+                showSection("editor", "logs");
+              }
+            }
+          }, 200)
         }
         showSection("editor", "logs");
       }

+ 3 - 0
apps/pig/static/js/pig.ko.js

@@ -124,6 +124,8 @@ var PigViewModel = function (props) {
   self.runningScripts = ko.observableArray([]);
   self.completedScripts = ko.observableArray([]);
 
+  self.isDashboardLoaded = false;
+
   var _defaultScript = {
     id: -1,
     name: self.LABELS.NEW_SCRIPT_NAME,
@@ -261,6 +263,7 @@ var PigViewModel = function (props) {
   };
 
   self.updateDashboard = function (workflows) {
+    self.isDashboardLoaded = true;
     var koWorkflows = ko.utils.arrayMap(workflows, function (wf) {
       return new Workflow(wf);
     });