timemanager/frontend/src/app/admin-dashboard/settings/settings.component.ts
2023-10-02 13:04:48 +02:00

56 lines
1.4 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import {PropertiesInfo, PropertiesService, PropertyInfo, UserInfo} from "../../../api";
import {Router} from "@angular/router";
import {MatLegacySnackBar as MatSnackBar} from "@angular/material/legacy-snack-bar";
@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.css']
})
export class SettingsComponent implements OnInit {
settings: PropertyInfo[] = []
pending: boolean = false;
constructor(
private propertyService: PropertiesService,
private router: Router,
private snackbar: MatSnackBar
) { }
ngOnInit(): void {
this.propertyService.settingsGet().subscribe({
next: resp => {
this.settings = resp.settings;
},
error: err => {
if(err.status == 403) {
this.router.navigateByUrl("/");
}
}
})
}
onUpdateBtn() {
this.pending = true;
this.propertyService.settingsUpdatePost({
settings: this.settings
}).subscribe({
next: resp => {
if(resp.status == "success") {
this.snackbar.open("Update Settings successfully!", "", {duration: 2000})
}
this.pending = false;
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permissions!", "", {duration: 2000})
}
this.pending = false;
}
})
}
}