Skip to content

Commit

Permalink
116131: Made the @renderAuthMethodFor themeable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Jun 26, 2024
1 parent aaf89dc commit 396bc9d
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { AuthMethod } from '../../../core/auth/models/auth.method';
import { AuthServiceStub } from '../../testing/auth-service.stub';
import { createTestComponent } from '../../testing/utils.test';
import { HardRedirectService } from '../../../core/services/hard-redirect.service';
import { ThemeService } from '../../theme-support/theme.service';
import { getMockThemeService } from '../../mocks/theme-service.mock';

describe('LogInContainerComponent', () => {

Expand Down Expand Up @@ -43,6 +45,7 @@ describe('LogInContainerComponent', () => {
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: HardRedirectService, useValue: hardRedirectService },
{ provide: ThemeService, useValue: getMockThemeService() },
LogInContainerComponent
],
schemas: [
Expand Down
13 changes: 6 additions & 7 deletions src/app/shared/log-in/container/log-in-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Injector, Input, OnInit } from '@angular/core';

import { rendersAuthMethodType } from '../methods/log-in.methods-decorator';
import { AuthMethod } from '../../../core/auth/models/auth.method';
import { ThemeService } from '../../theme-support/theme.service';

/**
* This component represents a component container for log-in methods available.
Expand All @@ -27,12 +28,10 @@ export class LogInContainerComponent implements OnInit {
*/
public objectInjector: Injector;

/**
* Initialize instance variables
*
* @param {Injector} injector
*/
constructor(private injector: Injector) {
constructor(
private injector: Injector,
private themeService: ThemeService,
) {
}

/**
Expand All @@ -52,7 +51,7 @@ export class LogInContainerComponent implements OnInit {
* Find the correct component based on the AuthMethod's type
*/
getAuthMethodContent(): string {
return rendersAuthMethodType(this.authMethod.authMethodType);
return rendersAuthMethodType(this.authMethod.authMethodType, this.themeService.getThemeName());
}

}
4 changes: 3 additions & 1 deletion src/app/shared/log-in/log-in.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { RouterTestingModule } from '@angular/router/testing';
import { HardRedirectService } from '../../core/services/hard-redirect.service';
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
import { of } from 'rxjs';
import { ThemeService } from '../theme-support/theme.service';
import { getMockThemeService } from '../mocks/theme-service.mock';

describe('LogInComponent', () => {

Expand Down Expand Up @@ -70,10 +72,10 @@ describe('LogInComponent', () => {
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
// { provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
{ provide: HardRedirectService, useValue: hardRedirectService },
{ provide: AuthorizationDataService, useValue: authorizationService },
{ provide: ThemeService, useValue: getMockThemeService() },
provideMockStore({ initialState }),
LogInComponent
],
Expand Down
19 changes: 12 additions & 7 deletions src/app/shared/log-in/methods/log-in.methods-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { AuthMethodType } from '../../../core/auth/models/auth.method-type';
import { DEFAULT_THEME } from '../../object-collection/shared/listable-object/listable-object.decorator';
import { hasNoValue } from '../../empty.util';
import { getMatch } from '../../abstract-component-loader/dynamic-component-loader.utils';

export const DEFAULT_AUTH_METHOD_TYPE = AuthMethodType.Password;

const authMethodsMap = new Map();

export function renderAuthMethodFor(authMethodType: AuthMethodType) {
return function decorator(objectElement: any) {
if (!objectElement) {
return;
export function renderAuthMethodFor(authMethodType: AuthMethodType, theme = DEFAULT_THEME) {
return function decorator(component: any) {
if (hasNoValue(authMethodsMap.get(authMethodType))) {
authMethodsMap.set(authMethodType, new Map());
}
authMethodsMap.set(authMethodType, objectElement);
authMethodsMap.get(authMethodType).set(theme, component);
};
}

export function rendersAuthMethodType(authMethodType: AuthMethodType) {
return authMethodsMap.get(authMethodType);
export function rendersAuthMethodType(authMethodType: AuthMethodType, theme: string) {
return getMatch(authMethodsMap, [authMethodType, theme], [DEFAULT_AUTH_METHOD_TYPE, DEFAULT_THEME]).match;
}
6 changes: 3 additions & 3 deletions src/app/shared/log-in/methods/oidc/log-in-oidc.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class LogInOidcComponent implements OnInit {
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject('isStandalonePage') public isStandalonePage: boolean,
@Inject(NativeWindowService) protected _window: NativeWindowRef,
private authService: AuthService,
private hardRedirectService: HardRedirectService,
private store: Store<CoreState>
protected authService: AuthService,
protected hardRedirectService: HardRedirectService,
protected store: Store<CoreState>
) {
this.authMethod = injectedAuthMethodModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export class LogInPasswordComponent implements OnInit {
constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject('isStandalonePage') public isStandalonePage: boolean,
private authService: AuthService,
private hardRedirectService: HardRedirectService,
private formBuilder: FormBuilder,
private store: Store<CoreState>
protected authService: AuthService,
protected hardRedirectService: HardRedirectService,
protected formBuilder: FormBuilder,
protected store: Store<CoreState>
) {
this.authMethod = injectedAuthMethodModel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Router } from '@angular/router';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { provideMockStore } from '@ngrx/store/testing';
Expand All @@ -17,7 +17,6 @@ import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
import { LogInShibbolethComponent } from './log-in-shibboleth.component';
import { NativeWindowService } from '../../../../core/services/window.service';
import { RouterStub } from '../../../testing/router.stub';
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
import { NativeWindowMockFactory } from '../../../mocks/mock-native-window-ref';
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';

Expand Down Expand Up @@ -74,7 +73,6 @@ describe('LogInShibbolethComponent', () => {
{ provide: 'isStandalonePage', useValue: true },
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
{ provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
{ provide: HardRedirectService, useValue: hardRedirectService },
provideMockStore({ initialState }),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ export class LogInShibbolethComponent implements OnInit {
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject('isStandalonePage') public isStandalonePage: boolean,
@Inject(NativeWindowService) protected _window: NativeWindowRef,
private route: RouteService,
private authService: AuthService,
private hardRedirectService: HardRedirectService,
private store: Store<CoreState>
protected authService: AuthService,
protected hardRedirectService: HardRedirectService,
protected store: Store<CoreState>
) {
this.authMethod = injectedAuthMethodModel;
}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, } from '@angular/core';

import { AuthMethodType } from '../../../../../../../app/core/auth/models/auth.method-type';
import { renderAuthMethodFor } from '../../../../../../../app/shared/log-in/methods/log-in.methods-decorator';
import { LogInOidcComponent as BaseComponent } from '../../../../../../../app/shared/log-in/methods/oidc/log-in-oidc.component';

@Component({
selector: 'ds-log-in-oidc',
// templateUrl: './log-in-oidc.component.html',
templateUrl: '../../../../../../../app/shared/log-in/methods/oidc/log-in-oidc.component.html',
})
@renderAuthMethodFor(AuthMethodType.Oidc, 'custom')
export class LogInOidcComponent extends BaseComponent {
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from '@angular/core';

import { AuthMethodType } from '../../../../../../../app/core/auth/models/auth.method-type';
import { fadeOut } from '../../../../../../../app/shared/animations/fade';
import { renderAuthMethodFor } from '../../../../../../../app/shared/log-in/methods/log-in.methods-decorator';
import { LogInPasswordComponent as BaseComponent } from '../../../../../../../app/shared/log-in/methods/password/log-in-password.component';

@Component({
selector: 'ds-log-in-password',
// templateUrl: './log-in-password.component.html',
templateUrl: '../../../../../../../app/shared/log-in/methods/password/log-in-password.component.html',
// styleUrls: ['./log-in-password.component.scss'],
styleUrls: ['../../../../../../../app/shared/log-in/methods/password/log-in-password.component.scss'],
animations: [fadeOut],
})
@renderAuthMethodFor(AuthMethodType.Password, 'custom')
export class LogInPasswordComponent extends BaseComponent {
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component, } from '@angular/core';

import { AuthMethodType } from '../../../../../../../app/core/auth/models/auth.method-type';
import { renderAuthMethodFor } from '../../../../../../../app/shared/log-in/methods/log-in.methods-decorator';
import { LogInShibbolethComponent as BaseComponent } from '../../../../../../../app/shared/log-in/methods/shibboleth/log-in-shibboleth.component';

@Component({
selector: 'ds-log-in-shibboleth',
// templateUrl: './log-in-shibboleth.component.html',
templateUrl: '../../../../../../../app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.html',
// styleUrls: ['./log-in-shibboleth.component.scss'],
styleUrls: ['../../../../../../../app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.scss'],
})
@renderAuthMethodFor(AuthMethodType.Shibboleth, 'custom')
export class LogInShibbolethComponent extends BaseComponent {
}
8 changes: 7 additions & 1 deletion src/themes/custom/entry-components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { PublicationComponent } from './app/item-page/simple/item-types/publication/publication.component';
import { LogInOidcComponent } from './app/shared/log-in/methods/oidc/log-in-oidc.component';
import { LogInPasswordComponent } from './app/shared/log-in/methods/password/log-in-password.component';
import { LogInShibbolethComponent } from './app/shared/log-in/methods/shibboleth/log-in-shibboleth.component';

export const ENTRY_COMPONENTS = [
PublicationComponent
PublicationComponent,
LogInOidcComponent,
LogInPasswordComponent,
LogInShibbolethComponent,
];

0 comments on commit 396bc9d

Please sign in to comment.