@@ -57,20 +57,12 @@ import { tagsFilter } from "projects/core/src/consts/filters/tags-filter.const";
5757 ProjectsFilterComponent ,
5858 SearchComponent ,
5959 RatingCardComponent ,
60- CheckboxComponent ,
6160 InfoCardComponent ,
6261 ] ,
6362 standalone : true ,
6463} )
6564export class ProgramListComponent implements OnInit , OnDestroy , AfterViewInit {
6665 constructor ( ) {
67- const isRatedByExpert =
68- this . route . snapshot . queryParams [ "is_rated_by_expert" ] === "true"
69- ? true
70- : this . route . snapshot . queryParams [ "is_rated_by_expert" ] === "false"
71- ? false
72- : null ;
73-
7466 const searchValue =
7567 this . route . snapshot . queryParams [ "search" ] ||
7668 this . route . snapshot . queryParams [ "name__contains" ] ;
@@ -79,10 +71,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
7971 this . searchForm = this . fb . group ( {
8072 search : [ decodedSearchValue ] ,
8173 } ) ;
82-
83- this . filterForm = this . fb . group ( {
84- filterTag : [ isRatedByExpert , Validators . required ] ,
85- } ) ;
8674 }
8775
8876 @ViewChild ( "listRoot" ) listRoot ?: ElementRef < HTMLUListElement > ;
@@ -102,7 +90,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
10290 private availableFilters : PartnerProgramFields [ ] = [ ] ;
10391
10492 searchForm : FormGroup ;
105- filterForm : FormGroup ;
10693
10794 listTotalCount ?: number ;
10895 listPage = 0 ;
@@ -157,10 +144,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
157144 }
158145
159146 this . setupFilters ( ) ;
160-
161- if ( this . listType === "rating" ) {
162- this . setupRatingQueryParams ( ) ;
163- }
164147 }
165148
166149 ngAfterViewInit ( ) : void {
@@ -233,7 +216,7 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
233216 }
234217
235218 private setupFilters ( ) : void {
236- if ( this . listType !== "projects ") return ;
219+ if ( this . listType === "members ") return ;
237220
238221 const filtersObservable$ = this . route . queryParams
239222 . pipe (
@@ -250,20 +233,48 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
250233 const params = new HttpParams ( { fromObject : { offset : 0 , limit : this . perPage } } ) ;
251234
252235 if ( hasFilters ) {
253- return this . programService . createProgramFilters ( programId , reqQuery [ "filters" ] ) . pipe (
236+ if ( this . listType === "projects" ) {
237+ return this . programService
238+ . createProgramFilters ( programId , reqQuery [ "filters" ] )
239+ . pipe (
240+ catchError ( err => {
241+ console . error ( "createFilters failed, fallback to getAllProjects()" , err ) ;
242+ return this . programService . getAllProjects ( programId , params ) ;
243+ } )
244+ ) ;
245+ } else if ( this . listType === "rating" ) {
246+ const filterParams = new HttpParams ( {
247+ fromObject : {
248+ offset : 0 ,
249+ limit : this . perPage ,
250+ ...this . flattenFilters ( reqQuery [ "filters" ] ) ,
251+ } ,
252+ } ) ;
253+
254+ return this . projectRatingService . getAll ( programId , filterParams ) . pipe (
255+ catchError ( err => {
256+ console . error ( "getAllRatingProjects failed" , err ) ;
257+ return this . projectRatingService . getAll ( programId , params ) ;
258+ } )
259+ ) ;
260+ }
261+ }
262+
263+ if ( this . listType === "projects" ) {
264+ return this . programService . getAllProjects ( programId , params ) . pipe (
254265 catchError ( err => {
255- console . error ( "createFilters failed, fallback to getAllProjects() " , err ) ;
266+ console . error ( "getAllProjects failed" , err ) ;
256267 return this . programService . getAllProjects ( programId , params ) ;
257268 } )
258269 ) ;
270+ } else if ( this . listType === "rating" ) {
271+ return this . projectRatingService . getAll ( programId , params ) . pipe (
272+ catchError ( err => {
273+ console . error ( "getAllRatingProjects failed" , err ) ;
274+ return this . projectRatingService . getAll ( programId , params ) ;
275+ } )
276+ ) ;
259277 }
260-
261- return this . programService . getAllProjects ( programId , params ) . pipe (
262- catchError ( err => {
263- console . error ( "getAllProjects failed" , err ) ;
264- return this . programService . getAllProjects ( programId , params ) ;
265- } )
266- ) ;
267278 }
268279
269280 return of ( null ) ;
@@ -282,44 +293,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
282293 this . subscriptions$ . push ( filtersObservable$ ) ;
283294 }
284295
285- private setupRatingQueryParams ( ) : void {
286- const queryParams$ = this . route . queryParams
287- . pipe (
288- debounceTime ( 200 ) ,
289- tap ( params => {
290- const isRatedByExpert =
291- params [ "is_rated_by_expert" ] === "true"
292- ? true
293- : params [ "is_rated_by_expert" ] === "false"
294- ? false
295- : undefined ;
296- const searchValue = params [ "name__contains" ] || "" ;
297-
298- this . isRatedByExpert . set ( isRatedByExpert ) ;
299- this . searchValue . set ( searchValue ) ;
300- } ) ,
301- switchMap ( ( ) => {
302- this . listPage = 0 ;
303- return this . onFetch ( ) ;
304- } )
305- )
306- . subscribe ( ) ;
307-
308- this . subscriptions$ . push ( queryParams$ ) ;
309- }
310-
311- // Методы фильтрации
312- setValue ( event : Event ) : void {
313- event . stopPropagation ( ) ;
314- this . filterForm . get ( "filterTag" ) ?. setValue ( ! this . filterForm . get ( "filterTag" ) ?. value ) ;
315-
316- this . router . navigate ( [ ] , {
317- queryParams : { is_rated_by_expert : this . filterForm . get ( "filterTag" ) ?. value } ,
318- relativeTo : this . route ,
319- queryParamsHandling : "merge" ,
320- } ) ;
321- }
322-
323296 // Универсальный метод скролла
324297 private onScroll ( ) {
325298 if ( this . listTotalCount && this . list . length >= this . listTotalCount ) return of ( { } ) ;
@@ -392,7 +365,7 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
392365
393366 case "rating" :
394367 return this . projectRatingService
395- . getAll ( programId , offset , this . itemsPerPage , this . isRatedByExpert ( ) , this . searchValue ( ) )
368+ . getAll ( programId , new HttpParams ( { fromObject : { offset, limit : this . itemsPerPage } } ) )
396369 . pipe (
397370 tap ( ( { count, results } ) => {
398371 this . listTotalCount = count ;
@@ -411,15 +384,15 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
411384 }
412385 }
413386
414- // Построение запроса для фильтров (только для проектов )
387+ // Построение запроса для фильтров (кроме участников )
415388 private buildFilterQuery ( q : any ) : Record < string , any > {
416- if ( this . listType !== "projects ") return { } ;
389+ if ( this . listType === "members ") return { } ;
417390
418391 const filters : Record < string , any [ ] > = { } ;
419392
420393 if ( this . availableFilters . length === 0 ) {
421394 Object . keys ( q ) . forEach ( key => {
422- if ( key !== "search" && q [ key ] !== undefined && q [ key ] !== "" ) {
395+ if ( key !== "search" && key !== "name__contains" && q [ key ] !== undefined && q [ key ] !== "" ) {
423396 filters [ key ] = Array . isArray ( q [ key ] ) ? q [ key ] : [ q [ key ] ] ;
424397 }
425398 } ) ;
@@ -482,6 +455,24 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
482455 this . isFilterOpen = false ;
483456 }
484457
458+ /**
459+ * Сброс всех активных фильтров
460+ * Очищает все query параметры и возвращает к состоянию по умолчанию
461+ */
462+ onClearFilters ( ) : void {
463+ this . searchForm . reset ( ) ;
464+
465+ this . router
466+ . navigate ( [ ] , {
467+ queryParams : {
468+ search : undefined ,
469+ } ,
470+ relativeTo : this . route ,
471+ queryParamsHandling : "merge" ,
472+ } )
473+ . then ( ( ) => console . log ( "Query change from ProjectsComponent" ) ) ;
474+ }
475+
485476 private get itemsPerPage ( ) : number {
486477 return this . listType === "rating"
487478 ? 8
@@ -493,4 +484,19 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
493484 private get searchParamName ( ) : string {
494485 return this . listType === "rating" ? "name__contains" : "search" ;
495486 }
487+
488+ private flattenFilters ( filters : Record < string , any [ ] > ) : Record < string , string > {
489+ const flattened : Record < string , string > = { } ;
490+
491+ Object . keys ( filters ) . forEach ( key => {
492+ const value = filters [ key ] ;
493+ if ( Array . isArray ( value ) && value . length > 0 ) {
494+ flattened [ key ] = Array . isArray ( value [ 0 ] ) ? value . join ( "," ) : value . toString ( ) ;
495+ } else if ( value !== undefined && value !== null ) {
496+ flattened [ key ] = value . toString ( ) ;
497+ }
498+ } ) ;
499+
500+ return flattened ;
501+ }
496502}
0 commit comments