merge
This commit is contained in:
@ -3,6 +3,10 @@ import { Tourmanent } from "../../api/tournament/Tournament.js";
|
||||
import {client, navigateTo} from "../../index.js";
|
||||
import AbstractAuthenticatedView from "../abstracts/AbstractAuthenticatedView.js";
|
||||
|
||||
const TEXT_CONVENTION = {
|
||||
"error": "[ERROR]"
|
||||
}
|
||||
|
||||
export default class extends AbstractAuthenticatedView
|
||||
{
|
||||
constructor(params)
|
||||
@ -13,44 +17,49 @@ export default class extends AbstractAuthenticatedView
|
||||
|
||||
pressButton()
|
||||
{
|
||||
this.tournament.toggle_participation();
|
||||
this.tournament.setParticipation(!this.tournament.isParticipating);
|
||||
this.updateParticipating()
|
||||
}
|
||||
|
||||
async receive(data)
|
||||
updateParticipating()
|
||||
{
|
||||
if (data.detail === "update_participants")
|
||||
document.getElementById("nb_participants").innerText = `${data.participants} / ${this.tournament.nb_participants}`;
|
||||
if (data.detail === "go_to")
|
||||
navigateTo(data.url);
|
||||
if (data.detail === "is_participant")
|
||||
this.updateParticipating(data.is_participant);
|
||||
if (data.detail === "error")
|
||||
document.getElementById("display").innerText = data.error_message;
|
||||
}
|
||||
|
||||
async updateParticipating(state)
|
||||
{
|
||||
document.getElementById("button").value = state ? `Leave ${this.tournament.name}` : `Join ${this.tournament.name}`;
|
||||
document.getElementById("display").innerText = state ? "You are a particpant" : "You are not a participant";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {[Profile]} oldParticipantsList
|
||||
* @param {[Profile]} currentParticipantsList
|
||||
*/
|
||||
async onParticipantsUpdate(oldParticipantsList, currentParticipantsList)
|
||||
{
|
||||
|
||||
document.getElementById("button").value = this.tournament.isParticipating ? `Leave ${this.tournament.name}` : `Join ${this.tournament.name}`;
|
||||
document.getElementById("display").innerText = this.tournament.isParticipating ? "You are a particpant" : "You are not a participant";
|
||||
}
|
||||
|
||||
async onDisconnect(event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
async onError(data)
|
||||
{
|
||||
this.addChatMessage(`${TEXT_CONVENTION} data.error_message`);
|
||||
}
|
||||
|
||||
async onFinish()
|
||||
{
|
||||
document.getElementById("state").innerText = "finished"
|
||||
}
|
||||
|
||||
async onStart()
|
||||
{
|
||||
document.getElementById("state").innerText = "started"
|
||||
}
|
||||
|
||||
async onGoTo(data)
|
||||
{
|
||||
await navigateTo(`/games/pong/${data.game_id}`)
|
||||
}
|
||||
|
||||
async onAddParticipant(nb_participants)
|
||||
{
|
||||
document.getElementById("nb_participants").innerText = nb_participants;
|
||||
}
|
||||
|
||||
async onDelParticipant(nb_participants)
|
||||
{
|
||||
document.getElementById("nb_participants").innerText = nb_participants;
|
||||
}
|
||||
|
||||
async postInit()
|
||||
@ -63,25 +72,32 @@ export default class extends AbstractAuthenticatedView
|
||||
if (this.tournament === null)
|
||||
return 404;
|
||||
|
||||
this.tournament.join(this.onParticipantsUpdate.bind(this), this.onError.bind(this), this.onDisconnect.bind(this));
|
||||
this.tournament.join(this.onAddParticipant, this.onDelParticipant, this.onStart, this.onFinish, this.onError, this.onGoTo, this.onDisconnect);
|
||||
|
||||
let button = document.getElementById("button");
|
||||
|
||||
button.onclick = this.pressButton.bind(this);
|
||||
|
||||
document.getElementById("name").innerText = this.tournament.name;
|
||||
document.getElementById("nb_participants").innerText = this.tournament.nb_participants;
|
||||
document.getElementById("nb_participants").innerText = this.tournament.participantList.length;
|
||||
document.getElementById("expected_nb_participants").innerText = this.tournament.nb_participants;
|
||||
document.getElementById("round").innerText = this.tournament.round;
|
||||
document.getElementById("state").innerText = this.tournament.state;
|
||||
|
||||
if (this.tournament.started === false)
|
||||
button.disabled = false;
|
||||
|
||||
console.log(this.tournament);
|
||||
this.chat = document.getElementById("chat");
|
||||
|
||||
console.log(this.tournament);
|
||||
this.display_tree_tournament(this.tournament.nb_participants, this.tournament.participantList);
|
||||
}
|
||||
|
||||
addChatMessage(message)
|
||||
{
|
||||
this.chat.innerText += message;
|
||||
}
|
||||
|
||||
async display_tree_tournament(nb_participants, participants) {
|
||||
const svg = document.getElementById('tree');
|
||||
|
||||
@ -137,15 +153,25 @@ export default class extends AbstractAuthenticatedView
|
||||
<td id="nb_participants">Loading...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>status</td>
|
||||
<td>Expected number of participants</td>
|
||||
<td id="expected_nb_participants">Loading...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>state</td>
|
||||
<td id="state">Loading...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="button" id="button" value="Join tournament" disabled>
|
||||
<<<<<<< HEAD
|
||||
<br>
|
||||
<svg id="tree" height="3000" width="3000">
|
||||
</svg>
|
||||
=======
|
||||
<span id="display"></span>
|
||||
<textarea id="chat" rows="4" cols="50" readonly>
|
||||
</textarea>
|
||||
>>>>>>> 55d29d5763f22f136d2b4bae6464463acb514a5c
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user