diff --git a/awx/ui/client/features/output/index.controller.js b/awx/ui/client/features/output/index.controller.js index 4f84cfbf8d..b65cb52a68 100644 --- a/awx/ui/client/features/output/index.controller.js +++ b/awx/ui/client/features/output/index.controller.js @@ -110,7 +110,7 @@ function next () { return page.next() .then(events => { if (!events) { - return; + return $q.resolve(); } return shift() @@ -119,13 +119,13 @@ function next () { } function previous () { - let initialPosition = scroll.getScrollPosition(); + const initialPosition = scroll.getScrollPosition(); let postPopHeight; return page.previous() .then(events => { if (!events) { - return; + return $q.resolve(); } return pop() @@ -134,7 +134,7 @@ function previous () { return prepend(events); }) - .then(() => { + .then(() => { const currentHeight = scroll.getScrollHeight(); scroll.setScrollPosition(currentHeight - postPopHeight + initialPosition); }); @@ -177,7 +177,7 @@ function shift () { function scrollHome () { if (scroll.isPaused()) { - return; + return $q.resolve(); } scroll.pause(); @@ -185,7 +185,7 @@ function scrollHome () { return page.first() .then(events => { if (!events) { - return; + return $q.resolve(); } return render.clear() @@ -200,7 +200,7 @@ function scrollHome () { function scrollEnd () { if (stream.isActive()) { if (stream.isTransitioning()) { - return; + return $q.resolve(); } if (stream.isPaused()) { @@ -209,9 +209,9 @@ function scrollEnd () { stream.pause(); } - return; + return $q.resolve(); } else if (scroll.isPaused()) { - return; + return $q.resolve(); } scroll.pause(); @@ -219,7 +219,7 @@ function scrollEnd () { return page.last() .then(events => { if (!events) { - return; + return $q.resolve(); } return render.clear() @@ -306,7 +306,7 @@ function toggleSearchKey () { vm.searchKey = !vm.searchKey; } -function getCurrentQueryset() { +function getCurrentQueryset () { const { job_event_search } = $state.params; return qs.decodeArr(job_event_search); diff --git a/awx/ui/client/features/output/index.js b/awx/ui/client/features/output/index.js index 64819e9ca3..ebf69f5243 100644 --- a/awx/ui/client/features/output/index.js +++ b/awx/ui/client/features/output/index.js @@ -17,7 +17,16 @@ const PAGE_LIMIT = 3; const PAGE_SIZE = 100; const WS_PREFIX = 'ws'; -function resolveResource (Job, ProjectUpdate, AdHocCommand, SystemJob, WorkflowJob, $stateParams, qs, Wait) { +function resolveResource ( + Job, + ProjectUpdate, + AdHocCommand, + SystemJob, + WorkflowJob, + $stateParams, + qs, + Wait +) { const { id, type, job_event_search } = $stateParams; let Resource; @@ -60,22 +69,20 @@ function resolveResource (Job, ProjectUpdate, AdHocCommand, SystemJob, WorkflowJ pageLimit: PAGE_LIMIT, params, })) - .then(model => { - return { - id, - type, - model, - related, - ws: { - namespace: `${WS_PREFIX}-${getWebSocketResource(type).key}-${id}` - }, - page: { - cache: PAGE_CACHE, - size: PAGE_SIZE, - pageLimit: PAGE_LIMIT - } - }; - }) + .then(model => ({ + id, + type, + model, + related, + ws: { + namespace: `${WS_PREFIX}-${getWebSocketResource(type).key}-${id}` + }, + page: { + cache: PAGE_CACHE, + size: PAGE_SIZE, + pageLimit: PAGE_LIMIT + } + })) .catch(({ data, status }) => qs.error(data, status)) .finally(() => Wait('stop')); } @@ -84,9 +91,6 @@ function resolveWebSocketConnection (SocketService, $stateParams) { const { type, id } = $stateParams; const resource = getWebSocketResource(type); - let name; - let events; - const state = { data: { socket: { @@ -132,12 +136,13 @@ function getWebSocketResource (type) { name = 'jobs'; key = 'job_events'; break; + default: + throw new Error('Unsupported WebSocket type'); } return { name, key }; } - function JobsRun ($stateRegistry) { const state = { name: 'jobz', diff --git a/awx/ui/client/features/output/page.service.js b/awx/ui/client/features/output/page.service.js index 3c5eca95e8..3f6461345e 100644 --- a/awx/ui/client/features/output/page.service.js +++ b/awx/ui/client/features/output/page.service.js @@ -47,7 +47,7 @@ function JobPageService ($q) { } else { reference.cache.unshift(page); reference.state.first = page.number; - reference.state.last = reference.cache[reference.cache.length -1].number; + reference.state.last = reference.cache[reference.cache.length - 1].number; } reference.state.current = page.number; @@ -101,7 +101,7 @@ function JobPageService ($q) { } return false; - } + }; this.emptyBuffer = () => { const reference = this.getReference(); @@ -137,8 +137,9 @@ function JobPageService ($q) { }; this.trim = left => { - let reference = this.getActiveReference(); - let excess = reference.cache.length - this.page.limit; + const reference = this.getActiveReference(); + const excess = reference.cache.length - this.page.limit; + let ejected; if (left) { @@ -152,9 +153,8 @@ function JobPageService ($q) { return ejected.reduce((total, page) => total + page.lines, 0); }; - this.isPageBookmarked = number => { - return number >= this.page.bookmark.first && number <= this.page.bookmark.last; - }; + this.isPageBookmarked = number => number >= this.page.bookmark.first && + number <= this.page.bookmark.last; this.updateLineCount = (lines, stream) => { let reference; @@ -168,15 +168,10 @@ function JobPageService ($q) { const index = reference.cache.findIndex(item => item.number === reference.state.current); reference.cache[index].lines += lines; - } - - this.isBookmarkPending = () => { - return this.bookmark.pending; }; - this.isBookmarkSet = () => { - return this.bookmark.set; - }; + this.isBookmarkPending = () => this.bookmark.pending; + this.isBookmarkSet = () => this.bookmark.set; this.setBookmark = () => { if (this.isBookmarkSet()) { @@ -190,12 +185,11 @@ function JobPageService ($q) { } this.bookmark.state.first = this.page.state.first; - this.bookmark.state.last = this.page.state.last - 1; + this.bookmark.state.last = this.page.state.last - 1; this.bookmark.state.current = this.page.state.current - 1; this.bookmark.cache = JSON.parse(JSON.stringify(this.page.cache)); this.bookmark.set = true; this.bookmark.pending = false; - console.log('applied', JSON.stringify(this.bookmark.state, 0, 2)); }; this.removeBookmark = () => { @@ -271,19 +265,16 @@ function JobPageService ($q) { }); }; - this.buildRequestConfig = number => { - return { - page: number, - related: this.resource.related, - params: { - order_by: 'start_line' - } - }; - }; + this.buildRequestConfig = number => ({ + page: number, + related: this.resource.related, + params: { + order_by: 'start_line' + } + }); - this.getActiveReference = () => { - return this.isBookmarkSet() ? this.getReference(true) : this.getReference(); - }; + this.getActiveReference = () => (this.isBookmarkSet() ? + this.getReference(true) : this.getReference()); this.getReference = (bookmark) => { if (bookmark) { diff --git a/awx/ui/client/features/output/render.service.js b/awx/ui/client/features/output/render.service.js index 9f883a126c..e8d1cd0dd0 100644 --- a/awx/ui/client/features/output/render.service.js +++ b/awx/ui/client/features/output/render.service.js @@ -5,8 +5,6 @@ const ELEMENT_TBODY = '#atStdoutResultTable'; const EVENT_START_TASK = 'playbook_on_task_start'; const EVENT_START_PLAY = 'playbook_on_play_start'; const EVENT_STATS_PLAY = 'playbook_on_stats'; -const JOB_START = 'playbook_on_start'; -const JOB_END = 'playbook_on_stats'; const EVENT_GROUPS = [ EVENT_START_TASK, @@ -70,7 +68,7 @@ function JobRenderService ($q, $sce, $window) { const current = this.createRecord(ln, lines, event); - const html = lines.reduce((html, line, i) => { + const html = lines.reduce((concat, line, i) => { ln++; const isLastLine = i === lines.length - 1; @@ -81,7 +79,7 @@ function JobRenderService ($q, $sce, $window) { count++; } - return `${html}${row}`; + return `${concat}${row}`; }, ''); return { html, count }; @@ -191,16 +189,16 @@ function JobRenderService ($q, $sce, $window) { ${tdEvent} ${timestamp} `; - } + }; - this.getTimestamp = (created) => { + this.getTimestamp = created => { const date = new Date(created); const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); const second = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(); return `${hour}:${minute}:${second}`; - } + }; this.getParentEvents = (uuid, list) => { list = list || []; @@ -216,9 +214,7 @@ function JobRenderService ($q, $sce, $window) { return list; }; - this.getEvents = () => { - return this.hooks.get(); - }; + this.getEvents = () => this.hooks.get(); this.insert = (events, insert) => { const result = this.transformEventGroup(events); @@ -229,23 +225,19 @@ function JobRenderService ($q, $sce, $window) { .then(() => result.lines); }; - this.remove = elements => { - return this.requestAnimationFrame(() => { - elements.remove(); - }); - }; + this.remove = elements => this.requestAnimationFrame(() => { + elements.remove(); + }); - this.requestAnimationFrame = fn => { - return $q(resolve => { - $window.requestAnimationFrame(() => { - if (fn) { - fn(); - } + this.requestAnimationFrame = fn => $q(resolve => { + $window.requestAnimationFrame(() => { + if (fn) { + fn(); + } - return resolve(); - }); + return resolve(); }); - }; + }); this.compile = html => { this.hooks.compile(html); @@ -271,13 +263,8 @@ function JobRenderService ($q, $sce, $window) { return this.remove(elements); }; - this.prepend = events => { - return this.insert(events, html => this.el.prepend(html)) - }; - - this.append = events => { - return this.insert(events, html => this.el.append(html)) - }; + this.prepend = events => this.insert(events, html => this.el.prepend(html)); + this.append = events => this.insert(events, html => this.el.append(html)); // TODO: stdout from the API should not be trusted. this.sanitize = html => { diff --git a/awx/ui/client/features/output/scroll.service.js b/awx/ui/client/features/output/scroll.service.js index 791d495796..ae186798e4 100644 --- a/awx/ui/client/features/output/scroll.service.js +++ b/awx/ui/client/features/output/scroll.service.js @@ -42,7 +42,6 @@ function JobScrollService ($q, $timeout) { this.register = () => { this.pause(); - const height = this.getScrollHeight(); const current = this.getScrollPosition(); const downward = current > this.position.previous; @@ -71,19 +70,16 @@ function JobScrollService ($q, $timeout) { }; this.isBeyondThreshold = (downward, current) => { - const previous = this.position.previous; - const height = this.getScrollHeight(); + const height = this.getScrollHeight(); - if (downward) { + if (downward) { current += this.getViewableHeight(); if (current >= height || ((height - current) / height) < THRESHOLD) { return true; } - } else { - if (current <= 0 || (current / height) < THRESHOLD) { - return true; - } + } else if (current <= 0 || (current / height) < THRESHOLD) { + return true; } return false; @@ -111,17 +107,9 @@ function JobScrollService ($q, $timeout) { this.setScrollPosition(top + height); }; - this.getScrollHeight = () => { - return this.el[0].scrollHeight; - }; - - this.getViewableHeight = () => { - return this.el[0].offsetHeight; - }; - - this.getScrollPosition = () => { - return this.el[0].scrollTop; - }; + this.getScrollHeight = () => this.el[0].scrollHeight; + this.getViewableHeight = () => this.el[0].offsetHeight; + this.getScrollPosition = () => this.el[0].scrollTop; this.setScrollPosition = position => { this.position.previous = this.position.current; @@ -159,9 +147,7 @@ function JobScrollService ($q, $timeout) { this.state.paused = true; }; - this.isPaused = () => { - return this.state.paused; - }; + this.isPaused = () => this.state.paused; this.lock = () => { this.state.locked = true; @@ -171,9 +157,7 @@ function JobScrollService ($q, $timeout) { this.state.locked = false; }; - this.isLocked = () => { - return this.state.locked; - }; + this.isLocked = () => this.state.locked; } JobScrollService.$inject = ['$q', '$timeout']; diff --git a/awx/ui/client/features/output/search-key.directive.js b/awx/ui/client/features/output/search-key.directive.js index f9a1ad1928..91455e3637 100644 --- a/awx/ui/client/features/output/search-key.directive.js +++ b/awx/ui/client/features/output/search-key.directive.js @@ -13,12 +13,11 @@ function AtSearchKeyController () { vm.examples = scope.examples || []; vm.fields = scope.fields || []; vm.relatedFields = scope.relatedFields || []; - } + }; } AtSearchKeyController.$inject = ['$scope']; - function atSearchKey () { return { templateUrl, diff --git a/awx/ui/client/features/output/stream.service.js b/awx/ui/client/features/output/stream.service.js index 05603d103a..a7e73cbdfa 100644 --- a/awx/ui/client/features/output/stream.service.js +++ b/awx/ui/client/features/output/stream.service.js @@ -102,26 +102,24 @@ function JobStreamService ($q) { .then(() => --this.lag); }; - this.renderFrame = events => { - return this.hooks.render(events) - .then(() => { - if (this.scroll.isLocked()) { - this.scroll.scrollToBottom(); + this.renderFrame = events => this.hooks.render(events) + .then(() => { + if (this.scroll.isLocked()) { + this.scroll.scrollToBottom(); + } + + if (this.isEnding()) { + const lastEvents = this.page.emptyBuffer(); + + if (lastEvents.length) { + return this.renderFrame(lastEvents); } - if (this.isEnding()) { - const lastEvents = this.page.emptyBuffer(); + this.end(true); + } - if (lastEvents.length) { - return this.renderFrame(lastEvents); - } - - this.end(true); - } - - return $q.resolve(); - }); - }; + return $q.resolve(); + }); this.resume = done => { if (done) { diff --git a/awx/ui/client/lib/models/Base.js b/awx/ui/client/lib/models/Base.js index 98f2b25007..f3b0d4dfba 100644 --- a/awx/ui/client/lib/models/Base.js +++ b/awx/ui/client/lib/models/Base.js @@ -400,7 +400,7 @@ function extend (related, config) { function goToPage (config) { const params = config.params || {}; - const page = config.page; + const { page } = config; let url; let key; @@ -473,7 +473,7 @@ function goToPage (config) { return { results: data.results, page: pageNumber - } + }; }); }