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 956d5ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
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());
}

}
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;
}

0 comments on commit 956d5ea

Please sign in to comment.