Commit 4765537e authored by Jérémy Destin's avatar Jérémy Destin
Browse files

feat: Add back to form button. Issue #15

parent d65a9698
......@@ -45,5 +45,15 @@
[href]="navbar.contributor.url" target="_blank">
<img src="{{ navbar.contributor.logo }}" alt="{{ navbar.contributor.name }} logo" height="60px"/>
</a>
<div>
<a [routerLink]="['/']"
[queryParams]="previousQueryParam">
<button *ngIf="displayBackButton" type="button" class="btn btn-secondary">
< Back to form
</button>
</a>
</div>
</div>
</nav>
import { Component } from '@angular/core';
import { environment } from '../../environments/environment';
import { routes as appUrlRoutes } from '../app-routing.module';
import { ActivatedRoute, Params, Router, RoutesRecognized } from '@angular/router';
@Component({
selector: 'faidare-navbar',
......@@ -8,10 +10,40 @@ import { environment } from '../../environments/environment';
})
export class NavbarComponent {
displayBackButton = false;
previousQueryParam: Params;
constructor(private router: Router, private route: ActivatedRoute
) {
this.router.events.subscribe(event => {
if (event instanceof RoutesRecognized) {
if (this.checkIsFormPage(event.url)) {
this.displayBackButton = false;
this.route.queryParams.subscribe(queryParam => {
this.previousQueryParam = queryParam;
});
} else {
this.displayBackButton = true;
}
}
});
}
navbar = environment.navbar;
navbarCollapsed = true;
toggleNavbar() {
this.navbarCollapsed = !this.navbarCollapsed;
}
checkIsFormPage(url: String) {
for (const route of appUrlRoutes) {
const routeType: string = route.path.split(':')[0];
if (routeType !== '' && url.startsWith('/' + routeType)) {
return false;
}
}
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment