Commit 12162cc12f0c87607c18a7e9758b7bed90c6785b

Authored by Geoffrey PREUD'HOMME
1 parent 55a10789

Liste de conversations

app/models/ConvModl.js 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +var mongoose = require('mongoose');
  2 +
  3 +module.exports = mongoose.model('Conv', {
  4 + titre: {
  5 + type: String,
  6 + default: "Conversation"
  7 + },
  8 + started: {
  9 + type: Date,
  10 + default: Date.now
  11 + }
  12 +});
app/routes/ApiRtes.js
1 var MembresServ = require('../services/MembresServ'); 1 var MembresServ = require('../services/MembresServ');
2 var SessionsServ = require('../services/SessionsServ'); 2 var SessionsServ = require('../services/SessionsServ');
3 var DecryptServ = require('../services/DecryptServ'); 3 var DecryptServ = require('../services/DecryptServ');
  4 +var ConvsServ = require('../services/ConvsServ');
4 var express = require('express'); 5 var express = require('express');
5 6
6 var api = express(); 7 var api = express();
@@ -92,4 +93,37 @@ api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membr @@ -92,4 +93,37 @@ api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membr
92 }); 93 });
93 }); 94 });
94 95
  96 +
  97 +// Conversations
  98 +api.get('/convs', function (req, res) { // Liste des convs
  99 + ConvsServ.list(function (err, convs) {
  100 + if (err)
  101 + res.send(err);
  102 + else
  103 + res.json(convs);
  104 + });
  105 +});
  106 +
  107 +api.post('/convs', function (req, res) { // Ajout d'un conv
  108 + ifPermission(req, res, 'canAddConv', function () {
  109 + ConvsServ.add(req.body, function (err, conv) {
  110 + if (err)
  111 + res.send(err);
  112 + else
  113 + res.json(conv);
  114 + });
  115 + });
  116 +});
  117 +
  118 +api.delete('/convs/:conv_id', function (req, res) { // Supression d'un conv
  119 + ifPermission(req, res, 'canDelConv', function () {
  120 + ConvsServ.remove(req.params.conv_id, function (err, conv) {
  121 + if (err)
  122 + res.send(err);
  123 + else
  124 + res.json(null);
  125 + });
  126 + });
  127 +});
  128 +
95 module.exports = api; 129 module.exports = api;
app/services/ConvsServ.js 0 → 100644
@@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
  1 +var ConvModl = require('../models/ConvModl');
  2 +// var NomsServ = require('../services/NomsServ');
  3 +var async = require('async');
  4 +
  5 +var ConvsServ = {};
  6 +
  7 +ConvsServ.addData = function (Conv, cb) {
  8 + // NomsServ.get(Conv.login, function (nom) {
  9 + // if (nom) {
  10 + // Conv.nom = nom;
  11 + // } else {
  12 + // Conv.nom = Conv.login;
  13 + // }
  14 + // cb(null, Conv);
  15 + // });
  16 + // TODO Démarré par
  17 + // TODO Dernier message
  18 + cb(null, Conv);
  19 +};
  20 +
  21 +ConvsServ.get = function(id, cb) {
  22 + ConvModl.findById(id).lean().exec(function (err, Conv) {
  23 + if (err)
  24 + cb(err);
  25 + else
  26 + ConvsServ.addData(Conv, cb);
  27 + });
  28 +};
  29 +
  30 +ConvsServ.list = function (cb) {
  31 + ConvModl.find({}).lean().exec(function (err, Convs) {
  32 + async.mapSeries(Convs, ConvsServ.addData, cb);
  33 + });
  34 +};
  35 +
  36 +ConvsServ.add = function (data, cb) {
  37 + ConvModl.create({
  38 + titre: data.titre
  39 + }, function(err, Conv) {
  40 + ConvsServ.get(Conv._id, cb);
  41 + });
  42 +};
  43 +
  44 +ConvsServ.remove = function (id, cb) {
  45 + // TODO Trash
  46 + ConvModl.remove({
  47 + _id: id
  48 + }, cb);
  49 +};
  50 +
  51 +module.exports = ConvsServ;
