Skip to content

Commit

Permalink
Merge pull request #275 from softwaremagico/273-not-handling-correctl…
Browse files Browse the repository at this point in the history
…y-tied-ranking-for-the-2nd-winner-of-a-group

Fixing draw groups not resolved.
  • Loading branch information
softwaremagico authored Nov 21, 2023
2 parents d07c371 + 787b8a3 commit bf36b1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
<mat-icon>file_download</mat-icon>
{{'download' | translate}}
</button>
<button (click)="undrawTeams(0)" *ngIf="!tournament!.locked && fightsFinished &&
(RbacActivity.READ_TEAMS_RANKINGS | rbac : this.rbacService.activities) &&
(isDrawWinner(0) || isDrawWinner(1) || isDrawWinner(2))" mat-flat-button mat-raised-button>
<button (click)="undrawAllTeams()" *ngIf="!tournament!.locked && fightsFinished && importantDrawWinner() &&
(RbacActivity.READ_TEAMS_RANKINGS | rbac : this.rbacService.activities)" mat-flat-button mat-raised-button>
<mat-icon class="kendo-icon" svgIcon="undraw-score"></mat-icon>
{{'undraw' | translate}}
</button>
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/app/components/team-ranking/team-ranking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class TeamRankingComponent extends RbacBasedComponent implements OnInit {
group: Group;
showIndex: boolean | undefined;
existsDraws: boolean = false;
numberOfWinners: number;

private destroy$: Subject<void> = new Subject<void>();
_loading = false;
Expand Down Expand Up @@ -57,6 +58,7 @@ export class TeamRankingComponent extends RbacBasedComponent implements OnInit {

forkJoin([rankingRequest, winnersRequest]).subscribe(([_scoresOfTeams, _numberOfWinners]): void => {
this.teamScores = _scoresOfTeams;
this.numberOfWinners = _numberOfWinners !== undefined ? Number(_numberOfWinners.propertyValue) : 1;
if (this.isDrawWinner(0) || (_numberOfWinners && _numberOfWinners.propertyValue == "2" && this.isDrawWinner(1))) {
this.messageService.warningMessage("drawScore");
this.existsDraws = true;
Expand All @@ -73,6 +75,16 @@ export class TeamRankingComponent extends RbacBasedComponent implements OnInit {
}
}

importantDrawWinner(): boolean {
for (let i = 0; i < this.numberOfWinners; i++) {
if (this.isDrawWinner(i)) {
console.log("Found draws on index ", i);
return true;
}
}
return false;
}

isDrawWinner(index: number): boolean {
return this.teamScores && this.fightsFinished && this.teamScores.filter((scoreOfTeam: ScoreOfTeam): boolean => scoreOfTeam.sortingIndex === index).length > 1;
}
Expand Down Expand Up @@ -118,6 +130,14 @@ export class TeamRankingComponent extends RbacBasedComponent implements OnInit {
}
}

undrawAllTeams(): void {
for (let i = 0; i < this.numberOfWinners; i++) {
if (this.isDrawWinner(i)) {
this.undrawTeams(i);
}
}
}

undrawTeams(index: number): void {
const teams: Team[] = this.getDrawWinners(index);
this.dialog.open(UndrawTeamsComponent, {
Expand Down

0 comments on commit bf36b1a

Please sign in to comment.