From b5dead51c507e40feda943435abd76266b171812 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 3 Apr 2015 16:45:45 +0200 Subject: [PATCH] Notifications --- bower.json | 20 +++++++++++--------- public/css/style.css | 4 ++++ public/js/app.js | 2 +- public/js/controllers/MembreCtrl.js | 15 +++++++-------- public/js/services/NotifyServ.js | 30 ++++++++++++++++++++++++++++++ public/js/services/SessionServ.js | 26 +++++++++++++++++--------- public/views/index.html | 5 ++++- 7 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 public/js/services/NotifyServ.js diff --git a/bower.json b/bower.json index d65a014..efa5419 100644 --- a/bower.json +++ b/bower.json @@ -1,11 +1,13 @@ { - "name": "ci-site", - "version": "0.0.1", - "dependencies": { - "font-awesome": "latest", - "angular": "latest", - "angular-route": "latest", - "bootswatch-dist": "3.3.2-cerulean", - "jsencrypt": "~2.1.0" - } + "name": "ci-site", + "version": "0.0.1", + "dependencies": { + "font-awesome": "latest", + "angular": "latest", + "angular-route": "latest", + "bootswatch-dist": "3.3.2-cerulean", + "jsencrypt": "~2.1.0", + "animate.css": "~3.2.6", + "remarkable-bootstrap-notify": "~3.0.0" + } } diff --git a/public/css/style.css b/public/css/style.css index 171965b..ced8790 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -9,3 +9,7 @@ body { #membre-list { width: 90%; } + +[data-notify="progressbar"] { + display: none; +} diff --git a/public/js/app.js b/public/js/app.js index 8770dbe..626c986 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1 +1 @@ -angular.module('ciApp', ['ngRoute', 'appRoutes', 'EncryptServ', 'SessionsServ', 'SessionsCtrl', 'ConnectCtrl', 'MembreCtrl']); +angular.module('ciApp', ['ngRoute', 'appRoutes', 'NotifyServ', 'EncryptServ', 'SessionsServ', 'SessionsCtrl', 'ConnectCtrl', 'MembreCtrl']); diff --git a/public/js/controllers/MembreCtrl.js b/public/js/controllers/MembreCtrl.js index d0f5bee..ef31bc0 100644 --- a/public/js/controllers/MembreCtrl.js +++ b/public/js/controllers/MembreCtrl.js @@ -1,5 +1,5 @@ -angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'SessionServ', - function ($scope, $http, SessionServ) { +angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'SessionServ', 'NotifyServ', + function ($scope, $http, SessionServ, NotifyServ) { $scope.formData = {}; $scope.session = SessionServ.cur; @@ -10,21 +10,20 @@ angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'S $http.get('/api/membres') .success(function (data) { $scope.membres = data; - console.log(data); }) .error(function (data) { - console.log('Error: ' + data); + NotifyServ.error("Impossible d'obtenir la liste des membres", data); }); $scope.createMembre = function () { - console.log('Adding', $scope.formData); $http.post('/api/membres', $scope.formData) .success(function (data) { $scope.formData = {}; $scope.membres = data; + NotifyServ.success("Membre ajouté"); }) .error(function (data) { - console.log('Error: ' + data); + NotifyServ.error("Impossible d'ajouter le membre", data); }); }; @@ -32,10 +31,10 @@ angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'S $http.delete('/api/membres/' + id) .success(function (data) { $scope.membres = data; - console.log(data); + NotifyServ.success("Membre supprimé."); }) .error(function (data) { - console.log('Error: ' + data); + NotifyServ.error("Impossible de supprimer le membre", data); }); }; diff --git a/public/js/services/NotifyServ.js b/public/js/services/NotifyServ.js new file mode 100644 index 0000000..5c3f55e --- /dev/null +++ b/public/js/services/NotifyServ.js @@ -0,0 +1,30 @@ +angular.module('NotifyServ', []).service('NotifyServ', [ + function () { + return { + notify: function (type, message) { + $.notify({ + message: message + }, { + type: type, + animate: { + enter: 'animated bounceInDown', + exit: 'animated bounceOutUp' + } + }); + }, + success: function (message) { + this.notify('success', message); + }, + info: function (message) { + this.notify('info', message); + }, + warn: function (message) { + this.notify('warning', message); + }, + error: function (context, error) { + this.notify('danger', context); + console.error(context, error); + } + }; + } +]); diff --git a/public/js/services/SessionServ.js b/public/js/services/SessionServ.js index 434aa5b..25eb0d1 100644 --- a/public/js/services/SessionServ.js +++ b/public/js/services/SessionServ.js @@ -1,5 +1,5 @@ -angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ', - function ($http, EncryptServ) { +angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ', 'NotifyServ', + function ($http, EncryptServ, NotifyServ) { a = { cur: false, changeHandlers: [], @@ -12,9 +12,10 @@ angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ } }, updateSessionInfos: function (data) { - console.log("Connection:", data); if (typeof data === 'object') { this.cur = data; + } else if (data === 'expired') { + NotifyServ.warn("Votre session a expiré"); } else { this.cur = false; } @@ -43,19 +44,26 @@ angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ EncryptServ.encrypt(data, function (dataCrypt) { $http.post('/api/session', [dataCrypt]).success(function (body) { _this.updateSessionInfos(body); - if (cb) { - if (this.logged) { + if (_this.cur) { + NotifyServ.info("Connecté en tant que " + _this.cur.nom + ""); + if (cb) cb(null); - } else { - cb(body); + } else { + if (body === 'invalid') { + NotifyServ.warn("Identifiants invalides"); } + if (cb) + cb(body); } }); }); }, disconnect: function () { - this.updateSessionInfos(false); - $http.delete('/api/session'); + _this = this; + $http.delete('/api/session').success(function () { + _this.updateSessionInfos(false); + NotifyServ.info("Déconnecté"); + }); } }; a.get(); diff --git a/public/views/index.html b/public/views/index.html index 17cf8a6..56b30dc 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -8,14 +8,17 @@ Club Informatique de Polytech Lille + - + + + -- libgit2 0.21.2