Commit b5dead51c507e40feda943435abd76266b171812

Authored by Geoffrey PREUD'HOMME
1 parent 338930e1

Notifications

bower.json
1 1 {
2   - "name": "ci-site",
3   - "version": "0.0.1",
4   - "dependencies": {
5   - "font-awesome": "latest",
6   - "angular": "latest",
7   - "angular-route": "latest",
8   - "bootswatch-dist": "3.3.2-cerulean",
9   - "jsencrypt": "~2.1.0"
10   - }
  2 + "name": "ci-site",
  3 + "version": "0.0.1",
  4 + "dependencies": {
  5 + "font-awesome": "latest",
  6 + "angular": "latest",
  7 + "angular-route": "latest",
  8 + "bootswatch-dist": "3.3.2-cerulean",
  9 + "jsencrypt": "~2.1.0",
  10 + "animate.css": "~3.2.6",
  11 + "remarkable-bootstrap-notify": "~3.0.0"
  12 + }
11 13 }
... ...
public/css/style.css
... ... @@ -9,3 +9,7 @@ body {
9 9 #membre-list {
10 10 width: 90%;
11 11 }
  12 +
  13 +[data-notify="progressbar"] {
  14 + display: none;
  15 +}
... ...
public/js/app.js
1   -angular.module('ciApp', ['ngRoute', 'appRoutes', 'EncryptServ', 'SessionsServ', 'SessionsCtrl', 'ConnectCtrl', 'MembreCtrl']);
  1 +angular.module('ciApp', ['ngRoute', 'appRoutes', 'NotifyServ', 'EncryptServ', 'SessionsServ', 'SessionsCtrl', 'ConnectCtrl', 'MembreCtrl']);
... ...
public/js/controllers/MembreCtrl.js
1   -angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'SessionServ',
2   - function ($scope, $http, SessionServ) {
  1 +angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'SessionServ', 'NotifyServ',
  2 + function ($scope, $http, SessionServ, NotifyServ) {
3 3 $scope.formData = {};
4 4  
5 5 $scope.session = SessionServ.cur;
... ... @@ -10,21 +10,20 @@ angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'S
10 10 $http.get('/api/membres')
11 11 .success(function (data) {
12 12 $scope.membres = data;
13   - console.log(data);
14 13 })
15 14 .error(function (data) {
16   - console.log('Error: ' + data);
  15 + NotifyServ.error("Impossible d'obtenir la liste des membres", data);
17 16 });
18 17  
19 18 $scope.createMembre = function () {
20   - console.log('Adding', $scope.formData);
21 19 $http.post('/api/membres', $scope.formData)
22 20 .success(function (data) {
23 21 $scope.formData = {};
24 22 $scope.membres = data;
  23 + NotifyServ.success("Membre ajouté");
25 24 })
26 25 .error(function (data) {
27   - console.log('Error: ' + data);
  26 + NotifyServ.error("Impossible d'ajouter le membre", data);
28 27 });
29 28 };
30 29  
... ... @@ -32,10 +31,10 @@ angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'S
32 31 $http.delete('/api/membres/' + id)
33 32 .success(function (data) {
34 33 $scope.membres = data;
35   - console.log(data);
  34 + NotifyServ.success("Membre supprimé.");
36 35 })
37 36 .error(function (data) {
38   - console.log('Error: ' + data);
  37 + NotifyServ.error("Impossible de supprimer le membre", data);
39 38 });
40 39 };
41 40  
... ...
public/js/services/NotifyServ.js 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +angular.module('NotifyServ', []).service('NotifyServ', [
  2 + function () {
  3 + return {
  4 + notify: function (type, message) {
  5 + $.notify({
  6 + message: message
  7 + }, {
  8 + type: type,
  9 + animate: {
  10 + enter: 'animated bounceInDown',
  11 + exit: 'animated bounceOutUp'
  12 + }
  13 + });
  14 + },
  15 + success: function (message) {
  16 + this.notify('success', message);
  17 + },
  18 + info: function (message) {
  19 + this.notify('info', message);
  20 + },
  21 + warn: function (message) {
  22 + this.notify('warning', message);
  23 + },
  24 + error: function (context, error) {
  25 + this.notify('danger', context);
  26 + console.error(context, error);
  27 + }
  28 + };
  29 + }
  30 +]);
... ...
public/js/services/SessionServ.js
1   -angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ',
2   - function ($http, EncryptServ) {
  1 +angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ', 'NotifyServ',
  2 + function ($http, EncryptServ, NotifyServ) {
3 3 a = {
4 4 cur: false,
5 5 changeHandlers: [],
... ... @@ -12,9 +12,10 @@ angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ
12 12 }
13 13 },
14 14 updateSessionInfos: function (data) {
15   - console.log("Connection:", data);
16 15 if (typeof data === 'object') {
17 16 this.cur = data;
  17 + } else if (data === 'expired') {
  18 + NotifyServ.warn("Votre session a expiré");
18 19 } else {
19 20 this.cur = false;
20 21 }
... ... @@ -43,19 +44,26 @@ angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ
43 44 EncryptServ.encrypt(data, function (dataCrypt) {
44 45 $http.post('/api/session', [dataCrypt]).success(function (body) {
45 46 _this.updateSessionInfos(body);
46   - if (cb) {
47   - if (this.logged) {
  47 + if (_this.cur) {
  48 + NotifyServ.info("Connecté en tant que <strong>" + _this.cur.nom + "</strong>");
  49 + if (cb)
48 50 cb(null);
49   - } else {
50   - cb(body);
  51 + } else {
  52 + if (body === 'invalid') {
  53 + NotifyServ.warn("Identifiants invalides");
51 54 }
  55 + if (cb)
  56 + cb(body);
52 57 }
53 58 });
54 59 });
55 60 },
56 61 disconnect: function () {
57   - this.updateSessionInfos(false);
58   - $http.delete('/api/session');
  62 + _this = this;
  63 + $http.delete('/api/session').success(function () {
  64 + _this.updateSessionInfos(false);
  65 + NotifyServ.info("Déconnecté");
  66 + });
59 67 }
60 68 };
61 69 a.get();
... ...
public/views/index.html
... ... @@ -8,14 +8,17 @@
8 8 <title>Club Informatique de Polytech Lille</title>
9 9 <link rel="stylesheet" href="libs/bootswatch-dist/css/bootstrap.min.css">
10 10 <link rel="stylesheet" href="css/style.css">
  11 + <link rel="stylesheet" href="libs/animate.css/animate.min.css">
11 12 <script src="libs/jquery/dist/jquery.min.js"></script>
12 13 <script src="libs/angular/angular.min.js"></script>
13 14 <script src="libs/angular-route/angular-route.min.js"></script>
14 15 <script src="libs/angular-bootstrap/ui-bootstrap.min.js"></script>
15 16 <script src="libs/jsencrypt/bin/jsencrypt.min.js"></script>
16   - <script src="js/controllers/MembreCtrl.js"></script>
  17 + <script src="libs/remarkable-bootstrap-notify/bootstrap-notify.min.js"></script>
  18 + <script src="js/services/NotifyServ.js"></script>
17 19 <script src="js/services/EncryptServ.js"></script>
18 20 <script src="js/services/SessionServ.js"></script>
  21 + <script src="js/controllers/MembreCtrl.js"></script>
19 22 <script src="js/controllers/SessionCtrl.js"></script>
20 23 <script src="js/controllers/ConnectCtrl.js"></script>
21 24 <script src="js/appRoutes.js"></script>
... ...