You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

84 rivejä
3.7 KiB

  1. import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core';
  2. import {UserJsonld, UserService} from "@app/core/api/v1";
  3. import {Subscription} from "rxjs";
  4. import {AccountService} from "@app/_services";
  5. import {AppHelperService} from "@app/_helpers/app-helper.service";
  6. import {UsersComponent} from "@app/_views/user/users.component";
  7. import {ToggleComponent} from "@app/_components/toggle/toggle.component";
  8. import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component";
  9. import {SaleListComponent} from "@app/_views/sales/sale-list/sale-list.component";
  10. import {ProductListComponent} from "@app/_views/products/product-list/product-list.component";
  11. import {PartnerListComponent} from "@app/_views/partners/partner-list/partner-list.component";
  12. import {PostListComponent} from "@app/_views/posts/post-list/post-list.component";
  13. import {SaleSummaryComponent} from "@app/_views/sales/sale-summary/sale-summary.component";
  14. import {ActivatedRoute} from "@angular/router";
  15. @Component({
  16. selector: 'app-user-detail',
  17. templateUrl: './user-detail.component.html',
  18. styleUrl: './user-detail.component.scss'
  19. })
  20. export class UserDetailComponent implements OnInit, AfterViewInit {
  21. @Input() public user!: UserJsonld;
  22. @ViewChild("togglePosts", { static: true }) togglePosts!: ToggleComponent;
  23. @ViewChild("postListComponent", { static: false }) postsComponent!: PostListComponent;
  24. @ViewChild("toggleTasks", { static: true }) toggleTasks!: ToggleComponent;
  25. @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent;
  26. @ViewChild("toggleSales", { static: true }) toggleSales!: ToggleComponent;
  27. @ViewChild("saleSummaryComponent", { static: false }) saleSummaryComponent!: SaleSummaryComponent;
  28. @ViewChild("saleListComponent", { static: false }) saleListComponent!: SaleListComponent;
  29. @ViewChild("toggleProducts", { static: true }) toggleProducts!: ToggleComponent;
  30. @ViewChild("productListComponent", { static: false }) productListComponent!: ProductListComponent;
  31. @ViewChild("toggleCustomers", { static: true }) toggleCustomers!: ToggleComponent;
  32. @ViewChild("customerListComponent", { static: false }) customerListComponent!: PartnerListComponent;
  33. @ViewChild("toggleSuppliers", { static: true }) toggleSuppliers!: ToggleComponent;
  34. @ViewChild("suppliersListComponent", { static: false }) suppliersListComponent!: PartnerListComponent;
  35. @ViewChild("toggleServices", { static: true }) toggleServices!: ToggleComponent;
  36. @ViewChild("servicesListComponent", { static: false }) servicesListComponent!: PartnerListComponent;
  37. protected userSub: Subscription;
  38. protected isCurrentUser: boolean;
  39. constructor(
  40. private accountService: AccountService,
  41. private userService: UserService,
  42. protected appHelperService: AppHelperService,
  43. private route: ActivatedRoute,
  44. ) {
  45. this.userSub = new Subscription();
  46. this.isCurrentUser = false;
  47. }
  48. ngOnInit() {
  49. if (this.user === undefined) {
  50. this.route.params.subscribe(params => {
  51. this.getUserData(params['id']);
  52. });
  53. } else {
  54. this.setIsCurrentUser();
  55. }
  56. }
  57. ngAfterViewInit(): void {
  58. }
  59. getUserData(userId: string) {
  60. this.userSub = this.userService.usersIdGet(
  61. userId
  62. ).subscribe(
  63. data => {
  64. this.user = data;
  65. this.setIsCurrentUser();
  66. }
  67. );
  68. }
  69. setIsCurrentUser() {
  70. if (this.accountService.userValue?.userResource) {
  71. let user = this.accountService.userValue?.userResource;
  72. this.isCurrentUser = this.user.id == user?.id;
  73. }
  74. }
  75. }