Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 114x 4x 4x 4x 4x 4x 4x 3x 3x 2x 3x 3x 3x 2x 2x 2x 2x 2x 2x 3x 3x 3x 2x 2x 110x | import { Component, inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { ToggleButtonModule } from 'primeng/togglebutton';
import { MessageService } from 'primeng/api';
import { FormsModule } from '@angular/forms';
import { User } from '../../models/users';
import { ActivatedRoute } from '@angular/router';
import { TwinpadApiService } from '../../services/twinpad-api.service';
@Component({
selector: 'app-profile',
imports: [FormsModule, ReactiveFormsModule, ToggleButtonModule],
templateUrl: './profile.component.html',
styleUrl: './profile.component.scss'
})
export class ProfileComponent implements OnInit {
private fb = inject(FormBuilder);
private twinpadApiService = inject(TwinpadApiService);
private route = inject(ActivatedRoute);
userId: string;
ownProfile: boolean = true;
messageService = inject(MessageService);
user: User;
profileForm: FormGroup;
theme: string = 'system'; // Default to system theme
themeOptions: string[];
firstname: string;
lastname: string;
mail: string;
password: string;
userBlocked: boolean;
userAdministrator: boolean;
ngOnInit() {
this.userId = this.route.snapshot.params['id'];
if (this.userId) {
this.ownProfile = false;
}
// Set themes options
this.themeOptions = ["system", "light", "dark"];
// Initialize the form
this.profileForm = this.fb.group({
firstname: ['', [Validators.required]],
lastname: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email]],
password: [''],
userBlocked: [''],
userAdministrator: ['']
});
this.twinpadApiService.getProfile(this.userId).subscribe({
next: value => {
this.userId = value.id;
this.profileForm.controls['firstname'].setValue(value.firstname);
this.profileForm.controls['lastname'].setValue(value.lastname);
this.profileForm.controls['email'].setValue(value.email);
this.profileForm.controls['userBlocked'].setValue(value.is_blocked);
this.profileForm.controls['userAdministrator'].setValue(value.is_admin);
},
error: _ => {
}
});
// Check if the user has a saved theme preference in localStorage
const savedTheme = localStorage.getItem('theme');
Iif (savedTheme) {
this.theme = savedTheme;
} else {
// Apply system theme if no saved preference
this.theme = "system";
}
}
editProfile(){
return this.twinpadApiService.editProfile(this.profileForm, this.userId).subscribe(
{
next: _value => {
this.messageService.add({severity:'success', summary: 'Saving success', detail: 'Your profile has been updated '});
},
error: err => {
this.messageService.add({severity:'error', summary: 'Saving failed', detail: err.error.detail});
}
}
);
}
}
|