Commit a8895d51 authored by Manish Kumar's avatar Manish Kumar
Browse files

Merge branch 'master' of gitlab.unige.ch:Manish.Kumar/webpoke

parents fb8b1c15 091a09cc
......@@ -108,4 +108,15 @@ exports.refuse = (req, res) => {
else res.send(data);
});
}
};
exports.wins = (req, res) => {
Joueur.wins((err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while retrieving Pokemon."
});
else res.send(data);
});
};
\ No newline at end of file
......@@ -88,4 +88,14 @@ exports.remove = (req, res) => {
}
} else res.send({ message: `Pokemon was deleted successfully from Team!` });
});
};
exports.popular = (req, res) => {
Pokemon.mostUsed((err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while retrieving the bests."
});
else res.send(data);
});
};
\ No newline at end of file
......@@ -68,7 +68,7 @@ Joueur.addAmi = (pseudo, ami, result) => {
};
Joueur.accept = (pseudo, ami, result) => {
sql.query("UPDATE ami SET accept = 1 WHERE id_joueur1 = ? AND id_joueur2 = ?", [pseudo, ami], (err, res) => {
sql.query("UPDATE ami SET accept = 1 WHERE id_joueur1 = ? AND id_joueur2 = ?", [ami, pseudo], (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
......@@ -95,5 +95,16 @@ Joueur.refuse = (pseudo, ami, result) => {
});
};
Joueur.wins = (result) => {
sql.query("SELECT pseudo, win from joueur ORDER BY win DESC", (err, res) => {
if (err) {
console.log("error: ", err);
result(null, err);
return;
}
result(null, res);
});
};
module.exports = Joueur;
\ No newline at end of file
......@@ -23,6 +23,17 @@ Pokemon.getAll = result => {
});
};
Pokemon.mostUsed = result => {
sql.query("SELECT pokeName, COUNT(*) as number FROM pokemon, team WHERE team.id_pokemon = pokemon.id_pokemon AND courant = 1 GROUP BY team.id_pokemon ORDER BY number DESC", (err, res) => {
if (err) {
console.log("error: ", err);
result(null, err);
return;
}
result(null, res);
});
};
// Pokemon.getTeamUtil = (joueur_id, result) => {
// sql.query('SELECT p.*, m.* FROM pokemon as p, team, moveutil as mu, move as m WHERE id_joueur= ? AND p.id_pokemon=team.id_pokemon AND mu.move_id=m.id_move AND mu.pokemon_id=p.id_pokemon;', [joueur_id], (err, res) => {
......
......@@ -25,4 +25,7 @@ module.exports = app => {
// Logout
app.get("/logout", joueur.desAuth);
//get the descendent wins
app.get("/winners", joueur.wins);
};
\ No newline at end of file
......@@ -15,4 +15,7 @@ module.exports = app => {
app.post("/updatemove", pokemon.updateMove);
//get the pokemons most present in teams
app.get("/popular", pokemon.popular);
};
\ No newline at end of file
......@@ -8,6 +8,7 @@ import { AccountMenuComponent } from './account-menu/account-menu.component';
import { ProfilComponent } from './profil/profil.component';
import { HomeComponent } from './home/home.component'
import { BattleComponent } from "./battle/battle.component";
import { LeaderboardComponent } from './leaderboard/leaderboard.component';
const routes: Routes = [
......
......@@ -22,6 +22,7 @@ import { OnlinePlayersComponent } from './sub-components/online-players/online-p
import { NotifierModule } from "angular-notifier";
import { BattleComponent } from './battle/battle.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { LeaderboardComponent } from './leaderboard/leaderboard.component';
@NgModule({
......@@ -37,7 +38,8 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
ProfilComponent,
HomeComponent,
OnlinePlayersComponent,
BattleComponent
BattleComponent,
LeaderboardComponent
],
imports: [
BrowserModule,
......
......@@ -22,12 +22,12 @@
<div class="container py-3" *ngIf="amis!=null">
<div *ngFor="let ami of amis; let i=index">
<h4>{{ami.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="refuser(ami)">
<div class="btn btn-primary" (click)="refuser(ami, i)">
<h6>Effacer</h6>
</div>
<!-- <div class="btn btn-primary" (click)="">
<div class="btn btn-primary" (click)="challenge(ami)">
<h6>Défier</h6>
</div> -->
</div>
</div>
</div>
</div>
......@@ -37,10 +37,10 @@
<div class="container py-3" *ngIf="requests!=null">
<div *ngFor="let req of requests; let i=index">
<h4>{{req.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="accepter(req)">
<div class="btn btn-primary" (click)="accepter(req, i)">
<h6>Accepter</h6>
</div>
<div class="btn btn-primary" id="ami" (click)="refuser(req)">
<div class="btn btn-primary" (click)="refuser(req,i)">
<h6>Refuser</h6>
</div>
</div>
......
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { FormControl } from '@angular/forms';
import { ChatService } from '../chat.service';
@Component({
selector: 'app-friends',
......@@ -24,7 +25,7 @@ export class FriendsMenuComponent implements OnInit {
uid;
temp;
constructor(private httpClient: HttpClient) { }
constructor(private httpClient: HttpClient, private chatService: ChatService) { }
displayPlayers(play){
this.currentAmi = play;
......@@ -36,9 +37,12 @@ export class FriendsMenuComponent implements OnInit {
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/newami', { id_joueur2: this.currentAmi.id_joueur}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
(response: any) => {
if(response.res){
this.amis.push(this.requests[this.currentAmi]);
}
}
)
}
......@@ -56,16 +60,16 @@ export class FriendsMenuComponent implements OnInit {
isFriend(){
if(this.resultat.res.length > 0){
for(let i = 0; i < this.resultat.res.length; i++){
if(this.resultat.res[i].accept === 1){
if(this.resultat.res[i].accept == 1){
this.amis.push(this.resultat.res[i])
} else if (this.resultat.res[i].id_joueur1 != this.uid){
} else {
this.requests.push(this.resultat.res[i])
}
}
}
}
accepter(idAmi){
accepter(idAmi, i){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
......@@ -74,12 +78,15 @@ export class FriendsMenuComponent implements OnInit {
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/yayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
(response: any) => {
if(response.res){
this.amis.push(this.requests[i]);
}
}
)
}
refuser(idAmi){
refuser(idAmi, i){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
......@@ -87,12 +94,31 @@ export class FriendsMenuComponent implements OnInit {
}
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: this.temp }, { headers: headers, withCredentials: true}).subscribe(
(response: any) => {
if(response.res){
this.requests.splice(i, 1);
}
}
)
}
challenge(user){
if(this.chatService.attaquer(user)){
this.addPartie(user);
console.log("sending challenge");
}
}
addPartie(user){
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/addpartie', {pseudo: user}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
}
liste(){
this.httpClient.get("http://localhost:3000/alljoueurs", { responseType: 'json', withCredentials:true}).
......@@ -110,6 +136,7 @@ export class FriendsMenuComponent implements OnInit {
this.pseudo = res.body;
this.uid = res.uid;
this.liste();
this.ordre();
});
}
}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
......
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/International_Pok%C3%A9mon_logo.svg/1200px-International_Pok%C3%A9mon_logo.svg.png" alt="Paris" class="center">
<div class="container">
<app-online-players></app-online-players>
<app-online-players></app-online-players>
<app-leaderboard></app-leaderboard>
</div>
\ No newline at end of file
<h1>Leaderboard</h1>
<div>
<table class="table">
<tr>
<th>Pseudo</th>
<th>Nombre de victoire</th>
</tr>
<tr *ngFor="let i of resultat">
<th>{{i.pseudo}}</th>
<th>{{i.win}}</th>
</tr>
</table>
<table class="table">
<tr>
<th>Pokemon</th>
<th>Nombre d'apparition </th>
</tr>
<tr *ngFor="let j of poke">
<th>{{j.pokeName}}</th>
<th>{{j.number}}</th>
</tr>
</table>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LeaderboardComponent } from './leaderboard.component';
describe('LeaderboardComponent', () => {
let component: LeaderboardComponent;
let fixture: ComponentFixture<LeaderboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LeaderboardComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LeaderboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-leaderboard',
templateUrl: './leaderboard.component.html',
styleUrls: ['./leaderboard.component.css']
})
export class LeaderboardComponent implements OnInit {
constructor(private httpClient: HttpClient) { }
resultat: any = {};
poke:any = {};
ngOnInit(): void {
this.httpClient.get('http://localhost:3000/winners', { responseType: 'json', withCredentials:true }).subscribe(res => {this.resultat = res})
this.httpClient.get('http://localhost:3000/popular', { responseType: 'json', withCredentials:true }).subscribe(res => {this.poke = res})
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment