pagination for invites

This commit is contained in:
_Bastler 2021-05-07 11:25:01 +02:00
parent 7b0364ae8e
commit e144a012b5
3 changed files with 54 additions and 34 deletions

View File

@ -1,6 +1,10 @@
<h3>{{'invites' | i18n}}</h3>
<table mat-table matSort [dataSource]="invites">
<div *ngIf="invites">
<mat-form-field>
<input matInput [formControl]="searchFormControl" placeholder="{{'invites.search' | i18n}}">
</mat-form-field>
<table mat-table matSort [dataSource]="invites.content">
<ng-container matColumnDef="starts">
<th mat-header-cell *matHeaderCellDef> {{'invite.starts' | i18n}} </th>
@ -34,7 +38,9 @@
<tr mat-header-row *matHeaderRowDef="inviteColumns"></tr>
<tr mat-row *matRowDef="let myRowData; columns: inviteColumns"></tr>
</table>
</table>
<mat-paginator [pageSizeOptions]="pageSizeOptions" [length]="invites.totalElements" [pageSize]="invites.size" (page)="updatePages($event)" showFirstLastButtons></mat-paginator>
</div>
<mat-card>
<mat-card-content>
@ -55,13 +61,13 @@
<h4>{{'invites.others' | i18n}}</h4>
<mat-form-field>
<input matInput [formControl]="searchFormControl" placeholder="{{'invites.search' | i18n}}">
<input matInput [formControl]="searchOthersFormControl" placeholder="{{'invites.search' | i18n}}">
</mat-form-field>
<table mat-table matSort [dataSource]="others.content">
<ng-container matColumnDef="note">
<th mat-header-cell *matHeaderCellDef> {{'invite.note' | i18n}} </th>
<td mat-cell *matCellDef="let invite"> {{ invite.note}} </td>
<td mat-cell *matCellDef="let invite"> <span *ngIf="invite.note">{{ invite.note}}</span> <i *ngIf="!invite.note">{{ 'invite.noNote' | i18n}}</i> </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="otherColumns"></tr>
<tr mat-row *matRowDef="let myRowData; columns: otherColumns"></tr>

View File

@ -18,7 +18,7 @@ import {debounceTime} from 'rxjs/operators';
export class InvitesComponent implements OnInit {
quota: string;
invites: any[];
invites: any;
others: any;
inviteQuota: number = 0;
success: boolean;
@ -26,6 +26,7 @@ export class InvitesComponent implements OnInit {
datetimeformat: string;
pageSizeOptions: number[] = [5, 10, 25, 50];
searchFormControl = new FormControl();
searchOthersFormControl = new FormControl();
inviteColumns = ["starts", "expires", "link", "note", "redeemed"];
otherColumns = ["note"];
@ -43,7 +44,11 @@ export class InvitesComponent implements OnInit {
this.datetimeformat = this.i18n.get('format.datetime', []);
this.quota = this.route.snapshot.paramMap.get('quota');
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => {
this.inviteService.getPages(this.quota, 0, this.invites.size, value).subscribe((data: any) => {
this.invites = data;
}, (error) => {})
})
this.searchOthersFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => {
this.inviteService.getOthersPages(this.quota, 0, this.others.size, value).subscribe((data: any) => {
this.others = data;
}, (error) => {})
@ -72,6 +77,12 @@ export class InvitesComponent implements OnInit {
}, (error) => {})
}
updatePages(event: PageEvent) {
this.inviteService.getPages(this.quota, event.pageIndex, event.pageSize, this.searchFormControl.value ? this.searchFormControl.value : "").subscribe((data: any) => {
this.invites = data;
}, (error) => {})
}
create(): void {
this.working = true;
@ -92,7 +103,7 @@ export class InvitesComponent implements OnInit {
}
updateOthers(event: PageEvent) {
this.inviteService.getOthersPages(this.quota, event.pageIndex, event.pageSize, "").subscribe((data: any) => {
this.inviteService.getOthersPages(this.quota, event.pageIndex, event.pageSize, this.searchOthersFormControl.value ? this.searchOthersFormControl.value : "").subscribe((data: any) => {
this.others = data;
}, (error) => {})
}

View File

@ -15,12 +15,15 @@ export class InviteService {
return this.http.get(environment.apiUrl + "/invites" + (quota ? "?quota=" + quota : ""));
}
getPages(quota: string, page: number, size: number, search: string) {
return this.http.get(environment.apiUrl + "/invites" + (quota ? "?quota=" + quota + "&" : "?") + "page=" + page + "&size=" + size + "&search=" + search);
}
getOthers(quota: string) {
return this.http.get(environment.apiUrl + "/invites/" + quota + "/others");
}
getOthersPages(quota: string, page : number, size : number, search : string) {
getOthersPages(quota: string, page: number, size: number, search: string) {
return this.http.get(environment.apiUrl + "/invites/" + quota + "/others?page=" + page + "&size=" + size + "&search=" + search);
}