diff --git a/src/app/root/root.component.ts b/src/app/root/root.component.ts index 3c2d65fc1f5..d7b33560d1b 100644 --- a/src/app/root/root.component.ts +++ b/src/app/root/root.component.ts @@ -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'; diff --git a/src/app/shared/mocks/theme-service.mock.ts b/src/app/shared/mocks/theme-service.mock.ts index e3c2960e51f..3997d175047 100644 --- a/src/app/shared/mocks/theme-service.mock.ts +++ b/src/app/shared/mocks/theme-service.mock.ts @@ -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 { diff --git a/src/app/shared/object-collection/shared/listable-object/listable-object.decorator.ts b/src/app/shared/object-collection/shared/listable-object/listable-object.decorator.ts index e5654e63e00..470bcfcdafd 100644 --- a/src/app/shared/object-collection/shared/listable-object/listable-object.decorator.ts +++ b/src/app/shared/object-collection/shared/listable-object/listable-object.decorator.ts @@ -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; diff --git a/src/config/theme.model.ts b/src/app/shared/theme-support/theme.model.ts similarity index 60% rename from src/config/theme.model.ts rename to src/app/shared/theme-support/theme.model.ts index 571d47a1d1d..ce470dedc07 100644 --- a/src/config/theme.model.ts +++ b/src/app/shared/theme-support/theme.model.ts @@ -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) { @@ -71,7 +27,7 @@ export class RegExTheme extends Theme { } matches(url: string, dso: DSpaceObject): Observable { - let match; + let match: RegExpMatchArray; const route = getDSORoute(dso); if (isNotEmpty(route)) { @@ -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), @@ -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; diff --git a/src/app/shared/theme-support/theme.service.spec.ts b/src/app/shared/theme-support/theme.service.spec.ts index c4669408e1c..34dffe2ef21 100644 --- a/src/app/shared/theme-support/theme.service.spec.ts +++ b/src/app/shared/theme-support/theme.service.spec.ts @@ -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'; diff --git a/src/app/shared/theme-support/theme.service.ts b/src/app/shared/theme-support/theme.service.ts index e2b0ea7589f..3e36f320585 100644 --- a/src/app/shared/theme-support/theme.service.ts +++ b/src/app/shared/theme-support/theme.service.ts @@ -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'; diff --git a/src/app/shared/theme-support/themed.component.spec.ts b/src/app/shared/theme-support/themed.component.spec.ts index 7776e603798..3ddc13ab6c6 100644 --- a/src/app/shared/theme-support/themed.component.spec.ts +++ b/src/app/shared/theme-support/themed.component.spec.ts @@ -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', diff --git a/src/config/app-config.interface.ts b/src/config/app-config.interface.ts index 84a30549a72..69aeab7cbf8 100644 --- a/src/config/app-config.interface.ts +++ b/src/config/app-config.interface.ts @@ -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'; diff --git a/src/config/config.util.spec.ts b/src/config/config.util.spec.ts index 2d1d8e1be79..4dc2b67260e 100644 --- a/src/config/config.util.spec.ts +++ b/src/config/config.util.spec.ts @@ -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', () => { diff --git a/src/config/config.util.ts b/src/config/config.util.ts index 9912a817d6f..c1d87e34909 100644 --- a/src/config/config.util.ts +++ b/src/config/config.util.ts @@ -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'; /** diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index a6e9e092e46..32bb6e0370b 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -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'; diff --git a/src/config/theme.config.ts b/src/config/theme.config.ts new file mode 100644 index 00000000000..7989dc3af9d --- /dev/null +++ b/src/config/theme.config.ts @@ -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; diff --git a/src/config/theme.model.spec.ts b/src/config/theme.model.spec.ts index d5005cb2457..de2e2f7cef6 100644 --- a/src/config/theme.model.spec.ts +++ b/src/config/theme.model.spec.ts @@ -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';