Commit 9378de0d18440dfdc250ca4884eebae89055cae2
1 parent
12162cc1
Affichage d'une conversation
Showing
9 changed files
with
94 additions
and
6 deletions
Show diff stats
app/routes/ApiRtes.js
@@ -104,6 +104,15 @@ api.get('/convs', function (req, res) { // Liste des convs | @@ -104,6 +104,15 @@ api.get('/convs', function (req, res) { // Liste des convs | ||
104 | }); | 104 | }); |
105 | }); | 105 | }); |
106 | 106 | ||
107 | +api.get('/convs/:conv_id', function (req, res) { // Une conv | ||
108 | + ConvsServ.get(req.params.conv_id, function (err, conv) { | ||
109 | + if (err) | ||
110 | + res.send(err); | ||
111 | + else | ||
112 | + res.json(conv); | ||
113 | + }); | ||
114 | +}); | ||
115 | + | ||
107 | api.post('/convs', function (req, res) { // Ajout d'un conv | 116 | api.post('/convs', function (req, res) { // Ajout d'un conv |
108 | ifPermission(req, res, 'canAddConv', function () { | 117 | ifPermission(req, res, 'canAddConv', function () { |
109 | ConvsServ.add(req.body, function (err, conv) { | 118 | ConvsServ.add(req.body, function (err, conv) { |
app/services/ConvsServ.js
@@ -4,7 +4,7 @@ var async = require('async'); | @@ -4,7 +4,7 @@ var async = require('async'); | ||
4 | 4 | ||
5 | var ConvsServ = {}; | 5 | var ConvsServ = {}; |
6 | 6 | ||
7 | -ConvsServ.addData = function (Conv, cb) { | 7 | +ConvsServ.addData = function (conv, cb) { |
8 | // NomsServ.get(Conv.login, function (nom) { | 8 | // NomsServ.get(Conv.login, function (nom) { |
9 | // if (nom) { | 9 | // if (nom) { |
10 | // Conv.nom = nom; | 10 | // Conv.nom = nom; |
@@ -15,15 +15,15 @@ ConvsServ.addData = function (Conv, cb) { | @@ -15,15 +15,15 @@ ConvsServ.addData = function (Conv, cb) { | ||
15 | // }); | 15 | // }); |
16 | // TODO Démarré par | 16 | // TODO Démarré par |
17 | // TODO Dernier message | 17 | // TODO Dernier message |
18 | - cb(null, Conv); | 18 | + cb(null, conv); |
19 | }; | 19 | }; |
20 | 20 | ||
21 | ConvsServ.get = function(id, cb) { | 21 | ConvsServ.get = function(id, cb) { |
22 | - ConvModl.findById(id).lean().exec(function (err, Conv) { | 22 | + ConvModl.findById(id).lean().exec(function (err, conv) { |
23 | if (err) | 23 | if (err) |
24 | cb(err); | 24 | cb(err); |
25 | else | 25 | else |
26 | - ConvsServ.addData(Conv, cb); | 26 | + ConvsServ.addData(conv, cb); |
27 | }); | 27 | }); |
28 | }; | 28 | }; |
29 | 29 |
public/js/app.js
1 | -angular.module('ciApp', ['ngAnimate', 'ngRoute', 'ConnectCtrl', 'MembreCtrl', 'ForumDirCtrl', 'SessionsCtrl']).config(['$routeProvider', '$locationProvider', | 1 | +angular.module('ciApp', ['ngAnimate', 'ngRoute', 'ConnectCtrl', 'MembreCtrl', 'ForumDirCtrl', 'ForumConvCtrl', 'SessionsCtrl']).config(['$routeProvider', '$locationProvider', |
2 | function ($routeProvider, $locationProvider) { | 2 | function ($routeProvider, $locationProvider) { |
3 | $routeProvider | 3 | $routeProvider |
4 | .when('/', { | 4 | .when('/', { |
@@ -9,9 +9,16 @@ angular.module('ciApp', ['ngAnimate', 'ngRoute', 'ConnectCtrl', 'MembreCtrl', 'F | @@ -9,9 +9,16 @@ angular.module('ciApp', ['ngAnimate', 'ngRoute', 'ConnectCtrl', 'MembreCtrl', 'F | ||
9 | controller: 'MembreCtrl' | 9 | controller: 'MembreCtrl' |
10 | }) | 10 | }) |
11 | .when('/forum', { | 11 | .when('/forum', { |
12 | + redirectTo: 'forum/dir/0' | ||
13 | + }) | ||
14 | + .when('/forum/dir/:dir_id', { | ||
12 | templateUrl: 'views/forumDir.html', | 15 | templateUrl: 'views/forumDir.html', |
13 | controller: 'ForumDirCtrl' | 16 | controller: 'ForumDirCtrl' |
14 | }) | 17 | }) |
18 | + .when('/forum/conv/:conv_id', { | ||
19 | + templateUrl: 'views/forumConv.html', | ||
20 | + controller: 'ForumConvCtrl' | ||
21 | + }) | ||
15 | .when('/connect', { | 22 | .when('/connect', { |
16 | templateUrl: 'views/connect.html', | 23 | templateUrl: 'views/connect.html', |
17 | controller: 'ConnectCtrl' | 24 | controller: 'ConnectCtrl' |
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +angular.module('ForumConvCtrl', ['SessionsServ', 'ForumServ', 'NotifyServ']).controller('ForumConvCtrl', ['$scope', '$routeParams', 'SessionServ', 'ForumServ', 'NotifyServ', | ||
2 | + function ($scope, $routeParams, SessionServ, ForumServ, NotifyServ) { | ||
3 | + $scope.conv = {}; | ||
4 | + // $scope.formData = {}; | ||
5 | + | ||
6 | + $scope.session = SessionServ.cur; | ||
7 | + SessionServ.onChange(function () { | ||
8 | + $scope.session = SessionServ.cur; | ||
9 | + }); | ||
10 | + ForumServ.getConv($routeParams.conv_id, function(err, conv) { | ||
11 | + if (!err) | ||
12 | + $scope.conv = conv; | ||
13 | + }); | ||
14 | + // | ||
15 | + // $scope.createConv = function () { | ||
16 | + // ForumServ.createConv($scope.formData, function(err, conv) { | ||
17 | + // if (!err) | ||
18 | + // $scope.formData = {}; | ||
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/controllers/ForumDirCtrl.js
@@ -16,6 +16,7 @@ angular.module('ForumDirCtrl', ['SessionsServ', 'ForumServ', 'NotifyServ']).cont | @@ -16,6 +16,7 @@ angular.module('ForumDirCtrl', ['SessionsServ', 'ForumServ', 'NotifyServ']).cont | ||
16 | $scope.createConv = function () { | 16 | $scope.createConv = function () { |
17 | ForumServ.createConv($scope.formData, function(err, conv) { | 17 | ForumServ.createConv($scope.formData, function(err, conv) { |
18 | if (!err) | 18 | if (!err) |
19 | + $scope.formData = {}; | ||
19 | $scope.convs.push(conv); | 20 | $scope.convs.push(conv); |
20 | }); | 21 | }); |
21 | }; | 22 | }; |
public/js/services/ForumServ.js
1 | angular.module('ForumServ', ['NotifyServ']).service('ForumServ', ['$http', 'NotifyServ', | 1 | angular.module('ForumServ', ['NotifyServ']).service('ForumServ', ['$http', 'NotifyServ', |
2 | function ($http, NotifyServ) { | 2 | function ($http, NotifyServ) { |
3 | a = { | 3 | a = { |
4 | + getConv: function (id, cb) { | ||
5 | + $http.get('/api/convs/' + id) | ||
6 | + .success(function (data) { | ||
7 | + cb(null, data); | ||
8 | + }) | ||
9 | + .error(function (data) { | ||
10 | + NotifyServ.error("Impossible d'obtenir la conv", data); | ||
11 | + }); | ||
12 | + }, | ||
13 | + | ||
4 | getConvs: function (cb) { | 14 | getConvs: function (cb) { |
5 | // TODO Dirs | 15 | // TODO Dirs |
6 | $http.get('/api/convs') | 16 | $http.get('/api/convs') |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
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">Conv</li> | ||
6 | + </ol> | ||
7 | + <h1>{{ conv.titre }}</h1> | ||
8 | + <nav> | ||
9 | + <ul class="pagination"> | ||
10 | + <li> | ||
11 | + <a href="#" aria-label="Previous"> | ||
12 | + <span aria-hidden="true">«</span> | ||
13 | + </a> | ||
14 | + </li> | ||
15 | + <li><a href="#">1</a></li> | ||
16 | + <li><a href="#">2</a></li> | ||
17 | + <li><a href="#">3</a></li> | ||
18 | + <li><a href="#">4</a></li> | ||
19 | + <li><a href="#">5</a></li> | ||
20 | + <li> | ||
21 | + <a href="#" aria-label="Next"> | ||
22 | + <span aria-hidden="true">»</span> | ||
23 | + </a> | ||
24 | + </li> | ||
25 | + </ul> | ||
26 | + </nav> | ||
27 | +</div> |
public/views/forumDir.html
@@ -6,7 +6,9 @@ | @@ -6,7 +6,9 @@ | ||
6 | </ol> | 6 | </ol> |
7 | <div class="panel panel-default" ng-repeat="conv in convs"> | 7 | <div class="panel panel-default" ng-repeat="conv in convs"> |
8 | <div class="panel-heading"> | 8 | <div class="panel-heading"> |
9 | - <h3 class="panel-title">{{ conv.titre }}</h3> | 9 | + <a href="/forum/conv/{{ conv._id }}"> |
10 | + <h3 class="panel-title">{{ conv.titre }}</h3> | ||
11 | + </a> | ||
10 | </div> | 12 | </div> |
11 | <div class="panel-body"> | 13 | <div class="panel-body"> |
12 | <strong>Date : </strong>{{ conv.date }} | 14 | <strong>Date : </strong>{{ conv.date }} |
public/views/index.html
@@ -27,6 +27,7 @@ | @@ -27,6 +27,7 @@ | ||
27 | <script src="js/controllers/ConnectCtrl.js"></script> | 27 | <script src="js/controllers/ConnectCtrl.js"></script> |
28 | <script src="js/controllers/MembreCtrl.js"></script> | 28 | <script src="js/controllers/MembreCtrl.js"></script> |
29 | <script src="js/controllers/ForumDirCtrl.js"></script> | 29 | <script src="js/controllers/ForumDirCtrl.js"></script> |
30 | + <script src="js/controllers/ForumConvCtrl.js"></script> | ||
30 | <script src="js/app.js"></script> | 31 | <script src="js/app.js"></script> |
31 | </head> | 32 | </head> |
32 | 33 |