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 c5e4c7a
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 15 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;
}
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 c5e4c7a

Please sign in to comment.