Skip to content

Commit

Permalink
Light revamp of name approvals
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Dec 19, 2024
1 parent 31a1b61 commit 20f065d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,49 @@ <h6>Score</h6>
</div>

<ng-container>
<h4 class="mt-4 px-3">Team Management</h4>
<div class="name-management">
<ul class="container mx-0">
<li class="row">
<div class="col-3">
<label class="mb-0 text-muted">Current Name</label>
</div>
<div class="col-4">
<label class="mb-0 text-muted">Requested Name</label>
</div>
<div class="col-3">
<label class="mb-0 text-muted" for="reason-input">Reason for Change</label>
</div>
</li>
<li *ngFor="let player of team.players" class="row mb-2">
<div class="col-3">
<div class="fs-10 player-current-name">{{ player.name }}</div>
</div>
<div class="col-4">
<input type="text" class="form-control" name="pending-name-input-{{player.id}}" type="text"
[placeholder]="(player.pendingName ? 'Name this player (requested: ' + player.pendingName + ')' : 'No pending name change requests from this player')"
minlength="2" [value]="player.pendingName" #pendingNameInput>
</div>
<div class="col-3">
<select name="reason-select" class="form-control" #reasonSelect>
<option [value]="''">[not disapproved]</option>
<option *ngFor="let reason of reasons" [value]="reason">
{{reason}}
</option>
</select>
</div>
<div>
<button type="button" class="btn btn-warning mr-2"
[disabled]="pendingNameInput.value.length < 2"
(click)="approveName(player.id, { name: pendingNameInput.value, revisionReason: reasonSelect.value })">Approve</button>
<div class="mt-4 px-3">
<h4>Team Management</h4>
<table class="width-100">
<col class="width-20">
<col class="width-20">
<col class="width-20">
<col class="width-20">
<col class="width-20">

<button type="button" class="btn btn-danger"
[disabled]="team.players.length == 1 || (player.id === team.captain.id)"
(click)="handleRemovePlayerConfirm(player)">Remove</button>
</div>
</li>
</ul>
<thead>
<th>Name</th>
<th>Requested Name</th>
<th>Override Name</th>
<th>Status</th>
<th></th>
</thead>

<tbody>
<tr *ngFor="let player of team.players">
<td>{{ player.name }}</td>
<td>{{ player.pendingName || "--" }}</td>
<td>
<input type="text" class="form-control" placeholder="Enter a name" #overrideName>
</td>
<td>
<select name="reason-select" class="form-control" #reasonSelect>
<option [value]="''">[approved]</option>
<option *ngFor="let reason of reasons" [value]="reason">
{{reason}}
</option>
</select>
</td>
<td class="d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-warning mr-2"
(click)="updateNameChangeRequest(player.id, overrideName.value, { requestedName: player.pendingName || '', approvedName: player.name || '', status: reasonSelect.value })">Update</button>

<button type="button" class="btn btn-danger"
[disabled]="team.players.length == 1 || (player.id === team.captain.id)"
(click)="handleRemovePlayerConfirm(player)">Remove</button>
</td>
</tr>
</tbody>
</table>
</div>
</ng-container>

Expand All @@ -81,9 +82,6 @@ <h4 class="mt-4 px-3">Session</h4>
</div>

<h4 class="px-3 mr-1">Timeline</h4>
<!-- <div class="d-flex align-items-baseline">
</div> -->
<div class="timeline-container px-3 mb-4">
<app-team-event-horizon [teamId]="team.id"></app-team-event-horizon>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AdminService } from '@/api/admin.service';
import { ToastService } from '@/utility/services/toast.service';
import { TeamService } from '@/api/team.service';
import { SimpleEntity } from '@/api/models';
import { UpdatePlayerNameChangeRequest } from '@/api/admin.models';

