From 17eef87fde3cb6defe6d31ce0c3044ca76138731 Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Thu, 8 Feb 2024 15:22:25 +0100 Subject: [PATCH] table pagination --- README.md | 3 ++ matsen-tool/openapi.yaml | 41 +++++++++++++++++++ .../app/core/api/v1/.openapi-generator/FILES | 1 - .../app/core/api/v1/api/partner.service.ts | 25 +++++++++-- .../src/app/partners/partners.component.html | 5 +++ .../src/app/partners/partners.component.ts | 10 +++-- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 72f2ce3..d0cffdd 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ - Wenn es nicht geht: brew install java - sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk - java -version) + - ACHTUNG: In Datei src/app/core/api/v1/model/partnerJsonId.ts diese zwei Zeilen löschen: + - readonly id?: string; + - readonly type?: string; ## Module anlegen - cd app diff --git a/matsen-tool/openapi.yaml b/matsen-tool/openapi.yaml index 1af3dc3..046a64b 100644 --- a/matsen-tool/openapi.yaml +++ b/matsen-tool/openapi.yaml @@ -420,6 +420,47 @@ paths: style: form explode: false allowReserved: false + - + name: 'order[name]' + in: query + description: '' + required: false + deprecated: false + allowEmptyValue: true + schema: + type: string + enum: + - asc + - desc + style: form + explode: false + allowReserved: false + - + name: type + in: query + description: '' + required: false + deprecated: false + allowEmptyValue: true + schema: + type: string + style: form + explode: false + allowReserved: false + - + name: 'type[]' + in: query + description: '' + required: false + deprecated: false + allowEmptyValue: true + schema: + type: array + items: + type: string + style: form + explode: true + allowReserved: false deprecated: false post: operationId: api_partners_post diff --git a/matsen-tool/src/app/core/api/v1/.openapi-generator/FILES b/matsen-tool/src/app/core/api/v1/.openapi-generator/FILES index 1c2dc22..812c87e 100644 --- a/matsen-tool/src/app/core/api/v1/.openapi-generator/FILES +++ b/matsen-tool/src/app/core/api/v1/.openapi-generator/FILES @@ -1,5 +1,4 @@ .gitignore -.openapi-generator-ignore README.md api.module.ts api/api.ts diff --git a/matsen-tool/src/app/core/api/v1/api/partner.service.ts b/matsen-tool/src/app/core/api/v1/api/partner.service.ts index 6d7b5c6..365dc54 100644 --- a/matsen-tool/src/app/core/api/v1/api/partner.service.ts +++ b/matsen-tool/src/app/core/api/v1/api/partner.service.ts @@ -103,19 +103,36 @@ export class PartnerService { * Retrieves the collection of Partner resources. * Retrieves the collection of Partner resources. * @param page The collection page number + * @param orderName + * @param type + * @param type2 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public partnersGetCollection(page?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable; - public partnersGetCollection(page?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable>; - public partnersGetCollection(page?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable>; - public partnersGetCollection(page?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable { + public partnersGetCollection(page?: number, orderName?: 'asc' | 'desc', type?: string, type2?: Array, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable; + public partnersGetCollection(page?: number, orderName?: 'asc' | 'desc', type?: string, type2?: Array, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable>; + public partnersGetCollection(page?: number, orderName?: 'asc' | 'desc', type?: string, type2?: Array, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable>; + public partnersGetCollection(page?: number, orderName?: 'asc' | 'desc', type?: string, type2?: Array, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/ld+json' | 'application/json' | 'text/html' | 'application/hal+json', context?: HttpContext}): Observable { let localVarQueryParameters = new HttpParams({encoder: this.encoder}); if (page !== undefined && page !== null) { localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, page, 'page'); } + if (orderName !== undefined && orderName !== null) { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + orderName, 'order[name]'); + } + if (type !== undefined && type !== null) { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + type, 'type'); + } + if (type2) { + type2.forEach((element) => { + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + element, 'type[]'); + }) + } let localVarHeaders = this.defaultHeaders; diff --git a/matsen-tool/src/app/partners/partners.component.html b/matsen-tool/src/app/partners/partners.component.html index f72fa1a..f157aa3 100644 --- a/matsen-tool/src/app/partners/partners.component.html +++ b/matsen-tool/src/app/partners/partners.component.html @@ -35,3 +35,8 @@ + + + diff --git a/matsen-tool/src/app/partners/partners.component.ts b/matsen-tool/src/app/partners/partners.component.ts index b34f185..20c6678 100644 --- a/matsen-tool/src/app/partners/partners.component.ts +++ b/matsen-tool/src/app/partners/partners.component.ts @@ -1,20 +1,22 @@ -import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; +import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; import {MatSort, Sort, MatSortModule} from "@angular/material/sort"; import {LiveAnnouncer} from "@angular/cdk/a11y"; import {MatTableDataSource, MatTableModule} from "@angular/material/table"; import {ActivatedRoute, RouterLink, RouterLinkActive} from "@angular/router"; import {Subscription} from "rxjs"; import {PartnerJsonld, PartnerService} from "@app/core/api/v1"; +import {MatPaginator, MatPaginatorIntl, MatPaginatorModule} from "@angular/material/paginator"; @Component({ selector: 'app-partners', templateUrl: './partners.component.html', styleUrl: './partners.component.scss', standalone: true, - imports: [MatTableModule, MatSortModule, RouterLink, RouterLinkActive], + imports: [MatTableModule, MatSortModule, MatPaginatorModule, RouterLink, RouterLinkActive], }) export class PartnersComponent implements OnInit, AfterViewInit { @ViewChild(MatSort) sort; + @ViewChild(MatPaginator) paginator: MatPaginator; protected partnersSub: Subscription; protected partners: Array = []; @@ -29,6 +31,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { private partnerService: PartnerService ) { this.sort = new MatSort(); + this.paginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); this.partnersSub = new Subscription(); this.partners = []; @@ -38,7 +41,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { this.dataType = this.route.snapshot.data['dataType']; console.log('Data Type:', this.dataType); - this.partnersSub = this.partnerService.partnersGetCollection().subscribe( + this.partnersSub = this.partnerService.partnersGetCollection(1, "asc", this.dataType).subscribe( data => { this.partners = data["hydra:member"]; @@ -51,6 +54,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { ngAfterViewInit() { this.dataSource.sort = this.sort; + this.dataSource.paginator = this.paginator; } /** Announce the change in sort state for assistive technology. */