clean: respect es11

This commit is contained in:
starnakin 2024-02-20 09:22:11 +01:00
parent 54ef19a340
commit c143d96443
36 changed files with 163 additions and 163 deletions

3
.jshintrc Normal file
View File

@ -0,0 +1,3 @@
{
"esversion": 11
}

View File

@ -1,11 +1,11 @@
import { reloadView } from '../index.js' import { reloadView } from '../index.js';
export default class LanguageManager { export default class LanguageManager {
constructor() { constructor() {
this.availableLanguages = ['en', 'fr', 'tp', 'cr']; this.availableLanguages = ['en', 'fr', 'tp', 'cr'];
this.dict = null; this.dict = null;
this.currentLang = 'en' this.currentLang = 'en';
this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang; this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang;
if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) { if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) {
this.loading = this.translatePage(); this.loading = this.translatePage();
@ -28,7 +28,7 @@ export default class LanguageManager {
document.querySelectorAll('[data-i18n]').forEach(el => { document.querySelectorAll('[data-i18n]').forEach(el => {
let key = el.getAttribute('data-i18n'); let key = el.getAttribute('data-i18n');
el.innerHTML = this.dict[key]; el.innerHTML = this.dict[key];
}) });
await reloadView(); await reloadView();
return 0; return 0;

View File

@ -9,7 +9,7 @@ class MyProfile extends Profile
*/ */
constructor (client) constructor (client)
{ {
super(client, "../me") super(client, "../me");
} }
/** /**
@ -20,11 +20,11 @@ class MyProfile extends Profile
async change_avatar(form_data) async change_avatar(form_data)
{ {
let response = await this.client._patch_file(`/api/profiles/settings`, form_data); let response = await this.client._patch_file(`/api/profiles/settings`, form_data);
let response_data = await response.json() let response_data = await response.json();
return response_data; return response_data;
} }
} }
export {MyProfile} export {MyProfile};

View File

@ -86,4 +86,4 @@ class Account
} }
} }
export { Account } export { Account };

View File

@ -1,4 +1,4 @@
import {Message} from "./message.js" import {Message} from "./message.js";
class Channel { class Channel {
constructor(client, channel_id, members_id, messages, reload) { constructor(client, channel_id, members_id, messages, reload) {
@ -18,7 +18,7 @@ class Channel {
this.chatSocket = new WebSocket(url); this.chatSocket = new WebSocket(url);
this.chatSocket.onmessage = (event) =>{ this.chatSocket.onmessage = (event) =>{
let data = JSON.parse(event.data) let data = JSON.parse(event.data);
this.messages.push(new Message( this.messages.push(new Message(
this.channel_id, this.channel_id,
@ -41,12 +41,12 @@ class Channel {
let new_messages = []; let new_messages = [];
messages.forEach((message) => { messages.forEach((message) => {
message = message["fields"]; message = message.fields;
new_messages.push(new Message( new_messages.push(new Message(
message["channel_id"], message.channel_id,
message["author_id"], message.author_id,
message["content"], message.content,
message["time"], message.time,
)); ));
}); });
@ -80,4 +80,4 @@ class Channel {
} }
export {Channel} export {Channel};

View File

@ -1,4 +1,4 @@
import {Channel} from "./channel.js" import {Channel} from "./channel.js";
class Channels { class Channels {
constructor(client) { constructor(client) {
@ -17,7 +17,7 @@ class Channels {
let data = await response.json(); let data = await response.json();
let messages = undefined; let messages;
if (response.status == 200) if (response.status == 200)
messages = data.messages; messages = data.messages;
@ -31,10 +31,9 @@ class Channels {
}); });
let data = await response.json(); let data = await response.json();
console.log(response.status)
return data; return data;
} }
} }
export {Channels} export {Channels};

View File

@ -7,4 +7,4 @@ class Message {
} }
} }
export {Message} export {Message};

View File

@ -30,11 +30,11 @@ class Notice {
console.log("receive_" + send.type + ": Function not found"); console.log("receive_" + send.type + ": Function not found");
} }
} };
this.chatSocket.onopen = (event) => { this.chatSocket.onopen = (event) => {
this.getOnlineUser(); this.getOnlineUser();
this.ask_friend(); this.ask_friend();
} };
} }
async disconnect() { async disconnect() {
@ -60,8 +60,8 @@ class Notice {
async receive_accept_invite(send) { async receive_accept_invite(send) {
this.data["invited"] = send.invites; this.data.invited = send.invites;
let id_game = send["id_game"]; let id_game = send.id_game;
navigateTo("/game/" + id_game); navigateTo("/game/" + id_game);
} }
@ -77,7 +77,7 @@ class Notice {
} }
async receive_refuse_invite(send) { async receive_refuse_invite(send) {
this.data["invited"] = send.invites; this.data.invited = send.invites;
if (send.author_id == this.client.me.id) { if (send.author_id == this.client.me.id) {
if (this.rewrite_invite !== undefined) if (this.rewrite_invite !== undefined)
@ -123,10 +123,10 @@ class Notice {
// Regarder qu'il est bien invité par l'auteur // Regarder qu'il est bien invité par l'auteur
// Et qu'il n'est pas déjà invité // Et qu'il n'est pas déjà invité
if (!content.includes(send.author_id) || if (!content.includes(send.author_id) ||
this.data["invited"].includes(send.author_id)) this.data.invited.includes(send.author_id))
return; return;
this.data["invited"] = content; this.data.invited = content;
let sender = await this.client.profiles.getProfileId(send.author_id); let sender = await this.client.profiles.getProfileId(send.author_id);
create_popup("Invitation received by " + sender.username); create_popup("Invitation received by " + sender.username);
@ -152,24 +152,24 @@ class Notice {
let content = send.online; let content = send.online;
if (content !== undefined) { if (content !== undefined) {
if (this.data["online"].length > 0) { if (this.data.online.length > 0) {
// get all disconnect user // get all disconnect user
//let disconnects = this.data["online"].filter(id => !Object.keys(content).includes(id)); //let disconnects = this.data["online"].filter(id => !Object.keys(content).includes(id));
let disconnects = []; let disconnects = [];
for (const [key, value] of Object.entries(this.data["online"])) { for (const [key, value] of Object.entries(this.data.online)) {
if (content[key] == "red" && value == "green") if (content[key] == "red" && value == "green")
disconnects.push(key); disconnects.push(key);
} }
// delete invite // delete invite
this.data["invited"] = this.data["invited"].filter(id => !disconnects.includes(id)); this.data.invited = this.data.invited.filter(id => !disconnects.includes(id));
//console.log(this.data["invited"]); //console.log(this.data["invited"]);
} }
this.data["online"] = content; this.data.online = content;
if (this.rewrite_usernames !== undefined) if (this.rewrite_usernames !== undefined)
this.rewrite_usernames(); this.rewrite_usernames();
@ -202,12 +202,12 @@ class Notice {
//this.data["asker"].includes(send.author_id)) //this.data["asker"].includes(send.author_id))
//return; //return;
this.data["asked"] = send.asked; this.data.asked = send.asked;
this.data["asker"] = send.asker; this.data.asker = send.asker;
if (send.author_id != my_id) { if (send.author_id != my_id) {
let sender = await this.client.profiles.getProfileId(send.author_id); let sender = await this.client.profiles.getProfileId(send.author_id);
if (this.data["asker"].includes(send.author_id)) if (this.data.asker.includes(send.author_id))
create_popup(sender.username + " ask you as friend"); create_popup(sender.username + " ask you as friend");
if (this.rewrite_profile !== undefined) if (this.rewrite_profile !== undefined)
await this.rewrite_profile(); await this.rewrite_profile();
@ -248,8 +248,8 @@ class Notice {
} }
async receive_accept_friend(send) { async receive_accept_friend(send) {
this.data["asked"] = send.asked; this.data.asked = send.asked;
this.data["asker"] = send.asker; this.data.asker = send.asker;
let sender = await this.client.profiles.getProfileId(send.author_id); let sender = await this.client.profiles.getProfileId(send.author_id);
if (send.author_id == this.client.me.id) { if (send.author_id == this.client.me.id) {
@ -279,8 +279,8 @@ class Notice {
} }
async receive_refuse_friend(send) { async receive_refuse_friend(send) {
this.data["asked"] = send.asked; this.data.asked = send.asked;
this.data["asker"] = send.asker; this.data.asker = send.asker;
let sender = await this.client.profiles.getProfileId(send.author_id); let sender = await this.client.profiles.getProfileId(send.author_id);
if (send.author_id == this.client.me.id) { if (send.author_id == this.client.me.id) {
@ -304,4 +304,4 @@ class Notice {
} }
} }
export {Notice} export {Notice};

View File

@ -3,11 +3,11 @@ import { MatchMaking } from "./matchmaking.js";
import { Profiles } from "./profiles.js"; import { Profiles } from "./profiles.js";
import { Channels } from './chat/channels.js'; import { Channels } from './chat/channels.js';
import { MyProfile } from "./MyProfile.js"; import { MyProfile } from "./MyProfile.js";
import { navigateTo } from "../index.js" import { navigateTo } from "../index.js";
import { Tourmanents } from "./tournament/tournaments.js"; import { Tourmanents } from "./tournament/tournaments.js";
import {Notice} from "./chat/notice.js" import {Notice} from "./chat/notice.js";
import { Channel } from "./chat/channel.js"; import { Channel } from "./chat/channel.js";
import LanguageManager from './LanguageManager.js' import LanguageManager from './LanguageManager.js';
function getCookie(name) function getCookie(name)
{ {
@ -15,7 +15,7 @@ function getCookie(name)
document.cookie.split(';').forEach(function(el) { document.cookie.split(';').forEach(function(el) {
let split = el.split('='); let split = el.split('=');
cookie[split[0].trim()] = split.slice(1).join("="); cookie[split[0].trim()] = split.slice(1).join("=");
}) });
return cookie[name]; return cookie[name];
} }
@ -72,7 +72,7 @@ class Client
*/ */
this.notice = new Notice(this); this.notice = new Notice(this);
this.lang = new LanguageManager; this.lang = new LanguageManager();
} }
@ -218,7 +218,7 @@ class Client
*/ */
async login(username, password) async login(username, password)
{ {
let response = await this._post("/api/accounts/login", {username: username, password: password}) let response = await this._post("/api/accounts/login", {username: username, password: password});
if (response.status == 200) if (response.status == 200)
await this._update_logged(true); await this._update_logged(true);
@ -244,8 +244,8 @@ class Client
let response = await this._get("/api/accounts/logged"); let response = await this._get("/api/accounts/logged");
await this._update_logged(response.status === 200); await this._update_logged(response.status === 200);
return response.status === 200 return response.status === 200;
} }
} }
export {Client} export {Client};

View File

@ -55,7 +55,7 @@ class Ball
*/ */
render(ctx) render(ctx)
{ {
let distance = this.speed * (this.game.time.deltaTime() / 1000) let distance = this.speed * (this.game.time.deltaTime() / 1000);
this.position.x = this.position.x + distance * Math.cos(this.angle); this.position.x = this.position.x + distance * Math.cos(this.angle);
this.position.y = this.position.y - distance * Math.sin(this.angle); this.position.y = this.position.y - distance * Math.sin(this.angle);
@ -70,8 +70,8 @@ class Ball
this.angle = data.angle; this.angle = data.angle;
this.speed = data.speed; this.speed = data.speed;
return this return this;
} }
} }
export { Ball } export { Ball };

