Fix a whole bunch of eslint errors

These apparently were silent until 92c532d mass-upgraded deps.
Apparently eslint returned status 0 despite errors before and now
returns 1.

Most of these were handled by its "--fix" option; I manually took care
of the remaining two:

/Users/slamb/git/moonfire-nvr/ui-src/lib/views/RecordingsView.js
  140:1  error  This line has a length of 82. Maximum allowed is 80  max-len

/Users/slamb/git/moonfire-nvr/ui-src/lib/views/StreamSelectorView.js
  72:1  error  This line has a length of 82. Maximum allowed is 80  max-len
This commit is contained in:
Scott Lamb 2020-03-01 22:26:26 -08:00
parent 92c532db3e
commit aa25a85477
15 changed files with 154 additions and 152 deletions

View File

@ -72,7 +72,7 @@ let loginDialog = null;
*
* @type {String}
*/
let timeFmt = 'YYYY-MM-DD HH:mm:ss';
const timeFmt = 'YYYY-MM-DD HH:mm:ss';
/**
* Currently active time formatter.
@ -128,24 +128,24 @@ function onSelectVideo(nvrSettingsView, camera, streamType, range, recording) {
console.log('Recording clicked: ', recording);
const trimmedRange = recording.range90k(nvrSettingsView.trim ? range : null);
const url = api.videoPlayUrl(
camera.uuid,
streamType,
recording,
trimmedRange,
nvrSettingsView.timeStampTrack
camera.uuid,
streamType,
recording,
trimmedRange,
nvrSettingsView.timeStampTrack
);
const [
formattedStart,
formattedEnd,
] = timeFormatter90k.formatSameDayShortened(
trimmedRange.startTime90k,
trimmedRange.endTime90k
trimmedRange.startTime90k,
trimmedRange.endTime90k
);
const videoTitle =
camera.shortName + ', ' + formattedStart + ' to ' + formattedEnd;
new VideoDialogView()
.attach($('body'))
.play(videoTitle, recording.videoSampleEntryWidth / 4, url);
.attach($('body'))
.play(videoTitle, recording.videoSampleEntryWidth / 4, url);
}
/**
@ -159,18 +159,18 @@ function fetch(selectedRange, videoLength) {
return;
}
console.log(
'Fetching> ' +
'Fetching> ' +
selectedRange.formatTimeStamp90k(selectedRange.startTime90k) +
' to ' +
selectedRange.formatTimeStamp90k(selectedRange.endTime90k)
);
for (let streamView of streamViews) {
let url = api.recordingsUrl(
streamView.camera.uuid,
streamView.streamType,
selectedRange.startTime90k,
selectedRange.endTime90k,
videoLength
for (const streamView of streamViews) {
const url = api.recordingsUrl(
streamView.camera.uuid,
streamView.streamType,
selectedRange.startTime90k,
selectedRange.endTime90k,
videoLength
);
if (streamView.recordingsReq !== null) {
/*
@ -181,7 +181,7 @@ function fetch(selectedRange, videoLength) {
streamView.recordingsReq.abort();
}
streamView.delayedShowLoading(500);
let r = api.request(url);
const r = api.request(url);
streamView.recordingsUrl = url;
streamView.recordingsReq = r;
streamView.recordingsRange = selectedRange.range90k();
@ -189,20 +189,20 @@ function fetch(selectedRange, videoLength) {
streamView.recordingsReq = null;
});
r
.then(function(data /* , status, req */) {
.then(function(data /* , status, req */) {
// Sort recordings in descending order.
data.recordings.sort(function(a, b) {
return b.startId - a.startId;
data.recordings.sort(function(a, b) {
return b.startId - a.startId;
});
console.log(
'Fetched results for "%s-%s" > updating recordings',
streamView.camera.shortName, streamView.streamType
);
streamView.recordingsJSON = data.recordings;
})
.catch(function(data, status, err) {
console.error(url, ' load failed: ', status, ': ', err);
});
console.log(
'Fetched results for "%s-%s" > updating recordings',
streamView.camera.shortName, streamView.streamType
);
streamView.recordingsJSON = data.recordings;
})
.catch(function(data, status, err) {
console.error(url, ' load failed: ', status, ': ', err);
});
}
}
@ -213,21 +213,21 @@ function fetch(selectedRange, videoLength) {
* or null.
*/
function updateSession(session) {
let sessionBar = $('#session');
const sessionBar = $('#session');
sessionBar.empty();
if (session === null || session === undefined) {
sessionBar.hide();
return;
}
sessionBar.append($('<span id="session-username" />').text(session.username));
let logout = $('<a>logout</a>');
const logout = $('<a>logout</a>');
logout.click(() => {
api
.logout(session.csrf)
.done(() => {
onReceivedTopLevel(null);
loginDialog.dialog('open');
});
.logout(session.csrf)
.done(() => {
onReceivedTopLevel(null);
loginDialog.dialog('open');
});
});
sessionBar.append(' | ', logout);
sessionBar.show();
@ -274,10 +274,10 @@ function onReceivedTopLevel(data) {
videos.empty();
streamViews = [];
let streamSelectorCameras = [];
const streamSelectorCameras = [];
for (const cameraJson of data.cameras) {
const camera = new Camera(cameraJson);
let cameraStreams = {};
const cameraStreams = {};
Object.keys(camera.streams).forEach((streamType) => {
const sv = new StreamView(
camera,
@ -288,11 +288,11 @@ function onReceivedTopLevel(data) {
sv.onRecordingClicked = (recordingModel) => {
console.log('Recording clicked', recordingModel);
onSelectVideo(
nvrSettingsView,
camera,
streamType,
calendarView.selectedRange,
recordingModel
nvrSettingsView,
camera,
streamType,
calendarView.selectedRange,
recordingModel
);
};
streamViews.push(sv);
@ -321,10 +321,10 @@ function sendLoginRequest() {
return;
}
let username = $('#login-username').val();
let password = $('#login-password').val();
let submit = $('#login-submit');
let error = $('#login-error');
const username = $('#login-username').val();
const password = $('#login-password').val();
const submit = $('#login-submit');
const error = $('#login-error');
error.empty();
error.removeClass('ui-state-highlight');
@ -332,36 +332,36 @@ function sendLoginRequest() {
loginDialog.pending = true;
console.info('logging in as', username);
api
.login(username, password)
.done(() => {
console.info('login successful');
loginDialog.dialog('close');
sendTopLevelRequest();
})
.catch((e) => {
console.info('login failed:', e);
error.show();
error.addClass('ui-state-highlight');
error.text(e.responseText);
})
.always(() => {
submit.button('option', 'disabled', false);
loginDialog.pending = false;
});
.login(username, password)
.done(() => {
console.info('login successful');
loginDialog.dialog('close');
sendTopLevelRequest();
})
.catch((e) => {
console.info('login failed:', e);
error.show();
error.addClass('ui-state-highlight');
error.text(e.responseText);
})
.always(() => {
submit.button('option', 'disabled', false);
loginDialog.pending = false;
});
}
/** Sends the top-level api request. */
function sendTopLevelRequest() {
api
.request(api.nvrUrl(true))
.done((data) => onReceivedTopLevel(data))
.catch((e) => {
console.error('NVR load exception: ', e);
onReceivedTopLevel(null);
if (e.status == 401) {
loginDialog.dialog('open');
}
});
.request(api.nvrUrl(true))
.done((data) => onReceivedTopLevel(data))
.catch((e) => {
console.error('NVR load exception: ', e);
onReceivedTopLevel(null);
if (e.status == 401) {
loginDialog.dialog('open');
}
});
}
/**

View File

@ -93,8 +93,8 @@ export default class MoonfireAPI {
query.split90k = split90k;
}
return this._builder.makeUrl(
'cameras/' + cameraUUID + '/' + streamType + '/recordings',
query
'cameras/' + cameraUUID + '/' + streamType + '/recordings',
query
);
}
@ -109,7 +109,7 @@ export default class MoonfireAPI {
* @return {String} Constructed url
*/
videoPlayUrl(cameraUUID, streamType, recording, trimmedRange,
timestampTrack = true) {
timestampTrack = true) {
let sParam = recording.startId;
if (recording.endId !== undefined) {
sParam += '-' + recording.endId;

View File

@ -138,9 +138,9 @@ export default class CalendarTSRange {
* @return {Range90k} Range object or null if don't have start and end
*/
range90k() {
return this.hasRange()
? new Range90k(this.startTime90k, this.endTime90k)
: null;
return this.hasRange() ?
new Range90k(this.startTime90k, this.endTime90k) :
null;
}
/**
@ -167,9 +167,9 @@ export default class CalendarTSRange {
*/
_setRangeTime(range, dateStr, timeStr, dateOnlyThenEndOfDay) {
const newTs90k = this._timeParser.parseDateTime90k(
dateStr,
timeStr,
dateOnlyThenEndOfDay
dateStr,
timeStr,
dateOnlyThenEndOfDay
);
if (newTs90k !== null) {
range.dateStr = dateStr;

View File

@ -37,7 +37,7 @@ import Range from './Range';
*
* @type {WeakMap}
*/
let _range = new WeakMap();
const _range = new WeakMap();
/**
* Class like Range to represent ranges over timestamps in 90k format.
@ -94,8 +94,8 @@ export default class Range90k {
*/
trimmed(against) {
return new Range90k(
Math.max(this.startTime90k, against.startTime90k),
Math.min(this.endTime90k, against.endTime90k)
Math.max(this.startTime90k, against.startTime90k),
Math.min(this.endTime90k, against.endTime90k)
);
}

View File

@ -102,7 +102,7 @@ export default class Recording {
* @return {Range90k} Resulting range
*/
range90k(trimmedAgainst = null) {
let result = new Range90k(this.startTime90k, this.endTime90k);
const result = new Range90k(this.startTime90k, this.endTime90k);
return trimmedAgainst ? result.trimmed(trimmedAgainst) : result;
}
/**

View File

@ -65,9 +65,9 @@ export default class Stream {
*/
get range90k() {
return new Range90k(
this.json_.minStartTime90k,
this.json_.maxEndTime90k,
this.json_.totalDuration90k
this.json_.minStartTime90k,
this.json_.maxEndTime90k,
this.json_.totalDuration90k
);
}
@ -94,11 +94,11 @@ export default class Stream {
*/
get days() {
return new Map(
Object.entries(this.json_.days).map(function(t) {
let [k, v] = t;
v = new Range90k(v.startTime90k, v.endTime90k, v.totalDuration90k);
return [k, v];
})
Object.entries(this.json_.days).map(function(t) {
let [k, v] = t;
v = new Range90k(v.startTime90k, v.endTime90k, v.totalDuration90k);
return [k, v];
})
);
}
}

View File

@ -45,13 +45,13 @@ import moment from 'moment-timezone';
* @type {RegExp}
*/
const timeRe = new RegExp(
[
'^', // Start
'([0-9]{1,2}:[0-9]{2})', // Capture HH:MM
'(?:(:[0-9]{2})(?::([0-9]{5}))?)?', // Capture [:ss][:FFFFF]
'([+-][0-9]{1,2}:?(?:[0-9]{2})?)?', // Capture [+-][zone]
'$', // End
].join('')
[
'^', // Start
'([0-9]{1,2}:[0-9]{2})', // Capture HH:MM
'(?:(:[0-9]{2})(?::([0-9]{5}))?)?', // Capture [:ss][:FFFFF]
'([+-][0-9]{1,2}:?(?:[0-9]{2})?)?', // Capture [+-][zone]
'$', // End
].join('')
);
/**

View File

@ -106,7 +106,7 @@ export default class TimeFormatter {
let format = this._formatStr;
const ms = ts90k / 90.0;
const fracFmt = 'FFFFF';
let fracLoc = format.indexOf(fracFmt);
const fracLoc = format.indexOf(fracFmt);
if (fracLoc != -1) {
const frac = ts90k % 90000;
format =

View File

@ -70,7 +70,7 @@ export default class TimeStamp90kFormatter {
formatSameDayShortened(ts1, ts2) {
let ts1Formatted = this.formatTimeStamp90k(ts1);
let ts2Formatted = this.formatTimeStamp90k(ts2);
let timePos = this._formatter.formatStr.indexOf('T');
const timePos = this._formatter.formatStr.indexOf('T');
if (timePos != -1) {
const datePortion = ts1Formatted.substr(0, timePos);
ts1Formatted = datePortion + ' ' + ts1Formatted.substr(timePos + 1);

View File

@ -57,11 +57,11 @@ function minMaxDates(streamViews) {
* have at least one recording available (allDates).
*/
const allDates = new Set(
[].concat(
...streamViews
.filter((v) => v.enabled)
.map((v) => Array.from(v.stream.days.keys()))
)
[].concat(
...streamViews
.filter((v) => v.enabled)
.map((v) => Array.from(v.stream.days.keys()))
)
);
return [
allDates,
@ -161,7 +161,7 @@ export default class CalendarView {
const fromPickerView = this._fromPickerView;
const toPickerView = this._toPickerView;
const beforeShowDay = function(date) {
let dateStr = date.toISOString().substr(0, 10);
const dateStr = date.toISOString().substr(0, 10);
return [dateSet.has(dateStr), '', ''];
};
@ -226,9 +226,9 @@ export default class CalendarView {
const pickerElement = event.currentTarget;
const newTimeStr = pickerElement.value;
const selectedRange = this._selectedRange;
const parsedTS = isEnd
? selectedRange.setEndTime(newTimeStr)
: selectedRange.setStartTime(newTimeStr);
const parsedTS = isEnd ?
selectedRange.setEndTime(newTimeStr) :
selectedRange.setStartTime(newTimeStr);
if (parsedTS === null) {
console.warn('bad time change');
$(pickerElement).addClass('ui-state-error');
@ -236,7 +236,7 @@ export default class CalendarView {
}
$(pickerElement).removeClass('ui-state-error');
console.log(
(isEnd ? 'End' : 'Start') +
(isEnd ? 'End' : 'Start') +
' time changed to: ' +
parsedTS +
' (' +
@ -261,9 +261,9 @@ export default class CalendarView {
* changes. We need to determine a new selected range and activiate it.
* Doing so will then also inform the change listener.
*/
const endDate = isSameDay
? this.selectedRange.start.dateStr
: this.selectedRange.end.dateStr;
const endDate = isSameDay ?
this.selectedRange.start.dateStr :
this.selectedRange.end.dateStr;
this._updateRangeDates(this.selectedRange.start.dateStr, endDate);
this._sameDay = isSameDay;
@ -334,7 +334,7 @@ export default class CalendarView {
initializeWith(streamViews) {
this._streamViews = streamViews;
[this._availableDates, this._minDateStr, this._maxDateStr] = minMaxDates(
streamViews
streamViews
);
this._configureDatePickers();

View File

@ -83,11 +83,11 @@ export default class DatePickerView {
_initWithOptions(options = null) {
this._alive = true;
options =
options !== null
? options
: {
disabled: true,
};
options !== null ?
options :
{
disabled: true,
};
this._pickerElement.datepicker(options);
}

View File

@ -79,7 +79,7 @@ export default class RecordingsView {
* @param {jQuery} parent Parent to which new DOM is attached, or null
*/
constructor(camera, streamType, recordingFormatter, trimmed = false,
parent = null) {
parent = null) {
this._cameraName = camera.shortName;
this._cameraRange = camera.range90k;
this._formatter = recordingFormatter;
@ -107,17 +107,17 @@ export default class RecordingsView {
_createElement(id, cameraName, streamType) {
const tab = $('<tbody>').attr('id', id);
tab.append(
$('<tr class="name">').append($('<th colspan=6/>')
.text(cameraName + ' ' + streamType)),
$('<tr class="hdr">').append(
$(
_columnOrder
.map((name) => '<th>' + _columnLabels[name] + '</th>')
.join('')
)
),
$('</tr>'),
$('<tr class="loading"><td colspan=6>loading...</td></tr>').hide()
$('<tr class="name">').append($('<th colspan=6/>')
.text(cameraName + ' ' + streamType)),
$('<tr class="hdr">').append(
$(
_columnOrder
.map((name) => '<th>' + _columnLabels[name] + '</th>')
.join('')
)
),
$('</tr>'),
$('<tr class="loading"><td colspan=6>loading...</td></tr>').hide()
);
return tab;
}
@ -136,8 +136,8 @@ export default class RecordingsView {
this._element.children('tr.r').each((rowIndex, row) => {
const values = this._formatter.format(recordings[rowIndex], trimRange);
$(row)
.children('td')
.each((index, element) => $(element).text(values[_columnOrder[index]]));
.children('td')
.each((i, e) => $(e).text(values[_columnOrder[i]]));
});
}
@ -269,7 +269,7 @@ export default class RecordingsView {
// Remove existing rows, replace with new ones
$('tr.r', tbody).remove();
this._recordings.forEach((r) => {
let row = $('<tr class="r" />');
const row = $('<tr class="r" />');
row.append(_columnOrder.map(() => $('<td/>')));
row.on('click', () => {
console.log('Video clicked');

View File

@ -53,7 +53,7 @@ export default class StreamSelectorView {
if (cameras.length !== 0) {
// Add a header row.
let hdr = $('<tr/>').append($('<th/>'));
const hdr = $('<tr/>').append($('<th/>'));
for (const streamType of allStreamTypes) {
hdr.append($('<th/>').text(streamType));
}
@ -61,7 +61,7 @@ export default class StreamSelectorView {
}
this._cameras.forEach((c) => {
let row = $('<tr/>').append($('<td>').text(c.camera.shortName));
const row = $('<tr/>').append($('<td>').text(c.camera.shortName));
let firstStreamType = true;
for (const streamType of allStreamTypes) {
const streamView = c.streamViews[streamType];
@ -69,7 +69,9 @@ export default class StreamSelectorView {
row.append('<td/>');
} else {
const id = 'cam-' + c.camera.uuid + '-' + streamType;
let cb = $('<input type="checkbox">').attr('name', id).attr('id', id);
const cb = $('<input type="checkbox">')
.attr('name', id)
.attr('id', id);
// Only the first stream type for each camera should be checked
// initially.

View File

@ -44,21 +44,21 @@ export default class StreamView {
* @param {[type]} recordingsParent Parent element to attach to or null)
*/
constructor(
cameraModel,
streamType,
recordingFormatter,
trimmed,
recordingsParent = null
cameraModel,
streamType,
recordingFormatter,
trimmed,
recordingsParent = null
) {
this.camera = cameraModel;
this.streamType = streamType;
this.stream = cameraModel.streams[streamType];
this.recordingsView = new RecordingsView(
this.camera,
this.streamType,
recordingFormatter,
trimmed,
recordingsParent
this.camera,
this.streamType,
recordingFormatter,
trimmed,
recordingsParent
);
this._enabled = true;
this.recordingsUrl = null;

View File

@ -65,7 +65,7 @@ export default class VideoDialogView {
attach(domElement) {
this._videoElement = $('<video controls preload="auto" autoplay="true" />');
this._dialogElement = $('<div class="playdialog" />').append(
this._videoElement
this._videoElement
);
$(domElement).append(this._dialogElement);
return this;