1
1
import { Component , OnDestroy , OnInit } from '@angular/core' ;
2
2
import * as moment from 'moment' ;
3
- import { Subject , takeUntil } from 'rxjs' ;
3
+ import { combineLatestWith , Subject , takeUntil } from 'rxjs' ;
4
4
import { ROLES } from '../../services/authentication/authentication.service' ;
5
5
import { BoardService , BoardWithFavourite } from '../../services/board/board.service' ;
6
6
import { UpcomingMeetingBoardMapDto , UpcomingMeetingDto } from '../../services/decision-meeting/decision-meeting.dto' ;
7
7
import { DecisionMeetingService } from '../../services/decision-meeting/decision-meeting.service' ;
8
8
import { ToastService } from '../../services/toast/toast.service' ;
9
9
import { UserService } from '../../services/user/user.service' ;
10
10
import { CardType } from '../card/card.component' ;
11
+ import { ActivatedRoute , Router } from '@angular/router' ;
11
12
12
13
type MeetingCollection = {
13
14
meetingDate : number ;
@@ -45,13 +46,22 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
45
46
private boardService : BoardService ,
46
47
private toastService : ToastService ,
47
48
private userService : UserService ,
49
+ private route : ActivatedRoute ,
50
+ private router : Router ,
48
51
) { }
49
52
50
53
ngOnInit ( ) : void {
51
- this . boardService . $boards . pipe ( takeUntil ( this . destroy ) ) . subscribe ( ( boards ) => {
52
- this . boards = boards ;
53
- this . loadMeetings ( ) ;
54
- } ) ;
54
+ this . boardService . $boards
55
+ . pipe ( combineLatestWith ( this . route . queryParams ) )
56
+ . pipe ( takeUntil ( this . destroy ) )
57
+ . subscribe ( async ( [ boards , params ] ) => {
58
+ this . boards = boards ;
59
+ await this . loadMeetings ( ) ;
60
+
61
+ if ( this . viewData . length > 0 && params [ 'file_number' ] !== undefined ) {
62
+ this . findAndExpandAll ( params [ 'file_number' ] ) ;
63
+ }
64
+ } ) ;
55
65
56
66
this . userService . $userProfile . pipe ( takeUntil ( this . destroy ) ) . subscribe ( ( currentUser ) => {
57
67
if ( currentUser ) {
@@ -72,11 +82,11 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
72
82
const meetings = await this . meetingService . fetch ( ) ;
73
83
if ( meetings ) {
74
84
this . meetings = meetings ;
75
- this . populateViewData ( ) ;
85
+ await this . populateViewData ( ) ;
76
86
}
77
87
}
78
88
79
- private populateViewData ( ) {
89
+ private async populateViewData ( ) {
80
90
if ( this . meetings && this . boards . length > 0 ) {
81
91
this . viewData = this . boards
82
92
. filter ( ( board ) => board . showOnSchedule )
@@ -146,26 +156,30 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
146
156
}
147
157
148
158
onSearch ( ) {
159
+ this . findAndExpandAll ( this . searchText ) ;
160
+ }
161
+
162
+ findAndExpandAll ( fileNumber : string ) {
149
163
let foundResult = false ;
150
164
this . viewData = this . viewData . map ( ( board ) => {
151
165
board . isExpanded = false ;
152
166
board . pastMeetings = board . pastMeetings . map ( ( meeting ) => {
153
- const res = this . findAndExpand ( meeting , board ) ;
167
+ const res = this . findAndExpand ( meeting , board , fileNumber ) ;
154
168
if ( res . isExpanded ) {
155
169
foundResult = true ;
156
170
}
157
171
return res ;
158
172
} ) ;
159
173
160
174
if ( board . nextMeeting ) {
161
- const res = this . findAndExpand ( board . nextMeeting , board ) ;
175
+ const res = this . findAndExpand ( board . nextMeeting , board , fileNumber ) ;
162
176
if ( res . isExpanded ) {
163
177
foundResult = true ;
164
178
}
165
179
}
166
180
167
181
board . upcomingMeetings = board . upcomingMeetings . map ( ( meeting ) => {
168
- const res = this . findAndExpand ( meeting , board ) ;
182
+ const res = this . findAndExpand ( meeting , board , fileNumber ) ;
169
183
if ( res . isExpanded ) {
170
184
foundResult = true ;
171
185
}
@@ -182,11 +196,11 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
182
196
}
183
197
}
184
198
185
- private findAndExpand ( meeting : MeetingCollection , board : BoardWithDecisionMeetings ) {
199
+ private findAndExpand ( meeting : MeetingCollection , board : BoardWithDecisionMeetings , fileNumber : string ) {
186
200
meeting . isExpanded = false ;
187
201
meeting . meetings = meeting . meetings . map ( ( application ) => {
188
202
application . isHighlighted = false ;
189
- if ( application . fileNumber === this . searchText ) {
203
+ if ( application . fileNumber === fileNumber ) {
190
204
meeting . isExpanded = true ;
191
205
board . isExpanded = true ;
192
206
application . isHighlighted = true ;
@@ -243,10 +257,10 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
243
257
return el ? el . offsetWidth < el . scrollWidth : false ;
244
258
}
245
259
246
- openMeetings ( fileNumber : string , type : CardType ) {
260
+ async openMeetings ( fileNumber : string , type : CardType ) {
247
261
this . clearHighlight ( ) ;
248
262
const target = type === CardType . PLAN ? 'planning-review' : 'application' ;
249
263
const url = this . isCommissioner ? `/commissioner/${ target } /${ fileNumber } ` : `/${ target } /${ fileNumber } /review` ;
250
- window . open ( url , '_blank' ) ;
264
+ await this . router . navigateByUrl ( url ) ;
251
265
}
252
266
}
0 commit comments