@@ -39,42 +39,6 @@ import { HttpParams } from "@angular/common/http";
3939import { IconComponent } from "@uilib" ;
4040import { PartnerProgramFields } from "@office/models/partner-program-fields.model" ;
4141
42- /**
43- * Компонент списка проектов программы
44- *
45- * Отображает все проекты, связанные с программой, с поддержкой:
46- * - Бесконечной прокрутки (infinite scroll)
47- * - Пагинации данных
48- * - Модального окна для оценки проектов (для экспертов)
49- *
50- * Принимает:
51- * @param {ActivatedRoute } route - Для получения данных из резолвера
52- * @param {ProgramService } programService - Сервис для загрузки проектов
53- * @param {AuthService } authService - Для проверки прав пользователя
54- *
55- * Данные:
56- * @property {Project[] } projects - Массив проектов программы
57- * @property {number } projectsTotalCount - Общее количество проектов
58- * @property {Observable<Program> } program$ - Поток данных программы
59- * @property {number } page - Текущая страница пагинации
60- * @property {number } perPage - Количество проектов на странице
61- * @property {boolean } isFilterOpen - состояние панели фильтров (мобильные)
62- * ViewChild:
63- * @ViewChild projectsRoot - Ссылка на DOM элемент списка проектов
64- *
65- * Функциональность:
66- * - Загрузка начальных данных из резолвера
67- * - Автоматическая подгрузка при прокрутке
68- * - Отображение карточек проектов
69- * - Интеграция с компонентом оценки проектов
70- *
71- * Методы:
72- * @method onScroll() - Обработчик прокрутки для подгрузки данных
73- * @method onFetch() - Загрузка следующей порции проектов
74- *
75- * Возвращает:
76- * HTML шаблон со списком проектов и элементами управления
77- */
7842@Component ( {
7943 selector : "app-projects" ,
8044 templateUrl : "./projects.component.html" ,
@@ -125,6 +89,8 @@ export class ProgramProjectsComponent implements OnInit, AfterViewInit, OnDestro
12589 private previousReqQuery : Record < string , any > = { } ;
12690 private availableFilters : PartnerProgramFields [ ] = [ ] ;
12791
92+ private currentFilters : Record < string , any > = { } ;
93+
12894 ngOnInit ( ) : void {
12995 const routeData$ = this . route . data
13096 . pipe (
@@ -170,18 +136,23 @@ export class ProgramProjectsComponent implements OnInit, AfterViewInit, OnDestro
170136 if ( JSON . stringify ( reqQuery ) !== JSON . stringify ( this . previousReqQuery ) ) {
171137 this . previousReqQuery = reqQuery ;
172138
139+ this . currentFilters = reqQuery [ "filters" ] || { } ;
140+ this . page = 1 ;
141+
173142 const hasFilters =
174143 reqQuery && reqQuery [ "filters" ] && Object . keys ( reqQuery [ "filters" ] ) . length > 0 ;
175144
176145 const params = new HttpParams ( { fromObject : { offset : 0 , limit : 21 } } ) ;
177146
178147 if ( hasFilters ) {
179- return this . programService . createProgramFilters ( programId , reqQuery [ "filters" ] ) . pipe (
180- catchError ( err => {
181- console . error ( "createFilters failed, fallback to getAllProjects()" , err ) ;
182- return this . programService . getAllProjects ( programId , params ) ;
183- } )
184- ) ;
148+ return this . programService
149+ . createProgramFilters ( programId , reqQuery [ "filters" ] , params )
150+ . pipe (
151+ catchError ( err => {
152+ console . error ( "createFilters failed, fallback to getAllProjects()" , err ) ;
153+ return this . programService . getAllProjects ( programId , params ) ;
154+ } )
155+ ) ;
185156 }
186157
187158 return this . programService . getAllProjects ( programId , params ) . pipe (
@@ -202,6 +173,7 @@ export class ProgramProjectsComponent implements OnInit, AfterViewInit, OnDestro
202173
203174 this . projects = projects . results ;
204175 this . searchedProjects = projects . results ;
176+ this . projectsTotalCount = projects . count ;
205177
206178 this . cdref . detectChanges ( ) ;
207179 } ) ;
@@ -299,19 +271,37 @@ export class ProgramProjectsComponent implements OnInit, AfterViewInit, OnDestro
299271 const offset = this . page * this . perPage ;
300272 const limit = this . perPage ;
301273
302- return this . programService
303- . getAllProjects ( programId , new HttpParams ( { fromObject : { offset, limit } } ) )
304- . pipe (
274+ const hasFilters = this . currentFilters && Object . keys ( this . currentFilters ) . length > 0 ;
275+
276+ if ( hasFilters ) {
277+ const params = new HttpParams ( { fromObject : { offset, limit } } ) ;
278+
279+ return this . programService . createProgramFilters ( programId , this . currentFilters , params ) . pipe (
305280 tap ( projects => {
306281 this . projectsTotalCount = projects . count ;
307282 this . projects = [ ...this . projects , ...projects . results ] ;
308283 this . searchedProjects = this . projects ;
309-
310284 this . page ++ ;
311-
312285 this . cdref . detectChanges ( ) ;
286+ } ) ,
287+ catchError ( err => {
288+ console . error ( "Pagination with filters failed" , err ) ;
289+ return of ( { results : [ ] , count : 0 } ) ;
313290 } )
314291 ) ;
292+ } else {
293+ return this . programService
294+ . getAllProjects ( programId , new HttpParams ( { fromObject : { offset, limit } } ) )
295+ . pipe (
296+ tap ( projects => {
297+ this . projectsTotalCount = projects . count ;
298+ this . projects = [ ...this . projects , ...projects . results ] ;
299+ this . searchedProjects = this . projects ;
300+ this . page ++ ;
301+ this . cdref . detectChanges ( ) ;
302+ } )
303+ ) ;
304+ }
315305 }
316306
317307 private buildFilterQuery ( q : Params ) : Record < string , any > {
0 commit comments