1- import { Component , OnInit , signal } from '@angular/core' ;
1+ import { Component , computed , OnInit , signal } from '@angular/core' ;
22import { ActivatedRoute , Router } from "@angular/router" ;
33import { CommonMessage } from "fusio-sdk" ;
44import { ErrorService } from "../service/error.service" ;
@@ -19,6 +19,20 @@ export abstract class List<T> implements OnInit {
1919 pageSize = signal < number > ( 16 ) ;
2020 response = signal < CommonMessage | undefined > ( undefined ) ;
2121
22+ collectionQuery = computed < Array < any > > ( ( ) => {
23+ let query : Array < any > = [ ] ;
24+ query . push ( ( this . page ( ) - 1 ) * this . pageSize ( ) ) ;
25+ query . push ( this . pageSize ( ) ) ;
26+ const search = this . search ( ) ;
27+ if ( search ) {
28+ query . push ( search ) ;
29+ } else {
30+ query . push ( '' ) ;
31+ }
32+
33+ return query ;
34+ } ) ;
35+
2236 protected constructor ( protected route : ActivatedRoute , public router : Router , protected error : ErrorService ) {
2337 }
2438
@@ -44,77 +58,78 @@ export abstract class List<T> implements OnInit {
4458 }
4559
4660 async doList ( ) {
47- try {
48- this . getService ( ) . onConfigurationCompleted ( ) . then ( async ( service ) => {
49- const response = await service . getAll ( this . getCollectionQuery ( ) ) ;
61+ this . getService ( ) . onReady ( ) . then ( async ( service ) => {
62+ try {
63+ const response = await service . getAll ( this . collectionQuery ( ) ) ;
5064
5165 this . totalResults . set ( response . totalResults || 0 ) ;
5266 this . entries . set ( response . entry || [ ] ) ;
5367
5468 this . onLoad ( ) ;
55- } ) ;
56- } catch ( error ) {
57- this . response . set ( this . error . convert ( error ) ) ;
69+ } catch ( error ) {
70+ this . response . set ( this . error . convert ( error ) ) ;
5871
59- this . onError ( ) ;
60- }
72+ this . onError ( ) ;
73+ }
74+ } ) ;
6175 }
6276
6377 async doSearch ( page ?: number , search ?: string ) {
6478 if ( ! this . hasQueryParamsChange ( page , search ) ) {
6579 return ;
6680 }
6781
68- await this . router . navigate ( this . getService ( ) . getLink ( ) , {
69- queryParams : {
70- page : page ,
71- search : search ,
72- }
82+ this . getService ( ) . onReady ( ) . then ( ( service ) => {
83+ this . router . navigate ( service . getLink ( ) , {
84+ queryParams : {
85+ page : page ,
86+ search : search ,
87+ }
88+ } ) ;
7389 } ) ;
7490 }
7591
76- public getDetailLink ( id : any ) : Array < string >
92+ public doDetail ( id : any ) : void
7793 {
78- const link = this . getService ( ) . getLink ( ) ;
79- link . push ( '' + id )
80- return link ;
94+ this . getService ( ) . onReady ( ) . then ( ( service ) => {
95+ const link = service . getLink ( ) ;
96+ link . push ( '' + id ) ;
97+
98+ this . router . navigate ( link ) ;
99+ } ) ;
81100 }
82101
83- public getNewLink ( ) : Array < string >
102+ public doNew ( ) : void
84103 {
85- const link = this . getService ( ) . getLink ( ) ;
86- link . push ( '-' )
87- link . push ( 'new' )
88- return link ;
104+ this . getService ( ) . onReady ( ) . then ( ( service ) => {
105+ const link = service . getLink ( ) ;
106+ link . push ( '-' ) ;
107+ link . push ( 'new' ) ;
108+
109+ this . router . navigate ( link ) ;
110+ } ) ;
89111 }
90112
91- public getEditLink ( id : any ) : Array < string >
113+ public doEdit ( id : any ) : void
92114 {
93- const link = this . getService ( ) . getLink ( ) ;
94- link . push ( '' + id )
95- link . push ( 'edit' )
96- return link ;
115+ this . getService ( ) . onReady ( ) . then ( ( service ) => {
116+ const link = service . getLink ( ) ;
117+ link . push ( '' + id ) ;
118+ link . push ( 'edit' ) ;
119+
120+ this . router . navigate ( link ) ;
121+ } ) ;
97122 }
98123
99- public getDeleteLink ( id : any ) : Array < string >
124+ public doDelete ( id : any ) : void
100125 {
101- const link = this . getService ( ) . getLink ( ) ;
102- link . push ( '' + id )
103- link . push ( 'delete' )
104- return link ;
105- }
126+ this . getService ( ) . onReady ( ) . then ( ( service ) => {
127+ const link = service . getLink ( ) ;
128+ link . push ( '' + id ) ;
129+ link . push ( 'delete' ) ;
106130
107- protected getCollectionQuery ( ) : Array < any > {
108- let query : Array < any > = [ ] ;
109- query . push ( ( this . page ( ) - 1 ) * this . pageSize ( ) ) ;
110- query . push ( this . pageSize ( ) ) ;
111- const search = this . search ( ) ;
112- if ( search ) {
113- query . push ( search ) ;
114- } else {
115- query . push ( '' ) ;
116- }
117- return query ;
131+ this . router . navigate ( link ) ;
132+ } ) ;
118133 }
119134
120135 protected hasQueryParamsChange ( page ?: number , search ?: string ) : boolean {
0 commit comments