View File

@ -1,6 +1,6 @@
import { sleep } from "../../utils/sleep.js"; import { sleep } from "../../utils/sleep.js";
import { Ball } from "./Ball.js"; import { Ball } from "./Ball.js";
import { GameConfig } from "./GameConfig.js" import { GameConfig } from "./GameConfig.js";
import { Player } from "./Player.js"; import { Player } from "./Player.js";
import { Time } from "./Time.js"; import { Time } from "./Time.js";
import { Wall } from "./Wall.js"; import { Wall } from "./Wall.js";
@ -150,7 +150,7 @@ class Game
if (data.detail === "update_paddle") if (data.detail === "update_paddle")
this._receive_update_paddle(data); this._receive_update_paddle(data);
else if (data.detail === "update_ball") else if (data.detail === "update_ball")
this._receive_ball(data) this._receive_ball(data);
else if (data.detail === "init_game") else if (data.detail === "init_game")
this._init_game(data); this._init_game(data);
} }
@ -160,7 +160,7 @@ class Game
/** /**
* @type {Ball} * @type {Ball}
*/ */
this.ball = (new Ball(this)).from_json(data.ball) this.ball = (new Ball(this)).from_json(data.ball);
/** /**
* @type {[Wall]} * @type {[Wall]}
@ -174,7 +174,7 @@ class Game
/** /**
* @type {[Player]} * @type {[Player]}
*/ */
this.players = [] this.players = [];
const players_data = data.players; const players_data = data.players;
players_data.forEach((player_data) => { players_data.forEach((player_data) => {
this.players.push(new Player(this).from_json(player_data)); this.players.push(new Player(this).from_json(player_data));
@ -216,4 +216,4 @@ class Game
} }
} }
export { Game } export { Game };

