aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-01-13 19:49:21 +0100
committerMartin Stockhammer <martin_s@apache.org>2021-01-13 20:01:53 +0100
commitd3b81be6136f6086e493ebd4e4497ce87e85cc2c (patch)
treee5c90fbb9875dc7630d7131b6fb7e1e304a978ea
parentdebc1d3c2a55646940aff0f51341af70edf7898c (diff)
downloadarchiva-d3b81be6136f6086e493ebd4e4497ce87e85cc2c.tar.gz
archiva-d3b81be6136f6086e493ebd4e4497ce87e85cc2c.zip
Fixing async handling for pagination table
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts19
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html1
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html38
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts25
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts2
-rwxr-xr-x[-rw-r--r--]archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh0
6 files changed, 50 insertions, 35 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts
index 4d5c758e8..524d4a58b 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts
@@ -20,4 +20,23 @@ export class PaginationInfo {
total_count : number;
offset: number;
limit: number;
+
+ multiple() : boolean {
+ return this.total_count>this.limit;
+ }
+
+ page() : number {
+ if (this.limit==0) {
+ return 1;
+ }
+ return Math.floor(this.offset/this.limit )+1;
+ }
+
+ static of(total_count:number, offset:number, limit:number) : PaginationInfo {
+ let info = new PaginationInfo();
+ info.total_count = total_count;
+ info.offset=offset;
+ info.limit=limit;
+ return info;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html
index f72b3e702..a8c7f2dbe 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html
@@ -17,6 +17,7 @@
-->
<app-paginated-entities [service]="service" pageSize="10" [(sortField)]="sortField" [(sortOrder)]="sortOrder"
+ [id]="'userList'"
#parent>
<ng-container *ngIf="parent.items$ |async as itemLoader">
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html
index 06622055e..031745355 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html
@@ -18,34 +18,34 @@
<!--
<ng-template [ngIf]="((total$|async)>0 || displayIfEmpty)" [ngIfElse]="noContent" >
-->
- <ng-template [ngIf]="true" [ngIfElse]="noContent" >
-
-
+<ng-container *ngIf="(paginationInfo$|async) as paginationInfo; else noContent">
<form class="mt-3 mb-3">
<!--
<div class="form-row align-items-center" *ngIf="(multiplePages$|async)||displayControlsIfSinglePage">
-->
- <div class="form-row align-items-center" *ngIf="(multiplePages$|async)==true">
- <div class="col-lg-4 col-md-2 col-sm-1">
- <label class="sr-only" for="searchQuery">{{'search.label' |translate}}</label>
- <input type="text" class="form-control" id="searchQuery" placeholder="{{'search.input'|translate}}" #searchTerm
- (keyup)="search(searchTerm.value)">
- </div>
- <div class="col-auto">
- <button type="submit" class="btn btn-primary">{{'search.button'|translate}}</button>
+ <div class="form-row align-items-center" *ngIf="paginationInfo.multiple()||displayControlsIfSinglePage">
+ <div class="col-lg-4 col-md-2 col-sm-1">
+ <label class="sr-only" for="searchQuery">{{'search.label' |translate}}</label>
+ <input type="text" class="form-control" id="searchQuery" placeholder="{{'search.input'|translate}}"
+ #searchTerm
+ (keyup)="search(searchTerm.value)">
+ </div>
+ <div class="col-auto">
+ <button type="submit" class="btn btn-primary">{{'search.button'|translate}}</button>
+ </div>
</div>
- </div>
-</form>
+ </form>
-<ng-content></ng-content>
+ <ng-content></ng-content>
-<ngb-pagination *ngIf="(multiplePages$|async)==true"
- [collectionSize]="total$|async" [pageSize]="pageSize" [maxSize]="pagination.maxSize" [rotate]="pagination.rotate"
- [boundaryLinks]="pagination.boundaryLinks" [ellipses]="pagination.ellipses"
- [(page)]="page" (pageChange)="changePage($event)" aria-label="Pagination"></ngb-pagination>
-</ng-template>
+ <ngb-pagination *ngIf="paginationInfo.multiple()||displayControlsIfSinglePage"
+ [collectionSize]="paginationInfo.total_count" [pageSize]="pageSize" [maxSize]="pagination.maxSize"
+ [rotate]="pagination.rotate"
+ [boundaryLinks]="pagination.boundaryLinks" [ellipses]="pagination.ellipses"
+ [(page)]="page" (pageChange)="changePage($event)" aria-label="Pagination"></ngb-pagination>
+</ng-container>
<ng-template #noContent>
{{displayKeyIfEmpty|translate}}
</ng-template> \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts
index 1e0c22d45..8c1605255 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts
@@ -26,6 +26,7 @@ import {
multicast,
pluck,
refCount,
+ share,
startWith,
switchMap, tap
} from "rxjs/operators";
@@ -34,6 +35,8 @@ import {FieldToggle} from "@app/model/field-toggle";
import {PageQuery} from "../model/page-query";
import {LoadingValue} from '../model/loading-value';
import {PagedResult} from "@app/model/paged-result";
+import {Multipage} from "@app/model/multipage";
+import {PaginationInfo} from "@app/model/pagination-info";
/**
@@ -138,26 +141,19 @@ export class PaginatedEntitiesComponent<T> implements OnInit, FieldToggle, After
/**
* The total number of elements available for the given search term
*/
- public total$: Observable<number>;
+ public paginationInfo$: Observable<PaginationInfo>;
/**
* The entity items retrieved from the service
*/
public items$: Observable<LoadingValue<PagedResult<T>>>;
- /**
- * true, if the current page result value represents a result with multiple pages,
- * otherwise false.
- */
- public multiplePages$:Observable<boolean>;
-
private pageStream: Subject<number> = new Subject<number>();
private searchTermStream: Subject<string> = new Subject<string>();
constructor() {
// console.log("Construct " + this.id);
this.items$=null;
- this.total$=null;
- this.multiplePages$=null;
+ this.paginationInfo$=null;
}
ngOnInit(): void {
@@ -184,14 +180,13 @@ export class PaginatedEntitiesComponent<T> implements OnInit, FieldToggle, After
),
// This is to avoid multiple REST calls, without each subscriber would
// cause a REST call.
- multicast(new Subject()),
+ multicast(()=>new Subject<LoadingValue<PagedResult<T>>>()),
refCount()
);
- this.total$ = source.pipe(tap((el)=>console.log("Total pipe "+this.id+": "+typeof(el)+" - "+JSON.stringify(el))),filter(val=>val.hasValue()),map(val=>val.value),
- pluck('pagination', 'total_count'),tap((el)=>console.log("Total end "+this.id+" - "+el)));
- this.multiplePages$ = source.pipe(tap((el)=>console.log("Multipage pipe "+this.id+": "+typeof(el)+" - "+JSON.stringify(el))),filter(val => val.hasValue()),
- map(val => val.value.pagination.total_count > val.value.pagination.limit));
- this.items$ = source.pipe(tap((el)=>console.log("Item pipe "+this.id+": "+typeof(el)+" - "+JSON.stringify(el))));
+ this.paginationInfo$ = source.pipe(filter(val => val.hasValue())
+ , map(val => PaginationInfo.of(val.value.pagination.total_count, val.value.pagination.offset, val.value.pagination.limit)),
+ tap((el) => this.page = el.page()));
+ this.items$ = source;
}
search(terms: string) {
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts
index f4955ef1f..3b87bdbd4 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts
@@ -87,7 +87,7 @@ export class ToastService {
options.classname=['alert','alert-info']
options.type='success'
if (!options.delay) {
- options.delay=8000
+ options.delay=6000
}
this.show(origin,textOrTpl,options)
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh
index 8e2245094..8e2245094 100644..100755
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh