Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

67 wiersze
1.9 KiB

  1. import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core';
  2. import {UserJsonld, UserService} from "@app/core/api/v1";
  3. import {AccountService} from "@app/_services";
  4. import {AppHelperService} from "@app/_helpers/app-helper.service";
  5. import {ActivatedRoute} from "@angular/router";
  6. import {FormMode, FormSubmitEvent} from "@app/_components/_abstract/abstract-data-form-component";
  7. import {ModalStatus} from "@app/_helpers/modal.states";
  8. @Component({
  9. selector: 'app-user-detail',
  10. templateUrl: './user-detail.component.html',
  11. styleUrl: './user-detail.component.scss'
  12. })
  13. export class UserDetailComponent implements OnInit, AfterViewInit {
  14. @Input() public user!: UserJsonld;
  15. protected readonly FormMode = FormMode;
  16. protected isCurrentUser: boolean;
  17. constructor(
  18. private accountService: AccountService,
  19. private userService: UserService,
  20. protected appHelperService: AppHelperService,
  21. private route: ActivatedRoute,
  22. ) {
  23. this.isCurrentUser = false;
  24. }
  25. ngOnInit() {
  26. if (this.user === undefined) {
  27. this.route.params.subscribe(params => {
  28. this.getUserData(params['id']);
  29. });
  30. } else {
  31. this.setIsCurrentUser();
  32. }
  33. }
  34. ngAfterViewInit(): void {
  35. }
  36. getUserData(userId: string) {
  37. this.userService.usersIdGet(
  38. userId
  39. ).subscribe(
  40. data => {
  41. this.user = data;
  42. this.setIsCurrentUser();
  43. }
  44. );
  45. }
  46. setIsCurrentUser() {
  47. if (this.accountService.userValue) {
  48. let user = this.accountService.userValue;
  49. this.isCurrentUser = this.appHelperService.extractId(this.user.id) == user?.id;
  50. }
  51. }
  52. onFormUpdate(event: FormSubmitEvent<UserJsonld>) {
  53. if (event.status === ModalStatus.Submitted && event.data) {
  54. this.user = event.data;
  55. }
  56. }
  57. }