admin page....
This commit is contained in:
parent
6e53a1e40a
commit
bd852937a6
3 changed files with 80 additions and 2 deletions
1
index.js
1
index.js
|
@ -122,6 +122,7 @@ fastify.post('/addPrank', async (request, reply) => {
|
|||
if (amount < MaxAmountCrepe) {
|
||||
let prankUid = makeid(16);
|
||||
PrankData[prankUid] = {
|
||||
date: new Date(),
|
||||
creator: content.uid,
|
||||
type: content.type,
|
||||
where: content.where,
|
||||
|
|
|
@ -79,8 +79,13 @@
|
|||
</footer>
|
||||
</div>
|
||||
|
||||
<div id="admin-page" style="display: none">
|
||||
|
||||
<div id="admin-page" class="container" style="display: none">
|
||||
<div class="admin-menu">Prank</div>
|
||||
<div class="admin-menu">Trésors</div>
|
||||
<div class="admin-menu">Activités</div>
|
||||
<div id="admin-content">
|
||||
|
||||
</div>
|
||||
</div> <!-- end admin page -->
|
||||
|
||||
<div class="container" id="login-page" style="display: none;">
|
||||
|
|
|
@ -61,6 +61,8 @@ $("#logo").click(function () {
|
|||
if (localStorage.getItem('token')) {
|
||||
if (localStorage.getItem('isAdmin')) {
|
||||
show_page('#admin-page');
|
||||
// Load prank by default
|
||||
|
||||
}
|
||||
else {
|
||||
show_page('#demande-page');
|
||||
|
@ -71,6 +73,76 @@ $("#logo").click(function () {
|
|||
}
|
||||
});
|
||||
|
||||
function get_admin(type) {
|
||||
$("#admin-content").innerHTML = "";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: base_url + "login",
|
||||
data: JSON.stringify({
|
||||
uid: localStorage.getItem('user'),
|
||||
token: localStorage.getItem('token'),
|
||||
type: type,
|
||||
}),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
|
||||
success: function (data) {
|
||||
if(data.success) {
|
||||
switch (type) {
|
||||
case: "prank":
|
||||
let doneCnt = 0;
|
||||
let prankData = [];
|
||||
for (prankUid in data.prankData) {
|
||||
data.prankData[prankUid].prankUid = prankUid;
|
||||
prankData.push(data.prankData[prankUid]);
|
||||
}
|
||||
prankData.sort((a, b) => Date(a.date) - Date(b.date));
|
||||
for (entry in prankData) {
|
||||
switch (prankData[entry].type) {
|
||||
case: "crêpe":
|
||||
if (prankData[entry].state == "pending"
|
||||
|| prankData[entry].state == "accepted") {
|
||||
$("#admin-content").insertAdjacentHTML("beforeend", `
|
||||
<span id="${prankData[entry].prankUid}" class="prank">
|
||||
<div class="prank-title">Demande de crêpe par ${prankData[entry].creator}</div>
|
||||
<div class="prank-amount">Quantité: ${prankData[entry].amount}</div>
|
||||
<div class="prank-supplement">Garniture: ${prankData[entry].supplement}</div>
|
||||
<div class="prank-where">Livraison: ${prankData[entry].where}</div>
|
||||
<div class="prank-note">Livraison: ${prankData[entry].note}</div>
|
||||
<span class="prank-footer">
|
||||
<div class="prank-uid">UID: ${prankData[entry].prankUid}</div>
|
||||
<div class="prank-date">UID: ${prankData[entry].date}</div>
|
||||
</span>
|
||||
<span class="prank-btn">
|
||||
<div class="prank-btn-accept">${(prankData[entry].state == "pending") ? "Accepter" : "Récupérer (accepté par: "+prankData[entry].manageBy+")"}</div>
|
||||
<div class="prank-btn-refused">Refuser</div>
|
||||
<div class="prank-btn-done">Done</div>
|
||||
</span>
|
||||
</span>
|
||||
`)
|
||||
} else if(prankData[entry].state == "done") {
|
||||
doneCnt++;
|
||||
}
|
||||
break;
|
||||
case: "kidnap":
|
||||
// On garde ou pas ?
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case: "treasure":
|
||||
break;
|
||||
case: "activity":
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
alert(data.why);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(window).on("load", function() {
|
||||
|
||||
/* Register the Service Worker */
|
||||
|
|
Loading…
Reference in a new issue