Fixed or disabled warnings

This commit is contained in:
baldo 2017-05-06 17:31:34 +02:00
parent 94a51921fd
commit 3d6fb5feec
11 changed files with 45 additions and 38 deletions

View file

@ -12,7 +12,7 @@ angular.module('ffffng')
$scope.monitoringInfo = {}; $scope.monitoringInfo = {};
$scope.monitoringStatus = 'loading'; $scope.monitoringStatus = 'loading';
MonitoringService.confirm($routeParams['token']) MonitoringService.confirm($routeParams.token)
.then( .then(
function (response) { function (response) {
// success // success

View file

@ -12,7 +12,7 @@ angular.module('ffffng')
$scope.monitoringInfo = {}; $scope.monitoringInfo = {};
$scope.monitoringStatus = 'loading'; $scope.monitoringStatus = 'loading';
MonitoringService.disable($routeParams['token']) MonitoringService.disable($routeParams.token)
.then( .then(
function (response) { function (response) {
// success // success

View file

@ -5,7 +5,7 @@ angular.module('ffffng')
var ctrl = function ($scope) { var ctrl = function ($scope) {
$scope.version = '?'; $scope.version = '?';
$http.get('/api/version') $http.get('/api/version')
.then(function (result) { $scope.version = result.data.version; }) .then(function (result) { $scope.version = result.data.version; });
}; };
return { return {

View file

@ -120,8 +120,8 @@ angular.module('ffffng')
}; };
$scope.monitoringInitialConfirmationRequired = function () { $scope.monitoringInitialConfirmationRequired = function () {
return $scope.node.monitoring return $scope.node.monitoring &&
&& ($scope.action === 'create' || $scope.node.email !== initialEmail || !initialMonitoring); ($scope.action === 'create' || $scope.node.email !== initialEmail || !initialMonitoring);
}; };
$scope.monitoringConfirmationPending = function () { $scope.monitoringConfirmationPending = function () {
@ -137,8 +137,8 @@ angular.module('ffffng')
var doSubmit = function (node) { var doSubmit = function (node) {
if ($scope.nodeForm.$invalid) { if ($scope.nodeForm.$invalid) {
var firstInvalid = _.filter($element.find('form').find('input'), function (input) { var firstInvalid = _.filter($element.find('form').find('input'), function (input) {
return (input.type === 'text' || input.type === 'email') return (input.type === 'text' || input.type === 'email') &&
&& $scope.nodeForm[input.name].$invalid; $scope.nodeForm[input.name].$invalid;
})[0]; })[0];
if (firstInvalid) { if (firstInvalid) {
$window.scrollTo(0, $window.pageYOffset + firstInvalid.getBoundingClientRect().top - 100); $window.scrollTo(0, $window.pageYOffset + firstInvalid.getBoundingClientRect().top - 100);

View file

@ -11,7 +11,7 @@ angular.module('ffffng').factory('app', function (fs, config, _) {
// urls beneath /internal are protected // urls beneath /internal are protected
var internalAuth = auth.basic( var internalAuth = auth.basic(
{ {
realm: "Knotenformular - Intern" realm: 'Knotenformular - Intern'
}, },
function (username, password, callback) { function (username, password, callback) {
callback( callback(

View file

@ -126,6 +126,8 @@ if (fs.existsSync(configJSONFile)) {
process.exit(1); process.exit(1);
} }
var _ = require('lodash');
function stripTrailingSlash(obj, field) { function stripTrailingSlash(obj, field) {
var url = obj[field]; var url = obj[field];
if (_.isString(url) && _.last(url) === '/') { if (_.isString(url) && _.last(url) === '/') {

View file

@ -29,10 +29,10 @@ function applyPatch(db, file, callback) {
return callback(null); return callback(null);
} }
var sql = 'BEGIN TRANSACTION;\n' var sql = 'BEGIN TRANSACTION;\n' +
+ contents.toString() + '\n' contents.toString() + '\n' +
+ 'INSERT INTO schema_version (version) VALUES (\'' + version + '\');\n' 'INSERT INTO schema_version (version) VALUES (\'' + version + '\');\n' +
+ 'END TRANSACTION;'; 'END TRANSACTION;';
db.exec(sql, function (err) { db.exec(sql, function (err) {
if (err) { if (err) {
@ -50,10 +50,10 @@ function applyPatch(db, file, callback) {
function applyMigrations(db, callback) { function applyMigrations(db, callback) {
Logger.tag('database', 'migration').info('Migrating database...'); Logger.tag('database', 'migration').info('Migrating database...');
var sql = 'BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS schema_version (\n' var sql = 'BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS schema_version (\n' +
+ ' version VARCHAR(255) PRIMARY KEY ASC,\n' ' version VARCHAR(255) PRIMARY KEY ASC,\n' +
+ ' applied_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL\n' ' applied_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL\n' +
+ '); END TRANSACTION;'; '); END TRANSACTION;';
db.exec(sql, function (err) { db.exec(sql, function (err) {
if (err) { if (err) {
return callback(err); return callback(err);

View file

@ -21,7 +21,9 @@ angular.module('ffffng')
return _.template(fs.readFileSync(snippetFile).toString())(deepExtend( return _.template(fs.readFileSync(snippetFile).toString())(deepExtend(
{}, {},
// jshint -W040
this, // parent data this, // parent data
// jshint +W040
data, data,
templateFunctions templateFunctions
)); ));
@ -30,7 +32,7 @@ angular.module('ffffng')
function snippet(name) { function snippet(name) {
return function (data) { return function (data) {
return renderSnippet.bind(this)(name, data); return renderSnippet.bind(this)(name, data);
} };
} }
function renderLink(href, text) { function renderLink(href, text) {
@ -76,7 +78,7 @@ angular.module('ffffng')
}, },
render: function (mailOptions, callback) { render: function (mailOptions, callback) {
var templatePathPrefix = templateBasePath + '/' + mailOptions.email var templatePathPrefix = templateBasePath + '/' + mailOptions.email;
async.parallel({ async.parallel({
subject: _.partial(fs.readFile, templatePathPrefix + '.subject.txt'), subject: _.partial(fs.readFile, templatePathPrefix + '.subject.txt'),

View file

@ -65,7 +65,9 @@ angular.module('ffffng')
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Node is known in monitoring: %s', nodeData.mac); .debug('Node is known in monitoring: %s', nodeData.mac);
// jshint -W106
if (!moment(row.import_timestamp).isBefore(nodeData.importTimestamp)) { if (!moment(row.import_timestamp).isBefore(nodeData.importTimestamp)) {
// jshint +W106
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('No new data for node, skipping: %s', nodeData.mac); .debug('No new data for node, skipping: %s', nodeData.mac);
@ -108,7 +110,9 @@ angular.module('ffffng')
nodeDataForStoring = { nodeDataForStoring = {
mac: node.mac, mac: node.mac,
state: 'OFFLINE', state: 'OFFLINE',
// jshint -W106
lastSeen: _.isUndefined(row) ? moment() : moment.unix(row.last_seen), lastSeen: _.isUndefined(row) ? moment() : moment.unix(row.last_seen),
// jshint +W106
importTimestamp: moment() importTimestamp: moment()
}; };
} else { } else {
@ -129,7 +133,7 @@ angular.module('ffffng')
Logger.tag('monitoring', 'information-retrieval').debug('Parsing nodes.json...'); Logger.tag('monitoring', 'information-retrieval').debug('Parsing nodes.json...');
function parseTimestamp(timestamp) { function parseTimestamp(timestamp) {
if (!_.isString(json.timestamp)) { if (!_.isString(timestamp)) {
return moment.invalid(); return moment.invalid();
} }
return moment.utc(timestamp); return moment.utc(timestamp);
@ -277,7 +281,9 @@ angular.module('ffffng')
mailType, mailType,
{ {
node: node, node: node,
// jshint -W106
lastSeen: nodeState.last_seen, lastSeen: nodeState.last_seen,
// jshint +W106
disableUrl: UrlBuilder.monitoringDisableUrl(nodeSecrets) disableUrl: UrlBuilder.monitoringDisableUrl(nodeSecrets)
}, },
@ -361,9 +367,7 @@ angular.module('ffffng')
* descriptive string that stores, which was the last mail type, stored in the database as last_status_mail_type * descriptive string that stores, which was the last mail type, stored in the database as last_status_mail_type
*/ */
var previousType = var previousType =
mailNumber === 1 mailNumber === 1 ? 'monitoring-online-again' : ('monitoring-offline-' + (mailNumber - 1));
? 'monitoring-online-again'
: ('monitoring-offline-' + (mailNumber - 1));
// the first time the first offline mail is send, there was no mail before // the first time the first offline mail is send, there was no mail before
var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : ''; var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : '';
@ -773,5 +777,5 @@ angular.module('ffffng')
} }
); );
} }
} };
}); });

View file

@ -206,7 +206,7 @@ angular.module('ffffng')
function deleteNodeFile(token, callback) { function deleteNodeFile(token, callback) {
findNodeFiles({ token: token }, function (err, files) { findNodeFiles({ token: token }, function (err, files) {
if (err) { if (err) {
Logger.tag('node', 'delete').error('Could not find node file: ' + file, error); Logger.tag('node', 'delete').error('Could not find node file: ' + files, err);
return callback({data: 'Could not delete node.', type: ErrorTypes.internalError}); return callback({data: 'Could not delete node.', type: ErrorTypes.internalError});
} }
@ -218,7 +218,7 @@ angular.module('ffffng')
fs.unlinkSync(files[0]); fs.unlinkSync(files[0]);
} }
catch (error) { catch (error) {
Logger.tag('node', 'delete').error('Could not delete node file: ' + file, error); Logger.tag('node', 'delete').error('Could not delete node file: ' + files, error);
return callback({data: 'Could not delete node.', type: ErrorTypes.internalError}); return callback({data: 'Could not delete node.', type: ErrorTypes.internalError});
} }
@ -256,8 +256,8 @@ angular.module('ffffng')
_.each(entries, function (value, key) { _.each(entries, function (value, key) {
if (key === 'mac') { if (key === 'mac') {
node['mac'] = value; node.mac = value;
node['mapId'] = _.toLower(value).replace(/:/g, '') node.mapId = _.toLower(value).replace(/:/g, '');
} else if (key === 'monitoring') { } else if (key === 'monitoring') {
var active = value === 'aktiv'; var active = value === 'aktiv';
var pending = value === 'pending'; var pending = value === 'pending';
@ -320,7 +320,7 @@ angular.module('ffffng')
}, },
function (err) { function (err) {
if (err) { if (err) {
Logger.tag('monitoring', 'confirmation').error('Could not enqueue confirmation mail.', error); Logger.tag('monitoring', 'confirmation').error('Could not enqueue confirmation mail.', err);
return callback({data: 'Internal error.', type: ErrorTypes.internalError}); return callback({data: 'Internal error.', type: ErrorTypes.internalError});
} }
@ -377,7 +377,7 @@ angular.module('ffffng')
} else { } else {
// monitoring is still enabled // monitoring is still enabled
if (currentNode.email != node.email) { if (currentNode.email !== node.email) {
// new email so we need a new token and a reconfirmation // new email so we need a new token and a reconfirmation
monitoringConfirmed = false; monitoringConfirmed = false;
monitoringToken = generateToken(); monitoringToken = generateToken();
@ -528,7 +528,7 @@ angular.module('ffffng')
}); });
callback(null, nodeStatistics); callback(null, nodeStatistics);
}) });
} }
}; };
}); });

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('ffffng').factory('Resources', function (_, Constraints, Validator, ErrorTypes) { angular.module('ffffng').factory('Resources', function (_, Constraints, Validator, ErrorTypes, Logger) {
function respond(res, httpCode, data, type) { function respond(res, httpCode, data, type) {
switch (type) { switch (type) {
case 'html': case 'html':
@ -24,7 +24,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
return { return {
query: 'ORDER BY ' + sortField + ' ' + (restParams._sortDir === 'ASC' ? 'ASC' : 'DESC'), query: 'ORDER BY ' + sortField + ' ' + (restParams._sortDir === 'ASC' ? 'ASC' : 'DESC'),
params: [] params: []
} };
} }
function limitOffsetClause(restParams) { function limitOffsetClause(restParams) {
@ -41,7 +41,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
return str return str
.replace(/\\/g, '\\\\') .replace(/\\/g, '\\\\')
.replace(/%/g, '\\%') .replace(/%/g, '\\%')
.replace(/_/g, '\\_') .replace(/_/g, '\\_');
} }
function filterCondition(restParams, filterFields) { function filterCondition(restParams, filterFields) {
@ -49,7 +49,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
return { return {
query: '1 = 1', query: '1 = 1',
params: [] params: []
} };
} }
var query = _.join( var query = _.join(
@ -74,9 +74,8 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
var values = {}; var values = {};
_.each(_.keys(constraints), function (key) { _.each(_.keys(constraints), function (key) {
var value = data[key]; var value = data[key];
values[key] = _.isUndefined(value) && !_.isUndefined(constraints[key].default) values[key] =
? constraints[key].default _.isUndefined(value) && !_.isUndefined(constraints[key].default) ? constraints[key].default : value;
: value;
}); });
return values; return values;
} }
@ -207,7 +206,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
return { return {
query: filter.query + ' ' + orderBy.query + ' ' + limitOffset.query, query: filter.query + ' ' + orderBy.query + ' ' + limitOffset.query,
params: _.concat(filter.params, orderBy.params, limitOffset.params) params: _.concat(filter.params, orderBy.params, limitOffset.params)
} };
}, },
success: function (res, data) { success: function (res, data) {