From 5a5c70cfb1fe981446918c261c51c110b4b5c12a Mon Sep 17 00:00:00 2001 From: baldo Date: Wed, 18 May 2016 23:15:43 +0200 Subject: [PATCH] Link to disable monitoring --- app/index.html | 1 + app/scripts/app.js | 5 ++ .../controllers/disableMonitoringCtrl.js | 35 +++++++++ app/scripts/services/monitoringService.js | 7 ++ app/styles/main.scss | 1 + app/styles/views/_disableMonitoring.scss | 55 ++++++++++++++ app/views/disableMonitoring.html | 75 +++++++++++++++++++ server/resources/monitoringResource.js | 27 +++++++ server/router.js | 1 + server/services/monitoringService.js | 23 ++++++ 10 files changed, 230 insertions(+) create mode 100644 app/scripts/controllers/disableMonitoringCtrl.js create mode 100644 app/styles/views/_disableMonitoring.scss create mode 100644 app/views/disableMonitoring.html diff --git a/app/index.html b/app/index.html index 814bbae..f425b8f 100644 --- a/app/index.html +++ b/app/index.html @@ -51,6 +51,7 @@ + diff --git a/app/scripts/app.js b/app/scripts/app.js index db5e64b..74758b7 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -36,6 +36,11 @@ angular.module('ffffng', [ controller: 'ConfirmMonitoringCtrl', title: 'Versand von Status-E-Mails bestätigen' }) + .when('/monitoring/disable', { + templateUrl: 'views/disableMonitoring.html', + controller: 'DisableMonitoringCtrl', + title: 'Versand von Status-E-Mails deaktivieren' + }) .otherwise({ redirectTo: '/' }); diff --git a/app/scripts/controllers/disableMonitoringCtrl.js b/app/scripts/controllers/disableMonitoringCtrl.js new file mode 100644 index 0000000..b6e205f --- /dev/null +++ b/app/scripts/controllers/disableMonitoringCtrl.js @@ -0,0 +1,35 @@ +'use strict'; + +angular.module('ffffng') +.controller('DisableMonitoringCtrl', function ($scope, Navigator, MonitoringService, $routeParams, config) { + if (!config.monitoring.enabled) { + Navigator.home(); + return; + } + + $scope.config = config; + + $scope.monitoringInfo = {}; + $scope.monitoringStatus = 'loading'; + + MonitoringService.disable($routeParams['mac'], $routeParams['token']) + .then( + function (response) { + // success + $scope.monitoringInfo = response.data; + $scope.monitoringStatus = 'disabled'; + }, + function () { + // error + $scope.monitoringStatus = 'error'; + } + ); + + $scope.goHome = function () { + Navigator.home(); + }; + + $scope.goToUpdate = function () { + Navigator.updateNode(); + }; +}); diff --git a/app/scripts/services/monitoringService.js b/app/scripts/services/monitoringService.js index eea79ed..302f3e1 100644 --- a/app/scripts/services/monitoringService.js +++ b/app/scripts/services/monitoringService.js @@ -8,6 +8,13 @@ angular.module('ffffng') return $q.reject({}); } return $http.put('/api/monitoring/confirm/' + mac + '?token=' + token); + }, + + 'disable': function (mac, token) { + if (!mac || !token) { + return $q.reject({}); + } + return $http.put('/api/monitoring/disable/' + mac + '?token=' + token); } }; }); diff --git a/app/styles/main.scss b/app/styles/main.scss index 57cbb53..9028f64 100644 --- a/app/styles/main.scss +++ b/app/styles/main.scss @@ -12,6 +12,7 @@ @import "views/_updateNodeForm"; @import "views/_deleteNodeForm"; @import "views/_confirmMonitoring"; +@import "views/_disableMonitoring"; @import "views/directives/_help"; @import "views/directives/_nodeForm"; @import "views/directives/_nodeSaved"; diff --git a/app/styles/views/_disableMonitoring.scss b/app/styles/views/_disableMonitoring.scss new file mode 100644 index 0000000..08a25c9 --- /dev/null +++ b/app/styles/views/_disableMonitoring.scss @@ -0,0 +1,55 @@ +.disable-monitoring { + @extend .jumbotron, .container; + + .actions { + text-align: center; + margin-top: 30px; + } + + .back-button { + @extend .btn, .btn-lg, .btn-info; + } + + .summary { + @extend .well; + + display: table; + margin: { + left: auto; + right: auto; + top: 30px; + bottom: 30px; + }; + + border: 3px dashed $gray; + + .icon { + @extend .fa, .fa-heartbeat; + + display: table-cell; + + color: $gray-light; + font-size: 64px; + } + + .node { + @extend .dl-horizontal; + + display: table-cell; + + overflow: hidden; + + font-family: monospace; + font-size: 24px; + + dt { + width: 100px; + } + + dd { + text-overflow: ellipsis; + margin-left: 120px; + } + } + } +} diff --git a/app/views/disableMonitoring.html b/app/views/disableMonitoring.html new file mode 100644 index 0000000..6336b9f --- /dev/null +++ b/app/views/disableMonitoring.html @@ -0,0 +1,75 @@ +
+

Einen Moment bitte...

+ +
+

Der Versand von Status-E-Mails ist nun deaktiviert!

+ +

+ Für diesen Knoten wirst Du in Zukunft keine weiteren Status-E-Mails mehr erhalten. Bitte habe Verständnis + dafür, dass das An- und Abschalten des Versands für jeden Deiner Knoten einzeln erfolgt. +

+ +
+ +
+
Name
+
{{monitoringInfo.hostname}}
+ +
MAC
+
{{monitoringInfo.mac}}
+ +
+
{{monitoringInfo.email}}
+
+
+ +

+ + Möchtest Du wieder Status-E-Mails zu Deinem Knoten erhalten, so kannst Du den Versand + jederzeit unter „Knotendaten ändern“ reaktivieren. + Gib dazu dort Dein Token ein und scrolle dann ganz nach unten. + +

+ +

+ Bei Fragen wende Dich gerne an + {{ config.community.contactEmail }}. +

+ +
+ +
+
+ +
+

Die Deaktivierung des Versands von Status-E-Mails ist fehlgeschlagen

+ + + +

+ Um zu prüfen, ob der Versand bereits deaktiviert ist, gehe bitte auf + „Knotendaten ändern“, gib dort Dein Token ein + und scrolle dann ganz nach unten. Dort kannst Du auch den Versand manuell an- und abschalten. +

+ +

+ + Sollte das Problem so nicht zu beheben sein, wende Dich gerne an + {{ config.community.contactEmail }}. + +

+ +
+ +
+
+
diff --git a/server/resources/monitoringResource.js b/server/resources/monitoringResource.js index 5f74599..5a90c24 100644 --- a/server/resources/monitoringResource.js +++ b/server/resources/monitoringResource.js @@ -34,9 +34,36 @@ angular.module('ffffng').factory('MonitoringResource', function ( hostname: node.hostname, mac: node.mac, email: node.email, + monitoring: node.monitoring, monitoringConfirmed: node.monitoringConfirmed }); }); + }, + + disable: function (req, res) { + var data = Resources.getData(req); + + var mac = Strings.normalizeMac(data.mac); + if (!isValidMac(mac)) { + return Resources.error(res, {data: 'Invalid MAC.', type: ErrorTypes.badRequest}); + } + + var token = Strings.normalizeString(data.token); + if (!isValidToken(token)) { + return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest}); + } + + return MonitoringService.disable(mac, token, function (err, node) { + if (err) { + return Resources.error(res, err); + } + return Resources.success(res, { + hostname: node.hostname, + mac: node.mac, + email: node.email, + monitoring: node.monitoring + }); + }); } }; }); diff --git a/server/router.js b/server/router.js index cea9a3e..a3a05e8 100644 --- a/server/router.js +++ b/server/router.js @@ -9,6 +9,7 @@ angular.module('ffffng').factory('Router', function (app, NodeResource, Monitori app.get('/api/node/:token', NodeResource.get); app.put('/api/monitoring/confirm/:mac', MonitoringResource.confirm); + app.put('/api/monitoring/disable/:mac', MonitoringResource.disable); } }; }); diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 77f90b9..9221ca4 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -18,6 +18,29 @@ angular.module('ffffng') } node.monitoringConfirmed = true; + NodeService.internalUpdateNode(node.token, node, nodeSecrets, function (err, token, node) { + if (err) { + return callback(err); + } + callback(null, node); + }); + }); + }, + + disable: function (mac, token, callback) { + NodeService.getNodeDataByMac(mac, function (err, node, nodeSecrets) { + if (err) { + return callback(err); + } + + if (!node.monitoring || !nodeSecrets.monitoringToken || nodeSecrets.monitoringToken !== token) { + return callback({data: 'Invalid token.', type: ErrorTypes.badRequest}); + } + + node.monitoring = false; + node.monitoringConfirmed = false; + nodeSecrets.monitoringToken = ''; + NodeService.internalUpdateNode(node.token, node, nodeSecrets, function (err, token, node) { if (err) { return callback(err);