feat: api

This commit is contained in:
Arek 2022-06-19 09:34:23 +02:00
parent 994ace08b8
commit ed7cd83584
14 changed files with 750 additions and 586 deletions

View File

@ -10,25 +10,47 @@ async function showTournaments() {
} }
} }
function loginVisibility() {
if (localStorage.getItem("token") !== null) {
document.getElementById("login").style.display = "none";
}
else {
document.getElementById("login").style.display = "";
}
}
async function renderTournaments() { async function renderTournaments() {
let tournaments = await showTournaments(); let tournaments = await showTournaments();
let html = ''; let html = '';
let htmlDate = ''; let htmlDate = '';
tournaments.forEach(tournament => { tournaments.forEach(tournament => {
let rank = 0
if (`${tournament.approved}` == 0) {
rank = "Nie"
}
else if (`${tournament.approved}` == 1) {
rank = "Tak, ale niezatwierdzony"
}
else {
rank = "Tak"
}
if (`${tournament.id}` == localStorage.getItem("tournamentId")) { if (`${tournament.id}` == localStorage.getItem("tournamentId")) {
console.log(`${tournament.rang}`) console.log(`${tournament.rang}`)
htmlDate = ` htmlDate = `
<h1 class="tournamentInfo">${tournament.name}</h1> <h1 class="tournamentInfo">${tournament.name}</h1>
<h2 class="tournamentInfo">${tournament.places}</br> <h2 class="tournamentInfo">Miejsc: ${tournament.places}</br>
${tournament.from} do ${tournament.to}</h2>` ${tournament.from} do ${tournament.to}</h2>`
let htmlSegment = ` let htmlSegment = `
<h1> ${tournament.name}</h1> <h1> ${tournament.name}</h1>
<h2>${tournament.places}</h2> <h2>Miejsca: ${tournament.places}</h2>
<h3 class="descriptor">Wpisowe:</h3> <h3 class="descriptor">Wpisowe:</h3>
${tournament.entryFee} ${tournament.entryFee}
@ -43,7 +65,7 @@ async function renderTournaments() {
${tournament.to} ${tournament.to}
<h3 class="descriptor">Czy rankingowy:</h3> <h3 class="descriptor">Czy rankingowy:</h3>
${tournament.rang} ${rank}
<h3 class="descriptor">Dyrektor turnieju:</h3> <h3 class="descriptor">Dyrektor turnieju:</h3>
${tournament.director} ${tournament.director}

View File

@ -46,3 +46,9 @@ main {
float: left; float: left;
} }
.tournaments {
display: flex;
}

View File

@ -10,7 +10,7 @@
<script type="text/javascript" src="app.js"></script> <script type="text/javascript" src="app.js"></script>
</head> </head>
<body onload="renderTournaments()"> <body onload="renderTournaments();loginVisibility();">
<header> <header>
<div class="logoBox"> <div class="logoBox">
<a class="header_link" href="../../index.html"><img class="logo" src="../../../_global/logo.svg" <a class="header_link" href="../../index.html"><img class="logo" src="../../../_global/logo.svg"

View File

@ -24,7 +24,7 @@
<div class="descriptor">ID partnera</div> <div class="descriptor">ID partnera</div>
<br> <br>
<label> <label>
<input id="ID_input" placeholder="Tutaj wpisz email lub nick"> <input id="ID_input" placeholder="Tutaj wpisz id partnera">
</label> </label>

View File

@ -15,13 +15,15 @@ for (i = 0; i < coll.length; i++) {
function acceptPlayers(id) { function acceptPlayers(id) {
console.log(id)
let idString = id.toString()
console.log(id)
const requestOptions = { const requestOptions = {
method: 'POST', method: 'POST',
headers: { headers: {
'Authorization': ("Bearer " + localStorage.getItem("token")) 'Authorization': ("Bearer " + localStorage.getItem("token"))
}, },
body: JSON.stringify({ title: id }) body: JSON.stringify({ title: idString })
}; };
fetch('https://dragonmaster.pl/inz_swag/registration/payedUsingCash', requestOptions) fetch('https://dragonmaster.pl/inz_swag/registration/payedUsingCash', requestOptions)
.then(response => response.json()) .then(response => response.json())
@ -30,18 +32,136 @@ function acceptPlayers(id) {
} }
// // GET request using fetch with set headers
// function registrationsGet() {
// let id = localStorage.getItem('tournamentId');
// const element = document.getElementById('tournament8');
// const headers = {
// 'Authorization': ("Bearer " + localStorage.getItem("token"))
// };
// fetch('https://dragonmaster.pl/inz/registrations' + '?id=' + id, { headers })
// .then(response => response.json())
// .then(data => element.innerHTML = data.map(dataItem =>
// `<div class="zapisani">${dataItem.userid} ${dataItem.paymenttype} ${dataItem.paymentstatus} ${dataItem.partner} <button id="paymentAccepted" onclick="acceptPlayers(${dataItem.id})">dopusc do turnieju</button> <span id="paymentCheck"><span> <br><div>`)
// );
// }
let fullUserName = null;
let fullPartnerName = null;
function testUser(userName, userSurname) {
fullUserName = userName + " " + userSurname
console.log(fullPartnerName)
const element = document.getElementById('a');
element.innerHTML = fullUserName + `<br>`
}
function testPartner(partnerName, partnerSurname) {
fullPartnerName = partnerName + " " + partnerSurname
console.log(fullUserName)
const element = document.getElementById('b');
element.innerHTML = fullPartnerName
}
function registrationsGetSaverName(idUser) {
let userName = null;
let userSurname = null;
const element = document.getElementById('tournament8');
const headers = {
'Authorization': ("Bearer " + localStorage.getItem("token"))
};
fetch('https://dragonmaster.pl/inz/user/byId?id=' + idUser, { headers })
.then(response => response.json())
.then(data => {
userName = data.name;
userSurname = data.surname;
testUser(userName, userSurname)
})
// .then(response => console.log({ userName, userSurname }))
}
function registrationsGetPartnerName(idPartner) {
let partnerName = null;
let partnerSurname = null;
const element = document.getElementById('tournament8');
const headers = {
'Authorization': ("Bearer " + localStorage.getItem("token"))
};
fetch('https://dragonmaster.pl/inz/user/byId?id=' + idPartner, { headers })
.then(response => response.json())
.then(data => {
partnerName = data.name;
partnerSurname = data.surname;
testPartner(partnerName, partnerSurname)
})
// .then(response => ({ partnerName, partnerSurname }))
}
// // GET request using fetch with set headers
// function showNames(nameUser, surnameUser, namePartner, surnamePartner) {
// console.log(nameUser)
// console.log(nameUser)
// let id = localStorage.getItem('tournamentId');
// const element = document.getElementById('tournament8');
// element.innerHTML =
// `<div class="participant">
// <div class="partID">
// 1.
// </div>
// <div class="partNames">
// ${nameUser} ${surnameUser} <br>
// ${namePartner} ${surnamePartner}
// </div>
// <div class="partParameters">
// Dopuszczeni do turnieju
// <div class="pretty p-switch p-fill" style="margin-left: 5%">
// <input type="checkbox" />
// <div class="state p-success">
// <label></label>
// </div>
// </div>
// <br>
// Zapis opłacony
// <div class="pretty p-switch p-fill" style="margin-left: 5%">
// <input type="checkbox" />
// <div class="state p-success">
// <label></label>
// </div>
// </div>
// </div>
// </div>`
// }
// GET request using fetch with set headers // GET request using fetch with set headers
function registrationsGet() { function registrationsGetId() {
let idUser = null;
let idPartner = null;
let lala = null;
let id = localStorage.getItem('tournamentId'); let id = localStorage.getItem('tournamentId');
const element = document.getElementById('tournament8'); const element = document.getElementById('tournament8');
const headers = { const headers = {
'Authorization': ("Bearer " + localStorage.getItem("token")) 'Authorization': ("Bearer " + localStorage.getItem("token"))
}; };
fetch('https://dragonmaster.pl/inz/registrations' + '?id=' + id, { headers }) fetch('https://dragonmaster.pl/inz/registrations?id=' + id, { headers })
.then(response => response.json()) .then(response => response.json())
.then(data => element.innerHTML = data.map(dataItem => .then(data => data.map(dataItem => {
`<div class="zapisani">${dataItem.userid} ${dataItem.paymenttype} ${dataItem.paymentstatus} ${dataItem.partner} <button id="paymentAccepted" onclick="acceptPlayers(${dataItem.id})">dopusc do turnieju</button> <span id="paymentCheck"></span> <br><div>`) console.log(data)
); idUser = `${dataItem.userid}`;
idPartner = `${dataItem.partner}`;
idSave = `${dataItem.id}`;
}))
.then(response => { registrationsGetSaverName(idUser); registrationsGetPartnerName(idPartner) })
} }

View File

@ -8,10 +8,10 @@
<title>Padel Tournaments System</title> <title>Padel Tournaments System</title>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css" />
</head> </head>
<body onload="registrationsGet()"> <body onload="registrationsGetId()">
<header> <header>
<div class="logoBox"> <div class="logoBox">
@ -42,86 +42,52 @@
<!-- OPEN--> <!-- OPEN-->
<button type="button" class="collapsible">Zapisani na turniej - OPEN</button> <button type="button" class="collapsible">Zapisani na turniej - OPEN</button>
<div class="collapsibleContent"> <div class="collapsibleContent" id="playersList">
<div class="participant"> <div class="participant">
<div class="partID"> <div class="partID">
1. 1.
</div>
<div class="partNames">
Adrian Trela <br>
Adam Kowalski
</div>
<div class="partParameters">
Dopuszczeni do turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
<br>
Zapis opłacony
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
</div>
</div> </div>
<div class="participant"> <div class="partNames" id="partNames">
<span id="a">Adrian Trela</span>
<div class="partID"> <span id="b">Adam Kowalski</span>
1.
</div>
<div class="partNames">
Adrian Trela <br>
Adam Kowalski
</div>
<div class="partParameters">
Dopuszczeni do turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
<br>
Zapis opłacony
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
</div>
</div> </div>
<div class="partParameters">
Dopuszczeni do turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
<br>
Zapis opłacony
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success">
<label></label>
</div>
</div>
</div>
</div> </div>
</div> -->
<!-- MIKST-->
<button type="button" class="collapsible">Zapisani na turniej - MIKST</button>
<div class="collapsibleContent">
<main id="tournament8">
</main>
</div> </div>
</div>
<!-- MIKST-->
<!-- <button type="button" class="collapsible">Zapisani na turniej - MIKST</button>
<div class="collapsibleContent">
<main id="tournament8">
</main>
</div> -->
</div> </div>

View File

@ -27,9 +27,10 @@ function checkRoleCreator() {
function tournamentDelete(id) { function tournamentDelete(id) {
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
console.log(id) console.log(id)
let textId = id.toString()
console.log(textId)
fetch('https://dragonmaster.pl/inz/tournament', { fetch('https://dragonmaster.pl/inz/tournament', {
method: "DELETE", method: "DELETE",
headers: { headers: {
@ -39,15 +40,19 @@ function tournamentDelete(id) {
body: JSON.stringify( body: JSON.stringify(
{ {
"id": id "id": textId
} }
) )
} }
) )
.then(res => res.json()) .then(res => res.json())
.then(data => console.log(data)) .then(data => {
console.log(data)
location.reload()
})
.catch(error => console.log(error)) .catch(error => console.log(error))
} }
@ -59,7 +64,7 @@ async function renderTournaments(organiserTournament) {
organiser = `${tournament.creator}`; organiser = `${tournament.creator}`;
// console.log(organiser) // console.log(organiser)
if (organiser == organiserTournament) { if (organiser == organiserTournament) {
let htmlSegment = `<div class = "tournamentBox" onclick="window.location.href='_main page/pojedynczy_turniej/index.html'; saveIdTournament(${tournament.id});"> let htmlSegment = `<div class = "tournamentBox" onclick="window.location.href='../panel_organizatora/edycja turnieju/index.html'; saveIdTournament(${tournament.id});">
<div class="tournamentIconBox"> <div class="tournamentIconBox">
<img class="tournamentIcon" src="_main%20page/cup.svg" alt=""> <img class="tournamentIcon" src="_main%20page/cup.svg" alt="">
</div> </div>
@ -74,7 +79,7 @@ async function renderTournaments(organiserTournament) {
</div> </div>
<input type="image" src="src/trash.svg" class="dots" onclick="tournamentDelete(${tournament.id});location.reload();"/> <input type="image" src="src/trash.svg" class="dots" onclick="tournamentDelete(${tournament.id}); event.stopPropagation();"/>
</div> </div>
` `

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paddle tournament system</title> <title>Padle tournament system</title>
<link href="style.css" rel="stylesheet"> <link href="style.css" rel="stylesheet">
</head> </head>

View File

@ -27,8 +27,33 @@
// '","category":"' + "cat1" + // '","category":"' + "cat1" +
// '","}'); // '","}');
// }); // });
function checkCheckBox() {
let checkBox = document.getElementById("checkBox");
if (checkBox.checked == true) {
return ("TRUE")
}
else {
return ("FALSE")
}
}
function checkRankingBox() {
let checkBox = document.getElementById("checkBoxRanking");
if (checkBox.checked == true) {
return ("1")
}
else {
return ("0")
}
}
function createTournament() { function createTournament() {
let rankingChecker = checkRankingBox();
console.log(rankingChecker)
let checker = checkCheckBox();
console.log(checker)
fetch('https://dragonmaster.pl/inz/tournament', { fetch('https://dragonmaster.pl/inz/tournament', {
method: "PUT", method: "PUT",
headers: { headers: {
@ -40,9 +65,9 @@ function createTournament() {
"name": document.getElementById("name").value, "name": document.getElementById("name").value,
"typeOfLadder": "string", "typeOfLadder": "string",
"pointsForTournament": "1", "pointsForTournament": "1",
"places": "1", "places": "12",
"roles": "role", "roles": "role",
"ranked": document.getElementById("rank").value, "ranked": rankingChecker,
"place": document.getElementById("place").value, "place": document.getElementById("place").value,
"from": document.getElementById("term_from").value, "from": document.getElementById("term_from").value,
"to": document.getElementById("term_to").value, "to": document.getElementById("term_to").value,
@ -53,14 +78,17 @@ function createTournament() {
"entriesTo": document.getElementById("entries").value, "entriesTo": document.getElementById("entries").value,
"additionalInformations": document.getElementById("add-info").value, "additionalInformations": document.getElementById("add-info").value,
"categotry": document.getElementById("category").value, "categotry": document.getElementById("category").value,
"visibility": "TRUE" "visibility": checker
} }
) )
} }
) )
.then(res => res.json()) .then(res => res.json())
.then(data => console.log(data)) .then(data => {
console.log(data)
window.location.href = '../../normal_user/index.html'
})
.catch(error => console.log(error)) .catch(error => console.log(error))
} }

View File

@ -99,7 +99,7 @@
Widoczność turnieju Widoczność turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%"> <div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" /> <input type="checkbox" id="checkBox" />
<div class="state p-success"> <div class="state p-success">
<label></label> <label></label>
</div> </div>
@ -111,7 +111,7 @@
<div class="pretty p-switch p-fill" style="margin-left: 5%"> <div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" /> <input type="checkbox" id="checkBoxRanking" />
<div class="state p-success"> <div class="state p-success">
<label></label> <label></label>
</div> </div>

View File

@ -27,8 +27,33 @@
// '","category":"' + "cat1" + // '","category":"' + "cat1" +
// '","}'); // '","}');
// }); // });
function checkCheckBox() {
let checkBox = document.getElementById("checkBox");
if (checkBox.checked == true) {
return ("TRUE")
}
else {
return ("FALSE")
}
}
function checkRankingBox() {
let checkBox = document.getElementById("checkBoxRanking");
if (checkBox.checked == true) {
return ("1")
}
else {
return ("0")
}
}
function createTournament() { function createTournament() {
let rankingChecker = checkRankingBox();
console.log(rankingChecker)
let checker = checkCheckBox();
console.log(checker)
fetch('https://dragonmaster.pl/inz/tournament', { fetch('https://dragonmaster.pl/inz/tournament', {
method: "POST", method: "POST",
headers: { headers: {
@ -52,7 +77,7 @@ function createTournament() {
"entriesTo": document.getElementById("entries").value, "entriesTo": document.getElementById("entries").value,
"additionalInformations": document.getElementById("add-info").value, "additionalInformations": document.getElementById("add-info").value,
"categotry": document.getElementById("category").value, "categotry": document.getElementById("category").value,
"visibility": "TRUE" "visibility": checker
} }
) )
} }

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html" <html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html"
xmlns="http://www.w3.org/1999/html"> xmlns="http://www.w3.org/1999/html">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -9,20 +9,20 @@
<title>Padel Tournaments System</title> <title>Padel Tournaments System</title>
<link href="style.css" rel="stylesheet"> <link href="style.css" rel="stylesheet">
<script type="text/javascript" src="app.js"></script> <script type="text/javascript" src="app.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css" />
</head> </head>
<body onload="logoutVisibility(); loginVisibility()"> <body onload="logoutVisibility(); loginVisibility()">
<header> <header>
<div class="logoBox"> <div class="logoBox">
<a class="header_link" href="../../normal_user/index.html"><img class="logo" src="../../_global/logo.svg" <a class="header_link" href="../../normal_user/index.html"><img class="logo" src="../../_global/logo.svg"
alt="Logo error"></a> alt="Logo error"></a>
</div> </div>
<div class="linkBox"> <div class="linkBox">
<!-- <span class="dot">JM</span>--> <!-- <span class="dot">JM</span>-->
<button class="loginButton" type="submit" onclick="window.location.href='../../normal_user/logowanie/index.html'" <button class="loginButton" type="submit"
id="login">LOGOWANIE</button> onclick="window.location.href='../../normal_user/logowanie/index.html'" id="login">LOGOWANIE</button>
<button class="loginButton" id="logout" onclick="logout()">Wyloguj</button> <button class="loginButton" id="logout" onclick="logout()">Wyloguj</button>
<a class="header_link" href="../../normal_user/kontakt/index.html">Kontakt</a> <a class="header_link" href="../../normal_user/kontakt/index.html">Kontakt</a>
@ -42,7 +42,8 @@
<ul> <ul>
<li><a href="#">Informacje</a></li> <li><a href="#">Informacje</a></li>
<li><a href="../../normal_user/_main%20page/pojedynczy_turniej/zapisy/index.html">Zapisy</a></li> <li><a href="../../normal_user/_main%20page/pojedynczy_turniej/zapisy/index.html">Zapisy</a></li>
<li><a href="../../normal_user/_main%20page/pojedynczy_turniej/drabinka/index.html">Drabinka</a></li> <li><a href="../../normal_user/_main%20page/pojedynczy_turniej/drabinka/index.html">Drabinka</a>
</li>
<li><a href="#">Wyniki</a></li> <li><a href="#">Wyniki</a></li>
</ul> </ul>
</nav> </nav>
@ -64,7 +65,7 @@
<input id="term_to"> <input id="term_to">
</label> </label>
<h3 class="descriptor">Miejsce</h3> <h3 class="descriptor">Miejsc</h3>
<label> <label>
<input id="place"> <input id="place">
</label> </label>
@ -111,19 +112,7 @@
Widoczność turnieju Widoczność turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%"> <div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" /> <input type="checkbox" id="checkBox" />
<div class="state p-success">
<label></label>
</div>
</div>
</div>
<div class="binaryButtonsBox2">
Rankingowość turnieju
<div class="pretty p-switch p-fill" style="margin-left: 5%">
<input type="checkbox" />
<div class="state p-success"> <div class="state p-success">
<label></label> <label></label>
</div> </div>
@ -134,7 +123,7 @@
<button class="cancelButton" type="button" id="cancel" onclick="">Anuluj</button> <button class="cancelButton" type="button" id="cancel" onclick="">Anuluj</button>
<button class="submitButton" type="submit" id="tournamentsubmit" onclick="createTournament()"> <button class="submitButton" type="submit" id="tournamentsubmit" onclick="createTournament()">
Załóż turniej Edytuj turniej
</button> </button>
</div> </div>