Skip to content
Permalink
Browse files
fix(routing): bring back the route handler in main component (DSP-1303)…
… (#373)

* chore(routing): Bring back the route handler in main.component

* chore(login): fix login redirection after login and logout

* test(main): Exclude some tests because they will never run in dsp-admin

* test(main): Exclude some tests because they will never run in dsp-admin
  • Loading branch information
kilchenmann committed Jan 28, 2021
1 parent 46dfdbb commit 8492c1acd23da73ed143e160388eb0080ff60b17
@@ -32,8 +32,7 @@ import { UsersComponent } from './system/users/users.component';
const routes: Routes = [
{
path: '',
component: LoginComponent
// component: MainComponent
component: MainComponent
},
{
path: 'help',
@@ -1,3 +1,3 @@
<div class="login-page">
<dsp-login-form (loginSuccess)="refresh($event)"></dsp-login-form>
<dsp-login-form (loginSuccess)="login($event)" (logoutSuccess)="logout($event)"></dsp-login-form>
</div>
@@ -1,7 +1,6 @@
import { Component } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { SessionService } from '@dasch-swiss/dsp-ui';
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';

@Component({
@@ -13,26 +12,37 @@ export class LoginComponent {

returnUrl: string;

constructor (private _titleService: Title,
constructor(private _titleService: Title,
private _route: ActivatedRoute,
private _router: Router,
private _session: SessionService,
private _componentCommsService: ComponentCommunicationEventService) {

// set the page title
this._titleService.setTitle('Login');

// this.returnUrl = this._route.snapshot.queryParams['returnUrl'] || '/';
this.returnUrl = this._route.snapshot.queryParams['returnUrl'] || '/';
}

refresh(status: boolean) {
login(status: boolean) {

// go to the dashboard:
if (status && this._session.getSession()) {
this._router.navigate(['dashboard']);
// go to the previous route: this._router.navigate([this.returnUrl]);
if (status) {
// go to the previous route; if it's not the help page
if (this.returnUrl !== 'help') {
this._router.navigate([this.returnUrl]);
} else {
// otherwise go to the dashboard
this._router.navigate(['dashboard']);
}
this._componentCommsService.emit(new EmitEvent(Events.LoginSuccess, true));
}
}

logout(status: boolean) {
if (status) {
// reload the page
window.location.reload();
}
}

}
@@ -206,14 +206,14 @@ describe('MainComponent', () => {
expect(projectSpy).toHaveBeenCalledTimes(1);
});

it('should display the title "bring everything together and simplify your research"', () => {
xit('should display the title "bring everything together and simplify your research"', () => {
const h1 = element.querySelector('h1.app-headline');

expect(h1.textContent).toEqual('bring everything together and simplify your research');
expect(projectSpy).toHaveBeenCalledTimes(1);
});

it('should load projects', () => {
xit('should load projects', () => {
expect(projectSpy).toHaveBeenCalledTimes(1);
expect(component.projects.length).toEqual(2);

@@ -224,7 +224,7 @@ describe('MainComponent', () => {
expect(component.projects[1].url).toEqual('project/0803');
});

it('should not display the Anything project in the list', () => {
xit('should not display the Anything project in the list', () => {
expect(projectSpy).toHaveBeenCalledTimes(1);
expect(component.projects.length).toEqual(2);

@@ -233,7 +233,7 @@ describe('MainComponent', () => {

});

it('should display the cookie banner', () => {
xit('should display the cookie banner', () => {
const cookieBanner = fixture.debugElement.query(By.css('div.cookie-banner'));
const acceptBtn = fixture.debugElement.query(By.css('div.action button'));

@@ -76,6 +76,10 @@ export class MainComponent implements OnInit {
// check if a session is active
if (this._session.getSession()) {
this._router.navigate(['dashboard']);
} else {
// if session does not exist, redirect to login page
// NOTE: this is a temporary solution for DSP-ADMIN-APP
this._router.navigate(['login']);
}
}

0 comments on commit 8492c1a

Please sign in to comment.