From 7e97165435ab78bba8a9f1d276bde6e9099df3fe Mon Sep 17 00:00:00 2001 From: johan Date: Sun, 8 Jan 2023 12:41:10 +0100 Subject: [PATCH] Un jour je serais le meilleur dresseur --- index.js | 17 ------- static/css/main.css | 10 ++-- static/index.html | 55 ++++++++++++++++---- static/js/main.js | 121 ++++++++++++++++++++++++++++++++++---------- 4 files changed, 143 insertions(+), 60 deletions(-) diff --git a/index.js b/index.js index 4e2e91b..81a8d51 100644 --- a/index.js +++ b/index.js @@ -620,23 +620,6 @@ fastify.post('/isGolden', async (request, reply) => { } }) -fastify.get('/lastActivity', async (request, reply) => { - let curr_date = new Date() - for(acti in ActivityData) { - if(acti.type == "event" && curr_date < acti.start) { - return { - success: true, - activity: acti - } - } - } - - return { - success: false, - why: "No next activity" - } -}) - function saveData(path, data) { fs.writeFileSync(path, JSON.stringify(data)); } diff --git a/static/css/main.css b/static/css/main.css index 5dc2c3d..c258fed 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -92,7 +92,7 @@ a:hover { text-align: center; } -#spacer { +.spacer { padding: 1px; margin: 30px 0 30px 0; background-color: #00000054; @@ -149,7 +149,7 @@ a:hover { width: 100%; } -.login-form-control { +.form-control { width: 100%; border: none; border-bottom: 1px solid #d75b00; @@ -158,7 +158,7 @@ a:hover { padding: 5px; } -.login-form-control:focus { +.form-control:focus { outline: none; border-bottom: 2px solid #923e01; } @@ -248,7 +248,7 @@ button[type="submit"]:hover { border-left: 3px solid black; } -.activity-uid, .prank-uid, .prank-date, .treasure-uid, .treasure-date { +.activity-uid, .prank-uid, .prank-date, .treasure-uid, .treasure-date, #activite-place { color: #00000078; margin-top: 5px; font-size: 12px; @@ -284,7 +284,7 @@ button[type="submit"]:hover { #logo > img { width: 150px; } - #spacer { + .spacer { display: none; } .row-section { diff --git a/static/index.html b/static/index.html index d424540..9a18493 100644 --- a/static/index.html +++ b/static/index.html @@ -38,17 +38,18 @@

Prochaine activité

- 00:00:10 -

Mongolfière

-

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dicta tenetur tempora similique. A id esse expedita atque dolor eum itaque fugiat enim nisi dicta. Architecto mollitia quasi sed voluptatibus? Veniam.

+ 2 jours 00:00:10 +

+

+


-

Planning des activité

+

Planning des activités

Planning des activité
-
+

Ordre de mission

@@ -95,10 +96,10 @@
- diff --git a/static/js/main.js b/static/js/main.js index 4e34ab8..c8a5b34 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -514,6 +514,85 @@ function refreshListener() { }) } +$('#demande-button').click(function () { + + $.ajax({ + type: "POST", + url: base_url + "addPrank", + data: JSON.stringify({ + uid: localStorage.getItem('user'), + token: localStorage.getItem('token'), + type: "crêpe", + amount: $('#demande-amount').val(), + where: $('#demande-where').val(), + supplement: $('#demande-supplement').val(), + note: $('#demande-note').val() + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + if(data.success) { + $('#demande-form input').val(""); + } else { + alert(data.why); + } + } + }); +}); + +function updateNextActivity() { + $.ajax({ + type: "POST", + url: base_url + "get", + data: JSON.stringify({ + token: "", + uid: "", + type: "activity", + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + success: (data) => { + if(data.success) { + let curr_date = new Date(); + let ad = data.activityData; + var candidate = []; + var next_acti = {title: "Pas encore d'activité", desc: "Encore aucune activité n'a été renseigné, faite le vite !"}; + for(const uid in ad) { + if(ad[uid].type == "event" && curr_date < new Date( ad[uid].start )) { + candidate.push(ad[uid]); + } + } + + next_acti = candidate.reduce(function(prev, curr) { + return new Date(prev.start) < new Date(curr.Cost) ? prev : curr; + }); + + var opt = {speed: 100}; + new TypeIt("#activite-title", opt) + .type(next_acti.title) + .go(); + new TypeIt("#activite-desc", opt) + .type(next_acti.desc) + .go(); + new TypeIt("#activite-place", opt) + .type("Lieu : " + next_acti.where) + .go(); + let diff = Math.ceil( (new Date(next_acti.start) - new Date()) / 1000 ) + let days = Math.trunc(diff / (3600*24) ) + let h = Math.trunc(diff / 3600) - days*24 + let m = Math.trunc(diff / 60) - (h + days*24)*60 + let s = diff - h*3600 - m*60 - days*24*3600 + $('#timer').text(days + " jours " + (new Date('December 17, 1995 ' + [h, m, s].join(':'))).toLocaleTimeString('default', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + })); + } + } + }) +} + $(window).on("load", function() { /* Register the Service Worker */ if ('serviceWorker' in navigator) { @@ -524,37 +603,15 @@ $(window).on("load", function() { $(page[i]).css('z-index', page.length - i); } - $.ajax({ - type: "GET", - url: base_url + "lastActivity", - contentType: "application/json; charset=utf-8", - dataType: "json", - success: (data) => { - if(data.success) { - opt = {speed: 100, likeLike: true}; - new TypeIt("#activite-title", opt) - .type(data.activity.title) - .go(); - new TypeIt("#activite-desc", opt) - .type(data.activity.desc) - .go(); - let diff = Math.ceil( (data.activity.start - new Date()) / 1000 ) - let h = Math.round(diff / 3600) - let m = Math.round(diff / 60) - h*60 - let s = diff - m*60 - $("#timer").text((new Date('December 17, 1995 ' + [h, m, s].join(':'))).toLocaleTimeString('default', { - hour: '2-digit', - minute: '2-digit', - second: '2-digit' - })); - } - } - }) + updateNextActivity(); /* load timer */ window.setInterval(function() { - var time = $("#timer").text(); + var b = $("#timer").text().split(' jours '); + var time = b[1]; + var days = b[0]; var t = time.split(":").map(t => parseInt(t)); + t[2] -= 1; if (t[2] < 0) { t[2] = 59; @@ -565,11 +622,19 @@ $(window).on("load", function() { t[0] -= 1; } if (t[0] < 0) { + t[0] = 23; + t[1] = 59; + t[2] = 59; + days -= 1; + } + if (days < 0) { t[0] = 0; t[1] = 0; t[2] = 0; + days = 0; + updateNextActivity(); } - $('#timer').text((new Date('December 17, 1995 ' + t.join(':'))).toLocaleTimeString('default', { + $('#timer').text(days + " jours " +(new Date('December 17, 1995 ' + t.join(':'))).toLocaleTimeString('default', { hour: '2-digit', minute: '2-digit', second: '2-digit'