|
- 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;
-
- constructor(
- private accountService: AccountService,
- private userService: UserService,
- protected appHelperService: AppHelperService,
- private route: ActivatedRoute,
- ) {
- this.userSub = new Subscription();
- this.isCurrentUser = false;
- }
-
- ngOnInit() {
- if (this.user === undefined) {
- this.route.params.subscribe(params => {
- this.getUserData(params['id']);
- });
- } else {
- this.setIsCurrentUser();
- }
- }
-
- ngAfterViewInit(): void {
-
- }
-
- getUserData(userId: string) {
- this.userSub = this.userService.usersIdGet(
- userId
- ).subscribe(
- data => {
- this.user = data;
- this.setIsCurrentUser();
- }
- );
- }
-
- setIsCurrentUser() {
- if (this.accountService.userValue?.userResource) {
- let user = this.accountService.userValue?.userResource;
- this.isCurrentUser = this.user.id == user?.id;
- }
- }
- }
|