@@ -5,7 +5,7 @@ import {ActivatedRoute, Router} from '@angular/router';
5
5
import { TranslateService } from '@ngx-translate/core' ;
6
6
import { ResizeEvent } from 'angular-resizable-element' ;
7
7
import { Observable , of , Subscription } from 'rxjs' ;
8
- import { map } from 'rxjs/operators' ;
8
+ import { filter , map , take } from 'rxjs/operators' ;
9
9
import { RoleAccess , View } from '../../../commons/schema' ;
10
10
import { AccessService } from '../../authorization/permission/access.service' ;
11
11
import { ConfigurationService } from '../../configuration/configuration.service' ;
@@ -21,6 +21,7 @@ import {Page} from '../../resources/interface/page';
21
21
import {
22
22
DynamicNavigationRouteProviderService ,
23
23
} from '../../routing/dynamic-navigation-route-provider/dynamic-navigation-route-provider.service' ;
24
+ import { RedirectService } from '../../routing/redirect-service/redirect.service' ;
24
25
import { NAE_ROUTING_CONFIGURATION_PATH } from '../../routing/routing-builder/routing-builder.service' ;
25
26
import { LanguageService } from '../../translate/language.service' ;
26
27
import { User } from '../../user/models/user' ;
@@ -111,9 +112,15 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
111
112
*/
112
113
protected _currentNode : UriNodeResource ;
113
114
115
+ /**
116
+ * Currently selected navigation item
117
+ */
118
+ protected _currentNavigationItem : NavigationItem ;
119
+
114
120
leftLoading$ : LoadingEmitter ;
115
121
rightLoading$ : LoadingEmitter ;
116
122
nodeLoading$ : LoadingEmitter ;
123
+ isRightSideInitialized : boolean ;
117
124
118
125
protected _configLeftMenu : ConfigDoubleMenu = {
119
126
mode : 'side' ,
@@ -143,15 +150,18 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
143
150
protected _caseResourceService : CaseResourceService ,
144
151
protected _impersonationUserSelect : ImpersonationUserSelectService ,
145
152
protected _impersonation : ImpersonationService ,
146
- protected _dynamicRoutingService : DynamicNavigationRouteProviderService ) {
153
+ protected _dynamicRoutingService : DynamicNavigationRouteProviderService ,
154
+ protected _redirectService : RedirectService ) {
147
155
this . leftItems = new Array < NavigationItem > ( ) ;
148
156
this . rightItems = new Array < NavigationItem > ( ) ;
149
157
this . leftLoading$ = new LoadingEmitter ( ) ;
150
158
this . rightLoading$ = new LoadingEmitter ( ) ;
151
159
this . nodeLoading$ = new LoadingEmitter ( ) ;
160
+ this . isRightSideInitialized = false ;
152
161
this . itemsOrder = MenuOrder . Ascending ;
153
162
this . hiddenCustomItems = [ ] ;
154
163
this . moreItems = new Array < NavigationItem > ( ) ;
164
+ this . _currentNavigationItem = null ;
155
165
this . _childCustomViews = { } ;
156
166
}
157
167
@@ -168,6 +178,14 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
168
178
this . currentNode = node ;
169
179
} ) ;
170
180
181
+ this . rightLoading$ . pipe (
182
+ filter ( ( ) => this . isRightSideInitialized === true ) ,
183
+ filter ( isRightLoading => isRightLoading === false ) ,
184
+ take ( 1 )
185
+ ) . subscribe ( ( ) => {
186
+ this . openAvailableView ( ) ;
187
+ } )
188
+
171
189
const viewConfigurationPath = this . _activatedRoute . snapshot . data [ NAE_ROUTING_CONFIGURATION_PATH ] ;
172
190
if ( ! ! viewConfigurationPath ) {
173
191
const viewConfiguration = this . _config . getViewByPath ( viewConfigurationPath ) ;
@@ -347,6 +365,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
347
365
}
348
366
349
367
onItemClick ( item : NavigationItem ) : void {
368
+ this . _currentNavigationItem = item ;
350
369
if ( item . resource === undefined ) {
351
370
// custom view represented only in nae.json
352
371
if ( item . processUri === this . currentNode . uriPath ) {
@@ -361,6 +380,12 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
361
380
this . _uriService . getNodeByPath ( path ) . subscribe ( node => {
362
381
this . _uriService . activeNode = node ;
363
382
this . itemClicked . emit ( { uriNode : this . _uriService . activeNode , isHome : false } ) ;
383
+ this . rightLoading$ . pipe (
384
+ filter ( isRightLoading => isRightLoading === false ) ,
385
+ take ( 1 )
386
+ ) . subscribe ( ( ) => {
387
+ this . openAvailableView ( ) ;
388
+ } )
364
389
} , error => {
365
390
this . _log . error ( error ) ;
366
391
} ) ;
@@ -374,10 +399,39 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
374
399
}
375
400
}
376
401
402
+ protected openAvailableView ( ) {
403
+ let allItems : Array < NavigationItem > = this . rightItems . concat ( this . moreItems ) ;
404
+
405
+ let autoOpenItems : Array < NavigationItem > = allItems . filter ( item => this . hasItemAutoOpenView ( item ) ) ;
406
+ if ( autoOpenItems . length > 0 ) {
407
+ this . _redirectService . redirect ( autoOpenItems [ 0 ] . routing . path ) ;
408
+ return ;
409
+ }
410
+
411
+ if ( this . hasItemView ( this . _currentNavigationItem ) ) {
412
+ // is routed by routerLink on item click
413
+ return ;
414
+ }
415
+
416
+ let itemsWithView : Array < NavigationItem > = allItems . filter ( item => this . hasItemView ( item ) ) ;
417
+ if ( itemsWithView . length > 0 ) {
418
+ this . _redirectService . redirect ( autoOpenItems [ 0 ] . routing . path ) ;
419
+ return ;
420
+ }
421
+ }
422
+
377
423
hasItemChildren ( item : NavigationItem ) : boolean {
378
424
return item . resource ?. immediateData . find ( f => f . stringId === GroupNavigationConstants . ITEM_FIELD_ID_HAS_CHILDREN ) ?. value ;
379
425
}
380
426
427
+ protected hasItemAutoOpenView ( item : NavigationItem ) : boolean {
428
+ return item . resource ?. immediateData . find ( f => f . stringId === GroupNavigationConstants . ITEM_FIELD_ID_IS_AUTO_SELECT ) ?. value ;
429
+ }
430
+
431
+ protected hasItemView ( item : NavigationItem ) : boolean {
432
+ return item ?. resource ?. immediateData . find ( f => f . stringId === GroupNavigationConstants . ITEM_FIELD_CONTAINS_FILTER ) ?. value ;
433
+ }
434
+
381
435
isItemAndNodeEqual ( item : NavigationItem , node : UriNodeResource ) : boolean {
382
436
return item . resource ?. immediateData . find ( f => f . stringId === GroupNavigationConstants . ITEM_FIELD_ID_NODE_PATH ) ?. value === node . uriPath ;
383
437
}
@@ -451,6 +505,7 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
451
505
this . rightItems = result . map ( folder => this . resolveItemCaseToNavigationItem ( folder ) ) . filter ( i => ! ! i ) ;
452
506
}
453
507
this . resolveCustomViewsInRightSide ( ) ;
508
+ this . isRightSideInitialized = true ;
454
509
this . rightLoading$ . off ( ) ;
455
510
this . itemLoaded . emit ( { menu : 'right' , items : this . rightItems } ) ;
456
511
} , error => {
0 commit comments