Skip to content

Commit

Permalink
Resolve GBAPI#415, GBAPI#424
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Feb 18, 2025
1 parent a494998 commit 3576ada
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<div>Playing now</div>
<strong class="text-success d-block"
[tooltip]="'Ends ' + (team.session.end | epochMsToDateTime | friendlyDateAndTime) || ''">{{
team.session.end | epochMsToDateTime | datetimeToDate | dateToCountdown | async
team.session.end | epochMsToDateTime | datetimeToDate | dateToCountdown:120000 | async
}}</strong>
<div class="fs-08 text-muted">remaining</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
tooltip="Deploy challenge resources" [disabled]="!isUnlocked">
<fa-icon [icon]="fa.play"></fa-icon>
</button>
<button
*ngIf="challenge.state != 'notStarted' && challenge.challengeId && ('Admin_View' | can)"
class="btn btn-danger" (click)="handleSyncClick(challenge.challengeId)"
tooltip="Sync with game engine" [disabled]="!isUnlocked">
<fa-icon [icon]="fa.sync"></fa-icon>
</button>
<button *ngIf="challenge.state == 'deployed' && ('Teams_DeployGameResources' | can)"
class="btn btn-danger" (click)="handleUneployClick(challenge.challengeId)"
tooltip="Undeploy challenge resources" [disabled]="!isUnlocked">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ToSupportCodePipe } from '@/standalone/core/pipes/to-support-code.pipe'
import { ChallengesService } from '@/api/challenges.service';
import { firstValueFrom, Subject } from 'rxjs';
import { fa } from '@/services/font-awesome.service';
import { ToastService } from '@/utility/services/toast.service';

@Component({
selector: 'app-team-challenges-modal',
Expand All @@ -26,6 +27,7 @@ import { fa } from '@/services/font-awesome.service';
export class TeamChallengesModalComponent implements OnInit {
private challengeService = inject(ChallengesService);
private teamService = inject(TeamService);
private toasts = inject(ToastService);
teamId!: string;

protected ctx?: GetTeamChallengeSpecsStatusesResponse;
Expand Down Expand Up @@ -68,6 +70,11 @@ export class TeamChallengesModalComponent implements OnInit {
await this.doChallengeStuff(() => this.challengeService.start({ teamId: this.teamId, challengeSpecId }));
}

async handleSyncClick(challengeId: string): Promise<void> {
await this.doChallengeStuff(() => this.challengeService.sync(challengeId));
this.toasts.showMessage("The challenge was **synchronized** with the game engine.");
}

handleUnlockAdminCodeInput(value: string) {
this.isUnlocked = value.toLowerCase() === this.unlockAdminCode.toLowerCase();
}
Expand Down
6 changes: 5 additions & 1 deletion projects/gameboard-ui/src/app/api/challenges.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject, firstValueFrom, map, tap } from 'rxjs';
import { DateTime } from 'luxon';
import { Challenge, NewChallenge, SectionSubmission } from './board-models';
import { Challenge, GameState, NewChallenge, SectionSubmission } from './board-models';
import { ApiUrlService } from '@/services/api-url.service';
import { ChallengeProgressResponse, ChallengeSolutionGuide, GetUserActiveChallengesResponse } from './challenges.models';

Expand Down Expand Up @@ -47,6 +47,10 @@ export class ChallengesService {
);
}

public sync(challengeId: string): Promise<GameState> {
return firstValueFrom(this.http.put<GameState>(this.apiUrl.build(`challenge/${challengeId}/sync`), {}));
}

public deploy(challenge: { id: string }): Observable<Challenge> {
return this.http.put<Challenge>(this.apiUrl.build("challenge/start"), challenge).pipe(tap(challenge => {
this._challengeDeployStateChanged$.next(challenge);
Expand Down
26 changes: 15 additions & 11 deletions projects/gameboard-ui/src/app/core/pipes/date-to-countdown.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ import { Observable, interval, map } from 'rxjs';
@Pipe({ name: 'dateToCountdown' })
export class DateToCountdownPipe implements PipeTransform {

transform(value: Date | string | undefined | null): Observable<string | null> | null {
transform(value: Date | string | undefined | null, showSecondsWhenRemainingLessThanMs?: number): Observable<string | null> | null {
if (!value)
return null;

const date = DateTime.fromJSDate(new Date(value!));

return interval(1000).pipe(
map(_ => {
const diffed = date.diffNow().rescale();
diffed.normalize();
let diffed = date
.diffNow()
.rescale()
.set({ milliseconds: 0 });

return diffed
.set({ milliseconds: 0 })
.set({ seconds: Math.floor(diffed.get("seconds")) })
.rescale();
}),
map(duration => {
if (duration.as("milliseconds") < 0)
if (diffed.as("milliseconds") < 0)
return null;

return duration.toHuman({ compactDisplay: "short", unitDisplay: "short" } as Intl.NumberFormatOptions);
if (showSecondsWhenRemainingLessThanMs && diffed.toMillis() > showSecondsWhenRemainingLessThanMs) {
diffed = diffed.set({ seconds: 0 });
} else {
diffed = diffed.set({ seconds: Math.floor(diffed.get("seconds")) });
}

return diffed
.rescale()
.toHuman({ compactDisplay: "short", unitDisplay: "short" } as Intl.NumberFormatOptions);
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<div *ngTemplateOutlet="isTeamGame ? teamNamePanel : playerNamePanel; context: {$implicit: teamScore};">
</div>
<div class="flex-grow-1 text-right"
*ngIf="teamScore.sessionEnds | datetimeToDate | dateToCountdown | async as sessionEnds">
*ngIf="teamScore.sessionEnds | datetimeToDate | dateToCountdown:60000 | async as sessionEnds">
<span class="badge badge-success fs-09">{{ sessionEnds }}</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class ModalConfirmService implements OnDestroy {
return this.bsModalService.show(config.content, {
initialState: config.context as unknown as Partial<TComponent>,
class: ["modal-dialog-centered", ...(config.modalClasses || [])].join(" "),
focus: true,
ignoreBackdropClick: config.ignoreBackdropClick || false,
scrollable: true
} as ModalOptions<TComponent>);
Expand Down

0 comments on commit 3576ada

Please sign in to comment.