@@ -9,6 +9,7 @@ import { of, take, map, BehaviorSubject, combineLatest, switchMap } from 'rxjs';
99import { ConfirmDialogComponent } from '@shared/components/confirm-dialog/confirm-dialog.component' ;
1010import { TopicIdeaService } from '@services/topic-idea.service' ;
1111import { Component , Input , NgZone } from '@angular/core' ;
12+ import { municipalities } from '@services/municipalitiy.service' ;
1213
1314import { CreateIdeaFolderComponent } from '../create-idea-folder/create-idea-folder.component' ;
1415import { ActivatedRoute } from '@angular/router' ;
@@ -34,6 +35,7 @@ export class TopicIdeationComponent {
3435 @Input ( ) ideation ! : any ;
3536 @Input ( ) topic ! : Topic ;
3637
38+ AGE_LIMIT = 110 ;
3739 public FILTERS_ALL = 'all' ;
3840 STATUSES = this . TopicService . STATUSES ;
3941 VISIBILITY = this . TopicService . VISIBILITY ;
@@ -51,6 +53,9 @@ export class TopicIdeationComponent {
5153 allIdeas$ : Idea [ ] = [ ] ;
5254 tabSelected = 'ideas' ;
5355 ideaFilters = {
56+ age : < string [ ] > [ ] ,
57+ gender : '' ,
58+ residence : '' ,
5459 type : '' ,
5560 orderBy : '' ,
5661 participants : < User | any > ''
@@ -59,12 +64,23 @@ export class TopicIdeationComponent {
5964 mobileIdeaFiltersList = false ;
6065
6166 mobileIdeaFilters : any = {
67+ age : < string [ ] > [ ] ,
68+ gender : '' ,
69+ residence : '' ,
6270 type : '' ,
6371 orderBy : '' ,
6472 participants : < User | any > ''
6573 }
6674
75+ mobileAges = < string [ ] > [ ] ;
76+
77+
78+ municipalities = municipalities ;
79+
6780 ideaTypeFilter$ = new BehaviorSubject ( '' ) ;
81+ ageFilter$ = new BehaviorSubject < ( number | string ) [ ] > ( [ ] ) ;
82+ genderFilter$ = new BehaviorSubject ( '' ) ;
83+ residenceFilter$ = new BehaviorSubject ( '' ) ;
6884 orderFilter$ = new BehaviorSubject ( '' ) ;
6985 ideaParticipantsFilter$ = new BehaviorSubject ( < User | string > '' ) ;
7086 searchIdeasInput = '' ;
@@ -90,9 +106,9 @@ export class TopicIdeationComponent {
90106 ) { }
91107
92108 ngOnInit ( ) : void {
93- this . ideas$ = combineLatest ( [ this . ideaTypeFilter$ , this . orderFilter$ , this . ideaParticipantsFilter$ , this . folderFilter$ , this . ideaSearchFilter$ , this . TopicIdeaService . reload$ ] )
109+ this . ideas$ = combineLatest ( [ this . ideaTypeFilter$ , this . orderFilter$ , this . ideaParticipantsFilter$ , this . folderFilter$ , this . ideaSearchFilter$ , this . TopicIdeaService . reload$ , this . ageFilter$ , this . genderFilter$ , this . residenceFilter$ ] )
94110 . pipe (
95- switchMap ( ( [ typeFilter , orderFilter , participantFilter , folderFilter , search , load ] ) => {
111+ switchMap ( ( [ typeFilter , orderFilter , participantFilter , folderFilter , search , load , age , gender , residence ] ) => {
96112 this . TopicIdeaService . reset ( ) ;
97113 this . TopicIdeaService . setParam ( 'topicId' , this . topic . id ) ;
98114 this . TopicIdeaService . setParam ( 'ideationId' , this . topic . ideationId ) ;
@@ -122,7 +138,15 @@ export class TopicIdeationComponent {
122138 this . TopicIdeaService . setParam ( 'search' , search ) ;
123139 }
124140
125- if ( typeFilter || orderFilter || participantFilter || folderFilter || search ) {
141+ if ( age || gender || residence ) {
142+ this . TopicIdeaService . setParam ( 'demographics' , JSON . stringify ( {
143+ ...( age && Array . isArray ( age ) && age . length && { age : age . map ( String ) } ) ,
144+ ...( gender && { gender } ) ,
145+ ...( residence && { residence } )
146+ } ) ) ;
147+ }
148+
149+ if ( typeFilter || orderFilter || participantFilter || folderFilter || search || age ?. length > 0 || gender || residence ) {
126150 this . filtersSet = true ;
127151 } else {
128152 this . filtersSet = false ;
@@ -172,12 +196,62 @@ export class TopicIdeationComponent {
172196 } )
173197 }
174198
199+ get isCountryEstonia ( ) {
200+ return this . topic . country === 'Estonia' ;
201+ }
202+
203+ get hasDemograficsField ( ) {
204+ return {
205+ age : this . ideation . demographicsConfig ?. age ,
206+ gender : this . ideation . demographicsConfig ?. gender ,
207+ residence : this . ideation . demographicsConfig ?. residence
208+ } ;
209+ }
210+
211+ get sortedSelectedAges ( ) {
212+ return this . ideaFilters . age . sort ( ( a , b ) => {
213+ const ageA = parseInt ( a , 10 ) ;
214+ const ageB = parseInt ( b , 10 ) ;
215+ return ageA - ageB ;
216+ }
217+ ) . join ( ', ' ) ;
218+ }
219+
175220 setType ( type : string ) {
176221 if ( type === 'all' || typeof type !== 'string' ) type = '' ;
177222 this . ideaTypeFilter$ . next ( type ) ;
178223 this . ideaFilters . type = type ;
179224 }
180225
226+ setAge ( _age : number | string ) {
227+ const age = _age . toString ( ) ;
228+ if ( age === 'all' || age === '' ) {
229+ this . ageFilter$ . next ( [ ] ) ;
230+ this . ideaFilters . age = [ ] ;
231+ return ;
232+ }
233+
234+ const idx = this . ideaFilters . age . indexOf ( age ) ;
235+ if ( idx > - 1 ) {
236+ this . ideaFilters . age . splice ( idx , 1 ) ;
237+ } else {
238+ this . ideaFilters . age . push ( age ) ;
239+ }
240+ this . ageFilter$ . next ( [ ...this . ideaFilters . age ] ) ;
241+ }
242+
243+ setGender ( value : string ) {
244+ if ( value === 'all' ) value = '' ;
245+ this . genderFilter$ . next ( value ) ;
246+ this . ideaFilters . gender = value ;
247+ }
248+
249+ setResidence ( value : string ) {
250+ if ( value === 'all' ) value = '' ;
251+ this . residenceFilter$ . next ( value ) ;
252+ this . ideaFilters . residence = value ;
253+ }
254+
181255 userIndex ( ) {
182256 let userIndex = this . users . findIndex ( ( user ) => user . id === this . ideaFilters . participants ?. id )
183257 return userIndex + 1 ;
@@ -233,8 +307,12 @@ export class TopicIdeationComponent {
233307 doClearFilters ( ) {
234308 this . setType ( '' ) ;
235309 this . orderBy ( '' ) ;
310+ this . setAge ( '' ) ;
311+ this . setGender ( '' ) ;
312+ this . setResidence ( '' ) ;
236313 this . setParticipant ( ) ;
237314 this . filtersSet = false ;
315+ this . mobileAges = [ ] ;
238316 }
239317
240318 saveIdeation ( ) {
@@ -405,6 +483,9 @@ export class TopicIdeationComponent {
405483
406484 showMobileOverlay ( ) {
407485 const filtersShow = Object . entries ( this . mobileIdeaFilters ) . find ( ( [ key , value ] ) => {
486+ if ( key === 'age' ) {
487+ return Array . isArray ( value ) && value . length > 0 ;
488+ }
408489 return ! ! value ;
409490 } ) ;
410491
0 commit comments