88 OnInit
99} from '@angular/core' ;
1010import { interval , Subscription } from 'rxjs' ;
11- import { ActivatedRoute , RouterLink } from '@angular/router' ;
11+ import { ActivatedRoute , Router , RouterLink } from '@angular/router' ;
1212import { GenericValidationError } from '../../../../../generic-responses' ;
1313import { PermissionsService } from '../../../../../permissions/permissions.service' ;
1414import { MapeditorsService } from '../mapeditors.service' ;
@@ -27,7 +27,6 @@ import { PermissionDirective } from '../../../../../permissions/permission.direc
2727import { BackButtonDirective } from '../../../../../directives/back-button.directive' ;
2828import { NgClass , NgIf } from '@angular/common' ;
2929import { XsButtonDirective } from '../../../../../layouts/coreui/xsbutton-directive/xsbutton.directive' ;
30- import { parseInt } from 'lodash' ;
3130import { MapViewComponent } from '../../../components/map-view/map-view.component' ;
3231import { SidebarService } from '../../../../../layouts/coreui/coreui-navbar/sidebar.service' ;
3332
@@ -61,14 +60,14 @@ export class MapeditorsViewComponent implements OnInit, OnDestroy, AfterViewInit
6160 private MapeditorsService : MapeditorsService = inject ( MapeditorsService ) ;
6261 public PermissionsService : PermissionsService = inject ( PermissionsService ) ;
6362 readonly sidebarService : SidebarService = inject ( SidebarService ) ;
64- private route = inject ( ActivatedRoute ) ;
63+ public readonly route = inject ( ActivatedRoute ) ;
64+ public readonly router = inject ( Router ) ;
6565 public errors : GenericValidationError | null = null ;
6666 private cdr = inject ( ChangeDetectorRef ) ;
6767
6868 public map ! : MapeditorsViewMap ;
69- private init = true ;
7069 protected mapId : number = 0 ;
71- protected rotate : null | string | string [ ] = null ;
70+ protected rotate : string [ ] = [ ] ;
7271
7372 protected fullscreen : boolean = false ;
7473 private rotationInterval : number = 0 ;
@@ -79,49 +78,49 @@ export class MapeditorsViewComponent implements OnInit, OnDestroy, AfterViewInit
7978 private refreshInterval : number = 0 ;
8079
8180 public ngOnInit ( ) : void {
82- this . mapId = Number ( this . route . snapshot . paramMap . get ( 'id' ) ) ;
83- this . fullscreen = ( this . route . snapshot . paramMap . get ( 'fullscreen' ) === 'true' ) ;
84- let rotationParam = this . route . snapshot . paramMap . get ( 'rotation' ) ;
85- if ( rotationParam != null ) this . rotate = rotationParam ;
86- let intervalParam = this . route . snapshot . paramMap . get ( 'interval' ) ;
87- if ( intervalParam != null ) {
88- this . rotationInterval = parseInt ( intervalParam , 10 ) * 1000 ;
89- this . intervalParam = parseInt ( intervalParam , 10 ) ;
90- }
91- this . loadMapDetails ( ) ;
9281
93- if ( this . rotate !== null && this . rotationInterval > 0 ) {
94- if ( typeof this . rotate === "string" ) {
95- this . rotate = this . rotate . split ( ',' ) ;
82+ this . subscriptions . add ( this . route . params . subscribe ( params => {
83+ this . mapId = Number ( params [ 'id' ] ?? 0 ) ;
84+ this . fullscreen = ( params [ 'fullscreen' ] ?? 'false' ) === 'true' ;
85+
86+ let rotationParam = params [ 'rotation' ]
87+ if ( rotationParam ) {
88+ this . rotate = String ( rotationParam ) . split ( ',' ) ;
9689 }
9790
98- this . intervalSubscription = interval ( this . rotationInterval ) . subscribe ( ( ) => {
99- this . rotationPosition ++ ;
100- if ( this . rotate != null && ( this . rotationPosition > this . rotate . length ) ) {
101- this . rotationPosition = 1 ;
102- }
91+ let intervalParam = Number ( params [ 'interval' ] ?? 0 ) ;
92+ if ( isNaN ( intervalParam ) ) {
93+ intervalParam = 90 ;
94+ }
95+ this . rotationInterval = intervalParam * 1000 ;
96+
97+
98+ // Load the current map / first map of a rotation
99+ this . loadMapDetails ( ) ;
100+ this . cdr . markForCheck ( ) ;
101+
102+ if ( this . rotate . length > 0 ) {
103+ // Handle map rotations
104+ this . intervalSubscription = interval ( this . rotationInterval ) . subscribe ( ( ) => {
105+ this . rotationPosition ++ ;
106+ if ( this . rotate != null && ( this . rotationPosition > this . rotate . length ) ) {
107+ this . rotationPosition = 1 ;
108+ }
103109
104- if ( this . rotate != null ) {
105110 this . mapId = Number ( this . rotate [ this . rotationPosition - 1 ] ) ;
106- }
107- this . loadMapDetails ( ) ;
108- this . cdr . markForCheck ( ) ;
109- } ) ;
110- }
111111
112- this . subscriptions . add ( this . route . params . subscribe ( params => {
113- // reload page to display new map
114- if ( params [ 'id' ] !== undefined && params [ 'id' ] !== null && params [ 'id' ] !== '' && params [ 'id' ] !== this . mapId . toString ( ) ) {
115- window . location . reload ( ) ;
112+ this . loadMapDetails ( ) ;
113+ this . cdr . markForCheck ( ) ;
114+ } ) ;
116115 }
117116 } ) ) ;
117+
118+
118119 }
119120
120121 public ngOnDestroy ( ) : void {
121122 this . subscriptions . unsubscribe ( ) ;
122- if ( this . intervalSubscription ) {
123- this . intervalSubscription . unsubscribe ( ) ;
124- }
123+ this . intervalSubscription . unsubscribe ( ) ;
125124 this . toggleFullscreenMode ( false , true ) ;
126125 this . cdr . markForCheck ( ) ;
127126 }
@@ -138,7 +137,6 @@ export class MapeditorsViewComponent implements OnInit, OnDestroy, AfterViewInit
138137 if ( this . refreshInterval !== 0 && this . refreshInterval < 5000 ) {
139138 this . refreshInterval = 5000 ;
140139 }
141- this . init = false ;
142140 this . cdr . markForCheck ( ) ;
143141 } ) ) ;
144142 } ;
@@ -166,5 +164,4 @@ export class MapeditorsViewComponent implements OnInit, OnDestroy, AfterViewInit
166164 this . cdr . markForCheck ( ) ;
167165 }
168166
169- protected readonly Array = Array ;
170167}
0 commit comments