Commit 3372d377 authored by AudreyGl's avatar AudreyGl

Tuto part.2 pour le squelette nodejs/mongodb

parent 1670acab
......@@ -4,11 +4,12 @@ var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/nodetest1');
var db = monk('localhost:27017/agoraviz');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var debatsRouter = require('./routes/debats');
var app = express();
......@@ -29,7 +30,7 @@ app.use(function(req,res,next){
});
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/debats', debatsRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
......@@ -5,7 +5,7 @@
*/
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var debug = require('debug')('agoraviz:server');
var http = require('http');
/**
......
WiredTiger
WiredTiger 3.1.1: (July 12, 2018)
WiredTiger version string
WiredTiger 3.1.1: (July 12, 2018)
WiredTiger version
major=3,minor=1,patch=1
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checkpoint=(WiredTigerCheckpoint.10=(addr="018681e4d6cbc3568781e42832f3978881e46f5a9eb7808080e2efc0e22fc0",order=10,time=1557666260,size=24576,write_gen=19)),checkpoint_lsn=(1,40960),checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1)
{
"name": "nodetest1",
"name": "agoraviz",
"version": "0.0.0",
"lockfileVersion": 1,
"requires": true,
......
{
"name": "nodetest1",
"name": "agoraviz",
"version": "0.0.0",
"private": true,
"scripts": {
......
// Debatslist data array for filling in info box
var debatsListData = [];
// DOM Ready =============================================================
$(document).ready(function() {
// Question link click
$('#debatsList table tbody').on('click', 'td a.linkshowuser', showDebatInfo());
// Populate the debat table on initial page load
populateTable();
});
// Functions =============================================================
// Fill table with data
function populateTable() {
// Empty content string
var tableContent = '';
// jQuery AJAX call for JSON
$.getJSON( '/debats/debatslist', function( data ) {
debatsListData = data;
// For each item in our JSON, add a table row and cells to the content string
$.each(data, function(){
tableContent += '<tr>';
tableContent += '<td><a href="#" class="linkshowdebat" rel="' + this.question + '">' + this.question + '</a></td>';
tableContent += '<td><a href="#" class="linkdeletedebat" rel="' + this._id + '">delete</a></td>';
tableContent += '</tr>';
});
// Inject the whole content string into our existing HTML table
$('#debatsList table tbody').html(tableContent);
});
};
// Show Debat Info
function showDebatInfo(event) {
// Prevent Link from Firing
event.preventDefault();
// Retrieve username from link rel attribute
var thisDebatQuestion = $(this).attr('rel');
// Get Index of object based on id value
var arrayPosition = debatsListData.map(function(arrayItem) { return arrayItem.question; }).indexOf(thisDebatQuestion);
// Get our Debat Object
var thisDebatObject = debatsListData[arrayPosition];
//Populate Info Box
$('#debatInfoQuestion').text(thisDebatObject.question);
};
\ No newline at end of file
var express = require('express');
var router = express.Router();
/* GET debatslist. */
router.get('/debatslist', function(req, res) {
var db = req.db;
var collection = db.get('debatcollection');
collection.find({},{},function(e,docs){
res.json(docs);
});
collection.find({},{},function(e,docs){
res.render('debatslist', {
"debatslist" : docs
});
});
});
module.exports = router;
......@@ -11,6 +11,7 @@ router.get('/helloworld', function(req, res) {
res.render('helloworld', { title: 'Hello, World!' });
});
router.get('/debatslist', function(req, res) {
var db = req.db;
var collection = db.get('debatcollection');
......
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
......@@ -6,14 +6,24 @@
</head>
<body>
<h1>Débats en cours</h1>
<table id='debatslist'>
</table>
<ul>
<%
var list = '';
for (i = 0; i < debatslist.length; i++) {
list += '<li>'' + debatslist[i].question + '</li>';
list += '<li>' + debatslist[i].question + '</li>';
}
%>
<%= list %>
</ul>
<h3 id='debatInfoQuestion'>
<p>
<a href='/newdebat'>Lancer un nouveau débat</a>
</p>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="/javascripts/global.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -8,4 +8,6 @@
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="/javascripts/global.js"></script>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment