Added @Input to the log-in component that indicates whether the component is being used in the standalone login page or the drop-down.

This commit is contained in:
Michael W Spalti
2019-09-04 14:02:07 -07:00
parent 54fc57d1f3
commit f0813fcbc1
4 changed files with 19 additions and 19 deletions

View File

@@ -3,7 +3,8 @@
<div> <div>
<img class="mb-4 login-logo" src="assets/images/dspace-logo.png"> <img class="mb-4 login-logo" src="assets/images/dspace-logo.png">
<h1 class="h3 mb-0 font-weight-normal">{{"login.form.header" | translate}}</h1> <h1 class="h3 mb-0 font-weight-normal">{{"login.form.header" | translate}}</h1>
<ds-log-in></ds-log-in> <ds-log-in
[isStandalonePage]="true"></ds-log-in>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -3,7 +3,8 @@
<div ngbDropdown placement="bottom-right" class="d-inline-block" @fadeInOut> <div ngbDropdown placement="bottom-right" class="d-inline-block" @fadeInOut>
<a href="#" id="dropdownLogin" (click)="$event.preventDefault()" ngbDropdownToggle class="px-1">{{ 'nav.login' | translate }}</a> <a href="#" id="dropdownLogin" (click)="$event.preventDefault()" ngbDropdownToggle class="px-1">{{ 'nav.login' | translate }}</a>
<div id="loginDropdownMenu" [ngClass]="{'pl-3 pr-3': (loading | async)}" ngbDropdownMenu aria-labelledby="dropdownLogin"> <div id="loginDropdownMenu" [ngClass]="{'pl-3 pr-3': (loading | async)}" ngbDropdownMenu aria-labelledby="dropdownLogin">
<ds-log-in></ds-log-in> <ds-log-in
[isStandalonePage]="false"></ds-log-in>
</div> </div>
</div> </div>
</li> </li>

View File

@@ -58,8 +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: RouteService, useValue: routeServiceStub }
{provide: HostWindowService, useValue: new HostWindowServiceStub(900) }
], ],
schemas: [ schemas: [
CUSTOM_ELEMENTS_SCHEMA CUSTOM_ELEMENTS_SCHEMA
@@ -151,6 +150,8 @@ describe('LogInComponent', () => {
const authService: AuthService = TestBed.get(AuthService); const authService: AuthService = TestBed.get(AuthService);
spyOn(authService, 'setRedirectUrl'); spyOn(authService, 'setRedirectUrl');
component.isStandalonePage = false;
fixture.detectChanges(); fixture.detectChanges();
expect(authService.setRedirectUrl).not.toHaveBeenCalledWith(); expect(authService.setRedirectUrl).not.toHaveBeenCalledWith();
@@ -193,8 +194,7 @@ describe('LogInComponent on small screen', () => {
{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: RouteService, useValue: routeServiceStub }
{provide: HostWindowService, useValue: new HostWindowServiceStub(300) }
], ],
schemas: [ schemas: [
CUSTOM_ELEMENTS_SCHEMA CUSTOM_ELEMENTS_SCHEMA
@@ -230,6 +230,7 @@ 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');
component.isStandalonePage = true;
fixture.detectChanges(); fixture.detectChanges();
// set FormControl values // set FormControl values
component.form.controls.email.setValue('user'); component.form.controls.email.setValue('user');

View File

@@ -1,5 +1,5 @@
import {filter, map, pairwise, take, takeUntil, 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, Input, 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';
@@ -86,13 +86,14 @@ export class LogInComponent implements OnDestroy, OnInit {
private redirectUrl = LOGIN_ROUTE; private redirectUrl = LOGIN_ROUTE;
@Input() isStandalonePage: boolean;
/** /**
* @constructor * @constructor
* @param {AuthService} authService * @param {AuthService} authService
* @param {FormBuilder} formBuilder * @param {FormBuilder} formBuilder
* @param {RouteService} routeService * @param {RouteService} routeService
* @param {Router} router * @param {Router} router
* @param {HostWindowService} windowService
* @param {Store<State>} store * @param {Store<State>} store
*/ */
constructor( constructor(
@@ -100,7 +101,6 @@ export class LogInComponent implements OnDestroy, OnInit {
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private routeService: RouteService, private routeService: RouteService,
private router: Router, private router: Router,
private windowService: HostWindowService,
private store: Store<CoreState> private store: Store<CoreState>
) { ) {
} }
@@ -114,17 +114,14 @@ export class LogInComponent implements OnDestroy, OnInit {
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)) if (this.isStandalonePage) {
.subscribe((isMobile) => { this.routeService.getHistory().pipe(
if (isMobile) { take(1)
this.routeService.getHistory().pipe( ).subscribe((history) => {
take(1) const previousIndex = history.length - 2;
).subscribe((history) => { this.setRedirectUrl(history[previousIndex]);
const previousIndex = history.length - 2;
this.setRedirectUrl(history[previousIndex]);
});
}
}); });
}
// set formGroup // set formGroup
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({