2022-06-14 08:46:41 +02:00
|
|
|
let tourId = localStorage.getItem("myElement")
|
|
|
|
|
|
|
|
async function showTournaments() {
|
2022-06-10 15:33:05 +02:00
|
|
|
let url = 'https://dragonmaster.pl/inz/tournaments';
|
|
|
|
try {
|
|
|
|
let res = await fetch(url);
|
|
|
|
return await res.json();
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2022-06-14 08:46:41 +02:00
|
|
|
}
|
2022-06-20 01:03:31 +02:00
|
|
|
function checkId() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
|
|
|
|
fetch('https://dragonmaster.pl/inz/user', {
|
|
|
|
headers: {
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
|
|
|
return (json['id'])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("creator").style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkOwner() {
|
|
|
|
if (localStorage.getItem("organisatorId") == checkId()) {
|
|
|
|
console.log("dziaua")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 08:46:41 +02:00
|
|
|
|
2022-06-19 22:50:57 +02:00
|
|
|
function checkRole() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
|
|
|
|
fetch('https://dragonmaster.pl/inz/user', {
|
|
|
|
headers: {
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
2022-06-20 01:03:31 +02:00
|
|
|
if (json['role'] == '1' || json['role'] == '2') {
|
2022-06-19 22:50:57 +02:00
|
|
|
document.getElementById("zapisy").style.display = "none";
|
|
|
|
document.getElementById("drabinka").style.display = "none";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("zapisy").style.display = '';
|
|
|
|
document.getElementById("drabinka").style.display = '';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("zapisy").style.display = "none";
|
|
|
|
document.getElementById("drabinka").style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-19 10:11:28 +02:00
|
|
|
function logout() {
|
2022-06-19 13:14:20 +02:00
|
|
|
localStorage.removeItem('token');
|
2022-06-19 10:11:28 +02:00
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function logoutVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("logout").style.display = "";
|
2022-06-19 13:14:20 +02:00
|
|
|
document.getElementById("saverForTournament").style.display = "";
|
2022-06-19 10:11:28 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("logout").style.display = "none";
|
2022-06-19 13:14:20 +02:00
|
|
|
document.getElementById("saverForTournament").style.display = "none";
|
2022-06-19 10:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-19 09:34:23 +02:00
|
|
|
function loginVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("login").style.display = "none";
|
2022-06-19 13:14:20 +02:00
|
|
|
document.getElementById("saverForTournament").style.display = "";
|
2022-06-19 09:34:23 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("login").style.display = "";
|
2022-06-19 13:14:20 +02:00
|
|
|
document.getElementById("saverForTournament").style.display = "none";
|
2022-06-19 09:34:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 10:11:28 +02:00
|
|
|
|
2022-06-14 08:46:41 +02:00
|
|
|
async function renderTournaments() {
|
2022-06-10 15:33:05 +02:00
|
|
|
let tournaments = await showTournaments();
|
2022-06-14 08:46:41 +02:00
|
|
|
let html = '';
|
2022-06-17 13:45:32 +02:00
|
|
|
let htmlDate = '';
|
2022-06-14 08:46:41 +02:00
|
|
|
tournaments.forEach(tournament => {
|
2022-06-19 09:34:23 +02:00
|
|
|
let rank = 0
|
|
|
|
if (`${tournament.approved}` == 0) {
|
|
|
|
rank = "Nie"
|
|
|
|
}
|
|
|
|
else if (`${tournament.approved}` == 1) {
|
|
|
|
rank = "Tak, ale niezatwierdzony"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rank = "Tak"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-14 08:46:41 +02:00
|
|
|
if (`${tournament.id}` == localStorage.getItem("tournamentId")) {
|
2022-06-17 13:45:32 +02:00
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
console.log(`${tournament.rang}`)
|
|
|
|
|
2022-06-17 13:45:32 +02:00
|
|
|
htmlDate = `
|
|
|
|
<h1 class="tournamentInfo">${tournament.name}</h1>
|
2022-06-19 13:14:20 +02:00
|
|
|
<h2 class="tournamentInfo">Miejsce: ${tournament.place}</br>
|
2022-06-17 13:45:32 +02:00
|
|
|
${tournament.from} do ${tournament.to}</h2>`
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-14 08:46:41 +02:00
|
|
|
let htmlSegment = `
|
|
|
|
<h1> ${tournament.name}</h1>
|
2022-06-19 13:14:20 +02:00
|
|
|
<h2>Miejsce: ${tournament.place}</h2>
|
2022-06-14 08:46:41 +02:00
|
|
|
|
|
|
|
<h3 class="descriptor">Wpisowe:</h3>
|
|
|
|
${tournament.entryFee}
|
|
|
|
|
|
|
|
<h3 class="descriptor">Ranga:</h3>
|
|
|
|
${tournament.rang}
|
|
|
|
|
|
|
|
<h3 class="descriptor">Kategorie:</h3>
|
|
|
|
${tournament.categotry}
|
|
|
|
|
|
|
|
<h3 class="descriptor">Zapisy do:</h3>
|
|
|
|
${tournament.to}
|
|
|
|
|
|
|
|
<h3 class="descriptor">Czy rankingowy:</h3>
|
2022-06-19 09:34:23 +02:00
|
|
|
${rank}
|
2022-06-14 08:46:41 +02:00
|
|
|
|
|
|
|
<h3 class="descriptor">Dyrektor turnieju:</h3>
|
|
|
|
${tournament.director}
|
|
|
|
|
|
|
|
<h3 class="descriptor">Dodatkowe informacje</h3>
|
|
|
|
${tournament.additionalInformations}
|
|
|
|
|
|
|
|
`;
|
|
|
|
html += htmlSegment;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-17 13:45:32 +02:00
|
|
|
let date = document.querySelector('.tournamentData')
|
|
|
|
date.innerHTML = htmlDate;
|
|
|
|
|
2022-06-14 08:46:41 +02:00
|
|
|
let container = document.querySelector('.form');
|
|
|
|
container.innerHTML = html;
|
|
|
|
}
|