diff --git a/webapp/class/meeting.js b/webapp/class/meeting.js index 14306c665c136fe767c66eab8bc720ae37bcab14..36c8d255c9926cf52e9405752b13826ff12a2211 100644 --- a/webapp/class/meeting.js +++ b/webapp/class/meeting.js @@ -11,8 +11,8 @@ module.exports = { choose_appointment: (idMeeting, callback) => { choose_date(idMeeting, function(result){ - console.log("date: " + result.date); - console.log("time: " + result.time); + console.log("result:"); + console.log(result); }) } @@ -20,20 +20,48 @@ module.exports = { function choose_date(idMeeting, callback){ var date - + db_request.get_calendar(idMeeting, function(calendar){ + date = {day: calendar[0].day, month: calendar[0].month, year: calendar[0].year} - }) + console.log("Date: "); + console.log(date); + var array = [] + array.push(calendar.find(function(element){ - choose_time(table_times, function(){ + if(element.day == date.day && element.month == date.month && element.year == date.year){ + return element + } + })) + choose_time(array, function(res){ + console.log(res); + + callback(date) + }) }) } function choose_time(table_times, callback){ + var latest = {hour: 0, min: 0} + console.log(table_times); + + + table_times.forEach(function(time){ + if(time.from.hour > latest.hour){ + latest.hour = time.from.hour + latest.min = time.from.minutes + + } else if(time.from.hour == latest.hour){ + if(time.from.minutes > latest.hour){ + latest.hour = time.from.hour + latest.min = time.from.minutes + } + } + }) - callback() + callback(latest) } diff --git a/webapp/ressources/db/db_request.js b/webapp/ressources/db/db_request.js index 7b2eb9fc9d4d55032366993fe3151738165a602d..9aca0c798a32ddda854c2f4debc3463e3dd635c0 100644 --- a/webapp/ressources/db/db_request.js +++ b/webapp/ressources/db/db_request.js @@ -23,7 +23,9 @@ module.exports = { var calendar = [] users.forEach(function(u){ - calendar.push(u.calendar) + u.calendar.forEach(function(d){ + calendar.push(d) + }) }) callback(calendar) diff --git a/webapp/ressources/socket.js b/webapp/ressources/socket.js index 33415b358579b444490be8d4034ee6778f97b5d8..b41d0fbf715d0dd0b8c2ac2411933ca60e4c2f2e 100644 --- a/webapp/ressources/socket.js +++ b/webapp/ressources/socket.js @@ -56,6 +56,12 @@ module.exports = function(server){ }) }) + socket.on('update_appointement', function(id){ + meeting.choose_appointment(id, function(res){ + get_meeting('get_meeting', id) + }) + }) + function get_meeting(idMeeting){ db.get_meeting(idMeeting, function(data){ socket.emit('get_meeting', data) diff --git a/webapp/views/index.ejs b/webapp/views/index.ejs index ae1dc12a79801e0a458b2f2a5dab5a2da95f555e..1392627f29402f03e45908f79e989d4a5d75f6d6 100644 --- a/webapp/views/index.ejs +++ b/webapp/views/index.ejs @@ -26,7 +26,7 @@ } </script> <%- include('elements/nav.inc.html') %> - <div class="col-sm-6 text-center"> + <div class="col-sm-6 text-center mb-4"> <div class="card"> <div class="card-body"> @@ -44,7 +44,7 @@ </div> - <div class="col-sm-6 text-center"> + <div class="col-sm-6 text-center mb-4"> <div class="card"> <div class="card-body"> diff --git a/webapp/views/js/meeting.js b/webapp/views/js/meeting.js index 6a4c6fd3e5b60fc2dada611daf01d989cec955c4..95a36070a72d26977eafb8e2fa3d08458625581e 100644 --- a/webapp/views/js/meeting.js +++ b/webapp/views/js/meeting.js @@ -181,6 +181,10 @@ function add_user(){ toggle_add_user() } +function update_appointement(){ + socket.emit('update_appointement', id_meeting) +} + function remove_user(idUser){ if(confirm("Voulez-vous vraiment supprimer cet utilsiateur ?")){ socket.emit('remove_user', {idMeeting: id_meeting, idUser: idUser});