Skip to content

Commit

Permalink
Some backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Apr 22, 2024
1 parent 9a2b2c2 commit 169ebcf
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/sign-up/sign-up.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class SignUpComponent {
message: 'Something went wrong, please check for validation errors. If the issue persists, please contact support in discord.',
duration: 5000,
position: 'is-right',
color: 'is-error'
color: 'is-danger'
});

const errors: { field: string; defaultMessage: string }[] = e.error.errors ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ScheduleManagementComponent implements OnInit {
scheduleLine.gameName = game.name;
scheduleLine.ratio = game.ratio;
scheduleLine.runners = [{ user: submission.user }];
category.opponentDtos.forEach(opponent => scheduleLine.runners.push({ user: opponent.user }));
category.opponents.forEach(opponent => scheduleLine.runners.push({ user: opponent.user }));
scheduleLine.setupTime = this.marathonService.marathon.defaultSetupTime;
scheduleLine.setupTimeHuman = DurationService.toHuman(this.marathonService.marathon.defaultSetupTime);
scheduleLine.setupBlock = false;
Expand Down
4 changes: 2 additions & 2 deletions src/app/marathon/selection/selection.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ <h4 class="subtitle is-4">{{ 'marathon.selection.selection.title' | translate}}<
</td>
<td>
{{ 'marathon.schedule.type.' + category.type | translate}}
<p *ngIf="category.type !== 'SINGLE' && category.opponentDtos && category.opponentDtos.length > 0">{{'marathon.submit.category.opponent.with' | translate}}
<span *ngFor="let opponent of category.opponentDtos">
<p *ngIf="category.type !== 'SINGLE' && category.opponents && category.opponents.length > 0">{{'marathon.submit.category.opponent.with' | translate}}
<span *ngFor="let opponent of category.opponents">
<div class="is-flex">
<a (click)="getAvailabilitiesForRunner(opponent.user.id)" style="margin-right: 0.4rem"
*ngIf="!availabilitiesSelected.includes(opponent.user.username)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
></app-delete-button>
</div>
<div class="message-body">
<ng-template [ngIf]="category.type !== 'SINGLE' && category.opponentDtos && category.opponentDtos.length > 0">
<ng-template [ngIf]="category.type !== 'SINGLE' && category.opponents && category.opponents.length > 0">
<p>
{{'marathon.submit.category.opponent.with' | translate}}
<span *ngFor="let opponent of category.opponentDtos; let i = index">
<span *ngFor="let opponent of category.opponents; let i = index">
<span *ngIf="i > 0">, </span>
<app-user-link [user]="opponent.user" [isLink]="true" [showAvatar]="true"></app-user-link>
<a [href]="opponent.video" target="_blank" aria-label="Video" *ngIf="opponent.video">
Expand Down
20 changes: 10 additions & 10 deletions src/app/marathon/submit/submit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h3 class="title is-3">{{'marathon.submit.availabilities.label' | translate}} <b
<span class="is-size-6" [innerHTML]="'footer.text' | translate:{'timezone': timezone}"></span>
<button type="submit" class="button is-primary is-pulled-right" [ngClass]="{'is-loading': loading}"
[disabled]="form.invalid || submission.availabilities.length === 0 || submission.games.length === 0 &&
submission.opponentDtos.length === 0">{{'action.submit' |
submission.opponents.length === 0">{{'action.submit' |
translate}}
</button>
<a type="button"
Expand Down Expand Up @@ -469,7 +469,7 @@ <h3 class="title is-3">{{'marathon.submit.submissions' | translate}}</h3>
<select [(ngModel)]="category.type" [disabled]="!marathonService.marathon.hasMultiplayer"
name="type-{{i}}-{{j}}">
<option value="SINGLE"
[disabled]="category.opponentDtos && category.opponentDtos.length > 0">
[disabled]="category.opponents && category.opponents.length > 0">
{{'marathon.schedule.type.SINGLE' | translate}}
</option>
<option value="RACE">{{ 'marathon.schedule.type.RACE' | translate}}</option>
Expand All @@ -484,12 +484,12 @@ <h3 class="title is-3">{{'marathon.submit.submissions' | translate}}</h3>
{{'marathon.submit.category.code.help.noCode' | translate}}
</p>
<p class="help"
*ngIf="category.opponentDtos && category.opponentDtos.length > 0">{{'marathon.submit.category.opponent.with' |
*ngIf="category.opponents && category.opponents.length > 0">{{'marathon.submit.category.opponent.with' |
translate}}
<span *ngFor="let opponent of category.opponentDtos; let i = index">
<span *ngIf="i > 0">, </span>
<app-user [user]="opponent.user" [showSocialLinks]="true"></app-user>
</span>
<span *ngFor="let opponent of category.opponents; let i = index">
<span *ngIf="i > 0">, </span>
<app-user [user]="opponent.user" [showSocialLinks]="true"></app-user>
</span>
</p>
<p class="help" *ngIf="category.code">
{{'marathon.submit.category.code.help.withCode' | translate}} <b>{{category.code}}</b></p>
Expand Down Expand Up @@ -542,7 +542,7 @@ <h3 class="title is-3">{{'marathon.submit.multiplayer.title' | translate}}</h3>
[disabled]="!code">{{'action.join' | translate}}</button>
</div>
</div>
<table class="table is-striped" *ngIf="submission.opponentDtos && submission.opponentDtos.length">
<table class="table is-striped" *ngIf="submission.opponents && submission.opponents.length">
<thead>
<tr>
<th>{{'marathon.submit.table.runners' | translate}}</th>
Expand All @@ -553,7 +553,7 @@ <h3 class="title is-3">{{'marathon.submit.multiplayer.title' | translate}}</h3>
</tr>
</thead>
<tbody>
<tr *ngFor="let opponent of submission.opponentDtos; let i = index">
<tr *ngFor="let opponent of submission.opponents; let i = index">
<td>
<div *ngFor="let user of opponent.users" class="is-flex">
<app-user-link [user]="user" [isLink]="true" target="_blank"></app-user-link>
Expand Down Expand Up @@ -590,7 +590,7 @@ <h3 class="title is-3">{{'marathon.submit.multiplayer.title' | translate}}</h3>
<div class="is-clearfix">
<button type="submit" class="button is-primary is-pulled-right" [ngClass]="{'is-loading': loading}"
[disabled]="form.invalid || submission.availabilities.length === 0 || submission.games.length === 0 &&
submission.opponentDtos.length === 0">{{'action.submit' |
submission.opponents.length === 0">{{'action.submit' |
translate}}
</button>
<a type="button"
Expand Down
22 changes: 18 additions & 4 deletions src/app/marathon/submit/submit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export class SubmitComponent implements OnInit {
});
}
}
if (!this.submission.opponentDtos || this.submission.opponentDtos.length === 0) {
this.submission.opponentDtos = [];
if (!this.submission.opponents || this.submission.opponents.length === 0) {
this.submission.opponents = [];
}
}

