Initial commit
This commit is contained in:
54
src/app/admin-view/notifications/notifications.component.ts
Normal file
54
src/app/admin-view/notifications/notifications.component.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { AdminCommService } from '../admin-comm.service';
|
||||
import { Notification } from 'src/app/types/notification';
|
||||
import { Group } from 'src/app/types/group';
|
||||
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-notifications',
|
||||
templateUrl: './notifications.component.html',
|
||||
styleUrls: ['./notifications.component.scss']
|
||||
})
|
||||
export class NotificationsComponent implements OnInit {
|
||||
|
||||
groups!: Group[]
|
||||
|
||||
constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.acs.notif.getGroups().subscribe((v) => {
|
||||
this.groups = v
|
||||
})
|
||||
}
|
||||
|
||||
success?: { sent: number; possible: number; };
|
||||
|
||||
form = new FormGroup<NotificationForm>({
|
||||
recp: new FormGroup({
|
||||
uname: new FormControl<string>(''),
|
||||
room: new FormControl<number|null>(null),
|
||||
group: new FormControl<string>(''),
|
||||
type: new FormControl<"all" | "room" | "uname" | "group">('uname', {nonNullable: true})
|
||||
}),
|
||||
title: new FormControl('', {nonNullable: true}),
|
||||
body: new FormControl('', {nonNullable: true})
|
||||
})
|
||||
|
||||
submit() {
|
||||
this.acs.notif.send(this.form.value as Notification).subscribe((data) => {
|
||||
this.success = data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
interface NotificationForm {
|
||||
body: FormControl<string>;
|
||||
title: FormControl<string>;
|
||||
recp: FormGroup<{
|
||||
uname: FormControl<string | null>;
|
||||
room: FormControl<number | null>;
|
||||
group: FormControl<string | null>;
|
||||
type: FormControl<"all" | "room" | "uname" | "group">;
|
||||
}>
|
||||
}
|
||||
Reference in New Issue
Block a user