2022-06-08 22:33:19 +02:00
|
|
|
async function showTournaments() {
|
|
|
|
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
|
|
|
function saveIdTournament(id) {
|
|
|
|
localStorage.setItem('tournamentId', id);
|
|
|
|
}
|
|
|
|
|
2022-06-17 13:45:32 +02:00
|
|
|
function checkRoleCreator() {
|
|
|
|
fetch('https://dragonmaster.pl/inz/user', {
|
|
|
|
headers: {
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
2022-06-18 14:35:43 +02:00
|
|
|
let organiser = (json['id'])
|
|
|
|
renderTournaments(organiser)
|
2022-06-17 13:45:32 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
function tournamentDelete(id) {
|
2022-06-19 09:34:23 +02:00
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
console.log(id)
|
2022-06-19 09:34:23 +02:00
|
|
|
let textId = id.toString()
|
|
|
|
console.log(textId)
|
2022-06-18 14:35:43 +02:00
|
|
|
fetch('https://dragonmaster.pl/inz/tournament', {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: {
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
},
|
|
|
|
|
|
|
|
body: JSON.stringify(
|
|
|
|
{
|
2022-06-19 09:34:23 +02:00
|
|
|
"id": textId
|
2022-06-18 14:35:43 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
.then(res => res.json())
|
2022-06-19 09:34:23 +02:00
|
|
|
.then(data => {
|
|
|
|
console.log(data)
|
|
|
|
location.reload()
|
|
|
|
})
|
2022-06-18 14:35:43 +02:00
|
|
|
.catch(error => console.log(error))
|
2022-06-19 09:34:23 +02:00
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function renderTournaments(organiserTournament) {
|
2022-06-08 22:33:19 +02:00
|
|
|
let tournaments = await showTournaments();
|
|
|
|
let html = '';
|
|
|
|
tournaments.forEach(tournament => {
|
2022-06-17 13:45:32 +02:00
|
|
|
// console.log(test)
|
|
|
|
organiser = `${tournament.creator}`;
|
|
|
|
// console.log(organiser)
|
2022-06-18 14:35:43 +02:00
|
|
|
if (organiser == organiserTournament) {
|
2022-06-19 09:34:23 +02:00
|
|
|
let htmlSegment = `<div class = "tournamentBox" onclick="window.location.href='../panel_organizatora/edycja turnieju/index.html'; saveIdTournament(${tournament.id});">
|
2022-06-14 22:51:00 +02:00
|
|
|
<div class="tournamentIconBox">
|
|
|
|
<img class="tournamentIcon" src="_main%20page/cup.svg" alt="">
|
|
|
|
</div>
|
|
|
|
<div class="tournamentDataBox">
|
|
|
|
<div class="tournamentData">
|
|
|
|
<h4>${tournament.name}</h4>
|
|
|
|
${tournament.place}
|
|
|
|
${tournament.from} do ${tournament.to}
|
|
|
|
|
|
|
|
<button class="tournamentOpen">OPEN</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2022-06-19 09:34:23 +02:00
|
|
|
<input type="image" src="src/trash.svg" class="dots" onclick="tournamentDelete(${tournament.id}); event.stopPropagation();"/>
|
2022-06-18 14:35:43 +02:00
|
|
|
|
2022-06-08 22:33:19 +02:00
|
|
|
</div>
|
2022-06-18 14:35:43 +02:00
|
|
|
`
|
2022-06-17 13:45:32 +02:00
|
|
|
html += htmlSegment;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let htmlSegment = `<div class = "tournamentBox" onclick="window.location.href='_main page/pojedynczy_turniej/index.html'; saveIdTournament(${tournament.id});">
|
|
|
|
<div class="tournamentIconBox">
|
|
|
|
<img class="tournamentIcon" src="_main%20page/cup.svg" alt="">
|
|
|
|
</div>
|
|
|
|
<div class="tournamentDataBox">
|
|
|
|
<div class="tournamentData">
|
|
|
|
<h4>${tournament.name}</h4>
|
|
|
|
${tournament.place}
|
|
|
|
${tournament.from} do ${tournament.to}
|
|
|
|
|
|
|
|
<button class="tournamentOpen">OPEN</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
html += htmlSegment;
|
|
|
|
}
|
2022-06-08 22:33:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let container = document.querySelector('.tournament-list');
|
|
|
|
container.innerHTML = html;
|
|
|
|
}
|
2022-06-10 12:23:44 +02:00
|
|
|
|
2022-06-17 13:45:32 +02:00
|
|
|
|
2022-06-10 12:23:44 +02:00
|
|
|
function logout() {
|
2022-06-19 22:40:31 +02:00
|
|
|
localStorage.removeItem('token');
|
2022-06-10 12:23:44 +02:00
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function logoutVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("logout").style.display = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("logout").style.display = "none";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loginVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("login").style.display = "none";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("login").style.display = "";
|
|
|
|
|
2022-06-10 15:33:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 13:11:09 +02:00
|
|
|
|
|
|
|
function checkRole() {
|
2022-06-10 15:33:05 +02:00
|
|
|
if (localStorage.getItem("token") !== null) {
|
2022-06-14 13:11:09 +02:00
|
|
|
|
|
|
|
fetch('https://dragonmaster.pl/inz/user', {
|
|
|
|
headers: {
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
|
|
|
if (json['role'] == '1') {
|
|
|
|
document.getElementById("creator").style.display = "none";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("creator").style.display = '';
|
|
|
|
}
|
|
|
|
})
|
2022-06-10 15:33:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-06-14 13:11:09 +02:00
|
|
|
document.getElementById("creator").style.display = "none";
|
2022-06-10 12:23:44 +02:00
|
|
|
}
|
2022-06-14 13:11:09 +02:00
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
}
|