diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f923641..8d0a97a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -41,6 +41,7 @@ import {RussianPaginatorIntl} from "./utils/RussianPaginatorIntl"; import {MatSelectModule} from "@angular/material/select"; import {MatDatepickerModule} from "@angular/material/datepicker"; import {MatNativeDateModule} from "@angular/material/core"; +import {MatProgressSpinnerModule} from "@angular/material/progress-spinner"; registerLocaleData(localeRu, "ru") @@ -55,34 +56,35 @@ registerLocaleData(localeRu, "ru") BanlistPageComponent, MessagesPageComponent ], - imports: [ - BrowserModule, - AppRoutingModule, - BrowserAnimationsModule, - MatToolbarModule, - MatIconModule, - MatButtonModule, - MatGridListModule, - MatCardModule, - MatInputModule, - MatChipsModule, - MatExpansionModule, - MatMenuModule, - HttpClientModule, - MatSnackBarModule, - MatAutocompleteModule, - FormsModule, - MatDividerModule, - MatListModule, - MatProgressBarModule, - ValueServerMapDatePipe, - MatPaginatorModule, - MatTableModule, - MatSortModule, - MatSelectModule, - MatDatepickerModule, - MatNativeDateModule - ], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatToolbarModule, + MatIconModule, + MatButtonModule, + MatGridListModule, + MatCardModule, + MatInputModule, + MatChipsModule, + MatExpansionModule, + MatMenuModule, + HttpClientModule, + MatSnackBarModule, + MatAutocompleteModule, + FormsModule, + MatDividerModule, + MatListModule, + MatProgressBarModule, + ValueServerMapDatePipe, + MatPaginatorModule, + MatTableModule, + MatSortModule, + MatSelectModule, + MatDatepickerModule, + MatNativeDateModule, + MatProgressSpinnerModule + ], providers: [ {provide: LOCALE_ID, useValue: 'ru' }, {provide: MatPaginatorIntl, useValue: RussianPaginatorIntl() }, diff --git a/src/app/entities/search/ISearchFilter.ts b/src/app/entities/search/ISearchFilter.ts new file mode 100644 index 0000000..46ba316 --- /dev/null +++ b/src/app/entities/search/ISearchFilter.ts @@ -0,0 +1,7 @@ +import {ParamMap} from "@angular/router"; +import {MatPaginator} from "@angular/material/paginator"; + +export interface ISearchFilter { + createQuery(paginator:MatPaginator|undefined): {[param: string]: any}; + fromQuery(param: ParamMap,paginator:MatPaginator|undefined):void; +} diff --git a/src/app/entities/search/MessageSearchFilter.ts b/src/app/entities/search/MessageSearchFilter.ts index ef5529f..2b6bed9 100644 --- a/src/app/entities/search/MessageSearchFilter.ts +++ b/src/app/entities/search/MessageSearchFilter.ts @@ -1,5 +1,20 @@ import {SearchFilter} from "./SearchFilter"; +import {ParamMap} from "@angular/router"; +import {MatPaginator} from "@angular/material/paginator"; export class MessageSearchFilter extends SearchFilter { message: string | null = null; + + override createQuery(paginator:MatPaginator|undefined): { [p: string]: any } { + let q:{[param: string]: any} = super.createQuery(paginator); + q["message"] = this.message; + return q; + } + + + override fromQuery(param: ParamMap,paginator:MatPaginator|undefined) { + try {if (param.get("message")) { // @ts-ignore + this.message = param.get("message");}}catch (e) {} + super.fromQuery(param, paginator); + } } diff --git a/src/app/entities/search/SearchFilter.ts b/src/app/entities/search/SearchFilter.ts index fe3a167..742ee73 100644 --- a/src/app/entities/search/SearchFilter.ts +++ b/src/app/entities/search/SearchFilter.ts @@ -1,7 +1,43 @@ -export class SearchFilter { +import {ISearchFilter} from "./ISearchFilter"; +import {ParamMap} from "@angular/router"; +import {MatPaginator} from "@angular/material/paginator"; + +export class SearchFilter implements ISearchFilter { accounts: string[]|null = null; begin: Date | null = null; end: Date | null = null; serverId : string | null = null; updated: boolean = false; + + createQuery(paginator:MatPaginator|undefined):{[param: string]: any} { + let q: {[param: string]: any} = {}; + q["accounts"] = this.accounts?this.accounts.join(","):null; + q["begin"] = this.begin?this.begin.getTime():null; + q["end"] = this.end?this.end.getTime():null; + q["serverId"] = this.serverId; + q["page"] = paginator?paginator.pageIndex:null; + q["size"] = paginator?paginator.pageSize:null; + console.log(q); + return q; + } + + fromQuery(param: ParamMap, paginator:MatPaginator|undefined): void { + try {if (param.has("accounts")) { // @ts-ignore + this.accounts = param.get("accounts")?.split(",");}} catch (e) {} + + try {if (param.has("begin")) {// @ts-ignore + this.begin = new Date(param.get("begin")*1);}} catch (e) {} + + try {if (param.get("end")) { // @ts-ignore + this.end = new Date(param.get("end")*1);}}catch (e) {} + + try {if (param.get("serverId")) { // @ts-ignore + this.serverId = param.get("serverId");}}catch (e) {} + + try {if (param.get("page") && paginator) { // @ts-ignore + paginator.pageIndex = param.get("page")*1;}}catch (e) {} + + try {if (param.get("size") && paginator) { // @ts-ignore + paginator.pageSize = param.get("size")*1;}}catch (e) {} + } } diff --git a/src/app/pages/internal-components/abstract-search-table.component.ts b/src/app/pages/internal-components/abstract-search-table.component.ts index 5d14d77..957a54a 100644 --- a/src/app/pages/internal-components/abstract-search-table.component.ts +++ b/src/app/pages/internal-components/abstract-search-table.component.ts @@ -6,23 +6,37 @@ 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"; @Component({template: ''}) export abstract class AbstractSearchTable implements AfterViewInit { dataSource: MatTableDataSource; - filter: U = new SearchFilter() as U; + filter: U; @ViewChild(MatPaginator) paginator: MatPaginator | undefined; @ViewChild(MatSort) sort: MatSort | undefined; - serverList: {name: string, server_id: string }[] = [] + serverList: {name: string, server_id: string }[] = []; + loading: boolean = false; + err: boolean = false; - protected constructor(protected serverService: ServerService) { + + protected constructor(protected serverService: ServerService, + protected route: ActivatedRoute, + protected router: Router) { + this.filter = new SearchFilter() as U; this.dataSource = new MatTableDataSource(); } - public updateData() {} + public updateData() { + this.router.navigate([], { + relativeTo: this.route, + queryParams: this.filter.createQuery(this.paginator), + queryParamsHandling: "merge" + }) + } ngAfterViewInit(): void { + this.filter.fromQuery(this.route.snapshot.queryParamMap, this.paginator); this.updateData(); this.serverService.getStats("servers").subscribe( (res) => { @@ -35,6 +49,12 @@ export abstract class AbstractSearchTable implements A ) } + changeAccountToSearch(prev: string, name: any) { + this.removeAccountFromSearch(prev); + this.addAccountToSearch(name.target.value); + this.filter.updated = true; + } + addAccountToSearch(name: string) { if (this.filter.accounts == null) this.filter.accounts = []; @@ -70,15 +90,14 @@ export abstract class AbstractSearchTable implements A } } - addBeginTimeToSearch(custom_date: number|null = null) { + addBeginTimeToSearch(custom_date: any = null) { if (custom_date == null) { const d: Date = new Date(); d.setUTCHours(0, 0, 0, 0); this.filter.begin = d; } - if (typeof custom_date == "number") { - this.filter.begin = new Date(custom_date); - } + else this.filter.begin = new Date(custom_date); + this.filter.updated = true; } @@ -93,9 +112,7 @@ export abstract class AbstractSearchTable implements A d.setUTCHours(23, 59, 59, 999); this.filter.end = d; } - if (typeof custom_date == "number") { - this.filter.end = new Date(custom_date); - } + else this.filter.end = new Date(custom_date); this.filter.updated = true; } @@ -103,4 +120,8 @@ export abstract class AbstractSearchTable implements A this.filter.end = null; this.filter.updated = true; } + + filterChanges(event:any) { + this.filter.updated = true; + } } diff --git a/src/app/pages/messages-page/messages-page.component.html b/src/app/pages/messages-page/messages-page.component.html index 5371f55..7e8a96d 100644 --- a/src/app/pages/messages-page/messages-page.component.html +++ b/src/app/pages/messages-page/messages-page.component.html @@ -11,32 +11,45 @@ Искать по... - + - - - + - Обновить - {{acId}} - - + Обновить +
+ Профиль: {{acId}} + + + + Ссылка, имя, все что угодно + + + + +
Сообщение содержит: {{filter.message}} + (removed)="removeMessageFromSearch()" [matMenuTriggerFor]="contentSearch">Сообщение содержит: {{filter.message}} + + + Сообщение содержит... + + + Дата после - + @@ -79,65 +94,77 @@ Дата после - +
- - - - - - +
+
+ +
+ Слишком много запросов или сервер не отвечает, обнови страницу. +
+
+
Игрок {{row.account_name}} - - - -
+ + + + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - - - -
Игрок {{row.account_name}} + + + + Дата {{row.utime*1000 | date:"HH:mm:ss dd/MM/yyyy"}} - - - - - Дата {{row.utime*1000 | date:"HH:mm:ss dd/MM/yyyy"}} + + + + + Сообщение {{row.message}} - - - Сообщение {{row.message}} + + + Сервер {{row.serverName}} - - - - Сервер {{row.serverName}} + + + +
Нет сообщений
+ +
+ + Нет сообщений + +
+ - + + diff --git a/src/app/pages/messages-page/messages-page.component.scss b/src/app/pages/messages-page/messages-page.component.scss index 666696a..b47270c 100644 --- a/src/app/pages/messages-page/messages-page.component.scss +++ b/src/app/pages/messages-page/messages-page.component.scss @@ -5,3 +5,21 @@ ::ng-deep .mat-form-field-underline { display: none; } + +.loading-shade { + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + background: rgba(0, 0, 0, 0.15); + z-index: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.err { + max-width: 360px; + text-align: center; +} diff --git a/src/app/pages/messages-page/messages-page.component.ts b/src/app/pages/messages-page/messages-page.component.ts index 92aa46e..433ec05 100644 --- a/src/app/pages/messages-page/messages-page.component.ts +++ b/src/app/pages/messages-page/messages-page.component.ts @@ -10,7 +10,7 @@ import {SearchFilter} from "../../entities/search/SearchFilter"; import {ServerService} from "../../services/server.service"; import {MessageSearchFilter} from "../../entities/search/MessageSearchFilter"; import {PlayerService} from "../../services/player.service"; -import {Router} from "@angular/router"; +import {ActivatedRoute, Router} from "@angular/router"; @Component({ selector: 'app-messages-page', @@ -25,26 +25,30 @@ export class MessagesPageComponent extends AbstractSearchTable { this.dataSource = new MatTableDataSource(res.data); - } + this.err = false; + }, (e) => this.err = true, () => this.loading = false ) return true; } override updateData() { + super.updateData(); this.getMessages(); } - addMessageToSearch(name: string) { + addMessageToSearch(name: any) { this.filter.message = name; this.filter.updated = true; } @@ -54,15 +58,12 @@ export class MessagesPageComponent extends AbstractSearchTable { if (res.steam64 != null) this.router.navigate(['profile', res.steam64])