Fix (most) lint errors

This commit is contained in:
gconsidine
2018-03-09 13:09:46 -05:00
committed by Jake McDermott
parent 57ea582898
commit c9612b8c75
8 changed files with 101 additions and 137 deletions

View File

@@ -110,7 +110,7 @@ function next () {
return page.next() return page.next()
.then(events => { .then(events => {
if (!events) { if (!events) {
return; return $q.resolve();
} }
return shift() return shift()
@@ -119,13 +119,13 @@ function next () {
} }
function previous () { function previous () {
let initialPosition = scroll.getScrollPosition(); const initialPosition = scroll.getScrollPosition();
let postPopHeight; let postPopHeight;
return page.previous() return page.previous()
.then(events => { .then(events => {
if (!events) { if (!events) {
return; return $q.resolve();
} }
return pop() return pop()
@@ -134,7 +134,7 @@ function previous () {
return prepend(events); return prepend(events);
}) })
.then(() => { .then(() => {
const currentHeight = scroll.getScrollHeight(); const currentHeight = scroll.getScrollHeight();
scroll.setScrollPosition(currentHeight - postPopHeight + initialPosition); scroll.setScrollPosition(currentHeight - postPopHeight + initialPosition);
}); });
@@ -177,7 +177,7 @@ function shift () {
function scrollHome () { function scrollHome () {
if (scroll.isPaused()) { if (scroll.isPaused()) {
return; return $q.resolve();
} }
scroll.pause(); scroll.pause();
@@ -185,7 +185,7 @@ function scrollHome () {
return page.first() return page.first()
.then(events => { .then(events => {
if (!events) { if (!events) {
return; return $q.resolve();
} }
return render.clear() return render.clear()
@@ -200,7 +200,7 @@ function scrollHome () {
function scrollEnd () { function scrollEnd () {
if (stream.isActive()) { if (stream.isActive()) {
if (stream.isTransitioning()) { if (stream.isTransitioning()) {
return; return $q.resolve();
} }
if (stream.isPaused()) { if (stream.isPaused()) {
@@ -209,9 +209,9 @@ function scrollEnd () {
stream.pause(); stream.pause();
} }
return; return $q.resolve();
} else if (scroll.isPaused()) { } else if (scroll.isPaused()) {
return; return $q.resolve();
} }
scroll.pause(); scroll.pause();
@@ -219,7 +219,7 @@ function scrollEnd () {
return page.last() return page.last()
.then(events => { .then(events => {
if (!events) { if (!events) {
return; return $q.resolve();
} }
return render.clear() return render.clear()
@@ -306,7 +306,7 @@ function toggleSearchKey () {
vm.searchKey = !vm.searchKey; vm.searchKey = !vm.searchKey;
} }
function getCurrentQueryset() { function getCurrentQueryset () {
const { job_event_search } = $state.params; const { job_event_search } = $state.params;
return qs.decodeArr(job_event_search); return qs.decodeArr(job_event_search);

View File

@@ -17,7 +17,16 @@ const PAGE_LIMIT = 3;
const PAGE_SIZE = 100; const PAGE_SIZE = 100;
const WS_PREFIX = 'ws'; 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; const { id, type, job_event_search } = $stateParams;
let Resource; let Resource;
@@ -60,22 +69,20 @@ function resolveResource (Job, ProjectUpdate, AdHocCommand, SystemJob, WorkflowJ
pageLimit: PAGE_LIMIT, pageLimit: PAGE_LIMIT,
params, params,
})) }))
.then(model => { .then(model => ({
return { id,
id, type,
type, model,
model, related,
related, ws: {
ws: { namespace: `${WS_PREFIX}-${getWebSocketResource(type).key}-${id}`
namespace: `${WS_PREFIX}-${getWebSocketResource(type).key}-${id}` },
}, page: {
page: { cache: PAGE_CACHE,
cache: PAGE_CACHE, size: PAGE_SIZE,
size: PAGE_SIZE, pageLimit: PAGE_LIMIT
pageLimit: PAGE_LIMIT }
} }))
};
})
.catch(({ data, status }) => qs.error(data, status)) .catch(({ data, status }) => qs.error(data, status))
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
@@ -84,9 +91,6 @@ function resolveWebSocketConnection (SocketService, $stateParams) {
const { type, id } = $stateParams; const { type, id } = $stateParams;
const resource = getWebSocketResource(type); const resource = getWebSocketResource(type);
let name;
let events;
const state = { const state = {
data: { data: {
socket: { socket: {
@@ -132,12 +136,13 @@ function getWebSocketResource (type) {
name = 'jobs'; name = 'jobs';
key = 'job_events'; key = 'job_events';
break; break;
default:
throw new Error('Unsupported WebSocket type');
} }
return { name, key }; return { name, key };
} }
function JobsRun ($stateRegistry) { function JobsRun ($stateRegistry) {
const state = { const state = {
name: 'jobz', name: 'jobz',

View File

@@ -47,7 +47,7 @@ function JobPageService ($q) {
} else { } else {
reference.cache.unshift(page); reference.cache.unshift(page);
reference.state.first = page.number; 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; reference.state.current = page.number;
@@ -101,7 +101,7 @@ function JobPageService ($q) {
} }
return false; return false;
} };
this.emptyBuffer = () => { this.emptyBuffer = () => {
const reference = this.getReference(); const reference = this.getReference();
@@ -137,8 +137,9 @@ function JobPageService ($q) {
}; };
this.trim = left => { this.trim = left => {
let reference = this.getActiveReference(); const reference = this.getActiveReference();
let excess = reference.cache.length - this.page.limit; const excess = reference.cache.length - this.page.limit;
let ejected; let ejected;
if (left) { if (left) {
@@ -152,9 +153,8 @@ function JobPageService ($q) {
return ejected.reduce((total, page) => total + page.lines, 0); return ejected.reduce((total, page) => total + page.lines, 0);
}; };
this.isPageBookmarked = number => { this.isPageBookmarked = number => number >= this.page.bookmark.first &&
return number >= this.page.bookmark.first && number <= this.page.bookmark.last; number <= this.page.bookmark.last;
};
this.updateLineCount = (lines, stream) => { this.updateLineCount = (lines, stream) => {
let reference; let reference;
@@ -168,15 +168,10 @@ function JobPageService ($q) {
const index = reference.cache.findIndex(item => item.number === reference.state.current); const index = reference.cache.findIndex(item => item.number === reference.state.current);
reference.cache[index].lines += lines; reference.cache[index].lines += lines;
}
this.isBookmarkPending = () => {
return this.bookmark.pending;
}; };
this.isBookmarkSet = () => { this.isBookmarkPending = () => this.bookmark.pending;
return this.bookmark.set; this.isBookmarkSet = () => this.bookmark.set;
};
this.setBookmark = () => { this.setBookmark = () => {
if (this.isBookmarkSet()) { if (this.isBookmarkSet()) {
@@ -190,12 +185,11 @@ function JobPageService ($q) {
} }
this.bookmark.state.first = this.page.state.first; 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.state.current = this.page.state.current - 1;
this.bookmark.cache = JSON.parse(JSON.stringify(this.page.cache)); this.bookmark.cache = JSON.parse(JSON.stringify(this.page.cache));
this.bookmark.set = true; this.bookmark.set = true;
this.bookmark.pending = false; this.bookmark.pending = false;
console.log('applied', JSON.stringify(this.bookmark.state, 0, 2));
}; };
this.removeBookmark = () => { this.removeBookmark = () => {
@@ -271,19 +265,16 @@ function JobPageService ($q) {
}); });
}; };
this.buildRequestConfig = number => { this.buildRequestConfig = number => ({
return { page: number,
page: number, related: this.resource.related,
related: this.resource.related, params: {
params: { order_by: 'start_line'
order_by: 'start_line' }
} });
};
};
this.getActiveReference = () => { this.getActiveReference = () => (this.isBookmarkSet() ?
return this.isBookmarkSet() ? this.getReference(true) : this.getReference(); this.getReference(true) : this.getReference());
};
this.getReference = (bookmark) => { this.getReference = (bookmark) => {
if (bookmark) { if (bookmark) {

View File

@@ -5,8 +5,6 @@ const ELEMENT_TBODY = '#atStdoutResultTable';
const EVENT_START_TASK = 'playbook_on_task_start'; const EVENT_START_TASK = 'playbook_on_task_start';
const EVENT_START_PLAY = 'playbook_on_play_start'; const EVENT_START_PLAY = 'playbook_on_play_start';
const EVENT_STATS_PLAY = 'playbook_on_stats'; const EVENT_STATS_PLAY = 'playbook_on_stats';
const JOB_START = 'playbook_on_start';
const JOB_END = 'playbook_on_stats';
const EVENT_GROUPS = [ const EVENT_GROUPS = [
EVENT_START_TASK, EVENT_START_TASK,
@@ -70,7 +68,7 @@ function JobRenderService ($q, $sce, $window) {
const current = this.createRecord(ln, lines, event); const current = this.createRecord(ln, lines, event);
const html = lines.reduce((html, line, i) => { const html = lines.reduce((concat, line, i) => {
ln++; ln++;
const isLastLine = i === lines.length - 1; const isLastLine = i === lines.length - 1;
@@ -81,7 +79,7 @@ function JobRenderService ($q, $sce, $window) {
count++; count++;
} }
return `${html}${row}`; return `${concat}${row}`;
}, ''); }, '');
return { html, count }; return { html, count };
@@ -191,16 +189,16 @@ function JobRenderService ($q, $sce, $window) {
${tdEvent} ${tdEvent}
<td class="at-Stdout-time">${timestamp}</td> <td class="at-Stdout-time">${timestamp}</td>
</tr>`; </tr>`;
} };
this.getTimestamp = (created) => { this.getTimestamp = created => {
const date = new Date(created); const date = new Date(created);
const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); const minute = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
const second = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(); const second = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
return `${hour}:${minute}:${second}`; return `${hour}:${minute}:${second}`;
} };
this.getParentEvents = (uuid, list) => { this.getParentEvents = (uuid, list) => {
list = list || []; list = list || [];
@@ -216,9 +214,7 @@ function JobRenderService ($q, $sce, $window) {
return list; return list;
}; };
this.getEvents = () => { this.getEvents = () => this.hooks.get();
return this.hooks.get();
};
this.insert = (events, insert) => { this.insert = (events, insert) => {
const result = this.transformEventGroup(events); const result = this.transformEventGroup(events);
@@ -229,23 +225,19 @@ function JobRenderService ($q, $sce, $window) {
.then(() => result.lines); .then(() => result.lines);
}; };
this.remove = elements => { this.remove = elements => this.requestAnimationFrame(() => {
return this.requestAnimationFrame(() => { elements.remove();
elements.remove(); });
});
};
this.requestAnimationFrame = fn => { this.requestAnimationFrame = fn => $q(resolve => {
return $q(resolve => { $window.requestAnimationFrame(() => {
$window.requestAnimationFrame(() => { if (fn) {
if (fn) { fn();
fn(); }
}
return resolve(); return resolve();
});
}); });
}; });
this.compile = html => { this.compile = html => {
this.hooks.compile(html); this.hooks.compile(html);
@@ -271,13 +263,8 @@ function JobRenderService ($q, $sce, $window) {
return this.remove(elements); return this.remove(elements);
}; };
this.prepend = events => { this.prepend = events => this.insert(events, html => this.el.prepend(html));
return this.insert(events, html => this.el.prepend(html)) this.append = events => this.insert(events, html => this.el.append(html));
};
this.append = events => {
return this.insert(events, html => this.el.append(html))
};
// TODO: stdout from the API should not be trusted. // TODO: stdout from the API should not be trusted.
this.sanitize = html => { this.sanitize = html => {

View File

@@ -42,7 +42,6 @@ function JobScrollService ($q, $timeout) {
this.register = () => { this.register = () => {
this.pause(); this.pause();
const height = this.getScrollHeight();
const current = this.getScrollPosition(); const current = this.getScrollPosition();
const downward = current > this.position.previous; const downward = current > this.position.previous;
@@ -71,19 +70,16 @@ function JobScrollService ($q, $timeout) {
}; };
this.isBeyondThreshold = (downward, current) => { this.isBeyondThreshold = (downward, current) => {
const previous = this.position.previous; const height = this.getScrollHeight();
const height = this.getScrollHeight();
if (downward) { if (downward) {
current += this.getViewableHeight(); current += this.getViewableHeight();
if (current >= height || ((height - current) / height) < THRESHOLD) { if (current >= height || ((height - current) / height) < THRESHOLD) {
return true; return true;
} }
} else { } else if (current <= 0 || (current / height) < THRESHOLD) {
if (current <= 0 || (current / height) < THRESHOLD) { return true;
return true;
}
} }
return false; return false;
@@ -111,17 +107,9 @@ function JobScrollService ($q, $timeout) {
this.setScrollPosition(top + height); this.setScrollPosition(top + height);
}; };
this.getScrollHeight = () => { this.getScrollHeight = () => this.el[0].scrollHeight;
return this.el[0].scrollHeight; this.getViewableHeight = () => this.el[0].offsetHeight;
}; this.getScrollPosition = () => this.el[0].scrollTop;
this.getViewableHeight = () => {
return this.el[0].offsetHeight;
};
this.getScrollPosition = () => {
return this.el[0].scrollTop;
};
this.setScrollPosition = position => { this.setScrollPosition = position => {
this.position.previous = this.position.current; this.position.previous = this.position.current;
@@ -159,9 +147,7 @@ function JobScrollService ($q, $timeout) {
this.state.paused = true; this.state.paused = true;
}; };
this.isPaused = () => { this.isPaused = () => this.state.paused;
return this.state.paused;
};
this.lock = () => { this.lock = () => {
this.state.locked = true; this.state.locked = true;
@@ -171,9 +157,7 @@ function JobScrollService ($q, $timeout) {
this.state.locked = false; this.state.locked = false;
}; };
this.isLocked = () => { this.isLocked = () => this.state.locked;
return this.state.locked;
};
} }
JobScrollService.$inject = ['$q', '$timeout']; JobScrollService.$inject = ['$q', '$timeout'];

View File

@@ -13,12 +13,11 @@ function AtSearchKeyController () {
vm.examples = scope.examples || []; vm.examples = scope.examples || [];
vm.fields = scope.fields || []; vm.fields = scope.fields || [];
vm.relatedFields = scope.relatedFields || []; vm.relatedFields = scope.relatedFields || [];
} };
} }
AtSearchKeyController.$inject = ['$scope']; AtSearchKeyController.$inject = ['$scope'];
function atSearchKey () { function atSearchKey () {
return { return {
templateUrl, templateUrl,

View File

@@ -102,26 +102,24 @@ function JobStreamService ($q) {
.then(() => --this.lag); .then(() => --this.lag);
}; };
this.renderFrame = events => { this.renderFrame = events => this.hooks.render(events)
return this.hooks.render(events) .then(() => {
.then(() => { if (this.scroll.isLocked()) {
if (this.scroll.isLocked()) { this.scroll.scrollToBottom();
this.scroll.scrollToBottom(); }
if (this.isEnding()) {
const lastEvents = this.page.emptyBuffer();
if (lastEvents.length) {
return this.renderFrame(lastEvents);
} }
if (this.isEnding()) { this.end(true);
const lastEvents = this.page.emptyBuffer(); }
if (lastEvents.length) { return $q.resolve();
return this.renderFrame(lastEvents); });
}
this.end(true);
}
return $q.resolve();
});
};
this.resume = done => { this.resume = done => {
if (done) { if (done) {

View File

@@ -400,7 +400,7 @@ function extend (related, config) {
function goToPage (config) { function goToPage (config) {
const params = config.params || {}; const params = config.params || {};
const page = config.page; const { page } = config;
let url; let url;
let key; let key;
@@ -473,7 +473,7 @@ function goToPage (config) {
return { return {
results: data.results, results: data.results,
page: pageNumber page: pageNumber
} };
}); });
} }