import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; import {UserJsonld, UserService} from "@app/core/api/v1"; import {Subscription} from "rxjs"; import {AccountService} from "@app/_services"; import {AppHelperService} from "@app/_helpers/app-helper.service"; import {UsersComponent} from "@app/_views/user/users.component"; import {ToggleComponent} from "@app/_components/toggle/toggle.component"; import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component"; import {SaleListComponent} from "@app/_views/sales/sale-list/sale-list.component"; import {ProductListComponent} from "@app/_views/products/product-list/product-list.component"; import {PartnerListComponent} from "@app/_views/partners/partner-list/partner-list.component"; import {PostListComponent} from "@app/_views/posts/post-list/post-list.component"; import {SaleSummaryComponent} from "@app/_views/sales/sale-summary/sale-summary.component"; import {ActivatedRoute} from "@angular/router"; @Component({ selector: 'app-user-detail', templateUrl: './user-detail.component.html', styleUrl: './user-detail.component.scss' }) export class UserDetailComponent implements OnInit, AfterViewInit { @Input() public user!: UserJsonld; @ViewChild("togglePosts", { static: true }) togglePosts!: ToggleComponent; @ViewChild("postListComponent", { static: false }) postsComponent!: PostListComponent; @ViewChild("toggleTasks", { static: true }) toggleTasks!: ToggleComponent; @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; @ViewChild("toggleSales", { static: true }) toggleSales!: ToggleComponent; @ViewChild("saleSummaryComponent", { static: false }) saleSummaryComponent!: SaleSummaryComponent; @ViewChild("saleListComponent", { static: false }) saleListComponent!: SaleListComponent; @ViewChild("toggleProducts", { static: true }) toggleProducts!: ToggleComponent; @ViewChild("productListComponent", { static: false }) productListComponent!: ProductListComponent; @ViewChild("toggleCustomers", { static: true }) toggleCustomers!: ToggleComponent; @ViewChild("customerListComponent", { static: false }) customerListComponent!: PartnerListComponent; @ViewChild("toggleSuppliers", { static: true }) toggleSuppliers!: ToggleComponent; @ViewChild("suppliersListComponent", { static: false }) suppliersListComponent!: PartnerListComponent; @ViewChild("toggleServices", { static: true }) toggleServices!: ToggleComponent; @ViewChild("servicesListComponent", { static: false }) servicesListComponent!: PartnerListComponent; protected userSub: Subscription; protected isCurrentUser: boolean; protected userId!: string; constructor( private accountService: AccountService, private userService: UserService, protected appHelperService: AppHelperService, private route: ActivatedRoute, ) { this.userSub = new Subscription(); this.isCurrentUser = false; } ngOnInit() { this.route.params.subscribe(params => { this.userId = params['id']; }); console.log(this.userId); } ngAfterViewInit(): void { if (this.accountService.userValue?.userResource) { let user = this.accountService.userValue?.userResource; this.isCurrentUser = this.userId == user?.id; } this.getData(); } getData() { this.userSub = this.userService.usersIdGet( this.userId ).subscribe( data => { this.user = data; } ); } }