11import { CommonModule } from '@angular/common' ;
2- import { ChangeDetectionStrategy , Component , DestroyRef , inject , OnInit , signal , WritableSignal } from '@angular/core' ;
2+ import {
3+ ChangeDetectionStrategy ,
4+ Component ,
5+ DestroyRef ,
6+ inject ,
7+ OnInit ,
8+ QueryList ,
9+ signal ,
10+ ViewChildren ,
11+ WritableSignal
12+ } from '@angular/core' ;
313import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
414import { LuigiContextService } from '@luigi-project/client-support-angular' ;
5- import { Ui5WebcomponentsModule } from '@ui5/webcomponents-ngx' ;
15+ import { CheckBoxComponent , Ui5WebcomponentsModule } from '@ui5/webcomponents-ngx' ;
616import { IconComponent } from '@ui5/webcomponents-ngx/main/icon' ;
717import { finalize } from 'rxjs/operators' ;
818import { LOCAL_STORAGE_CATALOG_KEY } from '../app.constants' ;
@@ -20,14 +30,17 @@ import { CatalogCardListComponent } from './catalog-card-list/catalog-card-list.
2030 changeDetection : ChangeDetectionStrategy . OnPush
2131} )
2232export class CatalogComponent implements OnInit {
33+ @ViewChildren ( CheckBoxComponent ) checkBoxes ! : QueryList < CheckBoxComponent > ;
2334 context ?: CatalogContext ;
2435 fetchFinalized = false ;
36+ filtersVisible = false ;
2537 items : WritableSignal < ExtensionClass [ ] > = signal ( [ ] ) ;
2638 categories : Set < string > = new Set ( ) ;
2739 providers : Set < string > = new Set ( ) ;
2840 selectedCategories : string [ ] = [ ] ;
2941 selectedProviders : string [ ] = [ ] ;
3042 filteredItems : WritableSignal < ExtensionClass [ ] > = signal ( [ ] ) ;
43+ categoryTree ! : any [ ] ;
3144 private destroyRef = inject ( DestroyRef ) ;
3245
3346 constructor ( private dataService : CatalogDataService , private luigiContextService : LuigiContextService ) { }
@@ -38,13 +51,39 @@ export class CatalogComponent implements OnInit {
3851 } ) ;
3952 }
4053
41- public onCategoriesChange ( e : any ) {
42- this . selectedCategories = this . updateSelection ( e ) ;
54+ public toggleFilterVisibility ( event : Event ) {
55+ event . preventDefault ( ) ;
56+
57+ this . filtersVisible = ! this . filtersVisible ;
58+ }
59+
60+ public clearAllFilters ( event : Event ) {
61+ event . preventDefault ( ) ;
62+ this . checkBoxes ?. toArray ( ) . forEach ( item => item . checked = false ) ;
63+
64+ this . selectedCategories . length = 0 ;
65+ this . selectedProviders . length = 0 ;
66+
4367 this . filterItems ( ) ;
4468 }
4569
46- public onProvidersChange ( e : any ) {
47- this . selectedProviders = this . updateSelection ( e ) ;
70+ public onCategoryChange ( event : any , category : string ) {
71+ if ( event . target . _state . checked && ! this . selectedCategories . includes ( category ) ) {
72+ this . selectedCategories . push ( category ) ;
73+ } else {
74+ this . selectedCategories = this . selectedCategories . filter ( item => item !== category ) ;
75+ }
76+
77+ this . filterItems ( ) ;
78+ }
79+
80+ public onProviderChange ( event : any , provider : string ) {
81+ if ( event . target . _state . checked && ! this . selectedProviders . includes ( provider ) ) {
82+ this . selectedProviders . push ( provider ) ;
83+ } else {
84+ this . selectedProviders = this . selectedProviders . filter ( item => item !== provider ) ;
85+ }
86+
4887 this . filterItems ( ) ;
4988 }
5089
@@ -94,8 +133,22 @@ export class CatalogComponent implements OnInit {
94133 private updateCatalogItems ( account : string , data : ExtensionClass [ ] ) {
95134 const storageKey = account ? `${ LOCAL_STORAGE_CATALOG_KEY } -${ account } ` : LOCAL_STORAGE_CATALOG_KEY ;
96135 const globalStorage : string [ ] = JSON . parse ( localStorage . getItem ( storageKey ) || '[]' ) ;
136+ const treeData : Record < string , any > = { } ;
97137
98138 data ?. forEach ( item => {
139+ const cat = item . category ?. toLowerCase ( ) . replaceAll ( ' &' , '' ) . replaceAll ( ' ' , '-' ) ;
140+
141+ if ( cat ) {
142+ if ( ! treeData [ cat ] ) {
143+ treeData [ cat ] = {
144+ name : item . category ,
145+ providers : new Set ( )
146+ }
147+ }
148+
149+ treeData [ cat ] . providers . add ( item . provider ) ;
150+ }
151+
99152 item . category && this . categories . add ( item . category ) ;
100153 item . provider && this . providers . add ( item . provider ) ;
101154
@@ -109,11 +162,9 @@ export class CatalogComponent implements OnInit {
109162 }
110163 } ) ;
111164
165+ this . categoryTree = treeData ? Object . values ( treeData ) : [ ] ;
166+
112167 this . items . set ( data ) ;
113168 this . filterItems ( ) ;
114169 }
115-
116- private updateSelection ( e : any ) : string [ ] {
117- return e . detail . items . map ( ( item : any ) => item . _state . text ) ;
118- }
119170}
0 commit comments