Skip to content

Commit

Permalink
Merge pull request #420 from softwaremagico/419-when-handling-multipl…
Browse files Browse the repository at this point in the history
…es-tournamentes-switching-winners-shows-others-championship-data

Fixed old groups data is shown on brackets
  • Loading branch information
softwaremagico authored May 11, 2024
2 parents 8a11671 + 7b6521a commit 2ed276e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager)
[![Time](https://img.shields.io/badge/development-613.5h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-614h-blueviolet.svg)]()

[![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]()
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ import {Message} from "@stomp/stompjs/esm6";
import {MessageContent} from "../../websockets/message-content.model";
import {RxStompService} from "../../websockets/rx-stomp.service";
import {EnvironmentService} from "../../environment.service";
import {TournamentChangedService} from "./tournament-brackets/tournament-changed.service";

@Component({
selector: 'app-tournament-brackets-editor',
templateUrl: './tournament-brackets-editor.component.html',
styleUrls: ['./tournament-brackets-editor.component.scss']
})
export class TournamentBracketsEditorComponent implements OnChanges, OnInit, OnDestroy {
export class TournamentBracketsEditorComponent implements OnInit, OnDestroy {

private websocketsPrefix: string = this.environmentService.getWebsocketPrefix();

Expand Down Expand Up @@ -87,7 +88,8 @@ export class TournamentBracketsEditorComponent implements OnChanges, OnInit, OnD
constructor(private teamService: TeamService, private groupService: GroupService, private groupLinkService: GroupLinkService,
public rbacService: RbacService, private systemOverloadService: SystemOverloadService, private dialog: MatDialog,
private groupsUpdatedService: GroupsUpdatedService, private numberOfWinnersUpdatedService: NumberOfWinnersUpdatedService,
private rxStompService: RxStompService, private environmentService: EnvironmentService) {
private rxStompService: RxStompService, private environmentService: EnvironmentService,
private tournamentChangedService: TournamentChangedService) {
}

ngOnInit(): void {
Expand All @@ -105,22 +107,21 @@ export class TournamentBracketsEditorComponent implements OnChanges, OnInit, OnD
this.updateData(false);
}
});
this.tournamentChangedService.isTournamentChanged.subscribe((_tournament: Tournament): void => {
this.tournament = _tournament;
if (_tournament) {
this.updateData(true);
}
})
}

ngOnDestroy(): void {
this.topicSubscription?.unsubscribe();
}

ngOnChanges(changes: SimpleChanges): void {
this.systemOverloadService.isBusy.next(true);
if (changes['tournament']) {
this.updateData(true);
}
}

updateData(showBusy: boolean): void {
this.systemOverloadService.isBusy.next(showBusy);
if (this.tournament) {
if (this.tournament && this.tournament.id) {
const teamsRequest: Observable<Team[]> = this.teamService.getFromTournament(this.tournament);
const groupsRequest: Observable<Group[]> = this.groupService.getFromTournament(this.tournament.id!);
const relationsRequest: Observable<GroupLink[]> = this.groupLinkService.getFromTournament(this.tournament.id!);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from "rxjs";
import {Tournament} from "../../../models/tournament";

@Injectable({
providedIn: 'root'
})
export class TournamentChangedService {

public isTournamentChanged: BehaviorSubject<Tournament> = new BehaviorSubject<Tournament>(new Tournament());
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,140 +19,144 @@ import {TournamentExtraPropertyKey} from "../../../models/tournament-extra-prope
import {TournamentExtendedPropertiesService} from "../../../services/tournament-extended-properties.service";
import {TournamentType} from "../../../models/tournament-type";
import {NumberOfWinnersUpdatedService} from "../../../services/notifications/number-of-winners-updated.service";
import {
TournamentChangedService
} from "../../../components/tournament-brackets-editor/tournament-brackets/tournament-changed.service";

@Component({
selector: 'app-tournament-generator',
templateUrl: './tournament-generator.component.html',
styleUrls: ['./tournament-generator.component.scss']
selector: 'app-tournament-generator',
templateUrl: './tournament-generator.component.html',
styleUrls: ['./tournament-generator.component.scss']
})
export class TournamentGeneratorComponent extends RbacBasedComponent implements OnInit {

@ViewChild(TournamentBracketsEditorComponent)
tournamentBracketsEditorComponent: TournamentBracketsEditorComponent;

groupsDisabled: boolean = true;

tournamentId: number;
tournament: Tournament;
isWizardEnabled: boolean = true;
groups: Group[];
groupsLevelZero: Group[] = [];
totalTeams: number;

numberOfWinners: number = 1;

constructor(private router: Router, rbacService: RbacService, private tournamentService: TournamentService,
private dialog: MatDialog, private fightService: FightService, private messageService: MessageService,
private groupService: GroupService,
private tournamentExtendedPropertiesService: TournamentExtendedPropertiesService,
private numberOfWinnersUpdatedService: NumberOfWinnersUpdatedService) {
super(rbacService);
const state = this.router.getCurrentNavigation()?.extras.state;
if (state) {
if (state['tournamentId'] && !isNaN(Number(state['tournamentId']))) {
this.tournamentId = Number(state['tournamentId']);
} else {
this.goBackToFights();
}
this.groupsDisabled = state['editionDisabled'];
} else {
this.goBackToFights();
}
}

ngOnInit(): void {
this.tournamentService.get(this.tournamentId).subscribe((tournament: Tournament): void => {
this.tournament = tournament;
this.refreshWinner();
});
}

goBackToFights(): void {
this.router.navigate(['/tournaments/fights'], {state: {tournamentId: this.tournamentId}});
@ViewChild(TournamentBracketsEditorComponent)
tournamentBracketsEditorComponent: TournamentBracketsEditorComponent;

groupsDisabled: boolean = true;

tournamentId: number;
tournament: Tournament;
isWizardEnabled: boolean = true;
groups: Group[];
groupsLevelZero: Group[] = [];
totalTeams: number;

numberOfWinners: number = 1;

constructor(private router: Router, rbacService: RbacService, private tournamentService: TournamentService,
private dialog: MatDialog, private fightService: FightService, private messageService: MessageService,
private groupService: GroupService, private tournamentChangedService: TournamentChangedService,
private tournamentExtendedPropertiesService: TournamentExtendedPropertiesService,
private numberOfWinnersUpdatedService: NumberOfWinnersUpdatedService) {
super(rbacService);
const state = this.router.getCurrentNavigation()?.extras.state;
if (state) {
if (state['tournamentId'] && !isNaN(Number(state['tournamentId']))) {
this.tournamentId = Number(state['tournamentId']);
} else {
this.goBackToFights();
}
this.groupsDisabled = state['editionDisabled'];
} else {
this.goBackToFights();
}

addGroup(): void {
if (this.groupsLevelZero.length < this.totalTeams / 2) {
this.tournamentBracketsEditorComponent.addGroup();
}
}

ngOnInit(): void {
this.tournamentService.get(this.tournamentId).subscribe((tournament: Tournament): void => {
this.tournament = tournament;
this.tournamentChangedService.isTournamentChanged.next(tournament);
this.refreshWinner();
});
}

goBackToFights(): void {
this.router.navigate(['/tournaments/fights'], {state: {tournamentId: this.tournamentId}});
}

addGroup(): void {
if (this.groupsLevelZero.length < this.totalTeams / 2) {
this.tournamentBracketsEditorComponent.addGroup();
}

deleteGroup(): void {
this.tournamentBracketsEditorComponent.deleteLast();
}

deleteGroup(): void {
this.tournamentBracketsEditorComponent.deleteLast();
}

openConfirmationGenerateElementsDialog(): void {
let dialogRef: MatDialogRef<ConfirmationDialogComponent> = this.dialog.open(ConfirmationDialogComponent, {
disableClose: false
});
dialogRef.componentInstance.messageTag = "deleteFightsWarning"

dialogRef.afterClosed().subscribe(result => {
if (result) {
this.generateElements();
}
});
}

generateElements(): void {
this.fightService.create(this.tournamentId, 0).subscribe((fights: Fight[]): void => {
this.messageService.infoMessage("infoFightCreated");
this.goBackToFights();
});
}

groupsUpdated(groups: Group[]): void {
this.groups = groups;
this.groupsLevelZero = this.groups.filter((g: Group): boolean => {
return g.level === 0;
});
}

teamsSizeUpdated(totalTeams: number): void {
this.totalTeams = totalTeams;
}

downloadPDF(): void {
if (this.tournament?.id) {
this.groupService.getGroupsByTournament(this.tournament.id).subscribe((pdf: Blob): void => {
const blob: Blob = new Blob([pdf], {type: 'application/pdf'});
const downloadURL: string = window.URL.createObjectURL(blob);

const anchor: HTMLAnchorElement = document.createElement("a");
anchor.download = "Group List - " + this.tournament.name + ".pdf";
anchor.href = downloadURL;
anchor.click();
});
}

openConfirmationGenerateElementsDialog(): void {
let dialogRef: MatDialogRef<ConfirmationDialogComponent> = this.dialog.open(ConfirmationDialogComponent, {
disableClose: false
});
dialogRef.componentInstance.messageTag = "deleteFightsWarning"

dialogRef.afterClosed().subscribe(result => {
if (result) {
this.generateElements();
}

private refreshWinner(): void {
if (this.tournament.type == TournamentType.CHAMPIONSHIP) {
this.tournamentExtendedPropertiesService.getByTournament(this.tournament).subscribe((_tournamentSelection: TournamentExtendedProperty[]): void => {
if (_tournamentSelection) {
for (const _tournamentProperty of _tournamentSelection) {
if (_tournamentProperty.propertyKey == TournamentExtraPropertyKey.NUMBER_OF_WINNERS) {
this.numberOfWinners = Number(_tournamentProperty.propertyValue.toLowerCase());
}
});
}

generateElements(): void {
this.fightService.create(this.tournamentId, 0).subscribe((fights: Fight[]): void => {
this.messageService.infoMessage("infoFightCreated");
this.goBackToFights();
});
}

groupsUpdated(groups: Group[]): void {
this.groups = groups;
this.groupsLevelZero = this.groups.filter((g: Group): boolean => {
return g.level === 0;
});
}

teamsSizeUpdated(totalTeams: number): void {
this.totalTeams = totalTeams;
}

downloadPDF(): void {
if (this.tournament?.id) {
this.groupService.getGroupsByTournament(this.tournament.id).subscribe((pdf: Blob): void => {
const blob: Blob = new Blob([pdf], {type: 'application/pdf'});
const downloadURL: string = window.URL.createObjectURL(blob);

const anchor: HTMLAnchorElement = document.createElement("a");
anchor.download = "Group List - " + this.tournament.name + ".pdf";
anchor.href = downloadURL;
anchor.click();
});
}
}
}

private refreshWinner(): void {
if (this.tournament.type == TournamentType.CHAMPIONSHIP) {
this.tournamentExtendedPropertiesService.getByTournament(this.tournament).subscribe((_tournamentSelection: TournamentExtendedProperty[]): void => {
if (_tournamentSelection) {
for (const _tournamentProperty of _tournamentSelection) {
if (_tournamentProperty.propertyKey == TournamentExtraPropertyKey.NUMBER_OF_WINNERS) {
this.numberOfWinners = Number(_tournamentProperty.propertyValue.toLowerCase());
}
}
}
if (this.numberOfWinners == undefined) {
this.numberOfWinners = 1;
}
});
if (this.numberOfWinners == undefined) {
this.numberOfWinners = 1;
}
});
}

changeNumberOfWinners(numberOfWinners: number): void {
this.numberOfWinners = numberOfWinners;

const tournamentProperty: TournamentExtendedProperty = new TournamentExtendedProperty();
tournamentProperty.tournament = this.tournament;
tournamentProperty.propertyValue = numberOfWinners + "";
tournamentProperty.propertyKey = TournamentExtraPropertyKey.NUMBER_OF_WINNERS;
this.tournamentService.setNumberOfWinners(this.tournament, numberOfWinners).subscribe((): void => {
this.numberOfWinnersUpdatedService.numberOfWinners.next(numberOfWinners);
this.messageService.infoMessage('infoTournamentUpdated');
});
}
}

changeNumberOfWinners(numberOfWinners: number): void {
this.numberOfWinners = numberOfWinners;

const tournamentProperty: TournamentExtendedProperty = new TournamentExtendedProperty();
tournamentProperty.tournament = this.tournament;
tournamentProperty.propertyValue = numberOfWinners + "";
tournamentProperty.propertyKey = TournamentExtraPropertyKey.NUMBER_OF_WINNERS;
this.tournamentService.setNumberOfWinners(this.tournament, numberOfWinners).subscribe((): void => {
this.numberOfWinnersUpdatedService.numberOfWinners.next(numberOfWinners);
this.messageService.infoMessage('infoTournamentUpdated');
});
}
}

0 comments on commit 2ed276e

Please sign in to comment.