From a6c4f15a86a9cd2c71ca859dcbf38e0740682cb3 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 19 Jun 2018 09:12:53 -0400 Subject: [PATCH] set page-up post-scroll height to beginning of new dataset --- .../features/output/index.controller.js | 10 ++--- .../client/features/output/slide.service.js | 38 +++++++++++-------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/awx/ui/client/features/output/index.controller.js b/awx/ui/client/features/output/index.controller.js index 04aa59aaf9..f970058825 100644 --- a/awx/ui/client/features/output/index.controller.js +++ b/awx/ui/client/features/output/index.controller.js @@ -99,11 +99,9 @@ function previous () { const initialPosition = scroll.getScrollPosition(); return slide.slideUp() - .then(changed => { - if (changed[0] !== 0 || changed[1] !== 0) { - const currentHeight = scroll.getScrollHeight(); - scroll.setScrollPosition((currentHeight / 4) - initialPosition); - } + .then(popHeight => { + const currentHeight = scroll.getScrollHeight(); + scroll.setScrollPosition(currentHeight - popHeight + initialPosition); return $q.resolve(); }); @@ -289,7 +287,7 @@ function OutputIndexController ( bufferInit(); status.init(resource); - slide.init(render, resource.events); + slide.init(render, resource.events, scroll); render.init({ compile, toggles: vm.toggleLineEnabled }); scroll.init({ previous, next }); diff --git a/awx/ui/client/features/output/slide.service.js b/awx/ui/client/features/output/slide.service.js index fdfbd41b42..6f46f54d91 100644 --- a/awx/ui/client/features/output/slide.service.js +++ b/awx/ui/client/features/output/slide.service.js @@ -59,7 +59,7 @@ function getOverlapArray (range, other) { } function SlidingWindowService ($q) { - this.init = (storage, api) => { + this.init = (storage, api, { getScrollHeight }) => { const { prepend, append, shift, pop, deleteRecord } = storage; const { getMaxCounter, getRange, getFirst, getLast } = api; @@ -78,6 +78,10 @@ function SlidingWindowService ($q) { deleteRecord, }; + this.hooks = { + getScrollHeight, + }; + this.records = {}; this.uuids = {}; this.chain = $q.resolve(); @@ -153,7 +157,7 @@ function SlidingWindowService ($q) { let lines = 0; - for (let i = min; i <= min + count; ++i) { + for (let i = min; i <= max; ++i) { if (this.records[i]) { lines += (this.records[i].end_line - this.records[i].start_line); } @@ -199,6 +203,21 @@ function SlidingWindowService ($q) { .then(events => this.pushFront(events)); } + if (overlap && overlap[0] < 0) { + this.chain = this.chain.then(() => this.popBack(Math.abs(overlap[0]))); + } + + if (overlap && overlap[1] < 0) { + this.chain = this.chain.then(() => this.popFront(Math.abs(overlap[1]))); + } + + let popHeight; + this.chain = this.chain.then(() => { + popHeight = this.hooks.getScrollHeight(); + + return $q.resolve(); + }); + if (overlap && overlap[0] > 0) { const pushBackRange = [head - overlap[0], head]; @@ -215,21 +234,8 @@ function SlidingWindowService ($q) { .then(events => this.pushFront(events)); } - if (overlap && overlap[0] < 0) { - this.chain = this.chain.then(() => this.popBack(Math.abs(overlap[0]))); - } - - if (overlap && overlap[1] < 0) { - this.chain = this.chain.then(() => this.popFront(Math.abs(overlap[1]))); - } - this.chain = this.chain - .then(() => { - const range = this.getRange(); - const displacement = [range[0] - head, range[1] - tail]; - - return $q.resolve(displacement); - }); + .then(() => $q.resolve(popHeight)); return this.chain; };