mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Modified mobile log-in to use history as provided by the store.
Minor typedoc and import updates.
This commit is contained in:
@@ -19,9 +19,9 @@ import {APP_BASE_HREF} from '@angular/common';
|
|||||||
import {HostWindowService} from '../host-window.service';
|
import {HostWindowService} from '../host-window.service';
|
||||||
import {HostWindowServiceStub} from '../testing/host-window-service-stub';
|
import {HostWindowServiceStub} from '../testing/host-window-service-stub';
|
||||||
import {RouterStub} from '../testing/router-stub';
|
import {RouterStub} from '../testing/router-stub';
|
||||||
import {NavigationEnd, Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {Observable, of as observableOf} from 'rxjs';
|
import {RouteService} from '../services/route.service';
|
||||||
import {RouterEventsStub} from '../testing/router-events-stub';
|
import {routeServiceStub} from '../testing/route-service-stub';
|
||||||
|
|
||||||
describe('LogInComponent', () => {
|
describe('LogInComponent', () => {
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ describe('LogInComponent', () => {
|
|||||||
{provide: AuthService, useClass: AuthServiceStub},
|
{provide: AuthService, useClass: AuthServiceStub},
|
||||||
{provide: APP_BASE_HREF, useValue: '/'},
|
{provide: APP_BASE_HREF, useValue: '/'},
|
||||||
{provide: Router, useClass: RouterStub},
|
{provide: Router, useClass: RouterStub},
|
||||||
|
{provide: RouteService, useValue: routeServiceStub },
|
||||||
{provide: HostWindowService, useValue: new HostWindowServiceStub(900) }
|
{provide: HostWindowService, useValue: new HostWindowServiceStub(900) }
|
||||||
],
|
],
|
||||||
schemas: [
|
schemas: [
|
||||||
@@ -164,11 +165,6 @@ describe('LogInComponent on small screen', () => {
|
|||||||
let page: Page;
|
let page: Page;
|
||||||
let user: EPerson;
|
let user: EPerson;
|
||||||
|
|
||||||
const navEvents = observableOf(
|
|
||||||
new NavigationEnd(0, 'http://localhost:3000/home', 'http://localhost:3000/home'),
|
|
||||||
new NavigationEnd(1, 'http://localhost:3000/login', 'http://localhost:3000/login')
|
|
||||||
);
|
|
||||||
|
|
||||||
const authState = {
|
const authState = {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
@@ -196,7 +192,8 @@ describe('LogInComponent on small screen', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{provide: AuthService, useClass: AuthServiceStub},
|
{provide: AuthService, useClass: AuthServiceStub},
|
||||||
{provide: APP_BASE_HREF, useValue: '/'},
|
{provide: APP_BASE_HREF, useValue: '/'},
|
||||||
{provide: Router, useValue: new RouterEventsStub(navEvents)},
|
{provide: Router, useClass: RouterStub},
|
||||||
|
{provide: RouteService, useValue: routeServiceStub },
|
||||||
{provide: HostWindowService, useValue: new HostWindowServiceStub(300) }
|
{provide: HostWindowService, useValue: new HostWindowServiceStub(300) }
|
||||||
],
|
],
|
||||||
schemas: [
|
schemas: [
|
||||||
@@ -231,12 +228,13 @@ describe('LogInComponent on small screen', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set the redirect url on init', () => {
|
it('should set the redirect url on init', () => {
|
||||||
|
|
||||||
const authService: AuthService = TestBed.get(AuthService);
|
const authService: AuthService = TestBed.get(AuthService);
|
||||||
spyOn(authService, 'setRedirectUrl');
|
spyOn(authService, 'setRedirectUrl');
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(authService.setRedirectUrl).toHaveBeenCalledWith('http://localhost:3000/home');
|
// set FormControl values
|
||||||
|
component.form.controls.email.setValue('user');
|
||||||
|
component.form.controls.password.setValue('password');
|
||||||
|
expect(authService.setRedirectUrl).toHaveBeenCalledWith('collection/123');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import {filter, map, pairwise, take, takeWhile, tap} from 'rxjs/operators';
|
import {filter, map, pairwise, take, takeUntil, takeWhile, tap} from 'rxjs/operators';
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
|
||||||
import { select, Store } from '@ngrx/store';
|
import { select, Store } from '@ngrx/store';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable, Subject} from 'rxjs';
|
||||||
import {
|
import {
|
||||||
AuthenticateAction,
|
AuthenticateAction,
|
||||||
ResetAuthenticationMessagesAction
|
ResetAuthenticationMessagesAction
|
||||||
@@ -17,11 +17,12 @@ import {
|
|||||||
} from '../../core/auth/selectors';
|
} from '../../core/auth/selectors';
|
||||||
import { CoreState } from '../../core/core.reducers';
|
import { CoreState } from '../../core/core.reducers';
|
||||||
|
|
||||||
import {isEmpty, isNotEmpty} from '../empty.util';
|
import {isNotEmpty} from '../empty.util';
|
||||||
import { fadeOut } from '../animations/fade';
|
import { fadeOut } from '../animations/fade';
|
||||||
import {AuthService, LOGIN_ROUTE} from '../../core/auth/auth.service';
|
import {AuthService, LOGIN_ROUTE} from '../../core/auth/auth.service';
|
||||||
import {NavigationEnd, Router, RoutesRecognized} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {HostWindowService} from '../host-window.service';
|
import {HostWindowService} from '../host-window.service';
|
||||||
|
import {RouteService} from '../services/route.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* /users/sign-in
|
* /users/sign-in
|
||||||
@@ -89,6 +90,7 @@ export class LogInComponent implements OnDestroy, OnInit {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {AuthService} authService
|
* @param {AuthService} authService
|
||||||
* @param {FormBuilder} formBuilder
|
* @param {FormBuilder} formBuilder
|
||||||
|
* @param {RouteService} routeService
|
||||||
* @param {Router} router
|
* @param {Router} router
|
||||||
* @param {HostWindowService} windowService
|
* @param {HostWindowService} windowService
|
||||||
* @param {Store<State>} store
|
* @param {Store<State>} store
|
||||||
@@ -96,6 +98,7 @@ export class LogInComponent implements OnDestroy, OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
|
private routeService: RouteService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private windowService: HostWindowService,
|
private windowService: HostWindowService,
|
||||||
private store: Store<CoreState>
|
private store: Store<CoreState>
|
||||||
@@ -106,18 +109,19 @@ export class LogInComponent implements OnDestroy, OnInit {
|
|||||||
* Lifecycle hook that is called after data-bound properties of a directive are initialized.
|
* Lifecycle hook that is called after data-bound properties of a directive are initialized.
|
||||||
* @method ngOnInit
|
* @method ngOnInit
|
||||||
*/
|
*/
|
||||||
public ngOnInit() { // set isAuthenticated
|
public ngOnInit() {
|
||||||
|
// set isAuthenticated
|
||||||
this.isAuthenticated = this.store.pipe(select(isAuthenticated));
|
this.isAuthenticated = this.store.pipe(select(isAuthenticated));
|
||||||
|
|
||||||
// for mobile login, set the redirect url to the previous route
|
// for mobile login, set the redirect url to the previous route
|
||||||
this.windowService.isXs().pipe(take(1))
|
this.windowService.isXs().pipe(take(1))
|
||||||
.subscribe((isMobile) => {
|
.subscribe((isMobile) => {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
this.router.events.pipe(
|
this.routeService.getHistory().pipe(
|
||||||
filter((e: any) => e instanceof NavigationEnd),
|
take(1)
|
||||||
pairwise()
|
).subscribe((history) => {
|
||||||
).subscribe((e: any) => {
|
const previousIndex = history.length - 2;
|
||||||
this.setRedirectUrl(e[0].urlAfterRedirects);
|
this.setRedirectUrl(history[previousIndex]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -211,7 +215,7 @@ export class LogInComponent implements OnDestroy, OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the redirect url if not LOGIN_ROUTE
|
* Sets the redirect url if not equal to LOGIN_ROUTE
|
||||||
* @param url
|
* @param url
|
||||||
*/
|
*/
|
||||||
private setRedirectUrl(url: string) {
|
private setRedirectUrl(url: string) {
|
||||||
|
@@ -27,6 +27,9 @@ export const routeServiceStub: any = {
|
|||||||
},
|
},
|
||||||
getRouteDataValue: (param) => {
|
getRouteDataValue: (param) => {
|
||||||
return observableOf({})
|
return observableOf({})
|
||||||
|
},
|
||||||
|
getHistory: () => {
|
||||||
|
return observableOf(['/home','collection/123','/login'])
|
||||||
}
|
}
|
||||||
/* tslint:enable:no-empty */
|
/* tslint:enable:no-empty */
|
||||||
};
|
};
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
import {Observable, of as observableOf} from 'rxjs';
|
|
||||||
export class RouterEventsStub {
|
|
||||||
url: string;
|
|
||||||
routeReuseStrategy = {shouldReuseRoute: {}};
|
|
||||||
//noinspection TypeScriptUnresolvedFunction
|
|
||||||
navigate = jasmine.createSpy('navigate');
|
|
||||||
parseUrl = jasmine.createSpy('parseUrl');
|
|
||||||
events = new Observable((observer) => {
|
|
||||||
this.eventArr.forEach((e) => {
|
|
||||||
observer.next(e);
|
|
||||||
});
|
|
||||||
observer.complete();
|
|
||||||
});
|
|
||||||
eventArr: any;
|
|
||||||
|
|
||||||
// Stub constructor takes array of event objects.
|
|
||||||
constructor( events: any = observableOf({})) {
|
|
||||||
this.eventArr = events;
|
|
||||||
}
|
|
||||||
|
|
||||||
navigateByUrl(url): void {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user