-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): discord configuration (#2421)
- Loading branch information
1 parent
b22a54e
commit 6e4804c
Showing
17 changed files
with
450 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Resolve } from '@angular/router'; | ||
import { map, Observable } from 'rxjs'; | ||
import { ConfigurationService } from '@app/configuration/configuration.service'; | ||
import { DiscordConfiguration } from './models/discord-configuration'; | ||
import { GuildConfiguration } from './models/guild-configuration'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class DiscordConfigurationResolver | ||
implements Resolve<DiscordConfiguration> | ||
{ | ||
constructor(private readonly configurationService: ConfigurationService) {} | ||
|
||
resolve(): Observable<DiscordConfiguration> { | ||
return this.configurationService | ||
.fetchValues<[GuildConfiguration[]]>('discord.guilds') | ||
.pipe( | ||
map(([guilds]) => ({ | ||
guilds: guilds.value, | ||
})), | ||
); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/app/admin/discord/discord-guild-edit/discord-guild-edit.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<div class="flex flex-col" [formGroup]="guildControl"> | ||
<div class="flex flex-row gap-2 items-center"> | ||
<input type="checkbox" name="id" formControlName="isEnabled" /> | ||
<span>{{ guildControl.get('name').value }}</span> | ||
</div> | ||
|
||
<div class="flex flex-col gap-2" *ngIf="guildControl.get('isEnabled').value"> | ||
<div | ||
class="flex flex-row gap-2 items-center" | ||
formGroupName="adminNotifications" | ||
> | ||
<span>Admin notifications channel:</span> | ||
<select formControlName="channel"> | ||
<option [ngValue]="null" class="text-gray-600">disabled</option> | ||
<optgroup | ||
*ngFor="let textChannelGroup of textChannels | async | keyvalue" | ||
label="{{ textChannelGroup.key }}" | ||
> | ||
<option | ||
*ngFor="let textChannel of textChannelGroup.value" | ||
[value]="textChannel.id" | ||
> | ||
{{ textChannel.name }} | ||
</option> | ||
</optgroup> | ||
</select> | ||
</div> | ||
|
||
<div | ||
class="flex flex-row gap-2 items-center" | ||
formGroupName="substituteNotifications" | ||
> | ||
<span>Substitute notifications channel:</span> | ||
<select formControlName="channel"> | ||
<option [ngValue]="null" class="text-gray-600">disabled</option> | ||
<optgroup | ||
*ngFor="let textChannelGroup of textChannels | async | keyvalue" | ||
label="{{ textChannelGroup.key }}" | ||
> | ||
<option | ||
*ngFor="let textChannel of textChannelGroup.value" | ||
[value]="textChannel.id" | ||
> | ||
{{ textChannel.name }} | ||
</option> | ||
</optgroup> | ||
</select> | ||
|
||
<span>mention role:</span> | ||
<select formControlName="role"> | ||
<option [ngValue]="null">disabled</option> | ||
<option *ngFor="let role of roles | async" [value]="role.id"> | ||
{{ role.name }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div class="flex flex-row gap-2 items-center" formGroupName="queuePrompts"> | ||
<span>Queue prompts channel:</span> | ||
<select formControlName="channel"> | ||
<option [ngValue]="null" class="text-gray-600">disabled</option> | ||
<optgroup | ||
*ngFor="let textChannelGroup of textChannels | async | keyvalue" | ||
label="{{ textChannelGroup.key }}" | ||
> | ||
<option | ||
*ngFor="let textChannel of textChannelGroup.value" | ||
[value]="textChannel.id" | ||
> | ||
{{ textChannel.name }} | ||
</option> | ||
</optgroup> | ||
</select> | ||
</div> | ||
</div> | ||
</div> |
Empty file.
85 changes: 85 additions & 0 deletions
85
src/app/admin/discord/discord-guild-edit/discord-guild-edit.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { DiscordService } from '../discord.service'; | ||
import { ReplaySubject, distinctUntilChanged, map } from 'rxjs'; | ||
import { TextChannel } from '../models/text-channel'; | ||
import { FormControl, FormGroup } from '@angular/forms'; | ||
import { Role } from '../models/role'; | ||
|
||
@Component({ | ||
selector: 'app-discord-guild-edit', | ||
templateUrl: './discord-guild-edit.component.html', | ||
styleUrls: ['./discord-guild-edit.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DiscordGuildEditComponent implements OnInit { | ||
@Input() | ||
guildControl: FormGroup<{ | ||
id: FormControl<string>; | ||
name: FormControl<string>; | ||
isEnabled: FormControl<boolean>; | ||
adminNotifications: FormGroup<{ channel: FormControl<string | null> }>; | ||
substituteNotifications: FormGroup<{ | ||
channel: FormControl<string | null>; | ||
role: FormControl<string | null>; | ||
}>; | ||
queuePrompts: FormGroup<{ channel: FormControl<string | null> }>; | ||
}>; | ||
|
||
textChannels = new ReplaySubject<Map<string, TextChannel[]>>(1); | ||
roles = new ReplaySubject<Role[]>(1); | ||
|
||
constructor(private readonly discordService: DiscordService) {} | ||
|
||
ngOnInit() { | ||
this.guildControl | ||
.get('isEnabled') | ||
.valueChanges.pipe(distinctUntilChanged()) | ||
.subscribe(isEnabled => { | ||
if (isEnabled) { | ||
this.loadTextChannels(); | ||
this.loadRoles(); | ||
} | ||
}); | ||
|
||
if (this.guildControl.get('isEnabled').value) { | ||
this.loadTextChannels(); | ||
this.loadRoles(); | ||
} | ||
} | ||
|
||
loadTextChannels() { | ||
this.discordService | ||
.fetchTextChannels(this.guildControl.get('id').value) | ||
.pipe( | ||
map(textChannels => | ||
textChannels.reduce((prev, curr) => { | ||
if (!prev.has(curr.parent)) { | ||
prev.set(curr.parent, []); | ||
} | ||
|
||
prev.get(curr.parent).push(curr); | ||
return prev; | ||
}, new Map<string, TextChannel[]>()), | ||
), | ||
map(groups => { | ||
groups.forEach(value => | ||
value.sort((a, b) => a.position - b.position), | ||
); | ||
return groups; | ||
}), | ||
) | ||
.subscribe(textChannels => this.textChannels.next(textChannels)); | ||
} | ||
|
||
loadRoles() { | ||
this.discordService | ||
.fetchTextChannels(this.guildControl.get('id').value) | ||
.pipe(map(roles => roles.sort((a, b) => a.name.localeCompare(b.name)))) | ||
.subscribe(roles => this.roles.next(roles)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<form [formGroup]="form" (submit)="save()"> | ||
<app-edit-page-wrapper | ||
title="Discord" | ||
[saveDisabled]="(isSaving | async) || !form.valid || form.pristine" | ||
> | ||
<div class="surface surface--white py-4 my-4 flex flex-col gap-2"> | ||
<ng-container formArrayName="guilds"> | ||
<div | ||
class="flex flex-row gap-2 items-center" | ||
*ngFor="let guildControl of guilds.controls" | ||
> | ||
<app-discord-guild-edit | ||
[guildControl]="guildControl | asFormGroup" | ||
></app-discord-guild-edit> | ||
</div> | ||
</ng-container> | ||
</div> | ||
</app-edit-page-wrapper> | ||
</form> |
Empty file.
Oops, something went wrong.