Skip to content

Commit

Permalink
Add support page greeting and config form.
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Feb 5, 2024
1 parent 3e7292c commit b9aa277
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ <h1 class="admin-header mb-0 pl-0">Administration</h1>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['registrar', 'users']">Users</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['registrar', 'players']">Players</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['registrar', 'sponsors']">Sponsors</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['support']">Challenges</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['support']"
[routerLinkActiveOptions]="{exact: true}">Challenges</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['support', 'settings']"
[routerLinkActiveOptions]="{exact: true}">Support</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['notifications']">Notifications</a>
<a class="btn btn-link" routerLinkActive="active" [routerLink]="['report']">Reports</a>
</nav>
Expand Down
3 changes: 3 additions & 0 deletions projects/gameboard-ui/src/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { UserRegistrarComponent } from './user-registrar/user-registrar.componen
import { UserReportComponent } from './user-report/user-report.component';
import { AdminSystemNotificationsComponent } from '@/system-notifications/components/admin-system-notifications/admin-system-notifications.component';
import { EventHorizonModule } from '@/event-horizon/event-horizon.module';
import { SupportSettingsComponent } from './components/support-settings/support-settings.component';


@NgModule({
Expand Down Expand Up @@ -100,6 +101,7 @@ import { EventHorizonModule } from '@/event-horizon/event-horizon.module';
UserReportComponent,
SiteOverviewStatsComponent,
AdminOverviewComponent,
SupportSettingsComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -133,6 +135,7 @@ import { EventHorizonModule } from '@/event-horizon/event-horizon.module';
{ path: 'report/support', component: SupportReportLegacyComponent },
{ path: 'report/participation', component: ParticipationReportComponent },
{ path: "notifications", component: AdminSystemNotificationsComponent },
{ path: "support/settings", component: SupportSettingsComponent },
{ path: 'support', component: ChallengeBrowserComponent }
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1>
Support Settings
</h1>

<div class="settings-section mt-4 mb-4" *ngIf="settings; else loading">
<h2>Greeting</h2>
<p>
This text appears as a banner on the Support page to welcome players. Edit it below
to customize it to your needs.
</p>

<label for="supportPageGreeting">Enter a greeting (allows markdown)</label>
<textarea id="supportPageGreeting" rows="8" [placeholder]="'Welcome to **' + appName + '** Support!'"
class="form-control" [(ngModel)]="settings.supportPageGreeting" (input)="handleSettingsChanged()"></textarea>
</div>

<ng-template #loading>
<app-spinner></app-spinner>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { SupportSettings } from '@/api/support-models';
import { SupportService } from '@/api/support.service';
import { UnsubscriberService } from '@/services/unsubscriber.service';
import { ConfigService } from '@/utility/config.service';
import { Component, OnInit } from '@angular/core';
import { Subject, debounceTime, firstValueFrom } from 'rxjs';

@Component({
selector: 'app-support-settings',
templateUrl: './support-settings.component.html',
styleUrls: ['./support-settings.component.scss'],
providers: [UnsubscriberService]
})
export class SupportSettingsComponent implements OnInit {
protected appName: string;
protected settings?: SupportSettings;
private update$ = new Subject<SupportSettings>();

constructor(
config: ConfigService,
private supportService: SupportService,
private unsub: UnsubscriberService) {
// use the app name to personalize the placeholder
this.appName = config.appName;

// debounce input on the big textboxes
this.unsub.add(
this.update$.pipe(
debounceTime(500)
).subscribe(async update => {
await firstValueFrom(this.supportService.updateSettings(update));
})
);
}

async ngOnInit(): Promise<void> {
this.settings = await firstValueFrom(this.supportService.getSettings());
}

protected async handleSettingsChanged() {
if (this.settings)
this.update$.next(this.settings);
}
}
4 changes: 4 additions & 0 deletions projects/gameboard-ui/src/app/api/support-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { Challenge, ChallengeOverview, ChallengeSummary } from "./board-models";
import { PlayerOverview } from "./player-models";
import { UserSummary } from "./user-models";

export interface SupportSettings {
supportPageGreeting?: string;
}

export interface Ticket {
id: string;
key: number;
Expand Down
12 changes: 11 additions & 1 deletion projects/gameboard-ui/src/app/api/support.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { catchError, first, last, map, tap } from 'rxjs/operators';
import { ConfigService } from '../utility/config.service';
import { ChallengeOverview } from './board-models';
import { PlayerService } from './player.service';
import { AttachmentFile, ChangedTicket, NewTicket, NewTicketComment, Ticket, TicketActivity, TicketSummary } from './support-models';
import { AttachmentFile, ChangedTicket, NewTicket, NewTicketComment, SupportSettings, Ticket, TicketActivity, TicketSummary } from './support-models';
import { UserSummary } from './user-models';
import { Search } from './models';
import { ApiUrlService } from '@/services/api-url.service';

@Injectable({ providedIn: 'root' })
export class SupportService {
Expand All @@ -19,6 +20,7 @@ export class SupportService {
seenStart = new Date();

constructor(
private apiUrl: ApiUrlService,
private http: HttpClient,
private playerService: PlayerService,
private config: ConfigService
Expand Down Expand Up @@ -118,6 +120,14 @@ export class SupportService {
}
}

getSettings() {
return this.http.get<SupportSettings>(this.apiUrl.build("support/settings"));
}

updateSettings(settings: SupportSettings) {
return this.http.put<SupportSettings>(this.apiUrl.build("support/settings"), settings);
}

getTicketMarkdown = (ticket: Ticket): Observable<string> =>
this.playerService.getTeam(ticket.teamId).pipe(
catchError(err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<h1 class="support-header mb-0">Support</h1>
</div>

<div class="container mb-4" *ngIf="settings?.supportPageGreeting">
<markdown [data]="settings?.supportPageGreeting"></markdown>
<hr />
</div>

<main class="mb-4 pb-4">
<router-outlet></router-outlet>
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
padding-top: 1rem;
padding-left: 2rem;
}

hr {
border: solid 1px #eee;
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { ConfigService } from '../../utility/config.service';
import { NotificationService } from '../../services/notification.service';
import { UserService } from '../../utility/user.service';
import { UnsubscriberService } from '@/services/unsubscriber.service';
import { SupportSettings } from '@/api/support-models';
import { SupportService } from '@/api/support.service';
import { firstValueFrom } from 'rxjs';

@Component({
selector: 'app-support-page',
templateUrl: './support-page.component.html',
styleUrls: ['./support-page.component.scss']
styleUrls: ['./support-page.component.scss'],
providers: [UnsubscriberService]
})
export class SupportPageComponent implements OnInit, OnDestroy {
s: Subscription[] = [];
export class SupportPageComponent implements OnInit {
protected settings?: SupportSettings;

constructor(
private config: ConfigService,
private supportService: SupportService,
private unsub: UnsubscriberService,
hub: NotificationService,
user: UserService
) {
this.s.push(
// join the hub to get ticket notifications
this.unsub.add(
user.user$.pipe(
filter(u => !!u),
tap(u => hub.init(u!.id))
).subscribe()
);
}

ngOnInit(): void {
}

ngOnDestroy(): void {
this.s.forEach(s => s.unsubscribe());
async ngOnInit(): Promise<void> {
this.settings = await firstValueFrom(this.supportService.getSettings());
}
}

0 comments on commit b9aa277

Please sign in to comment.