diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 4bddeea..e475bdf 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -5,13 +5,15 @@ import {ServersPageComponent} from "./pages/servers-page/servers-page.component" import {ProfilePageComponent} from "./pages/profile-page/profile-page.component"; import {RulesPageComponent} from "./pages/rules-page/rules-page.component"; import {BanlistPageComponent} from "./pages/banlist-page/banlist-page.component"; +import {MessagesPageComponent} from "./pages/messages-page/messages-page.component"; const routes: Routes = [ { path: "", component: MainPageComponent}, { path: "servers", component: ServersPageComponent }, { path: "profile/:steam64", component: ProfilePageComponent }, { path: "rules", component: RulesPageComponent }, - { path: "banlist", component: BanlistPageComponent } + { path: "banlist", component: BanlistPageComponent }, + { path: "messages", component: MessagesPageComponent } ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 39f4b7f..a4db615 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -33,6 +33,10 @@ import {Tf2dataService} from "./services/tf2data.service"; import {MatDividerModule} from "@angular/material/divider"; import {MatListModule} from "@angular/material/list"; import {MatProgressBarModule} from "@angular/material/progress-bar"; +import { MessagesPageComponent } from './pages/messages-page/messages-page.component'; +import {MatPaginatorModule} from "@angular/material/paginator"; +import {MatTableModule} from "@angular/material/table"; +import {MatSortModule} from "@angular/material/sort"; registerLocaleData(localeRu, "ru") @@ -44,7 +48,8 @@ registerLocaleData(localeRu, "ru") ProfilePageComponent, NeedAuthToContinue, RulesPageComponent, - BanlistPageComponent + BanlistPageComponent, + MessagesPageComponent ], imports: [ BrowserModule, @@ -66,7 +71,10 @@ registerLocaleData(localeRu, "ru") MatDividerModule, MatListModule, MatProgressBarModule, - ValueServerMapDatePipe + ValueServerMapDatePipe, + MatPaginatorModule, + MatTableModule, + MatSortModule ], providers: [ {provide: LOCALE_ID, useValue: 'ru' }, diff --git a/src/app/entities/PagingAndSortingPaginator.ts b/src/app/entities/PagingAndSortingPaginator.ts new file mode 100644 index 0000000..e79f8a9 --- /dev/null +++ b/src/app/entities/PagingAndSortingPaginator.ts @@ -0,0 +1,27 @@ +import {MatPaginator, MatPaginatorIntl} from "@angular/material/paginator"; +import {ChangeDetectorRef} from "@angular/core"; + +export class PagingAndSortingPaginator { + data: T[] = []; + count: number = 0; + size: number = 0; + + fromData(data: any) { + this.data = data['content']; + this.count = data['totalElements']; + this.size = data['size']; + return this; + } + + static newObj():PagingAndSortingPaginator { + return new PagingAndSortingPaginator(); + } + + updatePaginator(paginator: MatPaginator) { + if (paginator == null) + paginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); + paginator.pageSize = this.size; + paginator.length = this.count; + return this; + } +} diff --git a/src/app/entities/profile/Message.ts b/src/app/entities/profile/Message.ts new file mode 100644 index 0000000..f012a9c --- /dev/null +++ b/src/app/entities/profile/Message.ts @@ -0,0 +1,7 @@ +export class Message { + id: number = 0; + account_id: number = 0; + utime: number =0 ; + server_id: string = ""; + account_name: string = ""; +} diff --git a/src/app/pages/messages-page/messages-page.component.html b/src/app/pages/messages-page/messages-page.component.html new file mode 100644 index 0000000..aa9a493 --- /dev/null +++ b/src/app/pages/messages-page/messages-page.component.html @@ -0,0 +1,44 @@ +
+

Сообщения

+

Все что ты пишешь в чате игре, общедоступное достояние

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AccountId {{row.account_id}} Date {{row.utime*1000 | date:"hh:mm:ss dd/MM/yyyy"}} Message {{row.message}} ServerId {{row.server_id}}
No data matching the filter
+ + +
+
+
diff --git a/src/app/pages/messages-page/messages-page.component.scss b/src/app/pages/messages-page/messages-page.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/messages-page/messages-page.component.ts b/src/app/pages/messages-page/messages-page.component.ts new file mode 100644 index 0000000..30dac06 --- /dev/null +++ b/src/app/pages/messages-page/messages-page.component.ts @@ -0,0 +1,46 @@ +import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; +import {AuthService} from "../../services/auth.service"; +import {MatTableDataSource} from "@angular/material/table"; +import {MatPaginator, MatPaginatorIntl} from "@angular/material/paginator"; +import {MatSort} from "@angular/material/sort"; +import {Message} from "../../entities/profile/Message"; +import {MessageService} from "../../services/message.service"; + +@Component({ + selector: 'app-messages-page', + templateUrl: './messages-page.component.html', + styleUrls: ['./messages-page.component.scss'] +}) +export class MessagesPageComponent implements OnInit, AfterViewInit { + + displayedColumns: string[] = ['account_id', 'date', 'message', 'server_id']; + dataSource: MatTableDataSource; + + @ViewChild(MatPaginator, { static: true }) paginator!: MatPaginator; + @ViewChild(MatSort, { static: true }) sort!: MatSort; + + constructor(public authService: AuthService, + private messageService: MessageService) { + this.dataSource = new MatTableDataSource(); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + + ngOnInit(): void { + this.getMessages(null); + } + + getMessages(filter:any) { + this.messageService.getMessages(filter, this.paginator).subscribe( + (res) => { + this.dataSource = new MatTableDataSource(res.data) + } + ) + } + + ngAfterViewInit() { + this.paginator ? this.dataSource.paginator = this.paginator: null; + this.sort ? this.dataSource.sort = this.sort : null; + } + +} diff --git a/src/app/pages/profile-page/profile-page.component.html b/src/app/pages/profile-page/profile-page.component.html index 5cfce78..10ecf18 100644 --- a/src/app/pages/profile-page/profile-page.component.html +++ b/src/app/pages/profile-page/profile-page.component.html @@ -14,6 +14,7 @@
+
@@ -213,4 +214,5 @@
+
diff --git a/src/app/services/message.service.ts b/src/app/services/message.service.ts new file mode 100644 index 0000000..001ca2d --- /dev/null +++ b/src/app/services/message.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {MatPaginator} from "@angular/material/paginator"; +import {map} from "rxjs"; +import {PagingAndSortingPaginator} from "../entities/PagingAndSortingPaginator"; +import {Message} from "../entities/profile/Message"; + +@Injectable({ + providedIn: 'root' +}) +export class MessageService { + + constructor(private http: HttpClient) { } + + getMessages(filters: any, paginator: MatPaginator) { + return this.http.post( + `/api/profile/messages/pages`, + filters, + {params: {size: paginator?paginator.pageSize:20, page: paginator?paginator.pageIndex:0}}).pipe( + (map((res) => PagingAndSortingPaginator.newObj().fromData(res).updatePaginator(paginator))) + ); + } +}