import {AfterViewInit, Component, Input, ViewChild} from "@angular/core"; import {MatTableDataSource} from "@angular/material/table"; import {Message} from "../../entities/profile/Message"; import {MatPaginator} from "@angular/material/paginator"; import {merge, switchMap} from "rxjs"; import {MatSort} from "@angular/material/sort"; import {SearchFilter} from "../../entities/search/SearchFilter"; import {ServerService} from "../../services/server.service"; import {ActivatedRoute, Router} from "@angular/router"; import {AuthService} from "../../services/auth.service"; import {PlayerService} from "../../services/player.service"; @Component({template: ''}) export abstract class AbstractSearchTable implements AfterViewInit { dataSource: MatTableDataSource; filter: U; @ViewChild(MatPaginator) paginator: MatPaginator | undefined; @ViewChild(MatSort) sort: MatSort | undefined; serverList: {name: string, server_id: string }[] = []; loading: boolean = false; err: boolean = false; @Input("account_id") //[U:1:%s] account_id: number | null = null; @Input("use_query") use_query: boolean = true; @Input("lazy") lazy: boolean = false; protected constructor(public authService: AuthService, protected serverService: ServerService, protected playerService: PlayerService, protected route: ActivatedRoute, protected router: Router) { this.filter = new SearchFilter() as U; this.dataSource = new MatTableDataSource(); } public updateData() { if (this.account_id == null && this.use_query) this.router.navigate([], { relativeTo: this.route, queryParams: this.filter.createQuery(this.paginator), queryParamsHandling: "merge" }) } ngAfterViewInit(): void { if (this.account_id == null || !this.use_query) this.filter.fromQuery(this.route.snapshot.queryParamMap, this.paginator); else this.filter.addAccountToSearch(`[U:1:${this.account_id}]`); this.updateData(); this.serverService.servers.subscribe( (res) => { const keys = Object.keys(res.data); for (const key of keys) { this.serverList.push({name: res.data[key].name, server_id: key}); } console.log(this.serverList); } ) } }