This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git


The following commit(s) were added to refs/heads/master by this push:
     new d3b81be  Fixing async handling for pagination table
d3b81be is described below

commit d3b81be6136f6086e493ebd4e4497ce87e85cc2c
Author: Martin Stockhammer <[email protected]>
AuthorDate: Wed Jan 13 19:49:21 2021 +0100

    Fixing async handling for pagination table
---
 .../archiva-web/src/app/model/pagination-info.ts   | 19 +++++++++++
 .../manage-users-list.component.html               |  1 +
 .../paginated-entities.component.html              | 38 +++++++++++-----------
 .../paginated-entities.component.ts                | 25 ++++++--------
 .../archiva-web/src/app/services/toast.service.ts  |  2 +-
 .../src/test/resources/generate-users.sh           |  0
 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 4d5c758..524d4a5 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 f72b3e7..a8c7f2d 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 0662205..0317453 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 1e0c22d..8c16052 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 f4955ef..3b87bdb 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
old mode 100644
new mode 100755

Reply via email to