Skip to content

Commit a1e8edc

Browse files
author
OpenShift Bot
authored
Merge pull request #1294 from spadgett/logs-reisze-bug
Merged by openshift-bot
2 parents 188b0c8 + f46fe94 commit a1e8edc

File tree

4 files changed

+94
-42
lines changed

4 files changed

+94
-42
lines changed

app/scripts/directives/logViewer.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ angular.module('openshiftConsole')
182182
}
183183
};
184184

185+
var getLogOutputElement = function() {
186+
return $('#' + $scope.logViewerID + ' .log-view-output');
187+
};
188+
185189
var fillHeight = function(animate) {
186-
var content = $("#" + $scope.logViewerID + ' .log-view-output');
190+
var content = getLogOutputElement();
187191
var contentTop = content.offset().top;
188192
if (contentTop < 0) {
189193
// Content top is off the page already.
@@ -208,6 +212,37 @@ angular.module('openshiftConsole')
208212
}
209213
};
210214

215+
var visibleInterval;
216+
var resizeWhenVisible = function() {
217+
if (visibleInterval) {
218+
return;
219+
}
220+
221+
var done = function() {
222+
clearInterval(visibleInterval);
223+
visibleInterval = null;
224+
// To avoid flicker, the log doesn't display until sized === true
225+
$scope.$evalAsync(function() {
226+
$scope.sized = true;
227+
});
228+
};
229+
230+
var retries = 0;
231+
visibleInterval = setInterval(function() {
232+
if (retries > 10) {
233+
done();
234+
return;
235+
}
236+
237+
retries++;
238+
var content = getLogOutputElement();
239+
if (content.is(':visible')) {
240+
fillHeight();
241+
done();
242+
}
243+
}, 100);
244+
};
245+
211246
// roll up & debounce the various fns to call on resize
212247
var onResize = _.debounce(function() {
213248
fillHeight(true);
@@ -318,8 +353,7 @@ angular.module('openshiftConsole')
318353
$scope.empty = false;
319354
if($scope.state !== 'logs') {
320355
$scope.state = 'logs';
321-
// setTimeout so that the log content is visible to correctly calculate fill height.
322-
setTimeout(fillHeight);
356+
resizeWhenVisible();
323357
}
324358
});
325359

app/views/directives/logs/_log-viewer.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ <h2>Logs are not available.</h2>
6868

6969

7070
<!-- must be ng-show rather than ng-if, else DOM is not rendered in time to cache nodes -->
71-
<div ng-show="state=='logs'">
71+
<!-- Keep invisible until sized to avoid flicker on initial display. -->
72+
<div ng-show="state=='logs'" ng-class="{ invisible: !sized }">
7273
<div class="log-view" ng-attr-id="{{logViewerID}}" ng-class="{'log-fixed-height': fixedHeight}">
7374
<div
7475
id="{{logViewerID}}-affixedFollow"
@@ -81,7 +82,7 @@ <h2>Logs are not available.</h2>
8182
Go to End
8283
</a>
8384
</div>
84-
<div class="log-view-output" id="{{logViewerID}}-fixed-scrollable" >
85+
<div class="log-view-output" id="{{logViewerID}}-fixed-scrollable">
8586
<table>
8687
<tbody id="{{logViewerID}}-logContent"></tbody>
8788
</table>

dist/scripts/scripts.js

+52-36
Original file line numberDiff line numberDiff line change
@@ -12343,20 +12343,20 @@ var j, n, p, q, r, s = document.documentElement;
1234312343
i.logViewerID = _.uniqueId("log-viewer"), i.empty = !0;
1234412344
var t, u;
1234512345
"ReplicationController" === i.object.kind ? (t = "deploymentconfigs/log", u = d("annotation")(i.object, "deploymentConfig")) :(t = f.kindToResource(i.object.kind) + "/log", u = i.object.metadata.name);
12346-
var v = function() {
12346+
var v, w = function() {
1234712347
q = window.innerWidth < l.screenSmMin && !i.fixedHeight ? null :n;
12348-
}, w = function() {
12348+
}, x = function() {
1234912349
i.$apply(function() {
1235012350
var a = j.getBoundingClientRect();
1235112351
i.fixedHeight ? i.showScrollLinks = a && a.height > i.fixedHeight :i.showScrollLinks = a && (a.top < 0 || a.bottom > s.clientHeight);
1235212352
});
12353-
}, x = !1, y = function() {
12354-
x ? x = !1 :i.$evalAsync(function() {
12353+
}, y = !1, z = function() {
12354+
y ? y = !1 :i.$evalAsync(function() {
1235512355
i.autoScrollActive = !1;
1235612356
});
12357-
}, z = function() {
12358-
p.off("scroll", y), m.off("scroll", y), window.innerWidth <= l.screenSmMin && !i.fixedHeight ? m.on("scroll", y) :p.on("scroll", y);
1235912357
}, A = function() {
12358+
p.off("scroll", z), m.off("scroll", z), window.innerWidth <= l.screenSmMin && !i.fixedHeight ? m.on("scroll", z) :p.on("scroll", z);
12359+
}, B = function() {
1236012360
i.fixedHeight || (window.innerWidth < l.screenSmMin && !i.fixedHeight ? r.removeClass("target-logger-node").affix({
1236112361
target:window,
1236212362
offset:{
@@ -12368,30 +12368,46 @@ offset:{
1236812368
top:i.followAffixTop || 0
1236912369
}
1237012370
}));
12371-
}, B = function(a) {
12372-
var b = $("#" + i.logViewerID + " .log-view-output"), c = b.offset().top;
12371+
}, C = function() {
12372+
return $("#" + i.logViewerID + " .log-view-output");
12373+
}, D = function(a) {
12374+
var b = C(), c = b.offset().top;
1237312375
if (!(c < 0)) {
1237412376
var d = $(".ellipsis-pulser").outerHeight(!0), e = i.fixedHeight ? i.fixedHeight :Math.floor($(window).height() - c - d);
1237512377
i.chromeless || i.fixedHeight || (e -= 40), a ? b.animate({
1237612378
"min-height":e + "px"
1237712379
}, "fast") :b.css("min-height", e + "px"), i.fixedHeight && b.css("max-height", e);
1237812380
}
12379-
}, C = _.debounce(function() {
12380-
B(!0), v(), z(), w(), A(), y();
12381+
}, E = function() {
12382+
if (!v) {
12383+
var a = function() {
12384+
clearInterval(v), v = null, i.$evalAsync(function() {
12385+
i.sized = !0;
12386+
});
12387+
}, b = 0;
12388+
v = setInterval(function() {
12389+
if (b > 10) return void a();
12390+
b++;
12391+
var c = C();
12392+
c.is(":visible") && (D(), a());
12393+
}, 100);
12394+
}
12395+
}, F = _.debounce(function() {
12396+
D(!0), w(), A(), x(), B(), z();
1238112397
}, 100);
12382-
m.on("resize", C);
12383-
var D, E = function() {
12384-
x = !0, k.scrollBottom(q);
12385-
}, F = function() {
12386-
i.autoScrollActive = !i.autoScrollActive, i.autoScrollActive && E();
12387-
}, G = document.createDocumentFragment(), H = _.debounce(function() {
12388-
j.appendChild(G), G = document.createDocumentFragment(), i.autoScrollActive && E(), i.showScrollLinks || w();
12398+
m.on("resize", F);
12399+
var G, H = function() {
12400+
y = !0, k.scrollBottom(q);
12401+
}, I = function() {
12402+
i.autoScrollActive = !i.autoScrollActive, i.autoScrollActive && H();
12403+
}, J = document.createDocumentFragment(), K = _.debounce(function() {
12404+
j.appendChild(J), J = document.createDocumentFragment(), i.autoScrollActive && H(), i.showScrollLinks || x();
1238912405
}, 100, {
1239012406
maxWait:300
12391-
}), I = function(a) {
12392-
D && (D.stop(), D = null), a || (H.cancel(), j && (j.innerHTML = ""), G = document.createDocumentFragment());
12393-
}, J = function() {
12394-
if (I(), i.run) {
12407+
}), L = function(a) {
12408+
G && (G.stop(), G = null), a || (K.cancel(), j && (j.innerHTML = ""), J = document.createDocumentFragment());
12409+
}, M = function() {
12410+
if (L(), i.run) {
1239512411
angular.extend(i, {
1239612412
loading:!0,
1239712413
autoScrollActive:!0,
@@ -12403,32 +12419,32 @@ follow:!0,
1240312419
tailLines:5e3,
1240412420
limitBytes:10485760
1240512421
}, i.options);
12406-
D = h.createStream(t, u, i.context, a);
12422+
G = h.createStream(t, u, i.context, a);
1240712423
var c = 0, d = function(a) {
12408-
c++, G.appendChild(o(c, a)), H();
12424+
c++, J.appendChild(o(c, a)), K();
1240912425
};
12410-
D.onMessage(function(b, e, f) {
12426+
G.onMessage(function(b, e, f) {
1241112427
i.$evalAsync(function() {
12412-
i.empty = !1, "logs" !== i.state && (i.state = "logs", setTimeout(B));
12428+
i.empty = !1, "logs" !== i.state && (i.state = "logs", E());
1241312429
}), b && (a.limitBytes && f >= a.limitBytes && (i.$evalAsync(function() {
1241412430
i.limitReached = !0, i.loading = !1;
12415-
}), I(!0)), d(b), !i.largeLog && c >= a.tailLines && i.$evalAsync(function() {
12431+
}), L(!0)), d(b), !i.largeLog && c >= a.tailLines && i.$evalAsync(function() {
1241612432
i.largeLog = !0;
1241712433
}));
12418-
}), D.onClose(function() {
12419-
D = null, i.$evalAsync(function() {
12434+
}), G.onClose(function() {
12435+
G = null, i.$evalAsync(function() {
1242012436
i.autoScrollActive = !1, 0 !== c || i.emptyStateMessage || (i.state = "empty", i.emptyStateMessage = "The logs are no longer available or could not be loaded.");
1242112437
}), b(function() {
1242212438
i.loading = !1;
1242312439
}, 100);
12424-
}), D.onError(function() {
12425-
D = null, i.$evalAsync(function() {
12440+
}), G.onError(function() {
12441+
G = null, i.$evalAsync(function() {
1242612442
angular.extend(i, {
1242712443
loading:!1,
1242812444
autoScrollActive:!1
1242912445
}), 0 === c ? (i.state = "empty", i.emptyStateMessage = "The logs are no longer available or could not be loaded.") :i.errorWhileRunning = !0;
1243012446
});
12431-
}), D.start();
12447+
}), G.start();
1243212448
}
1243312449
};
1243412450
return g.getLoggingURL().then(function(b) {
@@ -12454,7 +12470,7 @@ j = a;
1245412470
}, this.cacheAffixable = function(a) {
1245512471
r = $(a);
1245612472
}, this.start = function() {
12457-
v(), z(), A();
12473+
w(), A(), B();
1245812474
}, angular.extend(i, {
1245912475
ready:!0,
1246012476
loading:!0,
@@ -12466,12 +12482,12 @@ k.scrollBottom(q);
1246612482
onScrollTop:function() {
1246712483
i.autoScrollActive = !1, k.scrollTop(q);
1246812484
},
12469-
toggleAutoScroll:F,
12485+
toggleAutoScroll:I,
1247012486
goChromeless:k.chromelessLink,
12471-
restartLogs:J
12487+
restartLogs:M
1247212488
}), i.$on("$destroy", function() {
12473-
I(), m.off("resize", C), m.off("scroll", y), p.off("scroll", y);
12474-
}), "deploymentconfigs/logs" !== t || u ? void i.$watchGroup([ "name", "options.container", "run" ], J) :(i.state = "empty", void (i.emptyStateMessage = "Logs are not available for this replication controller because it was not generated from a deployment configuration."));
12489+
L(), m.off("resize", F), m.off("scroll", z), p.off("scroll", z);
12490+
}), "deploymentconfigs/logs" !== t || u ? void i.$watchGroup([ "name", "options.container", "run" ], M) :(i.state = "empty", void (i.emptyStateMessage = "Logs are not available for this replication controller because it was not generated from a deployment configuration."));
1247512491
} ],
1247612492
require:"logViewer",
1247712493
link:function(a, c, d, e) {

dist/scripts/templates.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7586,7 +7586,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
75867586
"</div>\n" +
75877587
"</div>\n" +
75887588
"\n" +
7589-
"<div ng-show=\"state=='logs'\">\n" +
7589+
"\n" +
7590+
"<div ng-show=\"state=='logs'\" ng-class=\"{ invisible: !sized }\">\n" +
75907591
"<div class=\"log-view\" ng-attr-id=\"{{logViewerID}}\" ng-class=\"{'log-fixed-height': fixedHeight}\">\n" +
75917592
"<div id=\"{{logViewerID}}-affixedFollow\" class=\"log-scroll log-scroll-top\">\n" +
75927593
"<a ng-if=\"loading\" href=\"\" ng-click=\"toggleAutoScroll()\">\n" +

0 commit comments

Comments
 (0)