2025-05-30 21:41:13 +00:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
2025-04-26 18:58:47 +00:00
|
|
|
import {HeaderComponent} from '../header/header.component';
|
2025-05-30 21:41:13 +00:00
|
|
|
import {LoginService} from '../../api';
|
|
|
|
|
import {MatDialog} from '@angular/material/dialog';
|
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
|
import {LoginDialogComponent} from '../login/login.component';
|
|
|
|
|
import {KeyValuePipe, NgForOf, NgIf} from '@angular/common';
|
|
|
|
|
import {FormType} from './form_type';
|
|
|
|
|
import {MatButton} from '@angular/material/button';
|
2025-04-26 18:58:47 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-forms',
|
|
|
|
|
imports: [
|
2025-05-30 21:41:13 +00:00
|
|
|
HeaderComponent,
|
|
|
|
|
NgIf,
|
|
|
|
|
NgForOf,
|
|
|
|
|
MatButton,
|
|
|
|
|
KeyValuePipe
|
2025-04-26 18:58:47 +00:00
|
|
|
],
|
|
|
|
|
templateUrl: './forms.component.html',
|
|
|
|
|
styleUrl: './forms.component.scss'
|
|
|
|
|
})
|
2025-05-30 21:41:13 +00:00
|
|
|
export class FormsComponent implements OnInit {
|
2025-04-26 18:58:47 +00:00
|
|
|
@Input() formTitle: string = 'Form';
|
|
|
|
|
@Input() currentPage: string = 'forms';
|
2025-05-30 21:41:13 +00:00
|
|
|
|
|
|
|
|
public type: FormType | undefined;
|
|
|
|
|
|
|
|
|
|
constructor(private loginService: LoginService,
|
|
|
|
|
private dialog: MatDialog,
|
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
|
) {
|
|
|
|
|
this.route.paramMap.subscribe(async params => {
|
|
|
|
|
const code = params.get('code');
|
|
|
|
|
|
|
|
|
|
if (code) {
|
|
|
|
|
this.loginService.login(code).subscribe(jwt => this.saveJwt(jwt as JsonWebKey)); //TODO handle error
|
|
|
|
|
} else {
|
|
|
|
|
const dialogRef = this.dialog.open(LoginDialogComponent, {
|
|
|
|
|
width: '400px',
|
|
|
|
|
disableClose: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(jwt => {
|
|
|
|
|
this.saveJwt(jwt as JsonWebKey)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.route.paramMap.subscribe(params => {
|
|
|
|
|
switch (params.get('form')) {
|
|
|
|
|
case FormType.APPEAL:
|
|
|
|
|
this.type = FormType.APPEAL;
|
|
|
|
|
this.currentPage = 'appeal';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error("Invalid type");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private saveJwt(jwt: JsonWebKey) {
|
|
|
|
|
const claims = this.extractJwtClaims(jwt);
|
|
|
|
|
const authorizations = claims?.authorizations || [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extractJwtClaims(jwt: JsonWebKey): any {
|
|
|
|
|
const token = jwt.toString();
|
|
|
|
|
const base64Url = token.split('.')[1];
|
|
|
|
|
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
|
|
|
return JSON.parse(window.atob(base64));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected readonly FormType = FormType;
|
|
|
|
|
protected readonly Object = Object;
|
|
|
|
|
|
|
|
|
|
public setFormType(formType: FormType) {
|
|
|
|
|
this.type = formType;
|
|
|
|
|
}
|
2025-04-26 18:58:47 +00:00
|
|
|
}
|