diff --git a/src/frontend/app/administration/home/administration.component.ts b/src/frontend/app/administration/home/administration.component.ts index 9cfcdd9ea6eda29e6551aba37019c354b4564748..3559b0623fa70bcfc2a47d305112148ae3cebe8d 100644 --- a/src/frontend/app/administration/home/administration.component.ts +++ b/src/frontend/app/administration/home/administration.component.ts @@ -87,7 +87,7 @@ export class AdministrationComponent implements OnInit, AfterViewInit { } ngAfterViewInit(): void { - if (this.headerService.user.mode === 'root_visible' || this.headerService.user.mode === 'root_invisible') { + if (!this.featureTourService.isComplete()) { this.featureTourService.init(); } } diff --git a/src/frontend/app/home/home.component.ts b/src/frontend/app/home/home.component.ts index 417d9c08e61a3e5e65316ad1f90ade338b286339..56fdcd3c9db1d62b0b2c0b7e106c64064d9f944e 100644 --- a/src/frontend/app/home/home.component.ts +++ b/src/frontend/app/home/home.component.ts @@ -71,8 +71,8 @@ export class HomeComponent implements OnInit, AfterViewInit { }); } - ngAfterViewInit(): void { - if (this.headerService.user.mode === 'root_visible' || this.headerService.user.mode === 'root_invisible') { + ngAfterViewInit(): void { + if (!this.featureTourService.isComplete()) { this.featureTourService.init(); } this.http.get('../rest/home/lastRessources') diff --git a/src/frontend/service/featureTour.service.ts b/src/frontend/service/featureTour.service.ts index 52b2ade804b63c7113d36c2a7999968a4f6a5956..2bd8599222ee912f3a5a46df172903773019516d 100644 --- a/src/frontend/service/featureTour.service.ts +++ b/src/frontend/service/featureTour.service.ts @@ -102,10 +102,11 @@ export class FeatureTourService { private http: HttpClient, private notify: NotificationService, ) { - this.getCurrentStepType(); } init() { + this.getCurrentStepType(); + if (!this.functionService.empty(this.currentStepType)) { const steps = this.tour.filter(step => step.type === this.currentStepType).map(step => step.stepId); this.joyrideService.startTour( @@ -132,7 +133,9 @@ export class FeatureTourService { /*handle error*/ }, () => { - if (this.currentTour.redirectToAdmin) { + if (this.currentTour === null) { + this.router.navigate(['/home']); + } else if (this.currentTour.redirectToAdmin) { this.router.navigate(['/administration']); } else { this.endTour(); @@ -143,22 +146,28 @@ export class FeatureTourService { } getCurrentStepType() { - if (this.headerService.user.userId !== null) { - this.featureTourEnd = this.headerService.user.featureTour; - } - const unique = [...new Set(this.tour.map(item => item.type))]; - this.currentStepType = unique.filter(stepType => this.featureTourEnd.indexOf(stepType) === -1)[0]; + this.featureTourEnd = this.headerService.user.featureTour; + this.currentStepType = this.getFeatureTourTypes().filter(stepType => this.featureTourEnd.indexOf(stepType) === -1)[0]; } endTour() { - this.featureTourEnd.push(this.currentStepType); - this.http.put('../rest/currentUser/profile/featureTour', {featureTour : this.featureTourEnd}).pipe( - catchError((err: any) => { - this.notify.handleSoftErrors(err); - return of(false); - }) - ).subscribe(); - this.getCurrentStepType(); + if (this.currentStepType !== undefined) { + this.featureTourEnd.push(this.currentStepType); + this.http.put('../rest/currentUser/profile/featureTour', {featureTour : this.featureTourEnd}).pipe( + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + this.getCurrentStepType(); + } + } + + getFeatureTourTypes() { + return [...new Set(this.tour.map(item => item.type))]; } + isComplete() { + return (this.headerService.user.mode === 'root_visible' || this.headerService.user.mode === 'root_invisible') && this.headerService.user.featureTour.length === this.getFeatureTourTypes().length; + } }