Skip to content

Commit

Permalink
fix(routing): bring back the route handler in main component (DSP-130…
Browse files Browse the repository at this point in the history
…3) (#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
André Kilchenmann committed Jan 28, 2021
1 parent 46dfdbb commit 8492c1a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/app/app-routing.module.ts
Expand Up @@ -32,8 +32,7 @@ import { UsersComponent } from './system/users/users.component';
const routes: Routes = [
{
path: '',
component: LoginComponent
// component: MainComponent
component: MainComponent
},
{
path: 'help',
Expand Down
2 changes: 1 addition & 1 deletion src/app/main/login/login.component.html
@@ -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>
26 changes: 18 additions & 8 deletions src/app/main/login/login.component.ts
@@ -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({
Expand All @@ -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();
}
}

}
8 changes: 4 additions & 4 deletions src/app/main/main.component.spec.ts
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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'));

Expand Down
4 changes: 4 additions & 0 deletions src/app/main/main.component.ts
Expand Up @@ -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']);
}
}

Expand Down

0 comments on commit 8492c1a

Please sign in to comment.