11import { DcWorkflow } from '../definition/dc-workflow' ;
22import { Component , inject , input , InputSignal } from '@angular/core' ;
3- import { DcWorkflowModel } from '../models/dc-workflow-model' ;
3+ import { DcWorkflowModel , DcWorkflowSortModel , DcWorkflowSortOption } from '../models/dc-workflow-model' ;
44import { XtCompositeComponent , XtResolverService } from 'xt-components' ;
5- import { XtSignalStore , XtStoreManagerService } from 'xt-store' ;
5+ import { XtSignalStore , XtSortBy , XtSortByDirection , XtStoreEntityFeatureOptions , XtStoreManagerService } from 'xt-store' ;
66import { ManagedData } from 'xt-type' ;
77
88/**
@@ -13,7 +13,7 @@ import { ManagedData } from 'xt-type';
1313 imports : [ ] ,
1414 template : ''
1515} )
16- export class AbstractDcWorkflow < T extends ManagedData > extends XtCompositeComponent < T > implements DcWorkflow {
16+ export class AbstractDcWorkflow < T extends ManagedData = ManagedData > extends XtCompositeComponent < T > implements DcWorkflow {
1717 /**
1818 * The workflow config must be provided
1919 * @protected
@@ -27,9 +27,9 @@ export class AbstractDcWorkflow<T extends ManagedData> extends XtCompositeCompon
2727
2828 protected findStore ( ) : XtSignalStore < T > | null {
2929 if ( this . store === undefined ) {
30- this . store = this . storeMgr . getStoreFor ( this . config ( ) . entity , this . resolver . typeResolver ) ;
31- if ( this . store != null )
32- this . applyConfigToStore ( this . config ( ) , this . store ) ;
30+ const config = this . config ( ) ;
31+ const storeOptions = this . generateStoreOptions ( config ) ;
32+ this . store = this . storeMgr . getStoreFor ( config . entity , this . resolver . typeResolver , storeOptions ) ;
3333 }
3434 return ( this . store == null ) ?null :this . store ;
3535 }
@@ -40,7 +40,29 @@ export class AbstractDcWorkflow<T extends ManagedData> extends XtCompositeCompon
4040 return ret ;
4141 }
4242
43- protected applyConfigToStore ( config : DcWorkflowModel , store :XtSignalStore < T > ) : void {
43+ protected generateStoreOptions ( config : DcWorkflowModel ) : XtStoreEntityFeatureOptions < T > | undefined {
44+ const options = { sort :[ ] } as XtStoreEntityFeatureOptions < T > ;
45+ if ( config . data ?. sort != null ) {
46+ for ( const sortKey in config . data . sort ) {
47+ options . sort ?. push ( this . toSortOption ( sortKey , config . data . sort [ sortKey ] ) ) ;
48+ }
49+ }
4450
51+ return ( options . sort ! . length > 0 ) ?options :undefined ;
52+ }
53+
54+ protected toSortOption ( name :string , sort :DcWorkflowSortOption ) : XtSortBy < T > {
55+ const ret = { by :name } as XtSortBy < T > ;
56+
57+ if ( sort === "ascending" || sort === "descending" ) {
58+ ret . direction = ( sort === "ascending" ) ?XtSortByDirection . Ascending :XtSortByDirection . None ;
59+ } else if ( sort == null ) {
60+ ret . direction = XtSortByDirection . None ;
61+ } else if ( sort . type == 'metadata' ) {
62+ throw new Error ( "Metadata sort is not supported yet for element " + name ) ;
63+ } else {
64+ ret . direction = ( sort . direction === "ascending" ) ?XtSortByDirection . Ascending :XtSortByDirection . Descending ;
65+ }
66+ return ret ;
4567 }
4668}
0 commit comments