@Component({
selector: 'app-game-center-team-detail',
Expand Down Expand Up @@ -106,20 +107,29 @@ export class GameCenterTeamDetailComponent implements OnInit {
this.showChallengeYaml = isExpanding;
}

protected async approveName(playerId: string, args: { name: string, revisionReason: string }) {
const finalName = args.name.trim();
await this.adminService.approvePlayerName(playerId, args);
protected async updateNameChangeRequest(playerId: string, overrideName: string, args: UpdatePlayerNameChangeRequest) {
if (!args.status) {
args.approvedName = overrideName || args.requestedName;
}

// tell the API
await this.adminService.updatePlayerNameChangeRequest(playerId, args);

// rebind
const player = this.team.players.find(p => p.id === playerId);
if (player) {
player.pendingName = "";
player.name = args.name;
player.pendingName = player.pendingName == args.approvedName ? "" : player.pendingName;
player.name = args.approvedName;
}

if (this.team.captain.id === playerId)
this.team.name = args.name;
this.team.name = args.approvedName;

this.toastService.showMessage(`This player's name has been changed to **${args.approvedName}**.${args.status ? ` (reason: **${args.status}**)` : ""}`);
}

this.toastService.showMessage(`This player's name has been changed to **${args.name}**.${args.revisionReason ? ` (reason: **${args.revisionReason}**)` : ""}`);
protected handleAdminNameChangeRequest() {
this.modalService.openConfirm({ bodyContent: "Are you sure?" });
}

protected async handleRemovePlayerConfirm(player: SimpleEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ export class PlayerNamesComponent {
}

async approveName(model: Player) {
const requested = model.name;
const approved = model.approvedName;

model.approvedName = model.name;
model.nameStatus = "";
model.pendingName = "";
await this.adminService.approvePlayerName(model.id, { name: model.name });
await this.adminService.updatePlayerNameChangeRequest(model.id, { approvedName: approved, requestedName: requested, status: "" });
}

resetName(model: Player): void {
Expand Down
11 changes: 6 additions & 5 deletions projects/gameboard-ui/src/app/api/admin.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ export interface AppActiveChallengeGame {
isTeamGame: boolean;
}

export interface ApprovePlayerNameRequest {
name: string;
revisionReason?: string;
}

export interface GetAppActiveChallengesResponse {
specs: AppActiveChallengeSpec[];
}
Expand Down Expand Up @@ -89,3 +84,9 @@ export interface SendAnnouncement {
title?: string;
teamId?: string;
}

export interface UpdatePlayerNameChangeRequest {
approvedName: string;
requestedName: string;
status: string;
}
4 changes: 2 additions & 2 deletions projects/gameboard-ui/src/app/api/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { DateTime } from 'luxon';
import { Observable, firstValueFrom, map, tap } from 'rxjs';
import { ApiUrlService } from '@/services/api-url.service';
import { ApprovePlayerNameRequest, GetAppActiveChallengesResponse, GetAppActiveTeamsResponse, GetPlayersCsvExportResponse, GetPlayersCsvExportResponsePlayer, GetSiteOverviewStatsResponse, SendAnnouncement } from './admin.models';
import { UpdatePlayerNameChangeRequest, GetAppActiveChallengesResponse, GetAppActiveTeamsResponse, GetPlayersCsvExportResponse, GetPlayersCsvExportResponsePlayer, GetSiteOverviewStatsResponse, SendAnnouncement } from './admin.models';
import { PlayerMode } from './player-models';
import { GameCenterContext, GameCenterPracticeContext, GameCenterTeamsRequestArgs, GameCenterTeamsResults, GetGameCenterPracticeContextRequest } from '@/admin/components/game-center/game-center.models';

Expand All @@ -13,7 +13,7 @@ export class AdminService {
private apiUrl: ApiUrlService,
private http: HttpClient) { }

async approvePlayerName(playerId: string, request: ApprovePlayerNameRequest) {
async updatePlayerNameChangeRequest(playerId: string, request: UpdatePlayerNameChangeRequest) {
return await firstValueFrom(this.http.put(this.apiUrl.build(`admin/players/${playerId}/name`), request));
}

Expand Down

0 comments on commit 20f065d

Please sign in to comment.