diff --git a/showtime/client/src/scripts/admin.client.js b/showtime/client/src/scripts/admin.client.js index e59f476ab47f9aa825a0cb5a9accfb717cadeb7c..098a0d286a9ca1976eba2b430c1462be15745051 100644 --- a/showtime/client/src/scripts/admin.client.js +++ b/showtime/client/src/scripts/admin.client.js @@ -42,7 +42,7 @@ const addToList = (show,list) => { list.appendChild(node); } -// fetch DELETE to delete one task with given task id +// fetch DELETE to delete one task with given show id const deleteShow = async showId => { const requestOptions = { @@ -59,7 +59,7 @@ const deleteShow = } } -// fetch POST to create one task +// fetch POST to create one show const createShow = async () => { const newShowData = { diff --git a/showtime/client/src/scripts/user.client.js b/showtime/client/src/scripts/user.client.js index 936e9f355984015e244f54c73a36002669548952..f2df60b7e4dc79d606a0a865cfe2a5ce8ed9bf7a 100644 --- a/showtime/client/src/scripts/user.client.js +++ b/showtime/client/src/scripts/user.client.js @@ -11,8 +11,8 @@ window.addEventListener('DOMContentLoaded', setup); const getUser = async () => { const requestOptions = { - method :'GET', - }; + method: 'GET', + }; const response = await fetch('/me', requestOptions); if (response.ok) { const user = await response.json(); @@ -26,15 +26,15 @@ const getUser = async () => { const displayShowList = async () => { const requestOptions = { - method : 'GET' - }; - const response = await fetch('/admin/items', requestOptions) + method: 'GET' + }; + const response = await fetch('/items', requestOptions) if (response.ok) { const allShows = await response.json(); //(ici : code exploitation de allShows) const list = document.getElementById('list'); list.textContent = ''; - allShows.forEach( show => addToList(show, list) ); + allShows.forEach(show => addToList(show, list)); } else { const error = await response.json(); @@ -42,32 +42,32 @@ const displayShowList = async () => { } } -const addToList = (show,list) => { -const node = document.createElement('div'); -node.id = show._id; -node.className = "show"; -const span = document.createElement('span'); -span.className = "places"; -span.textContent = `${show.places} places` -node.textContent = `${show.description} : `; -node.appendChild(span); -// -const ticketsButton = document.createElement('button'); -ticketsButton.className = 'ticket'; -ticketsButton.addEventListener('click', addTicketShow); -ticketsButton.textContent = '+1 tickets'; -node.appendChild(ticketsButton); -// -list.appendChild(node); +const addToList = (show, list) => { + const node = document.createElement('div'); + node.id = show._id; + node.className = "show"; + const span = document.createElement('span'); + span.className = "places"; + span.textContent = `${show.places} places` + node.textContent = `${show.description} : `; + node.appendChild(span); + // + const ticketsButton = document.createElement('button'); + ticketsButton.className = 'ticket'; + ticketsButton.addEventListener('click', addTicketShow); + ticketsButton.textContent = '+1 tickets'; + node.appendChild(ticketsButton); + // + list.appendChild(node); } -const update = async (data) => { +const update = async (data) => { const body = JSON.stringify(data); const requestOptions = { - method :'PUT', - headers : { "Content-Type": "application/json" }, - body : body - }; + method: 'PUT', + headers: { "Content-Type": "application/json" }, + body: body + }; const response = await fetch('/tickets', requestOptions); if (response.ok) { const updatedUser = await response.json(); @@ -81,12 +81,12 @@ const update = async (data) => { const displayTicketsList = async () => { const requestOptions = { - method : 'GET' - }; + method: 'GET' + }; const response = await fetch('/tickets', requestOptions) if (response.ok) { const allTickets = await response.json(); - allTickets.forEach( ticket => addTicketsToList(ticket) ); + allTickets.forEach(ticket => addTicketsToList(ticket)); } else { const error = await response.json(); @@ -97,13 +97,13 @@ const displayTicketsList = async () => { const addTicketsToList = (ticket) => { const list = document.getElementById("showTickets"); createDivTickets(ticket, list); -} +} const addTicketShow = async (event) => { const divShow = event.target.parentElement; const showId = divShow.id; const description = divShow.textContent.split(':')[0]; - const ticket = {show : showId, description : description, tickets : 1}; + const ticket = { show: showId, description: description, tickets: 1 }; const list = document.getElementById("showTickets"); const nbTickets = addToTicketsList(ticket, list); @@ -113,11 +113,11 @@ const addTicketShow = async (event) => { const addToTicketsList = (ticket, list) => { let nbTickets; - if(document.getElementById(ticket.show+"-t") === null) { + if (document.getElementById(ticket.show + "-t") === null) { createDivTickets(ticket, list); nbTickets = 1; - }else { - const sp = document.getElementById(ticket.show+"-t").querySelector(".tickets"); + } else { + const sp = document.getElementById(ticket.show + "-t").querySelector(".tickets"); sp.textContent = 1 + parseInt(sp.textContent); nbTickets = parseInt(sp.textContent); } @@ -150,8 +150,8 @@ const cancelTicketShow = async (event) => { const showId = ticketDiv.id.split('-')[0]; const body = JSON.stringify(showId); const requestOptions = { - method :'DELETE', - }; + method: 'DELETE', + }; const response = await fetch(`/${showId}`, requestOptions); if (response.ok) { const updatedUser = await response.json(); @@ -165,17 +165,17 @@ const cancelTicketShow = async (event) => { const logout = async () => { const requestOptions = { - method :'GET', - }; + method: 'GET', + }; const response = await fetch(`/access/logout`, requestOptions); if (response.ok) { - window.location.href= '/'; + window.location.href = '/'; } } const handleError = error => { if (error.redirectTo) - window.location.href= error.redirectTo; + window.location.href = error.redirectTo; else console.log(`erreur : ${error.message}`); } \ No newline at end of file diff --git a/showtime/client/src/scripts/utils.js b/showtime/client/src/scripts/utils.js deleted file mode 100644 index 4640cdfe6be6103ffa6a7d49141603cf21863671..0000000000000000000000000000000000000000 --- a/showtime/client/src/scripts/utils.js +++ /dev/null @@ -1,31 +0,0 @@ -const displayList = async () => { - const requestOptions = { - method : 'GET' - }; - const response = await fetch('/items', requestOptions) - const allShows = await response.json(); - - //(ici : code exploitation de allShows) - const list = document.getElementById('list'); - list.textContent = ''; - allShows.forEach( show => addToList(show, list) ); - } - - const addToList = (show,list) => { - const node = document.createElement('div'); - node.className = 'show'; - node.textContent = `${show.description} (${show.places})`; - // - //node.addEventListener('mouseover', () => getTask(show._id)); - // - const deleteButton = document.createElement('button'); - deleteButton.className = 'ticket'; - deleteButton.addEventListener('click', () => deleteShow(show._id)); - deleteButton.textContent = '+1 tickets'; - node.appendChild(deleteButton); - // - list.appendChild(node); - } - -module.exports.displayList = displayList; - \ No newline at end of file diff --git a/showtime/client/src/style/style.css b/showtime/client/src/style/style.css index 9b0d9748c6529bc2eb24d414ac3289348c12e16d..69cc4ccd4ad928b3f7ea3417b4d0d2209ed8d62b 100644 --- a/showtime/client/src/style/style.css +++ b/showtime/client/src/style/style.css @@ -4,42 +4,49 @@ body { } div { - width : 280px; - margin : auto; - padding : 2px; - text-align :center; + width: 280px; + margin: auto; + padding: 2px; + text-align: center; + overflow: hidden; + box-sizing: border-box; + border: solid thin #999; } div label { - padding : 7px; + padding: 7px; } + input { - text-align :center; + text-align: center; } #place { width: 10px; } + button { - padding : 3px; - width : 100px; - margin : 0px 5px; - font-weight : bold; + padding: 3px; + width: 100px; + margin: 0px 5px; + font-weight: bold; } #shows, #tickets { - margin : 10px; - padding : 4px; - border : solid thin #999; + padding: 4px; + border: solid thin #999; } #list, #shows { - padding : 2px; - margin : 4px 4px; + padding: 2px; +} + +#list, #showTickets{ + overflow: auto; } .tickets { - width : 50px; + width: 50px; color: green; } @@ -48,13 +55,14 @@ div.reservation:nth-of-type(even), div.show:nth-of-type(even) { } #userdata { - background-color : #DDD; + background-color: #DDD; } -#userdata div{ - text-align : center; - margin : 2px; + +#userdata div { + text-align: center; + margin: 2px; } + #controls { - margin-top : 10px; + margin-top: 10px; } - diff --git a/showtime/server/public/style/style.css b/showtime/server/public/style/style.css index 9b0d9748c6529bc2eb24d414ac3289348c12e16d..69cc4ccd4ad928b3f7ea3417b4d0d2209ed8d62b 100644 --- a/showtime/server/public/style/style.css +++ b/showtime/server/public/style/style.css @@ -4,42 +4,49 @@ body { } div { - width : 280px; - margin : auto; - padding : 2px; - text-align :center; + width: 280px; + margin: auto; + padding: 2px; + text-align: center; + overflow: hidden; + box-sizing: border-box; + border: solid thin #999; } div label { - padding : 7px; + padding: 7px; } + input { - text-align :center; + text-align: center; } #place { width: 10px; } + button { - padding : 3px; - width : 100px; - margin : 0px 5px; - font-weight : bold; + padding: 3px; + width: 100px; + margin: 0px 5px; + font-weight: bold; } #shows, #tickets { - margin : 10px; - padding : 4px; - border : solid thin #999; + padding: 4px; + border: solid thin #999; } #list, #shows { - padding : 2px; - margin : 4px 4px; + padding: 2px; +} + +#list, #showTickets{ + overflow: auto; } .tickets { - width : 50px; + width: 50px; color: green; } @@ -48,13 +55,14 @@ div.reservation:nth-of-type(even), div.show:nth-of-type(even) { } #userdata { - background-color : #DDD; + background-color: #DDD; } -#userdata div{ - text-align : center; - margin : 2px; + +#userdata div { + text-align: center; + margin: 2px; } + #controls { - margin-top : 10px; + margin-top: 10px; } - diff --git a/showtime/server/routes/admin.route.js b/showtime/server/routes/admin.route.js index 81b5998fe00af8c593c1c1ac2348d8974befc1bf..7bfdd37a3ee6180f894da75f8fd4b598a52ac393 100644 --- a/showtime/server/routes/admin.route.js +++ b/showtime/server/routes/admin.route.js @@ -6,10 +6,8 @@ const authMiddleware = require('../middlewares/authentication.middleware'); router.get('/', adminController.home ); -router.get('/me', authMiddleware.validToken, adminController.me ); -router.get('/items', authMiddleware.validToken, adminController.list); +router.get('/items', authMiddleware.validToken, authMiddleware.isAdmin, adminController.list); router.post('/items', authMiddleware.validToken, authMiddleware.isAdmin, adminController.create); router.delete('/:showId', authMiddleware.validToken, authMiddleware.isAdmin, adminController.deleteShow); -// router.put('/me', authMiddleware.validToken, adminController.update ); module.exports = router; \ No newline at end of file