Initial commit

This commit is contained in:
2025-03-05 21:38:10 +01:00
commit 503909d762
198 changed files with 19203 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<!-- TODO: Remake the notifications module -->
<form [formGroup]="form" (ngSubmit)="submit()">
<div formGroupName="recp">
<mat-radio-group formControlName="type">
<mat-radio-button value="uname">
<mat-form-field>
<mat-label>Nazwa użytkownika</mat-label>
<input matInput type="text" formControlName="uname">
</mat-form-field>
</mat-radio-button>
<mat-radio-button value="room">
<mat-form-field>
<mat-label>Pokój</mat-label>
<input matInput type="number" formControlName="room">
</mat-form-field>
</mat-radio-button>
<mat-radio-button value="group" *ngIf="ls.capCheck(8)">
<mat-form-field>
<mat-label>Grupa</mat-label>
<mat-select formControlName="group">
<mat-option *ngFor="let item of groups" [value]="item._id">{{item.name}}</mat-option>
</mat-select>
</mat-form-field>
</mat-radio-button>
<mat-radio-button value="all">Wychowankowie</mat-radio-button>
</mat-radio-group>
</div>
<mat-form-field>
<mat-label>Tytuł</mat-label>
<input matInput type="text" formControlName="title">
</mat-form-field>
<br>
<mat-form-field>
<mat-label>Zawartość wiadomości</mat-label>
<textarea matInput cdkTextareaAutosize formControlName="body"></textarea>
</mat-form-field>
<br>
<button mat-fab extended type="submit">
<mat-icon>send</mat-icon>
Wyślij
</button>
</form>
<p *ngIf="success">Udało się wysłać {{success.sent}} z {{success.possible}} = {{success.sent/success.possible | percent}}</p>

View File

@@ -0,0 +1,3 @@
mat-radio-button {
display: block;
}

View File

@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NotificationsComponent } from './notifications.component';
describe('NotificationsComponent', () => {
let component: NotificationsComponent;
let fixture: ComponentFixture<NotificationsComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NotificationsComponent]
});
fixture = TestBed.createComponent(NotificationsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View 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">;
}>
}