Commit 6b51f1bd authored by Clement Brizard's avatar Clement Brizard

Enabled listing debates with datatables

parent 8c6114c3
const express = require('express');
const getJSON = require('get-json');
const Debate = require('../models/debate');
const router = express.Router();
......@@ -38,7 +39,13 @@ router.get('/new', (req, res) => {
// Get list of existing debates
router.get('/', (req, res) => {
res.render('pages/debate/debates');
})
getJSON('http://localhost:3000/api/debates', (err, docs) => {
res.render(
'pages/debate/debates', {
debates: docs,
},
);
});
});
module.exports = router;
......@@ -756,6 +756,16 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true
},
"get-json": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-json/-/get-json-1.0.1.tgz",
"integrity": "sha512-buUOE2bLaxIsF6zGIrwvsTVlvgU85qwAWf0Hgq/EJBBoSssUqOauXWKpsh4wgPdTlZHEVllLtphiuIzFM4UEHQ==",
"requires": {
"is-node": "0.0.0",
"jsonp": "0.0.4",
"phin": "^2.2.6"
}
},
"glob": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
......@@ -940,6 +950,11 @@
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"is-node": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/is-node/-/is-node-0.0.0.tgz",
"integrity": "sha1-h91lC4f7ajnFDKr+4On2g17BXkE="
},
"is-promise": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
......@@ -1003,6 +1018,14 @@
"integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
"dev": true
},
"jsonp": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/jsonp/-/jsonp-0.0.4.tgz",
"integrity": "sha1-lGZaS3caq+y4qshBNbmVlHVpGL0=",
"requires": {
"debug": "*"
}
},
"levn": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
......@@ -1439,6 +1462,11 @@
"pify": "^2.0.0"
}
},
"phin": {
"version": "2.9.3",
"resolved": "https://registry.npmjs.org/phin/-/phin-2.9.3.tgz",
"integrity": "sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA=="
},
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
......
......@@ -10,6 +10,7 @@
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"get-json": "^1.0.1",
"http-errors": "~1.6.3",
"mongodb": "^3.2.4",
"monk": "^6.0.6",
......
$(document).ready(function() {
console.log("hello boy");
populateDebates();
$('#debates').DataTable();
});
function populateDebates() {
let tableContent = '';
$.getJSON('/api/debates', function (data) {
let debatsListData = [];
debatsListData = data;
$.each(data, function() {
tableContent += '<tr>';
tableContent += '<td><a href="#" rel="' + this.question + '">' + this.question + '</a></td>';
tableContent += '<td><a href="#" rel="' + this._id + '">Supprimer</a></td>';
tableContent += '</tr>';
});
$('#debates table tbody').html(tableContent);
});
}
<!DOCTYPE html>
<html>
<head>
<% include ../../partials/head %>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
<% include ../../partials/head %>
</head>
<body>
<h1>Débats en cours</h1>
<header>
<% include ../../partials/header %>
</header>
<div id="debates" class="container-fluid">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<table class="table table-hover">
<table id="debates" class="display" style="width:100%">
<thead>
<th scope="col">Titre</th>
<th scope="col">Supprimer</th>
<tr>
<th>Titre</th>
<th>Supprimer</th>
</tr>
</thead>
<tbody>
<%debates.forEach(function(debate) { %>
<tr>
<td><%= debate.question %></td>
<td>Supprimer</td>
</tr>
<% }); %>
</tbody>
</table>
</div>
<div class="col-md-8">
<% include ./debat %>
</div>
</div>
</div>
......@@ -31,8 +40,10 @@
<% include ../../partials/footer %>
</footer>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/javascript/debate.js"></script>
</body>
</html>
<meta charset="UTF-8">
<title>AgoraViz</title>
<link rel='stylesheet' href='/static/stylesheet/style.css' />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
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