From 3d6fb5feecc72eb3dbadc077bf294dfd5d19f4c3 Mon Sep 17 00:00:00 2001 From: baldo Date: Sat, 6 May 2017 17:31:34 +0200 Subject: [PATCH] Fixed or disabled warnings --- app/scripts/controllers/confirmMonitoringCtrl.js | 2 +- app/scripts/controllers/disableMonitoringCtrl.js | 2 +- app/scripts/directives/footer.js | 2 +- app/scripts/directives/nodeForm.js | 8 ++++---- server/app.js | 2 +- server/config.js | 2 ++ server/db/database.js | 16 ++++++++-------- server/services/mailTemplateService.js | 6 ++++-- server/services/monitoringService.js | 14 +++++++++----- server/services/nodeService.js | 14 +++++++------- server/utils/resources.js | 15 +++++++-------- 11 files changed, 45 insertions(+), 38 deletions(-) diff --git a/app/scripts/controllers/confirmMonitoringCtrl.js b/app/scripts/controllers/confirmMonitoringCtrl.js index 86d2d7b..283f699 100644 --- a/app/scripts/controllers/confirmMonitoringCtrl.js +++ b/app/scripts/controllers/confirmMonitoringCtrl.js @@ -12,7 +12,7 @@ angular.module('ffffng') $scope.monitoringInfo = {}; $scope.monitoringStatus = 'loading'; - MonitoringService.confirm($routeParams['token']) + MonitoringService.confirm($routeParams.token) .then( function (response) { // success diff --git a/app/scripts/controllers/disableMonitoringCtrl.js b/app/scripts/controllers/disableMonitoringCtrl.js index c39ee28..3a9a44b 100644 --- a/app/scripts/controllers/disableMonitoringCtrl.js +++ b/app/scripts/controllers/disableMonitoringCtrl.js @@ -12,7 +12,7 @@ angular.module('ffffng') $scope.monitoringInfo = {}; $scope.monitoringStatus = 'loading'; - MonitoringService.disable($routeParams['token']) + MonitoringService.disable($routeParams.token) .then( function (response) { // success diff --git a/app/scripts/directives/footer.js b/app/scripts/directives/footer.js index 6138201..b2875da 100644 --- a/app/scripts/directives/footer.js +++ b/app/scripts/directives/footer.js @@ -5,7 +5,7 @@ angular.module('ffffng') var ctrl = function ($scope) { $scope.version = '?'; $http.get('/api/version') - .then(function (result) { $scope.version = result.data.version; }) + .then(function (result) { $scope.version = result.data.version; }); }; return { diff --git a/app/scripts/directives/nodeForm.js b/app/scripts/directives/nodeForm.js index 30d587b..291a551 100644 --- a/app/scripts/directives/nodeForm.js +++ b/app/scripts/directives/nodeForm.js @@ -120,8 +120,8 @@ angular.module('ffffng') }; $scope.monitoringInitialConfirmationRequired = function () { - return $scope.node.monitoring - && ($scope.action === 'create' || $scope.node.email !== initialEmail || !initialMonitoring); + return $scope.node.monitoring && + ($scope.action === 'create' || $scope.node.email !== initialEmail || !initialMonitoring); }; $scope.monitoringConfirmationPending = function () { @@ -137,8 +137,8 @@ angular.module('ffffng') var doSubmit = function (node) { if ($scope.nodeForm.$invalid) { var firstInvalid = _.filter($element.find('form').find('input'), function (input) { - return (input.type === 'text' || input.type === 'email') - && $scope.nodeForm[input.name].$invalid; + return (input.type === 'text' || input.type === 'email') && + $scope.nodeForm[input.name].$invalid; })[0]; if (firstInvalid) { $window.scrollTo(0, $window.pageYOffset + firstInvalid.getBoundingClientRect().top - 100); diff --git a/server/app.js b/server/app.js index 1fac098..c58dfa3 100644 --- a/server/app.js +++ b/server/app.js @@ -11,7 +11,7 @@ angular.module('ffffng').factory('app', function (fs, config, _) { // urls beneath /internal are protected var internalAuth = auth.basic( { - realm: "Knotenformular - Intern" + realm: 'Knotenformular - Intern' }, function (username, password, callback) { callback( diff --git a/server/config.js b/server/config.js index a3388d1..9676d88 100644 --- a/server/config.js +++ b/server/config.js @@ -126,6 +126,8 @@ if (fs.existsSync(configJSONFile)) { process.exit(1); } +var _ = require('lodash'); + function stripTrailingSlash(obj, field) { var url = obj[field]; if (_.isString(url) && _.last(url) === '/') { diff --git a/server/db/database.js b/server/db/database.js index f40f1e7..571f576 100644 --- a/server/db/database.js +++ b/server/db/database.js @@ -29,10 +29,10 @@ function applyPatch(db, file, callback) { return callback(null); } - var sql = 'BEGIN TRANSACTION;\n' - + contents.toString() + '\n' - + 'INSERT INTO schema_version (version) VALUES (\'' + version + '\');\n' - + 'END TRANSACTION;'; + var sql = 'BEGIN TRANSACTION;\n' + + contents.toString() + '\n' + + 'INSERT INTO schema_version (version) VALUES (\'' + version + '\');\n' + + 'END TRANSACTION;'; db.exec(sql, function (err) { if (err) { @@ -50,10 +50,10 @@ function applyPatch(db, file, callback) { function applyMigrations(db, callback) { Logger.tag('database', 'migration').info('Migrating database...'); - var sql = 'BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS schema_version (\n' - + ' version VARCHAR(255) PRIMARY KEY ASC,\n' - + ' applied_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL\n' - + '); END TRANSACTION;'; + var sql = 'BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS schema_version (\n' + + ' version VARCHAR(255) PRIMARY KEY ASC,\n' + + ' applied_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL\n' + + '); END TRANSACTION;'; db.exec(sql, function (err) { if (err) { return callback(err); diff --git a/server/services/mailTemplateService.js b/server/services/mailTemplateService.js index e3b3192..cdecc1f 100644 --- a/server/services/mailTemplateService.js +++ b/server/services/mailTemplateService.js @@ -21,7 +21,9 @@ angular.module('ffffng') return _.template(fs.readFileSync(snippetFile).toString())(deepExtend( {}, + // jshint -W040 this, // parent data + // jshint +W040 data, templateFunctions )); @@ -30,7 +32,7 @@ angular.module('ffffng') function snippet(name) { return function (data) { return renderSnippet.bind(this)(name, data); - } + }; } function renderLink(href, text) { @@ -76,7 +78,7 @@ angular.module('ffffng') }, render: function (mailOptions, callback) { - var templatePathPrefix = templateBasePath + '/' + mailOptions.email + var templatePathPrefix = templateBasePath + '/' + mailOptions.email; async.parallel({ subject: _.partial(fs.readFile, templatePathPrefix + '.subject.txt'), diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 8a032e1..438d221 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -65,7 +65,9 @@ angular.module('ffffng') .tag('monitoring', 'information-retrieval') .debug('Node is known in monitoring: %s', nodeData.mac); + // jshint -W106 if (!moment(row.import_timestamp).isBefore(nodeData.importTimestamp)) { + // jshint +W106 Logger .tag('monitoring', 'information-retrieval') .debug('No new data for node, skipping: %s', nodeData.mac); @@ -108,7 +110,9 @@ angular.module('ffffng') nodeDataForStoring = { mac: node.mac, state: 'OFFLINE', + // jshint -W106 lastSeen: _.isUndefined(row) ? moment() : moment.unix(row.last_seen), + // jshint +W106 importTimestamp: moment() }; } else { @@ -129,7 +133,7 @@ angular.module('ffffng') Logger.tag('monitoring', 'information-retrieval').debug('Parsing nodes.json...'); function parseTimestamp(timestamp) { - if (!_.isString(json.timestamp)) { + if (!_.isString(timestamp)) { return moment.invalid(); } return moment.utc(timestamp); @@ -277,7 +281,9 @@ angular.module('ffffng') mailType, { node: node, + // jshint -W106 lastSeen: nodeState.last_seen, + // jshint +W106 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 */ var previousType = - mailNumber === 1 - ? 'monitoring-online-again' - : ('monitoring-offline-' + (mailNumber - 1)); + mailNumber === 1 ? 'monitoring-online-again' : ('monitoring-offline-' + (mailNumber - 1)); // 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' : ''; @@ -773,5 +777,5 @@ angular.module('ffffng') } ); } - } + }; }); diff --git a/server/services/nodeService.js b/server/services/nodeService.js index 21263c0..a2b2479 100644 --- a/server/services/nodeService.js +++ b/server/services/nodeService.js @@ -206,7 +206,7 @@ angular.module('ffffng') function deleteNodeFile(token, callback) { findNodeFiles({ token: token }, function (err, files) { 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}); } @@ -218,7 +218,7 @@ angular.module('ffffng') fs.unlinkSync(files[0]); } 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}); } @@ -256,8 +256,8 @@ angular.module('ffffng') _.each(entries, function (value, key) { if (key === 'mac') { - node['mac'] = value; - node['mapId'] = _.toLower(value).replace(/:/g, '') + node.mac = value; + node.mapId = _.toLower(value).replace(/:/g, ''); } else if (key === 'monitoring') { var active = value === 'aktiv'; var pending = value === 'pending'; @@ -320,7 +320,7 @@ angular.module('ffffng') }, function (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}); } @@ -377,7 +377,7 @@ angular.module('ffffng') } else { // 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 monitoringConfirmed = false; monitoringToken = generateToken(); @@ -528,7 +528,7 @@ angular.module('ffffng') }); callback(null, nodeStatistics); - }) + }); } }; }); diff --git a/server/utils/resources.js b/server/utils/resources.js index 02fe5e4..be125e9 100644 --- a/server/utils/resources.js +++ b/server/utils/resources.js @@ -1,6 +1,6 @@ '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) { switch (type) { case 'html': @@ -24,7 +24,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato return { query: 'ORDER BY ' + sortField + ' ' + (restParams._sortDir === 'ASC' ? 'ASC' : 'DESC'), params: [] - } + }; } function limitOffsetClause(restParams) { @@ -41,7 +41,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato return str .replace(/\\/g, '\\\\') .replace(/%/g, '\\%') - .replace(/_/g, '\\_') + .replace(/_/g, '\\_'); } function filterCondition(restParams, filterFields) { @@ -49,7 +49,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato return { query: '1 = 1', params: [] - } + }; } var query = _.join( @@ -74,9 +74,8 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato var values = {}; _.each(_.keys(constraints), function (key) { var value = data[key]; - values[key] = _.isUndefined(value) && !_.isUndefined(constraints[key].default) - ? constraints[key].default - : value; + values[key] = + _.isUndefined(value) && !_.isUndefined(constraints[key].default) ? constraints[key].default : value; }); return values; } @@ -207,7 +206,7 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato return { query: filter.query + ' ' + orderBy.query + ' ' + limitOffset.query, params: _.concat(filter.params, orderBy.params, limitOffset.params) - } + }; }, success: function (res, data) {