Commit dbab321c authored by Clement Brizard's avatar Clement Brizard

Merge branch 'try-fixes'

parents 1ccfac4c 821e1536
......@@ -3,6 +3,7 @@ const Contribution = require('../models/contribution');
const router = express.Router();
// Get all contributions of a given debate
router.get('/:debateId', (req, res) => {
const debateId = req.params.debateId;
......
......@@ -4,5 +4,6 @@ const router = express.Router();
router.use('/debates', require('./debate'));
router.use('/contributions', require('./contribution'));
router.use('/syntheses', require('./synthese'));
module.exports = router;
const express = require('express');
const Synthese = require('../models/synthese');
const router = express.Router();
// Get all syntheses of a given debate
router.get('/:debateId', (req, res) => {
const debateId = req.params.debateId;
Synthese.alldebate(req.db, debateId, (err, syntheses) => {
res.json(syntheses);
});
});
// Get all syntheses
router.get('/', (req, res) => {
Synthese.all(req.db, (err, syntheses) => {
res.json(syntheses);
});
});
module.exports = router;
......@@ -64,16 +64,22 @@ router.get('/new', (req, res) => {
);
});
// Show debate
//Show debate
router.get('/show/:id', async (req, res) => {
const id = req.params.id;
const debate = await getJSON(`http://localhost:3000/api/debates/${id}`);
const contributions = await getJSON(`http://localhost:3000/api/contributions/${id}`);
const syntheses = await getJSON(`http://localhost:3000/api/syntheses/${id}`);
const stats = await getJSON(`http://localhost:3000/api/contributions/${id}/stat/stat`);
res.render(
'pages/debate/debate', {
title: debate.question,
debate: debate,
contributions: contributions,
syntheses: syntheses,
stats: stats
},
);
});
......
......@@ -4,12 +4,11 @@ const router = express.Router();
router.use('/debates', require('./debate'));
router.use('/contributions', require('./contribution'));
router.use('/syntheses', require('./synthese'));
// Home page
router.get('/', (req, res) => {
res.render('index', {
title: 'AgoraViz',
});
res.redirect('/debates');
});
// About page
......
const express = require('express');
const getJSON = require('get-json');
const Synthese = require('../models/synthese');
const router = express.Router();
/*
CRUD
*/
// Create a new synthese
router.post('/', (req, res) => {
var dateNewSynthese = new Date();
var jour = dateNewSynthese.getDate();
var mois = dateNewSynthese.getMonth()+1;
var annee = dateNewSynthese.getFullYear();
var heure = dateNewSynthese.getHours();
var minute = dateNewSynthese.getMinutes();
var seconde = dateNewSynthese.getSeconds();
var syntheseDateHeure =jour+'/'+mois+'/'+annee+':'+heure+'H'+minute+'min'+seconde+'s';
/*
contribsToInsert = [];
req.body.contributions.forEach(function (c){
contribsToInsert.push(ObjectId(c));
})*/
const obj = {
description: req.body.description,
contributions: req.body.contributions,
debate: req.body.debate,
auteur: req.body.auteur,
timestamp: syntheseDateHeure,
};
Synthese.new(req.db, obj, (err) => {
if (err) {
res.send('Error when trying to create a synthese');
}
res.redirect('/debates');
});
});
// Delete a synthese
router.post('/delete/:id', (req, res) => {
const id = req.params.id;
Synthese.delete(req.db, id, (err) => {
if (err) {
res.send('Error trying to delete a synthese')
}
res.redirect('/debates');
});
});
module.exports = router;
......@@ -12,6 +12,7 @@ exports.all = (db, debate, cb) => {
});
};
exports.getByDate = (db, debate, end, cb) => {
const debateId = debate;
db.get('contribcollection').find({
......
const ObjectId = require('mongodb').ObjectID;
// Get all syntheses of a given debate
exports.alldebate = (db, debate, cb) => {
const debateId = debate;
db.get('synthesecollection').find({
debate: ObjectId(debateId),
}, {}, (err, docs) => {
return err ?
cb(err)
: cb(null, docs);
});
};
// Get all syntheses
exports.all = (db, cb) => {
db.get('synthesecollection').find({}, {}, (err, docs) => {
if (err) return cb(err);
return cb(null, docs);
});
};
// Get one synthese
exports.one = (db, id, cb) => {
db.get('synthesecollection').findOne({
_id: id,
}, {}, (err, doc) => {
return err ?
cb(err)
: cb(null, doc);
});
};
// Create a new synthese
exports.new = (db, obj, cb) => {
db.get('synthesecollection').insert({
description: obj.description,
contributions: obj.contributions,
debate: ObjectId(obj.debate),
auteur: obj.auteur,
timestamp: obj.timestamp,
}, {}, (err, doc) => {
db.get('contribcollection').find({}).each(function (contrib) {
var synthese = db.get('synthesecollection').find({ description : obj.description});
if (obj.contributions.includes(JSON.stringify(contrib.name))) {
console.log(synthese._id);
db.get('contribcollection').update({ _id: contrib._id},{$set: {synthese: obj.description}});
}},{}, (err, doc) => {
return err ?
cb(err)
: cb(null, doc);
});
return err ?
cb(err)
: cb(null, doc);
});
};
// Delete a synthese
exports.delete = (db, id, cb) => {
db.get('synthesecollection').remove({
_id: id,
}, {}, (err) => {
return err ?
cb(err)
: cb(null);
});
};
.line {
fill: none;
stroke: steelblue;
stroke-width: 2px;
}
.node circle {
fill: #fff;
stroke-width: 1.5px;
......@@ -11,15 +17,161 @@
stroke-width: 1.5px;
}
div.tooltip {
position: absolute;
text-align: center;
width: 260px;
height: 90px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
\ No newline at end of file
div.tooltip {
position: absolute;
text-align: center;
width: 260px;
height: 90px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
#addNode {
visibility: hidden;
}
.draggable {
cursor: move;
}
#leTitre{
height: 100px;
}
#fondnavbar{
width : 100%;
height : 50px;
background : linear-gradient(#ffffff,#cbcbcb);
border-radius : 4px 4px 4px 4px;
box-shadow: 0px 0px 2px 2px rgba(120,120,120,0.5),
0px 1px 0px 1px rgba(255, 255, 255,0.5) inset,
0px -3px 0px 1px rgba(120,120,120,0.1) inset;
}
#navbar{
font-family: "Trebuchet MS";
margin-right: auto;
margin-left: auto;
margin-top: 0;
display: table;
padding: 0;
}
#navbar li{
display: table-cell;
width : 180px;
transition: 1s;
}
#navbar li:hover{
width: 190px;
transition: 1s;
}
#navbar a{
color: #3b3b3b;
text-decoration: none;
display: block;
line-height : 50px;
text-align: center;
text-shadow: 0 1px 0px rgba(0,0,0,0.2);
transition: 1s;
}
#navbar a:hover{
color : black;
text-shadow: 0 1px 0px rgba(0,0,0,0.5);
background: rgba(255, 255, 255, 0.5);
transition: 1s;
}
#grandFond{
background : linear-gradient(#ffffff,#e0e0e0);
box-shadow: 0px 0px 2px 2px rgba(120,120,120,0.5),
0px 1px 0px 1px rgba(255, 255, 255,0.5) inset,
0px -3px 0px 1px rgba(120,120,120,0.1) inset;
}
#colGauche{
background: #e0e0e0;
}
#colDroite{
background: #e0e0e0;
}
#menuResume li{
display: table;
width:100px;
height: 20px;
border-radius: 2px 2px 2px 2px;
float:left;
}
#lContrib{
display: none;
}
#lContrib li{
display: table;
height: 70px;
}
#lSynth{
display: none;
}
#lSynth li{
display: table;
height: 70px;
}
#definitions{
display: none;
}
#sources{
display: none;
}
#dateForm{
display: none;
}
#label{
width:100%;
}
#comment{
width:100%;
}
#auteur{
width:100%;
}
#description{
width:100%;
}
#auteursynthese{
width:100%;
}
#NewDebatContainer{
margin-top: 50px;
}
#listAddDebat li{
display: table-row;
height: 50px;
}
#inputDebatQuestion{
width:400px;
}
#basPage{
position: absolute;
bottom: 0px;
width: 90%;
}
#basPage p{
text-align: center;
}
$(document).ready(function () {
$('#debates').DataTable();
})
function addCircleDraggable(){
var offset, x, y;
$("#newNode").remove();
d3.select("g").append("circle")
.attr("r", 4.5)
.style('fill', function() { return color($('#type').val());})
.attr("class", "draggable")
.attr("id", "newNode")
.attr("cx", 700)
.attr("cy", 400)
.attr("transform", function() { return "translate(-200 -200)"; })
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended)
);
function dragstarted(d) {
x=+d3.event.x;
y=+d3.event.y;
d3.select(this).raise().classed("active", true);
offset=d3.event;
offset.x -= parseFloat(d3.select(this).attr("cx"));
offset.y -= parseFloat(d3.select(this).attr("cx"));
}
function dragged(d) {
console.log("start");
d3.select(this).attr("cx", d3.event.x - offset.x);
d3.select(this).attr("cy", d3.event.y - offset.y);
$(this).css({
'pointer-events' : 'none'
})
}
function dragended(d) {
console.log("ended");
d3.select(this).classed("active", false);
$(this).css({
'pointer-events' : 'auto'
})
}
/*
d3.selectAll(".node").on("mouseover", handle)
function handle(d){
console.log("you", d);
selected=d;
$("#addNode").click();
}
*/
}
var data=[
{ "date":"01-01-2019",
"count":7
},
{ "date":"02-02-2019",
"count":5
},
{ "date":"03-02-2019",
"count":1
},
{ "date":"10-02-2019",
"count":6
},
{ "date":"20-02-2019",
"count":5
},
{ "date":"21-02-2019",
"count":3
},
{ "date":"22-02-2019",
"count":6
},
]
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// parse the date / time
var parseTime = d3.timeParse("%d-%m-%Y");
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
var bisect = d3.bisector(function (data) {
return data.date;
}).right;
createLine(stats);
function createLine(data){
// define the line
var valueline = d3.line()
.x(function(d) { console.log("x", x(d.date)); return x(d.date); })
.y(function(d) { console.log("y", y(d.count)); return y(d.count); })
.curve(d3.curveMonotoneX)
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
$("#affTreeMap").append('<svg width="672" id="stat" height="372"></svg>')
var svg = d3.select("#stat")
// .attr("width", width + margin.left + margin.right)
// .attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.bottom + ") scale(0.6,0.45)")
// format the data
data.forEach(function(d) {
// d.date = parseTime(d.date);
d.date = parseTime(d._id.day+"-"+d._id.month+"-"+d._id.year)
d.count = +d.count;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.count; })]);
// Add the valueline path.
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
// Add the X Axis
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// Add the Y Axis
svg.append("g")
.call(d3.axisLeft(y));
svg
.append("g")
.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("r", 4.5)
.attr("class", "plot")
.attr("cx", function(d) { console.log(d.date); return x(d.date); })
.attr("cy", function(d) { console.log(d.count); return y(d.count); })
.style("fill", "white")
.style("stroke", "blue")
.on("click", handleCircle)
$(svg).css({
'pointer-events' : 'auto'
})
function handleCircle(d){
var x= d.date;
var y= d.count;
var month = d.date.getMonth() <10 ? "0"+d.date.getMonth().toString() : d.date.getMonth().toString();
var day = d.date.getDay() <10 ? "0"+d.date.getDay().toString() : d.date.getDay().toString();
console.log( d.date.getMonth()<10, d.date.getFullYear()+"-"+month+"-"+day);
$("#dateValue").val(d.date.getFullYear()+"-"+month+"-"+day)
//$("#end").click();
}
}
\ No newline at end of file
function showHideContrib() {
var x = document.getElementById("lContrib");
if (x.style.display == 'none')
{
x.style.display = 'block';
}else
{
x.style.display = 'none';
}
}
function showHideSynth() {
var x = document.getElementById("lSynth");
if (x.style.display == 'none')
{
x.style.display = 'block';
}else
{
x.style.display = 'none';
}
}
function showDefs() {
var x = document.getElementById("definitions");
if (x.style.display == 'none')
{
x.style.display = 'block';
}else
{
x.style.display = 'none';
}
}
function showSources() {
var x = document.getElementById("sources");
if (x.style.display == 'none')
{
x.style.display = 'block';
}else
{
x.style.display = 'none';
}
}
function showDateForm() {
var x = document.getElementById("dateForm");
if (x.style.display == 'none')
{
x.style.display = 'block';
}else
{
x.style.display = 'none';
}
}
This diff is collapsed.
......@@ -55,4 +55,83 @@ a {
fieldset {
border:0;
padding:0; margin:0;
}
.form-container {
width:100%;
float:left;
position:relative;
background:#00BCD4;
height:40px;
display:inline-block;
border-radius:5px;
border-width:5px;
border-color: #2087a6;
margin:5px 0px;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;