feat: Wyświetlanie usuwania tylko dla organizatora danego turnieju

This commit is contained in:
Arek 2022-06-17 13:45:32 +02:00
parent 411a03501c
commit d8b0af0461
4 changed files with 63 additions and 22 deletions

View File

@ -10,23 +10,20 @@ async function showTournaments() {
}
}
// async function renderTournaments() {
// let tournaments = await showTournaments();
// let html = '';
// tournaments[1]; (tournament => {
// let htmlSegment = `<h1>${tournament.id}</h2>`;
// html += htmlSegment;
// });
// let container = document.querySelector('.form');
// container.innerHTML = html;
// }
async function renderTournaments() {
let tournaments = await showTournaments();
let html = '';
let htmlDate = '';
tournaments.forEach(tournament => {
if (`${tournament.id}` == localStorage.getItem("tournamentId")) {
htmlDate = `
<h1 class="tournamentInfo">${tournament.name}</h1>
<h2 class="tournamentInfo">${tournament.places}</br>
${tournament.from} do ${tournament.to}</h2>`
let htmlSegment = `
<h1> ${tournament.name}</h1>
<h2>${tournament.places}</h2>
@ -57,6 +54,9 @@ async function renderTournaments() {
}
});
let date = document.querySelector('.tournamentData')
date.innerHTML = htmlDate;
let container = document.querySelector('.form');
container.innerHTML = html;
}

View File

@ -35,9 +35,7 @@
<div class="tournamentDataBox">
<div class="tournamentData">
<h1 class="tournamentInfo">Turniej majowy 2022</h1>
<h2 class="tournamentInfo">Propadel, Warszawa </br>
13/05/2022 do 15/05/2022</h2>
</div>
</div>

View File

@ -12,10 +12,29 @@ function saveIdTournament(id) {
localStorage.setItem('tournamentId', id);
}
async function renderTournaments() {
function checkRoleCreator() {
fetch('https://dragonmaster.pl/inz/user', {
headers: {
Authorization: ("Bearer " + localStorage.getItem("token"))
}
})
.then(res => res.json())
.then(json => {
let test = (json['id'])
renderTournaments(test)
})
}
async function renderTournaments(test) {
let tournaments = await showTournaments();
let html = '';
tournaments.forEach(tournament => {
// console.log(test)
organiser = `${tournament.creator}`;
console.log(organiser)
// console.log(organiser)
if (organiser == test) {
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="">
@ -31,16 +50,40 @@ async function renderTournaments() {
</div>
<img class="dots" src="src/trash.svg">
<img class="dots" id="deleteMatch" src="src/trash.svg">
</div>
`;
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;
}
});
let container = document.querySelector('.tournament-list');
container.innerHTML = html;
}
function checkRoleforDelete() {
}
function logout() {
localStorage.clear();
location.reload();

View File

@ -10,15 +10,15 @@
<script type="text/javascript" src="app.js"></script>
</head>
<body onload="renderTournaments();logoutVisibility(); loginVisibility(); checkRole();">
<body onload="renderTournaments();logoutVisibility(); loginVisibility(); checkRole(); checkRoleCreator();">
<header>
<div class="logoBox">
<a class="header_link" href="./index.html"><img class="logo" src="../_global/logo.svg" alt="Logo error"></a>
</div>
<div class="linkBox">
<!-- <span class="dot">JM</span>-->
<button class="loginButton" type="submit"
onclick="window.location.href='logowanie/index.html'" id="login">LOGOWANIE</button>
<button class="loginButton" type="submit" onclick="window.location.href='logowanie/index.html'"
id="login">LOGOWANIE</button>
<button class="loginButton" id="logout" onclick="logout()">Wyloguj</button>
<a class="header_link" href="kontakt/index.html">Kontakt</a>