diff --git a/app/models/membre.js b/app/models/membre.js new file mode 100644 index 0000000..a34280f --- /dev/null +++ b/app/models/membre.js @@ -0,0 +1,20 @@ +var mongoose = require('mongoose'); + +module.exports = mongoose.model('Membre', { + login: { // On récupèrera le nom via les passwd + type: String, + default: 'login' + }, + section: { + type: String, + default: 'IMA' + }, + promo: { // Nécessaire pour calculer le numéro de section + type: Number, + default: 2017 + }, + role: { + type: String, + default: 'Membre' + } +}); \ No newline at end of file diff --git a/app/models/nerd.js b/app/models/nerd.js deleted file mode 100644 index 5efbcbc..0000000 --- a/app/models/nerd.js +++ /dev/null @@ -1,24 +0,0 @@ -// app/models/nerd.js -// grab the mongoose module -var mongoose = require('mongoose'); - -// define our nerd model -// module.exports allows us to pass this to other files when it is called -module.exports = mongoose.model('Nerd', { - login: { - type: String, - default: 'login' - }, - section: { - type: String, - default: 'IMA' - }, - promo: { - type: Number, - default: 2017 - }, - role: { - type: String, - default: 'Membre' - } -}); \ No newline at end of file diff --git a/app/routes.js b/app/routes.js index 7a32c8e..917fcff 100644 --- a/app/routes.js +++ b/app/routes.js @@ -1,59 +1,45 @@ -// app/routes.js - -// grab the nerd model we just created -var Nerd = require('./models/nerd'); +var Membre = require('./models/membre'); module.exports = function (app) { - // server routes =========================================================== - // handle things like api calls - // authentication routes - - // sample api route - app.get('/api/nerds', function (req, res) { - // use mongoose to get all nerds in the database - Nerd.find(function (err, nerds) { + app.get('/api/membres', function (req, res) { + Membre.find(function (err, membres) { if (err) res.send(err); - res.json(nerds); + res.json(membres); }); }); - app.post('/api/nerds', function (req, res) { - Nerd.create({ + app.post('/api/membres', function (req, res) { + Membre.create({ login: req.body.login, role: req.body.role, section: req.body.section, - }, function (err, nerd) { + }, function (err, membre) { if (err) res.send(err); - Nerd.find(function (err, nerds) { + Membre.find(function (err, membres) { if (err) res.send(err); - res.json(nerds); + res.json(membres); }); }); }); - app.delete('/api/nerds/:nerd_id', function (req, res) { - Nerd.remove({ - _id: req.params.nerd_id - }, function (err, nerd) { + app.delete('/api/membres/:membre_id', function (req, res) { + Membre.remove({ + _id: req.params.membre_id + }, function (err, membre) { if (err) res.send(err); - Nerd.find(function (err, nerds) { + Membre.find(function (err, membres) { if (err) res.send(err); - res.json(nerds); + res.json(membres); }); }) }) - // route to handle creating goes here (app.post) - // route to handle delete goes here (app.delete) - - // frontend routes ========================================================= - // route to handle all angular requests app.get('*', function (req, res) { - res.sendfile('./public/views/index.html'); // load our public/index.html file + res.sendfile('./public/views/index.html'); }); }; \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index b11e73a..dd8f285 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1,9 +1,11 @@ html { overflow-y: scroll; } + body { padding-top: 50px; } -#nerd-list { + +#membre-list { width: 90 %; } \ No newline at end of file diff --git a/public/js/app.js b/public/js/app.js index 145886e..b09133c 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,2 +1 @@ -// public/js/app.js -angular.module('sampleApp', ['ngRoute', 'appRoutes', 'MainCtrl', 'NerdCtrl', 'NerdService']); \ No newline at end of file +angular.module('ciApp', ['ngRoute', 'appRoutes', 'MembreCtrl']); \ No newline at end of file diff --git a/public/js/appRoutes.js b/public/js/appRoutes.js index 0816e66..ccb1ab5 100644 --- a/public/js/appRoutes.js +++ b/public/js/appRoutes.js @@ -6,14 +6,13 @@ angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', // home page .when('/', { - templateUrl: 'views/home.html', - controller: 'MainController' + templateUrl: 'views/home.html' }) - // nerds page that will use the NerdController - .when('/nerds', { - templateUrl: 'views/nerd.html', - controller: 'NerdController' + // membres page that will use the MembreController + .when('/membres', { + templateUrl: 'views/membres.html', + controller: 'MembreController' }); $locationProvider.html5Mode(true); diff --git a/public/js/controllers/MainCtrl.js b/public/js/controllers/MainCtrl.js deleted file mode 100644 index fa569cb..0000000 --- a/public/js/controllers/MainCtrl.js +++ /dev/null @@ -1,6 +0,0 @@ -// public/js/controllers/MainCtrl.js -angular.module('MainCtrl', []).controller('MainController', function ($scope) { - - $scope.tagline = 'To the moon and back!'; - -}); \ No newline at end of file diff --git a/public/js/controllers/MembreCtrl.js b/public/js/controllers/MembreCtrl.js new file mode 100644 index 0000000..f0ddfc2 --- /dev/null +++ b/public/js/controllers/MembreCtrl.js @@ -0,0 +1,40 @@ +// public/js/controllers/MembreCtrl.js +angular.module('MembreCtrl', []).controller('MembreController', function ($scope, $http) { + $scope.formData = {}; + + // when landing on the page, get all Membres and show them + $http.get('/api/membres') + .success(function (data) { + $scope.membres = data; + console.log(data); + }) + .error(function (data) { + console.log('Error: ' + data); + }); + + // when submitting the add form, send the text to the node API + $scope.createMembre = function () { + console.log('Adding', $scope.formData); + $http.post('/api/membres', $scope.formData) + .success(function (data) { + $scope.formData = {}; // clear the form so our user is ready to enter another + $scope.membres = data; + }) + .error(function (data) { + console.log('Error: ' + data); + }); + }; + + // delete a Membre after checking it + $scope.deleteMembre = function (id) { + $http.delete('/api/membres/' + id) + .success(function (data) { + $scope.membres = data; + console.log(data); + }) + .error(function (data) { + console.log('Error: ' + data); + }); + }; + +}); \ No newline at end of file diff --git a/public/js/controllers/NerdCtrl.js b/public/js/controllers/NerdCtrl.js deleted file mode 100644 index 67cb397..0000000 --- a/public/js/controllers/NerdCtrl.js +++ /dev/null @@ -1,40 +0,0 @@ -// public/js/controllers/NerdCtrl.js -angular.module('NerdCtrl', []).controller('NerdController', function ($scope, $http) { - $scope.formData = {}; - - // when landing on the page, get all Nerds and show them - $http.get('/api/nerds') - .success(function (data) { - $scope.nerds = data; - console.log(data); - }) - .error(function (data) { - console.log('Error: ' + data); - }); - - // when submitting the add form, send the text to the node API - $scope.createNerd = function () { - console.log('Adding', $scope.formData); - $http.post('/api/nerds', $scope.formData) - .success(function (data) { - $scope.formData = {}; // clear the form so our user is ready to enter another - $scope.nerds = data; - }) - .error(function (data) { - console.log('Error: ' + data); - }); - }; - - // delete a Nerd after checking it - $scope.deleteNerd = function (id) { - $http.delete('/api/nerds/' + id) - .success(function (data) { - $scope.nerds = data; - console.log(data); - }) - .error(function (data) { - console.log('Error: ' + data); - }); - }; - -}); \ No newline at end of file diff --git a/public/js/services/NerdService.js b/public/js/services/NerdService.js deleted file mode 100644 index 513f0e6..0000000 --- a/public/js/services/NerdService.js +++ /dev/null @@ -1,22 +0,0 @@ -// public/js/services/NerdService.js -angular.module('NerdService', []).factory('Nerd', ['$http', - function ($http) { - - return { - // call to get all nerds - get: function () { - return $http.get('/api/nerds'); - }, - // call to POST and create a new nerd - create: function (nerdData) { - return $http.post('/api/nerds', nerdData); - }, - - // call to DELETE a nerd - delete: function (id) { - return $http.delete('/api/nerds/' + id); - } - } - - } -]); \ No newline at end of file diff --git a/public/views/home.html b/public/views/home.html index b12bc2e..340af94 100644 --- a/public/views/home.html +++ b/public/views/home.html @@ -1,7 +1,5 @@ - -
-

Home Page 4 Life

- -

{{ tagline }}

+

Site internet du Club Info

+

Hey ! Bienvenue sur le site internet du Club Info !
+ Pour l'instant, on travaille encore dessus, donc n'hésites pas à t'y aventurer, mais prends garde, les erreurs 404 te guettent !

\ No newline at end of file diff --git a/public/views/index.html b/public/views/index.html index 9125c92..eeef180 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -8,25 +8,24 @@ Club Informatique de Polytech Lille - + - + - - - + + - +
diff --git a/public/views/membres.html b/public/views/membres.html new file mode 100644 index 0000000..990396b --- /dev/null +++ b/public/views/membres.html @@ -0,0 +1,45 @@ +
+ +
+

Il y a {{ membres.length }} personnes au Club Info !

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NomSectionRôleAction
{{ membre.login }}{{ membre.section }}{{ membre.role }} +
+ + + + + + + +
+
\ No newline at end of file diff --git a/public/views/nerd.html b/public/views/nerd.html deleted file mode 100644 index 4a4ecaa..0000000 --- a/public/views/nerd.html +++ /dev/null @@ -1,45 +0,0 @@ -
- -
-

Il y a {{ nerds.length }} personnes au Club Info !

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
NomSectionRôleAction
{{ nerd.login }}{{ nerd.section }}{{ nerd.role }} -
- - - - - - - -
-
\ No newline at end of file diff --git a/server.js b/server.js index 25a867f..389d93a 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,4 @@ -// server.js - -// modules ================================================= +// Modules ==================================================================== var express = require('express'); var app = express(); var mongoose = require('mongoose'); @@ -8,47 +6,32 @@ var morgan = require('morgan'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); -// configuration =========================================== - -// config files -var db = require('./config/db'); +// Application ================================================================ -// set our port var port = process.env.PORT || 8080; -// connect to our mongoDB database -// (uncomment after you enter in your own credentials in config/db.js) +// Connection à la BDD +var db = require('./config/db'); mongoose.connect(db.url); -// get all data/stuff of the body (POST) parameters -// parse application/json +// Tricks app.use(bodyParser.json()); - -// parse application/vnd.api+json as json app.use(bodyParser.json({ type: 'application/vnd.api+json' })); - -// parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: true })); - -// override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT app.use(methodOverride('X-HTTP-Method-Override')); -// set the static files location /public/img will be /img for users +// Dossier public app.use(express.static(__dirname + '/public')); -// routes ================================================== -require('./app/routes')(app); // configure our routes +// Routes +require('./app/routes')(app); -// start app =============================================== -// startup our app at http://localhost:8080 app.listen(port); -// shoutout to the user -console.log('Magic happens on port ' + port); +console.log('La magie du CI se passe au port ' + port); -// expose app exports = module.exports = app; \ No newline at end of file -- libgit2 0.21.2