-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,292 additions
and
346 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 4 additions & 62 deletions
66
src/app/home/register-winner/register-match.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,5 @@ | ||
<section class="container"> | ||
<div class="register-match row"> | ||
<div class="col-md-12"> | ||
<h2 *ngIf="!isLoading && !hasRegisterd">Register a match</h2> | ||
<div *ngIf="isLoading"><span class="fa fa-cog fa-spin fa-4x"></span></div> | ||
<div *ngIf="!isLoading && !hasRegisterd"> | ||
<div class="row"> | ||
<div class="col-5"> | ||
<label class="select-label" for="player1">Winner</label> | ||
<ng-select id="player1" [(ngModel)]="player1Id"> | ||
<ng-option [value]="''">Velg...</ng-option> | ||
<ng-option *ngFor="let user of users" [value]="user.uid" [disabled]="user.uid === player2Id" >{{user.username}} ({{user.name}})</ng-option> | ||
</ng-select> | ||
</div> | ||
<div class="col-2"><span class="vs">won against</span></div> | ||
<div class="col-5"> | ||
<label class="select-label" for="player2">Loser</label> | ||
<ng-select id="player2" [(ngModel)]="player2Id"> | ||
<ng-option [value]="''">Velg...</ng-option> | ||
<ng-option *ngFor="let user of users" [value]="user.uid" [disabled]="user.uid === player1Id" >{{user.username}} ({{user.name}})</ng-option> | ||
</ng-select> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-12"> | ||
<button (click)="registerWinner()" class="create-game">REGISTER WINNER</button> | ||
</div> | ||
</div> | ||
</div> | ||
<div *ngIf="!isLoading && hasRegisterd"> | ||
<h3 class="header-winner">🏆 {{player1.name}} WON! 🏆 </h3> | ||
<div class="row summary-match"> | ||
<div class="col-3"> | ||
<p [ngClass]="{'loss': (matchResult.player1NewRating - matchResult.player1OldRating) <= 0, 'win' : (matchResult.player1NewRating - matchResult.player1OldRating) > 0}"> | ||
<span *ngIf="(matchResult.player1NewRating - matchResult.player1OldRating) > 0">+</span> | ||
{{matchResult.player1NewRating - matchResult.player1OldRating}} | ||
</p> | ||
</div> | ||
<div class="col-3"> | ||
<p>{{matchResult.player1Username}} ({{matchResult.player1NewRating}})</p> | ||
</div> | ||
<div class="col-3"> | ||
<p>{{matchResult.player2Username}} ({{matchResult.player2NewRating}})</p> | ||
</div> | ||
<div class="col-3"> | ||
<p [ngClass]="{'loss': (matchResult.player2NewRating - matchResult.player2OldRating) <= 0, 'win' : (matchResult.player2NewRating - matchResult.player2OldRating) > 0}"> | ||
<span *ngIf="(matchResult.player2NewRating - matchResult.player2OldRating) > 0">+</span> | ||
{{matchResult.player2NewRating - matchResult.player2OldRating}} | ||
</p> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<button (click)="registerNewMatch()" class="create-game">REGISTER NEW MATCH</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<section class="container" [ngSwitch]="display"> | ||
<app-match-type-selector (selected)="select($event)"></app-match-type-selector> | ||
<app-register1vs1-match *ngSwitchDefault></app-register1vs1-match> | ||
<app-register2vs2-match *ngSwitchCase="matchTypes.TWO_VS_TWO"></app-register2vs2-match> | ||
</section> |
57 changes: 3 additions & 54 deletions
57
src/app/home/register-winner/register-match.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,4 @@ | ||
@import "../../../styles/variables"; | ||
@import "../../../styles/mixins"; | ||
|
||
.register-match{ | ||
margin-top: 35px; | ||
text-align: center; | ||
|
||
.select-label{ | ||
text-align: left; | ||
font-size: 18px; | ||
} | ||
.vs{ | ||
display: block; | ||
text-align: center; | ||
margin-top: 24px; | ||
font-size: 28px | ||
} | ||
.select-box{ | ||
margin: auto; | ||
width: 100%; | ||
font-size: 18px; | ||
border: none; | ||
background: none; | ||
border: 1px solid $tangarine; | ||
border-radius: 0px; | ||
background-color: white; | ||
display: block; | ||
} | ||
|
||
.create-game{ | ||
@include no-button-styling(); | ||
@include standard-button($tangarine, $tangarine-transparent, white); | ||
width: 300px; | ||
font-size: 22px; | ||
padding: 5px; | ||
margin-top: 35px; | ||
} | ||
|
||
.loss{ | ||
color: red; | ||
} | ||
|
||
.win{ | ||
color: green; | ||
} | ||
|
||
.header-winner{ | ||
margin-top: 35px; | ||
} | ||
|
||
.summary-match{ | ||
font-size: 22px; | ||
margin-top: 35px; | ||
} | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,23 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {UserService} from '../../shared/services/user.service'; | ||
import {AuthenticationService} from '../../shared/services/authentication.service'; | ||
import {MatchmakerService} from '../../shared/services/matchmaker.service'; | ||
import {UserModel} from '../../shared/models/user.model'; | ||
import {MatchModel} from '../../shared/models/match.model'; | ||
import {HistoryModel} from '../../shared/models/history.model'; | ||
import {MatchType} from '../../shared/models/match-type.enum'; | ||
|
||
@Component({ | ||
selector: 'app-register-match', | ||
templateUrl: 'register-match.component.html', | ||
styleUrls: ['register-match.component.scss'] | ||
}) | ||
export class RegisterMatchComponent implements OnInit { | ||
users: UserModel[]; | ||
player1: UserModel; | ||
player2: UserModel; | ||
matchResult: HistoryModel; | ||
player1Id: string; | ||
player2Id: string; | ||
isLoading: boolean; | ||
hasRegisterd: boolean; | ||
matchTypes = MatchType; | ||
|
||
constructor(private userService: UserService, private auth: AuthenticationService, private matchmaker: MatchmakerService) { | ||
} | ||
|
||
ngOnInit() { | ||
this.player1Id = ''; | ||
this.player2Id = ''; | ||
this.auth.isLoggedIn().subscribe(result => { | ||
this.loadUsers(result.uid); | ||
}, error => { | ||
console.log(error); | ||
}); | ||
} | ||
display: string; | ||
|
||
private loadUsers(id: string) { | ||
this.userService.getUsersByName().subscribe(result => { | ||
this.users = result; | ||
}, error => { | ||
console.log(error); | ||
}); | ||
constructor() { | ||
} | ||
|
||
registerWinner() { | ||
if (this.player2Id && this.player1Id) { | ||
this.player1 = this.users.filter(u => u.uid === this.player1Id)[0]; | ||
if (confirm('Did ' + this.player1.name + ' win?')) { | ||
this.isLoading = true; | ||
this.player2 = this.users.filter(u => u.uid === this.player2Id)[0]; | ||
const matchModel: MatchModel = this.createMatch(this.player1, this.player2); | ||
this.matchmaker.registerWinner(true, matchModel).then(result => { | ||
this.isLoading = false; | ||
if (result) { | ||
this.matchResult = result; | ||
this.hasRegisterd = true; | ||
} | ||
}); | ||
} else { | ||
console.log('Cancel'); | ||
} | ||
} | ||
} | ||
|
||
registerNewMatch() { | ||
this.hasRegisterd = false; | ||
ngOnInit() { | ||
} | ||
|
||
private createMatch(player1: UserModel, player2): MatchModel { | ||
const match: MatchModel = { | ||
player1: player1, | ||
player2: player2, | ||
lastUpdated: new Date(), | ||
created: new Date().getTime() | ||
}; | ||
return match; | ||
select(type) { | ||
this.display = type; | ||
} | ||
} |
Oops, something went wrong.