Expand All @@ -138,6 +138,20 @@ export class SubmitComponent implements OnInit {
game.console = '';
game.categories.push(new Category());

// TODO: remove, for testing only

// game.name = 'Portal';
// game.console = 'PC';
// game.ratio = '1:1';
// game.emulated = true;
// game.description = 'Cool game pls accept';
//
// game.categories[0].name = 'Any%';
// game.categories[0].estimate = 'PT115M';
// game.categories[0].estimateHuman = '00:15:00';
// game.categories[0].description = 'Very cool';
// game.categories[0].video = 'https://www.youtube.com/watch?v=dQw4w9WgXc';

this.submission.games.push(game);
}

Expand Down Expand Up @@ -247,7 +261,7 @@ export class SubmitComponent implements OnInit {

getMultiplayerSubmission() {
this.categoryService.getFromCode(this.marathonService.marathon.id, this.code).subscribe(response => {
this.submission.opponentDtos.push(response);
this.submission.opponents.push(response);
}, error => {
this.translateService.get('alert.submit.' + error.error).subscribe((res: string) => {
const alertConfig: NwbAlertConfig = {
Expand All @@ -262,7 +276,7 @@ export class SubmitComponent implements OnInit {
}

removeMultiplayer(index: number) {
this.submission.opponentDtos.splice(index, 1);
this.submission.opponents.splice(index, 1);
}

deleteSubmission(marathonId: string, submissionId: number) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class Category {
type: string;
code: string;
status: string;
opponentDtos: Opponent[];
opponents: Opponent[];

constructor() {
this.id = -1;
this.opponentDtos = [];
this.opponents = [];
this.type = 'SINGLE';
}
}
Expand Down
1 change: 1 addition & 0 deletions src/model/opponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Opponent {
availabilities: Availability[];

constructor() {
this.id = -1;
this.users = [];
this.availabilities = [];
}
Expand Down
5 changes: 3 additions & 2 deletions src/model/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export class Submission {
games: Game[];
availabilities: Availability[];
answers: Answer[];
opponentDtos: Opponent[];
opponents: Opponent[];

constructor() {
this.id = -1;
this.games = [];
this.availabilities = [];
this.answers = [];
this.opponentDtos = [];
this.opponents = [];
}
}

0 comments on commit 169ebcf

Please sign in to comment.