]> source.dussan.org Git - archiva.git/commitdiff
Fixing async handling for pagination table
authorMartin Stockhammer <martin_s@apache.org>
Wed, 13 Jan 2021 18:49:21 +0000 (19:49 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Wed, 13 Jan 2021 19:01:53 +0000 (20:01 +0100)
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/model/pagination-info.ts
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/users/manage-users-list/manage-users-list.component.html
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.html
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/shared/paginated-entities/paginated-entities.component.ts
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/toast.service.ts
archiva-modules/archiva-web/archiva-webapp/src/test/resources/generate-users.sh [changed mode: 0644->0755]

index 4d5c758e8b0727efec05bef4a27b64fab6123253..524d4a58b12ac5b9c95745411981613f5c3c75af 100644 (file)
@@ -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;
+    }
 }
index f72b3e70213b70876898581775524c7618bbd7a8..a8c7f2dbebf4115016f07b525027a72ed80bd29a 100644 (file)
@@ -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">
index 06622055e4976b4f1ed794edafaaf8c1ddd7ae5d..0317453550b409e64bf7aac79c73984b01e5d4ba 100644 (file)
 <!--
 <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
index 1e0c22d4522a2f9864ef373654b3e21d0216e247..8c1605255a618545fc017f6ef0b8f90d2fea31e9 100644 (file)
@@ -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) {
index f4955ef1f2c871e0dee63b6e555058a798ad735b..3b87bdbd48b6c7f55ae769b656687e906c1bed94 100644 (file)
@@ -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)
   }