View File

@ -1,5 +1,5 @@
import { Player } from "./Player.js"; import { Player } from "./Player.js";
import { Client } from "../client.js" import { Client } from "../client.js";
import { Game } from "./Game.js"; import { Game } from "./Game.js";
import { Segment } from "./Segment.js"; import { Segment } from "./Segment.js";
@ -66,4 +66,4 @@ class MyPlayer extends Player
} }
} }
export { MyPlayer } export { MyPlayer };

View File

@ -115,8 +115,8 @@ class Player
*/ */
this.rail = this.rail.from_json(data.rail); this.rail = this.rail.from_json(data.rail);
return this return this;
} }
} }
export { Player } export { Player };

View File

@ -20,11 +20,11 @@ class Point
from_json(data) from_json(data)
{ {
this.x = data.x this.x = data.x;
this.y = data.y this.y = data.y;
return this return this;
} }
} }
export { Point } export { Point };

View File

@ -1,4 +1,4 @@
import { Point } from "./Point.js" import { Point } from "./Point.js";
class Segment class Segment
{ {
@ -54,4 +54,4 @@ class Segment
} }
} }
export { Segment } export { Segment };

View File

@ -39,4 +39,4 @@ class Time
} }
} }
export { Time } export { Time };

View File

@ -20,10 +20,10 @@ class Wall
from_json(data) from_json(data)
{ {
this.rail = this.rail.from_json(data.rail) this.rail = this.rail.from_json(data.rail);
return this return this;
} }
} }
export { Wall } export { Wall };

View File

@ -10,7 +10,7 @@ class MatchMaking
/** /**
* @type {Client} * @type {Client}
*/ */
this.client = client this.client = client;
this.searching = false; this.searching = false;
} }
@ -56,10 +56,10 @@ class MatchMaking
async stop() async stop()
{ {
if (this._socket) if (this._socket)
this._socket.close() this._socket.close();
this._socket = undefined this._socket = undefined;
this.searching = false; this.searching = false;
} }
} }
export {MatchMaking} export {MatchMaking};

View File

@ -63,16 +63,16 @@ class Profile
let block_response = await this.client._get("/api/profiles/block"); let block_response = await this.client._get("/api/profiles/block");
if (block_response.status != 200) if (block_response.status != 200)
return return;
let block_data = await block_response.json(); let block_data = await block_response.json();
let block_list = JSON.parse(block_data["blockeds"]); let block_list = JSON.parse(block_data.blockeds);
let client_id = block_data["user_id"]; let client_id = block_data.user_id;
block_list.forEach(block => { block_list.forEach(block => {
let blocker = block.fields.blocker; let blocker = block.fields.blocker;
let blocked = block.fields.blocked; let blocked = block.fields.blocked;
if (blocker == client_id && blocked == this.id) if (blocker == client_id && blocked == this.id)
return this.isBlocked = true; return (this.isBlocked = true);
}); });
} }
@ -84,8 +84,8 @@ class Profile
return this.isFriend; return this.isFriend;
let friend_data = await friend_response.json(); let friend_data = await friend_response.json();
let friends_list = friend_data["friends"]; let friends_list = friend_data.friends;
let client_id = friend_data["user_id"]; let client_id = friend_data.user_id;
friends_list.forEach(friend => { friends_list.forEach(friend => {
if (friend == this.id) { if (friend == this.id) {
this.isFriend = true; this.isFriend = true;
@ -97,4 +97,4 @@ class Profile
} }
export {Profile} export {Profile};

View File

@ -10,7 +10,7 @@ class Profiles
/** /**
* @type {Client} client * @type {Client} client
*/ */
this.client = client this.client = client;
} }
/** /**
@ -22,9 +22,9 @@ class Profiles
let response = await this.client._get("/api/profiles/"); let response = await this.client._get("/api/profiles/");
let response_data = await response.json(); let response_data = await response.json();
let profiles = [] let profiles = [];
response_data.forEach((profile) => { response_data.forEach((profile) => {
profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar)) profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar));
}); });
return profiles; return profiles;
} }
@ -85,4 +85,4 @@ class Profiles
} }
} }
export {Profiles} export {Profiles};

View File

@ -65,7 +65,7 @@ class Tourmanent
/** /**
* @type {Number} * @type {Number}
*/ */
this.id = id this.id = id;
/** /**
* @type {Boolean} if a websocket connection is enabled * @type {Boolean} if a websocket connection is enabled
@ -99,16 +99,16 @@ class Tourmanent
leave(event) leave(event)
{ {
if (this.connected == false) if (this.connected == false)
return return;
this.connected = false; this.connected = false;
this._socket.close() this._socket.close();
this.disconnect_func(event); this.disconnect_func(event);
} }
toggle_participation() toggle_participation()
{ {
if (!this.connected) if (!this.connected)
return return;
this._socket.send(JSON.stringify({participate: ""})); this._socket.send(JSON.stringify({participate: ""}));
} }
@ -143,4 +143,4 @@ class Tourmanent
} }
export { Tourmanent } export { Tourmanent };

View File

@ -11,7 +11,7 @@ class Tourmanents
/** /**
* @type {Client} * @type {Client}
*/ */
this.client = client this.client = client;
} }
/** /**
@ -52,7 +52,7 @@ class Tourmanents
async search(state) async search(state)
{ {
let response = await this.client._get(`/api/tournaments/search/${state}`); let response = await this.client._get(`/api/tournaments/search/${state}`);
let response_data = await response.json() let response_data = await response.json();
if (response.status === 403) if (response.status === 403)
{ {
@ -88,4 +88,4 @@ class Tourmanents
} }
export { Tourmanents } export { Tourmanents };

View File

@ -7,7 +7,7 @@ import LogoutView from "./views/accounts/LogoutView.js";
import GameOfflineView from "./views/GameOfflineView.js"; import GameOfflineView from "./views/GameOfflineView.js";
import GameView from "./views/GameView.js"; import GameView from "./views/GameView.js";
import PageNotFoundView from './views/PageNotFoundView.js' import PageNotFoundView from './views/PageNotFoundView.js' ;
import AbstractRedirectView from "./views/abstracts/AbstractRedirectView.js"; import AbstractRedirectView from "./views/abstracts/AbstractRedirectView.js";
import SettingsView from "./views/SettingsView.js"; import SettingsView from "./views/SettingsView.js";
@ -21,8 +21,8 @@ import AuthenticationView from "./views/accounts/AuthenticationView.js";
let client = new Client(location.origin); let client = new Client(location.origin);
let lang = client.lang; let lang = client.lang;
let lastView = undefined; let lastView;
let lastPageUrlBeforeLogin = undefined; let lastPageUrlBeforeLogin;
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$"); const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
@ -52,7 +52,7 @@ const navigateTo = async (uri) => {
const reloadView = async _ => { const reloadView = async _ => {
await lastView?.leavePage(); await lastView?.leavePage();
await renderView(lastView); await renderView(lastView);
} };
async function renderView(view) async function renderView(view)
{ {
@ -61,7 +61,7 @@ async function renderView(view)
return 1; return 1;
view.setTitle(); view.setTitle();
document.querySelector("#app").innerHTML = content document.querySelector("#app").innerHTML = content;
let error_code = await view.postInit(); let error_code = await view.postInit();
@ -129,7 +129,7 @@ const router = async(uri) => {
return 0; return 0;
}; };
window.addEventListener("popstate", function() {router(location.pathname)}); window.addEventListener("popstate", function() {router(location.pathname);});
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
document.body.addEventListener("click", e => { document.body.addEventListener("click", e => {
@ -162,4 +162,4 @@ document.addEventListener("DOMContentLoaded", async () => {
document.querySelector('a[href=\'' + location.pathname + '\']')?.classList.add('active'); document.querySelector('a[href=\'' + location.pathname + '\']')?.classList.add('active');
}); });
export { client, lang, navigateTo, reloadView } export { client, lang, navigateTo, reloadView };

View File

@ -26,13 +26,13 @@ export default class extends AbstractView {
startGame() { startGame() {
if (this.game == null) { if (this.game == null) {
document.getElementById('startGameButton').innerHTML = 'Reset Game'; document.getElementById('startGameButton').innerHTML = 'Reset Game';
this.game = new Game; this.game = new Game();
} }
else { else {
document.getElementById('app').removeChild(this.game.canvas); document.getElementById('app').removeChild(this.game.canvas);
document.getElementById('app').removeChild(this.game.scoresDisplay); document.getElementById('app').removeChild(this.game.scoresDisplay);
this.game.cleanup(); this.game.cleanup();
this.game = new Game; this.game = new Game();
} }
} }

View File

@ -77,7 +77,7 @@ export default class extends AbstractView
async join_game() async join_game()
{ {
await this.game.join() await this.game.join();
let canva = document.createElement("canvas"); let canva = document.createElement("canvas");
@ -100,7 +100,7 @@ export default class extends AbstractView
this.game.players[index] = this.my_player; this.game.players[index] = this.my_player;
} }
this.register_key() this.register_key();
this.render(); this.render();
} }

View File

@ -4,7 +4,7 @@ import AbstractAuthenticatedView from "./abstracts/AbstractAuthenticatedView.js"
export default class extends AbstractAuthenticatedView { export default class extends AbstractAuthenticatedView {
constructor(params) { constructor(params) {
super(params, 'homeWindowTitle'); super(params, 'homeWindowTitle');
this.redirect_url = "/login" this.redirect_url = "/login";
} }
async getHtml() { async getHtml() {

View File

@ -13,23 +13,23 @@ export default class extends AbstractAuthenticatedView {
if (client.matchmaking.searching) if (client.matchmaking.searching)
{ {
client.matchmaking.stop(); client.matchmaking.stop();
document.getElementById("button").value = "Find a game" document.getElementById("button").value = "Find a game";
} }
else else
{ {
let nb_players = document.getElementById("nb_players-input").value let nb_players = document.getElementById("nb_players-input").value;
await client.matchmaking.start(this.onreceive.bind(this), this.ondisconnect.bind(this), nb_players); await client.matchmaking.start(this.onreceive.bind(this), this.ondisconnect.bind(this), nb_players);
document.getElementById("button").value = "Stop matchmaking" document.getElementById("button").value = "Stop matchmaking";
} }
} }
ondisconnect(event) ondisconnect(event)
{ {
if (event.code === 1000) if (event.code === 1000)
clear("innerText", ["detail"]) clear("innerText", ["detail"]);
document.getElementById("button").value = "Find a game" document.getElementById("button").value = "Find a game";
} }
onreceive(data) onreceive(data)
@ -39,7 +39,7 @@ export default class extends AbstractAuthenticatedView {
navigateTo(`/games/${data.game_id}`); navigateTo(`/games/${data.game_id}`);
return; return;
} }
this.display_data(data) this.display_data(data);
} }
display_data(data) display_data(data)
@ -50,7 +50,7 @@ export default class extends AbstractAuthenticatedView {
async postInit() async postInit()
{ {
document.getElementById("button").onclick = this.press_button.bind(this) document.getElementById("button").onclick = this.press_button.bind(this);
} }
async getHtml() { async getHtml() {

View File

@ -1,5 +1,5 @@
import AbstractView from "./abstracts/AbstractView.js"; import AbstractView from "./abstracts/AbstractView.js";
import { lang } from '../index.js' import { lang } from '../index.js';
export default class extends AbstractView { export default class extends AbstractView {
constructor(params) { constructor(params) {

View File

@ -1,5 +1,5 @@
import AbstractView from "./abstracts/AbstractView.js"; import AbstractView from "./abstracts/AbstractView.js";
import { client, lang } from "../index.js" import { client, lang } from "../index.js";
export default class extends AbstractView { export default class extends AbstractView {
constructor(params) { constructor(params) {
@ -37,9 +37,9 @@ export default class extends AbstractView {
client.notice.rewrite_profile = async () => { client.notice.rewrite_profile = async () => {
let result = await this.profile.getFriend(); let result = await this.profile.getFriend();
await this.profile.getBlock() await this.profile.getBlock();
await this.friendButton(); await this.friendButton();
} };
} }
async blockButton() { async blockButton() {
@ -80,7 +80,7 @@ export default class extends AbstractView {
let no = document.getElementById("no") || document.createElement("p"); let no = document.getElementById("no") || document.createElement("p");
let friend = document.getElementById("friend") || document.createElement("p"); let friend = document.getElementById("friend") || document.createElement("p");
if (client.notice.data["asker"].includes(this.user_id)) { if (client.notice.data.asker.includes(this.user_id)) {
if (friend) if (friend)
friend.remove(); friend.remove();
@ -89,13 +89,13 @@ export default class extends AbstractView {
yes.textContent = lang.get('profileAcceptRequest', 'Accept Friend'); yes.textContent = lang.get('profileAcceptRequest', 'Accept Friend');
yes.onclick = async () => { yes.onclick = async () => {
client.notice.accept_friend(this.user_id); client.notice.accept_friend(this.user_id);
} };
no.id = "no"; no.id = "no";
no.textContent = lang.get('profileDenyRequest', 'Decline Friend'); no.textContent = lang.get('profileDenyRequest', 'Decline Friend');
no.onclick = async () => { no.onclick = async () => {
client.notice.refuse_friend(this.user_id); client.notice.refuse_friend(this.user_id);
} };
this.info.appendChild(yes); this.info.appendChild(yes);
this.info.appendChild(document.createTextNode(" ")); this.info.appendChild(document.createTextNode(" "));
@ -107,7 +107,7 @@ export default class extends AbstractView {
if (yes && no) if (yes && no)
yes.remove(); no.remove(); yes.remove(); no.remove();
friend.id = "friend" friend.id = "friend";
friend.onclick = async () => { friend.onclick = async () => {
if (this.profile.isFriend) if (this.profile.isFriend)
await client.notice.remove_friend(this.user_id); await client.notice.remove_friend(this.user_id);

View File

@ -1,6 +1,6 @@
import AbstractView from "./abstracts/AbstractView.js"; import AbstractView from "./abstracts/AbstractView.js";
import { client, lang } from "../index.js"; import { client, lang } from "../index.js";
import {Message} from "../api/chat/message.js" import {Message} from "../api/chat/message.js";
export default class extends AbstractView { export default class extends AbstractView {
constructor(params) { constructor(params) {
@ -10,8 +10,8 @@ export default class extends AbstractView {
async wait_get_online_users() { async wait_get_online_users() {
return new Promise((resolve) => { return new Promise((resolve) => {
const checkInterval = setInterval(() => { const checkInterval = setInterval(() => {
console.log(client.notice.data["online"]); console.log(client.notice.data.online);
if (Object.keys(client.notice.data["online"]).length > 0) { if (Object.keys(client.notice.data.online).length > 0) {
clearInterval(checkInterval); clearInterval(checkInterval);
resolve(); resolve();
} }
@ -25,7 +25,7 @@ export default class extends AbstractView {
let profiles = await client.profiles.all(); let profiles = await client.profiles.all();
//console.log(client.notice.data); //console.log(client.notice.data);
if (client.notice.data == undefined || client.notice.data["online"] == undefined) if (client.notice.data == undefined || client.notice.data.online == undefined)
return console.log("Error"); return console.log("Error");
//await client.notice.getOnlineUser(); //await client.notice.getOnlineUser();
@ -66,12 +66,12 @@ export default class extends AbstractView {
// username // username
let username = document.createElement("a"); let username = document.createElement("a");
username.setAttribute('data-link', ''); username.setAttribute('data-link', '');
username.id = `username${user.id}` username.id = `username${user.id}`;
username.href = `/profiles/${user.username}`; username.href = `/profiles/${user.username}`;
if (logged && user.id == client.me.id) if (logged && user.id == client.me.id)
username.style.color = "green"; username.style.color = "green";
else { else {
let online = client.notice.data["online"][user.id]; let online = client.notice.data.online[user.id];
username.style.color = online !== undefined ? online : "gray"; username.style.color = online !== undefined ? online : "gray";
} }
username.appendChild(document.createTextNode(user.username)); username.appendChild(document.createTextNode(user.username));
@ -134,7 +134,7 @@ export default class extends AbstractView {
let search_document = document.getElementById("input_user"); let search_document = document.getElementById("input_user");
if (search_document == undefined || search_document == null) if (search_document == undefined || search_document == null)
return return;
let search = search_document.value.toLowerCase(); let search = search_document.value.toLowerCase();
@ -146,7 +146,7 @@ export default class extends AbstractView {
if (user.id == client.me.id) if (user.id == client.me.id)
username.style.color = "green"; username.style.color = "green";
else { else {
let online = client.notice.data["online"][user.id]; let online = client.notice.data.online[user.id];
username.style.color = online !== undefined ? online : "gray"; username.style.color = online !== undefined ? online : "gray";
} }
} }
@ -233,7 +233,7 @@ export default class extends AbstractView {
messages.appendChild(text); messages.appendChild(text);
}); });
return messages return messages;
} }
async reload_display_messages() { async reload_display_messages() {
@ -274,7 +274,7 @@ export default class extends AbstractView {
chat.appendChild(members); chat.appendChild(members);
return members return members;
} }
async display_invite() { async display_invite() {
@ -291,9 +291,9 @@ export default class extends AbstractView {
let yes = document.getElementById("yes") || document.createElement("button"); let yes = document.getElementById("yes") || document.createElement("button");
let no = document.getElementById("no") || document.createElement("button"); let no = document.getElementById("no") || document.createElement("button");
let invitedBy = undefined; let invitedBy;
for (let x in others) { for (let x in others) {
if (client.notice.data["invited"].includes(others[x])) { if (client.notice.data.invited.includes(others[x])) {
invitedBy = others[x]; invitedBy = others[x];
} }
} }
@ -309,7 +309,7 @@ export default class extends AbstractView {
invite.id = "invite"; invite.id = "invite";
invite.style.background = "orange"; invite.style.background = "orange";
invite.innerText = "invite"; invite.innerText = "invite";
invite.title = "Invite to play a game" invite.title = "Invite to play a game";
invite.onclick = async () => { invite.onclick = async () => {
await client.notice.send_invite(others); await client.notice.send_invite(others);
}; };
@ -318,18 +318,18 @@ export default class extends AbstractView {
else { else {
if (invite) if (invite)
invite.remove() invite.remove();
yes.id = "yes"; yes.id = "yes";
yes.style.background = "green"; yes.style.background = "green";
yes.title = "Accept to play a game" yes.title = "Accept to play a game";
yes.onclick = async () => { yes.onclick = async () => {
await client.notice.accept_invite(invitedBy); await client.notice.accept_invite(invitedBy);
}; };
no.id = "no"; no.id = "no";
no.style.background = "red"; no.style.background = "red";
no.title = "Refuse to play a game" no.title = "Refuse to play a game";
no.onclick = async () => { no.onclick = async () => {
await client.notice.refuse_invite(invitedBy); await client.notice.refuse_invite(invitedBy);
}; };
@ -342,7 +342,7 @@ export default class extends AbstractView {
async hide_chat() { async hide_chat() {
let closes = ["chat", "invite"] let closes = ["chat", "invite"];
closes.forEach(close => { closes.forEach(close => {
if (document.getElementById(close)) if (document.getElementById(close))
document.getElementById(close).remove(); document.getElementById(close).remove();

View File

@ -36,14 +36,13 @@ export default class extends AbstractAuthenticatedView
let response_data = await client.account.delete(current_password); let response_data = await client.account.delete(current_password);
console.log(await client.isAuthenticated())
if (response_data === null || response_data === "user deleted") if (response_data === null || response_data === "user deleted")
{ {
navigateTo("/login"); navigateTo("/login");
return; return;
} }
clear("innerHTML", ["current_password-input"]) clear("innerHTML", ["current_password-input"]);
fill_errors({"current_password-input": response_data["password"]}, "innerHTML") fill_errors({"current_password-input": response_data.password}, "innerHTML");
} }
async save_account() async save_account()
@ -67,10 +66,10 @@ export default class extends AbstractAuthenticatedView
} }
if (response_data === "data has been alterate") if (response_data === "data has been alterate")
response_data = {"save-account": "saved"} response_data = {"save-account": "saved"};
clear("innerHTML", ["username", "new_password", "current_password", "save-account", "delete-account"]) clear("innerHTML", ["username", "new_password", "current_password", "save-account", "delete-account"]);
fill_errors(response_data, "innerHTML") fill_errors(response_data, "innerHTML");
} }
async save_profile() async save_profile()

View File

@ -1,4 +1,4 @@
import {lang} from '../../index.js' import {lang} from '../../index.js';
export default class { export default class {
constructor(params, titleKey) { constructor(params, titleKey) {

View File

@ -8,7 +8,6 @@ export default class extends AbstractNonAuthenticatedView
{ {
super(params, 'loginWindowTitle', lastUrlBeforeLogin); super(params, 'loginWindowTitle', lastUrlBeforeLogin);
this.redirect_url = lastUrlBeforeLogin; this.redirect_url = lastUrlBeforeLogin;
this.current_mode = undefined
} }
async leavePage() async leavePage()
@ -36,7 +35,7 @@ export default class extends AbstractNonAuthenticatedView
[username_input, password_input].forEach(input => { [username_input, password_input].forEach(input => {
input.addEventListener('keydown', async ev => { input.addEventListener('keydown', async ev => {
if (ev.key === 'Enter') if (ev.key === 'Enter')
await this.authentication.bind(this)() await this.authentication.bind(this)();
}); });
}); });
username_input.focus(); username_input.focus();
@ -59,7 +58,7 @@ export default class extends AbstractNonAuthenticatedView
if (username === '' || password === '') if (username === '' || password === '')
return false; return false;
return true return true;
} }
/** /**
@ -102,7 +101,7 @@ export default class extends AbstractNonAuthenticatedView
password_label.innerText = lang.get(password_label_text, "ERROR LANG"); password_label.innerText = lang.get(password_label_text, "ERROR LANG");
let toggle_register_login_label_text = this.current_mode === "register" ? "registerAlreadyAccount" : "loginNoAccount"; let toggle_register_login_label_text = this.current_mode === "register" ? "registerAlreadyAccount" : "loginNoAccount";
toggle_register_login_label.innerText = lang.get(toggle_register_login_label_text, "ERROR LANG");; toggle_register_login_label.innerText = lang.get(toggle_register_login_label_text, "ERROR LANG");
let toggle_register_login_text = this.current_mode === "register" ? "registerLogin" : "loginRegister"; let toggle_register_login_text = this.current_mode === "register" ? "registerLogin" : "loginRegister";
toggle_register_login.innerText = lang.get(toggle_register_login_text, "ERROR LANG"); toggle_register_login.innerText = lang.get(toggle_register_login_text, "ERROR LANG");
@ -130,7 +129,7 @@ export default class extends AbstractNonAuthenticatedView
let response; let response;
if (this.current_mode === "register") if (this.current_mode === "register")
response = await client.account.create(username, password) response = await client.account.create(username, password);
else else
response = await client.login(username, password); response = await client.login(username, password);
@ -140,7 +139,7 @@ export default class extends AbstractNonAuthenticatedView
return; return;
} }
let response_data = await response.json() let response_data = await response.json();
console.log(response_data); console.log(response_data);

View File

@ -14,14 +14,14 @@ export default class extends AbstractAuthenticatedView
{ {
let name = document.getElementById("name-input").value; let name = document.getElementById("name-input").value;
let nb_players = document.getElementById("nb_players-input").value; let nb_players = document.getElementById("nb_players-input").value;
let nb_players_by_game = document.getElementById("nb_players_by_game-input").value let nb_players_by_game = document.getElementById("nb_players_by_game-input").value;
let response_data = await client.tournaments.createTournament(nb_players, nb_players_by_game, name); let response_data = await client.tournaments.createTournament(nb_players, nb_players_by_game, name);
if (response_data === null) if (response_data === null)
return; return;
let id = response_data["id"] let id = response_data.id;
if (id !== undefined) if (id !== undefined)
{ {
navigateTo(`/tournaments/${id}`); navigateTo(`/tournaments/${id}`);
@ -47,6 +47,6 @@ export default class extends AbstractAuthenticatedView
<input type="number" id="nb_players_by_game-input" placeholder="Number of players by game"> <input type="number" id="nb_players_by_game-input" placeholder="Number of players by game">
<span id="nb_players_by_game"></span> <span id="nb_players_by_game"></span>
<input type="button" id="create-button" value="Create tournament"> <input type="button" id="create-button" value="Create tournament">
` `;
} }
} }

View File

@ -17,13 +17,13 @@ export default class extends AbstractAuthenticatedView
async receive(data) async receive(data)
{ {
if (data.detail === "nb_participants" || data.detail === "update_participants") if (data.detail === "nb_participants" || data.detail === "update_participants")
document.getElementById("nb_participants").innerText = `${data.nb_participants} / ${this.tournament.nb_players}` document.getElementById("nb_participants").innerText = `${data.nb_participants} / ${this.tournament.nb_players}`;
if (data.detail === "go_to") if (data.detail === "go_to")
navigateTo(data.url); navigateTo(data.url);
if (data.detail === "is_participant") if (data.detail === "is_participant")
this.updateParticipating(data.is_participant) this.updateParticipating(data.is_participant);
if (data.detail === "error") if (data.detail === "error")
document.getElementById("display").innerText = data.error_message document.getElementById("display").innerText = data.error_message;
} }
async updateParticipating(state) async updateParticipating(state)
@ -45,7 +45,7 @@ export default class extends AbstractAuthenticatedView
this.tournament.join(this.receive.bind(this), this.ondisconnect.bind(this)); this.tournament.join(this.receive.bind(this), this.ondisconnect.bind(this));
let button = document.getElementById("button") let button = document.getElementById("button");
button.onclick = this.pressButton.bind(this); button.onclick = this.pressButton.bind(this);
@ -93,6 +93,6 @@ export default class extends AbstractAuthenticatedView
</table> </table>
<input type="button" id="button" value="Join tournament" disabled> <input type="button" id="button" value="Join tournament" disabled>
<span id="display"></span> <span id="display"></span>
` `;
} }
} }

View File

@ -17,14 +17,14 @@ export default class extends AbstractAuthenticatedView
add_nb_player_by_game_selector() add_nb_player_by_game_selector()
{ {
let nb_players_by_game_list = new Set() let nb_players_by_game_list = new Set();
this.tournaments.forEach(tournament => { this.tournaments.forEach(tournament => {
nb_players_by_game_list.add(tournament.nb_players_by_game); nb_players_by_game_list.add(tournament.nb_players_by_game);
}); });
let select = document.getElementById("nb-players-by-game-select"); let select = document.getElementById("nb-players-by-game-select");
let new_children = [] let new_children = [];
const opt = document.createElement("option"); const opt = document.createElement("option");
opt.value = "all"; opt.value = "all";
@ -37,7 +37,7 @@ export default class extends AbstractAuthenticatedView
opt.value = nb_players_by_game; opt.value = nb_players_by_game;
opt.text = nb_players_by_game; opt.text = nb_players_by_game;
new_children.push(opt); new_children.push(opt);
}) });
select.replaceChildren(...new_children); select.replaceChildren(...new_children);
} }
@ -56,7 +56,7 @@ export default class extends AbstractAuthenticatedView
{ {
const tournaments_list = document.getElementById("tournaments-list"); const tournaments_list = document.getElementById("tournaments-list");
const new_children = [] const new_children = [];
this.display_tournaments.forEach(tournament => { this.display_tournaments.forEach(tournament => {
@ -102,7 +102,7 @@ export default class extends AbstractAuthenticatedView
async postInit() async postInit()
{ {
await this.update_search() await this.update_search();
document.getElementById("state-select").onchange = this.update_search.bind(this); document.getElementById("state-select").onchange = this.update_search.bind(this);
document.getElementById("nb-players-by-game-select").onchange = this.update_query.bind(this); document.getElementById("nb-players-by-game-select").onchange = this.update_query.bind(this);
} }
@ -128,6 +128,6 @@ export default class extends AbstractAuthenticatedView
<tbody id="tournaments-list"> <tbody id="tournaments-list">
</tbody> </tbody>
</table> </table>
` `;
} }
} }