app/services/SessionsServ.js
@@ -15,6 +15,8 @@ sessions.addData = function (session, cb) { @@ -15,6 +15,8 @@ sessions.addData = function (session, cb) {
15 } 15 }
16 session.canAddMembre = session.login == 'gbontoux'; 16 session.canAddMembre = session.login == 'gbontoux';
17 session.canDelMembre = session.login == 'gbontoux'; 17 session.canDelMembre = session.login == 'gbontoux';
  18 + session.canAddConv = session.login == 'gbontoux';
  19 + session.canDelConv = session.login == 'gbontoux';
18 cb(session); 20 cb(session);
19 }); 21 });
20 }; 22 };
1 -angular.module('ciApp', ['ngAnimate', 'ngRoute', 'SessionsCtrl', 'ConnectCtrl', 'MembreCtrl']).config(['$routeProvider', '$locationProvider', 1 +angular.module('ciApp', ['ngAnimate', 'ngRoute', 'ConnectCtrl', 'MembreCtrl', 'ForumDirCtrl', 'SessionsCtrl']).config(['$routeProvider', '$locationProvider',
2 function ($routeProvider, $locationProvider) { 2 function ($routeProvider, $locationProvider) {
3 $routeProvider 3 $routeProvider
4 .when('/', { 4 .when('/', {
@@ -8,6 +8,10 @@ angular.module('ciApp', ['ngAnimate', 'ngRoute', 'SessionsCtrl', 'ConnectCtrl', @@ -8,6 +8,10 @@ angular.module('ciApp', ['ngAnimate', 'ngRoute', 'SessionsCtrl', 'ConnectCtrl',
8 templateUrl: 'views/membres.html', 8 templateUrl: 'views/membres.html',
9 controller: 'MembreCtrl' 9 controller: 'MembreCtrl'
10 }) 10 })
  11 + .when('/forum', {
  12 + templateUrl: 'views/forumDir.html',
  13 + controller: 'ForumDirCtrl'
  14 + })
11 .when('/connect', { 15 .when('/connect', {
12 templateUrl: 'views/connect.html', 16 templateUrl: 'views/connect.html',
13 controller: 'ConnectCtrl' 17 controller: 'ConnectCtrl'
public/js/controllers/ForumDirCtrl.js 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +angular.module('ForumDirCtrl', ['SessionsServ', 'ForumServ', 'NotifyServ']).controller('ForumDirCtrl', ['$scope', 'SessionServ', 'ForumServ', 'NotifyServ',
  2 + function ($scope, SessionServ, ForumServ, NotifyServ) {
  3 + $scope.convs = [];
  4 + $scope.formData = {};
  5 +
  6 + $scope.session = SessionServ.cur;
  7 + SessionServ.onChange(function () {
  8 + $scope.session = SessionServ.cur;
  9 + });
  10 +
  11 + ForumServ.getConvs(function(err, convs) {
  12 + if (!err)
  13 + $scope.convs = convs;
  14 + });
  15 +
  16 + $scope.createConv = function () {
  17 + ForumServ.createConv($scope.formData, function(err, conv) {
  18 + if (!err)
  19 + $scope.convs.push(conv);
  20 + });
  21 + };
  22 +
  23 + $scope.deleteConv = function (index) {
  24 + ForumServ.deleteConv($scope.convs[index]._id, function(err) {
  25 + if (!err)
  26 + $scope.convs.splice(index, 1);
  27 + });
  28 + };
  29 +
  30 + }
  31 +]);
public/js/services/ForumServ.js 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  1 +angular.module('ForumServ', ['NotifyServ']).service('ForumServ', ['$http', 'NotifyServ',
  2 + function ($http, NotifyServ) {
  3 + a = {
  4 + getConvs: function (cb) {
  5 + // TODO Dirs
  6 + $http.get('/api/convs')
  7 + .success(function (data) {
  8 + cb(null, data);
  9 + })
  10 + .error(function (data) { // TODO CBs
  11 + NotifyServ.error("Impossible d'obtenir la liste des convs", data);
  12 + });
  13 + },
  14 +
  15 + createConv: function (data, cb) {
  16 + var not = NotifyServ.promise("Ajout du conv...");
  17 + $http.post('/api/convs', data)
  18 + .success(function (conv) {
  19 + not.success("Conv ajouté");
  20 + cb(null, conv);
  21 + })
  22 + .error(function (data) {
  23 + not.error("Impossible d'ajouter le conv");
  24 + });
  25 + },
  26 +
  27 + deleteConv: function (id, cb) {
  28 + var not = NotifyServ.promise("Suppression du conv...");
  29 + $http.delete('/api/convs/' + id)
  30 + .success(function (conv) {
  31 + not.success("Conv supprimé");
  32 + cb(null);
  33 + })
  34 + .error(function (data) {
  35 + not.error("Impossible de supprimer le conv", data);
  36 + });
  37 + }
  38 + };
  39 + return a;
  40 + }
  41 +]);
public/views/forumDir.html 0 → 100644
@@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
  1 +<div class="container">
  2 + <ol class="breadcrumb">
  3 + <li><a href="#">Home</a></li>
  4 + <li><a href="#">Library</a></li>
  5 + <li class="active">Data</li>
  6 + </ol>
  7 + <div class="panel panel-default" ng-repeat="conv in convs">
  8 + <div class="panel-heading">
  9 + <h3 class="panel-title">{{ conv.titre }}</h3>
  10 + </div>
  11 + <div class="panel-body">
  12 + <strong>Date : </strong>{{ conv.date }}
  13 + <br/>
  14 + <button ng-if="session.canDelConv" type="button" class="btn btn-danger" ng-click="deleteConv($index)">
  15 + <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Supprimer
  16 + </button>
  17 + </div>
  18 + </div>
  19 + <div class="form-group" ng-if="session.canAddConv">
  20 + <div class="panel panel-default">
  21 + <div class="panel-heading">
  22 + <h3 class="panel-title">
  23 + <input type="text" class="form-control" placeholder="Titre" ng-model="formData.titre" />
  24 + </h3>
  25 + </div>
  26 + <div class="panel-body">
  27 + <textarea class="form-control" rows="3"></textarea>
  28 + <button type="submit" class="btn btn-primary" aria-label="Ajouter" ng-click="createConv()">
  29 + <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter
  30 + </button>
  31 + </div>
  32 + </div>
  33 + </div>
  34 + <nav>
  35 + <ul class="pagination">
  36 + <li>
  37 + <a href="#" aria-label="Previous">
  38 + <span aria-hidden="true">&laquo;</span>
  39 + </a>
  40 + </li>
  41 + <li><a href="#">1</a></li>
  42 + <li><a href="#">2</a></li>
  43 + <li><a href="#">3</a></li>
  44 + <li><a href="#">4</a></li>
  45 + <li><a href="#">5</a></li>
  46 + <li>
  47 + <a href="#" aria-label="Next">
  48 + <span aria-hidden="true">&raquo;</span>
  49 + </a>
  50 + </li>
  51 + </ul>
  52 + </nav>
  53 +</div>
public/views/index.html
@@ -22,9 +22,11 @@ @@ -22,9 +22,11 @@
22 <script src="js/services/NotifyServ.js"></script> 22 <script src="js/services/NotifyServ.js"></script>
23 <script src="js/services/EncryptServ.js"></script> 23 <script src="js/services/EncryptServ.js"></script>
24 <script src="js/services/SessionServ.js"></script> 24 <script src="js/services/SessionServ.js"></script>
25 - <script src="js/controllers/MembreCtrl.js"></script> 25 + <script src="js/services/ForumServ.js"></script>
26 <script src="js/controllers/SessionCtrl.js"></script> 26 <script src="js/controllers/SessionCtrl.js"></script>
27 <script src="js/controllers/ConnectCtrl.js"></script> 27 <script src="js/controllers/ConnectCtrl.js"></script>
  28 + <script src="js/controllers/MembreCtrl.js"></script>
  29 + <script src="js/controllers/ForumDirCtrl.js"></script>
28 <script src="js/app.js"></script> 30 <script src="js/app.js"></script>
29 </head> 31 </head>
30 32