Skip to content

Commit

Permalink
107671: Split Theme model & ThemeConfig classes in separate files to …
Browse files Browse the repository at this point in the history
…prevent circular dependencies
  • Loading branch information
alexandrevryghem committed Nov 9, 2023
1 parent a7faf7d commit da8880e
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/app/root/root.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AuthService } from '../core/auth/auth.service';
import { CSSVariableService } from '../shared/sass-helper/css-variable.service';
import { MenuService } from '../shared/menu/menu.service';
import { HostWindowService } from '../shared/host-window.service';
import { ThemeConfig } from '../../config/theme.model';
import { ThemeConfig } from '../../config/theme.config';
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
import { environment } from '../../environments/environment';
import { slideSidebarPadding } from '../shared/animations/slide';
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/mocks/theme-service.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ThemeService } from '../theme-support/theme.service';
import { of as observableOf } from 'rxjs';
import { ThemeConfig } from '../../../config/theme.model';
import { ThemeConfig } from '../../../config/theme.config';
import { isNotEmpty } from '../empty.util';

export function getMockThemeService(themeName = 'base', themes?: ThemeConfig[]): ThemeService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { hasNoValue, hasValue, isNotEmpty } from '../../../empty.util';
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
import { ListableObject } from '../listable-object.model';
import { environment } from '../../../../../environments/environment';
import { ThemeConfig } from '../../../../../config/theme.model';
import { ThemeConfig } from '../../../../../config/theme.config';
import { InjectionToken } from '@angular/core';

export const DEFAULT_VIEW_MODE = ViewMode.ListElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
/* eslint-disable max-classes-per-file */
import { Config } from './config.interface';
import { hasValue, hasNoValue, isNotEmpty } from '../app/shared/empty.util';
import { DSpaceObject } from '../app/core/shared/dspace-object.model';
import { getDSORoute } from '../app/app-routing-paths';
import { HandleObject } from '../app/core/shared/handle-object.model';
import { hasValue, hasNoValue, isNotEmpty } from '../empty.util';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { getDSORoute } from '../../app-routing-paths';
import { HandleObject } from '../../core/shared/handle-object.model';
import { Injector } from '@angular/core';
import { HandleService } from '../app/shared/handle.service';
import { HandleService } from '../handle.service';
import { combineLatest, Observable, of as observableOf } from 'rxjs';
import { map, take } from 'rxjs/operators';

export interface NamedThemeConfig extends Config {
name: string;

/**
* Specify another theme to build upon: whenever a themed component is not found in the current theme,
* its ancestor theme(s) will be checked recursively before falling back to the default theme.
*/
extends?: string;

/**
* A list of HTML tags that should be added to the HEAD section of the document, whenever this theme is active.
*/
headTags?: HeadTagConfig[];
}

/**
* Interface that represents a single theme-specific HTML tag in the HEAD section of the page.
*/
export interface HeadTagConfig extends Config {
/**
* The name of the HTML tag
*/
tagName: string;

/**
* The attributes on the HTML tag
*/
attributes?: {
[key: string]: string;
};
}

export interface RegExThemeConfig extends NamedThemeConfig {
regex: string;
}

export interface HandleThemeConfig extends NamedThemeConfig {
handle: string;
}

export interface UUIDThemeConfig extends NamedThemeConfig {
uuid: string;
}
import { HandleThemeConfig, NamedThemeConfig, RegExThemeConfig, UUIDThemeConfig, ThemeConfig } from '../../../config/theme.config';

export class Theme {
constructor(public config: NamedThemeConfig) {
Expand All @@ -71,7 +27,7 @@ export class RegExTheme extends Theme {
}

matches(url: string, dso: DSpaceObject): Observable<boolean> {
let match;
let match: RegExpMatchArray;
const route = getDSORoute(dso);

if (isNotEmpty(route)) {
Expand All @@ -92,7 +48,7 @@ export class HandleTheme extends Theme {

constructor(public config: HandleThemeConfig,
protected handleService: HandleService
) {
) {
super(config);
this.normalizedHandle$ = this.handleService.normalizeHandle(this.config.handle).pipe(
take(1),
Expand Down Expand Up @@ -133,9 +89,3 @@ export const themeFactory = (config: ThemeConfig, injector: Injector): Theme =>
return new Theme(config as NamedThemeConfig);
}
};

export type ThemeConfig
= NamedThemeConfig
| RegExThemeConfig
| HandleThemeConfig
| UUIDThemeConfig;
2 changes: 1 addition & 1 deletion src/app/shared/theme-support/theme.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { provideMockActions } from '@ngrx/effects/testing';
import { LinkService } from '../../core/cache/builders/link.service';
import { hot } from 'jasmine-marbles';
import { SetThemeAction } from './theme.actions';
import { Theme } from '../../../config/theme.model';
import { Theme } from './theme.model';
import { provideMockStore } from '@ngrx/store/testing';
import { Community } from '../../core/shared/community.model';
import { COMMUNITY } from '../../core/shared/community.resource-type';
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/theme-support/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { hasNoValue, hasValue, isNotEmpty } from '../empty.util';
import { RemoteData } from '../../core/data/remote-data';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData, getRemoteDataPayload } from '../../core/shared/operators';
import { HeadTagConfig, Theme, ThemeConfig, themeFactory } from '../../../config/theme.model';
import { Theme, themeFactory } from './theme.model';
import { ThemeConfig, HeadTagConfig } from '../../../config/theme.config';
import { NO_OP_ACTION_TYPE, NoOpAction } from '../ngrx/no-op.action';
import { followLink } from '../utils/follow-link-config.model';
import { LinkService } from '../../core/cache/builders/link.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/theme-support/themed.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { VarDirective } from '../utils/var.directive';
import { ThemeService } from './theme.service';
import { getMockThemeService } from '../mocks/theme-service.mock';
import { TestComponent } from './test/test.component.spec';
import { ThemeConfig } from '../../../config/theme.model';
import { ThemeConfig } from '../../../config/theme.config';

@Component({
selector: 'ds-test-themed-component',
Expand Down
2 changes: 1 addition & 1 deletion src/config/app-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FormConfig } from './form-config.interfaces';
import { LangConfig } from './lang-config.interface';
import { ItemConfig } from './item-config.interface';
import { CollectionPageConfig } from './collection-page-config.interface';
import { ThemeConfig } from './theme.model';
import { ThemeConfig } from './theme.config';
import { AuthConfig } from './auth-config.interfaces';
import { UIServerConfig } from './ui-server-config.interface';
import { MediaViewerConfig } from './media-viewer-config.interface';
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { environment } from '../environments/environment.production';
import { extendEnvironmentWithAppConfig } from './config.util';
import { DefaultAppConfig } from './default-app-config';
import { HandleThemeConfig } from './theme.model';
import { HandleThemeConfig } from './theme.config';

describe('Config Util', () => {
describe('extendEnvironmentWithAppConfig', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { environment } from '../environments/environment';
import { hasNoValue } from '../app/shared/empty.util';

import { AppConfig } from './app-config.interface';
import { ThemeConfig, NamedThemeConfig } from './theme.model';
import { ThemeConfig, NamedThemeConfig } from './theme.config';
import { BASE_THEME_NAME } from '../app/shared/theme-support/theme.constants';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MediaViewerConfig } from './media-viewer-config.interface';
import { INotificationBoardOptions } from './notifications-config.interfaces';
import { ServerConfig } from './server-config.interface';
import { SubmissionConfig } from './submission-config.interface';
import { ThemeConfig } from './theme.model';
import { ThemeConfig } from './theme.config';
import { UIServerConfig } from './ui-server-config.interface';
import { BundleConfig } from './bundle-config.interface';
import { ActuatorsConfig } from './actuators.config';
Expand Down
51 changes: 51 additions & 0 deletions src/config/theme.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Config } from './config.interface';

export interface NamedThemeConfig extends Config {
name: string;

/**
* Specify another theme to build upon: whenever a themed component is not found in the current theme,
* its ancestor theme(s) will be checked recursively before falling back to the default theme.
*/
extends?: string;

/**
* A list of HTML tags that should be added to the HEAD section of the document, whenever this theme is active.
*/
headTags?: HeadTagConfig[];
}

/**
* Interface that represents a single theme-specific HTML tag in the HEAD section of the page.
*/
export interface HeadTagConfig extends Config {
/**
* The name of the HTML tag
*/
tagName: string;

/**
* The attributes on the HTML tag
*/
attributes?: {
[key: string]: string;
};
}

export interface RegExThemeConfig extends NamedThemeConfig {
regex: string;
}

export interface HandleThemeConfig extends NamedThemeConfig {
handle: string;
}

export interface UUIDThemeConfig extends NamedThemeConfig {
uuid: string;
}

export type ThemeConfig
= NamedThemeConfig
| RegExThemeConfig
| HandleThemeConfig
| UUIDThemeConfig;
2 changes: 1 addition & 1 deletion src/config/theme.model.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HandleTheme, RegExTheme, Theme, UUIDTheme } from './theme.model';
import { HandleTheme, RegExTheme, Theme, UUIDTheme } from '../app/shared/theme-support/theme.model';
import { getCommunityModuleRoute } from '../app/community-page/community-page-routing-paths';
import { Community } from '../app/core/shared/community.model';
import { COMMUNITY } from '../app/core/shared/community.resource-type';
Expand Down

0 comments on commit da8880e

Please sign in to comment.