Skip to content

Commit da8880e

Browse files
107671: Split Theme model & ThemeConfig classes in separate files to prevent circular dependencies
1 parent a7faf7d commit da8880e

File tree

13 files changed

+71
-69
lines changed

13 files changed

+71
-69
lines changed

src/app/root/root.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AuthService } from '../core/auth/auth.service';
1313
import { CSSVariableService } from '../shared/sass-helper/css-variable.service';
1414
import { MenuService } from '../shared/menu/menu.service';
1515
import { HostWindowService } from '../shared/host-window.service';
16-
import { ThemeConfig } from '../../config/theme.model';
16+
import { ThemeConfig } from '../../config/theme.config';
1717
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
1818
import { environment } from '../../environments/environment';
1919
import { slideSidebarPadding } from '../shared/animations/slide';

src/app/shared/mocks/theme-service.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ThemeService } from '../theme-support/theme.service';
22
import { of as observableOf } from 'rxjs';
3-
import { ThemeConfig } from '../../../config/theme.model';
3+
import { ThemeConfig } from '../../../config/theme.config';
44
import { isNotEmpty } from '../empty.util';
55

66
export function getMockThemeService(themeName = 'base', themes?: ThemeConfig[]): ThemeService {

src/app/shared/object-collection/shared/listable-object/listable-object.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { hasNoValue, hasValue, isNotEmpty } from '../../../empty.util';
44
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
55
import { ListableObject } from '../listable-object.model';
66
import { environment } from '../../../../../environments/environment';
7-
import { ThemeConfig } from '../../../../../config/theme.model';
7+
import { ThemeConfig } from '../../../../../config/theme.config';
88
import { InjectionToken } from '@angular/core';
99

1010
export const DEFAULT_VIEW_MODE = ViewMode.ListElement;
Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
11
/* eslint-disable max-classes-per-file */
2-
import { Config } from './config.interface';
3-
import { hasValue, hasNoValue, isNotEmpty } from '../app/shared/empty.util';
4-
import { DSpaceObject } from '../app/core/shared/dspace-object.model';
5-
import { getDSORoute } from '../app/app-routing-paths';
6-
import { HandleObject } from '../app/core/shared/handle-object.model';
2+
import { hasValue, hasNoValue, isNotEmpty } from '../empty.util';
3+
import { DSpaceObject } from '../../core/shared/dspace-object.model';
4+
import { getDSORoute } from '../../app-routing-paths';
5+
import { HandleObject } from '../../core/shared/handle-object.model';
76
import { Injector } from '@angular/core';
8-
import { HandleService } from '../app/shared/handle.service';
7+
import { HandleService } from '../handle.service';
98
import { combineLatest, Observable, of as observableOf } from 'rxjs';
109
import { map, take } from 'rxjs/operators';
11-
12-
export interface NamedThemeConfig extends Config {
13-
name: string;
14-
15-
/**
16-
* Specify another theme to build upon: whenever a themed component is not found in the current theme,
17-
* its ancestor theme(s) will be checked recursively before falling back to the default theme.
18-
*/
19-
extends?: string;
20-
21-
/**
22-
* A list of HTML tags that should be added to the HEAD section of the document, whenever this theme is active.
23-
*/
24-
headTags?: HeadTagConfig[];
25-
}
26-
27-
/**
28-
* Interface that represents a single theme-specific HTML tag in the HEAD section of the page.
29-
*/
30-
export interface HeadTagConfig extends Config {
31-
/**
32-
* The name of the HTML tag
33-
*/
34-
tagName: string;
35-
36-
/**
37-
* The attributes on the HTML tag
38-
*/
39-
attributes?: {
40-
[key: string]: string;
41-
};
42-
}
43-
44-
export interface RegExThemeConfig extends NamedThemeConfig {
45-
regex: string;
46-
}
47-
48-
export interface HandleThemeConfig extends NamedThemeConfig {
49-
handle: string;
50-
}
51-
52-
export interface UUIDThemeConfig extends NamedThemeConfig {
53-
uuid: string;
54-
}
10+
import { HandleThemeConfig, NamedThemeConfig, RegExThemeConfig, UUIDThemeConfig, ThemeConfig } from '../../../config/theme.config';
5511

5612
export class Theme {
5713
constructor(public config: NamedThemeConfig) {
@@ -71,7 +27,7 @@ export class RegExTheme extends Theme {
7127
}
7228

7329
matches(url: string, dso: DSpaceObject): Observable<boolean> {
74-
let match;
30+
let match: RegExpMatchArray;
7531
const route = getDSORoute(dso);
7632

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

9349
constructor(public config: HandleThemeConfig,
9450
protected handleService: HandleService
95-
) {
51+
) {
9652
super(config);
9753
this.normalizedHandle$ = this.handleService.normalizeHandle(this.config.handle).pipe(
9854
take(1),
@@ -133,9 +89,3 @@ export const themeFactory = (config: ThemeConfig, injector: Injector): Theme =>
13389
return new Theme(config as NamedThemeConfig);
13490
}
13591
};
136-
137-
export type ThemeConfig
138-
= NamedThemeConfig
139-
| RegExThemeConfig
140-
| HandleThemeConfig
141-
| UUIDThemeConfig;

src/app/shared/theme-support/theme.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { provideMockActions } from '@ngrx/effects/testing';
44
import { LinkService } from '../../core/cache/builders/link.service';
55
import { hot } from 'jasmine-marbles';
66
import { SetThemeAction } from './theme.actions';
7-
import { Theme } from '../../../config/theme.model';
7+
import { Theme } from './theme.model';
88
import { provideMockStore } from '@ngrx/store/testing';
99
import { Community } from '../../core/shared/community.model';
1010
import { COMMUNITY } from '../../core/shared/community.resource-type';

src/app/shared/theme-support/theme.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { hasNoValue, hasValue, isNotEmpty } from '../empty.util';
88
import { RemoteData } from '../../core/data/remote-data';
99
import { DSpaceObject } from '../../core/shared/dspace-object.model';
1010
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData, getRemoteDataPayload } from '../../core/shared/operators';
11-
import { HeadTagConfig, Theme, ThemeConfig, themeFactory } from '../../../config/theme.model';
11+
import { Theme, themeFactory } from './theme.model';
12+
import { ThemeConfig, HeadTagConfig } from '../../../config/theme.config';
1213
import { NO_OP_ACTION_TYPE, NoOpAction } from '../ngrx/no-op.action';
1314
import { followLink } from '../utils/follow-link-config.model';
1415
import { LinkService } from '../../core/cache/builders/link.service';

src/app/shared/theme-support/themed.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { VarDirective } from '../utils/var.directive';
66
import { ThemeService } from './theme.service';
77
import { getMockThemeService } from '../mocks/theme-service.mock';
88
import { TestComponent } from './test/test.component.spec';
9-
import { ThemeConfig } from '../../../config/theme.model';
9+
import { ThemeConfig } from '../../../config/theme.config';
1010

1111
@Component({
1212
selector: 'ds-test-themed-component',

src/config/app-config.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FormConfig } from './form-config.interfaces';
99
import { LangConfig } from './lang-config.interface';
1010
import { ItemConfig } from './item-config.interface';
1111
import { CollectionPageConfig } from './collection-page-config.interface';
12-
import { ThemeConfig } from './theme.model';
12+
import { ThemeConfig } from './theme.config';
1313
import { AuthConfig } from './auth-config.interfaces';
1414
import { UIServerConfig } from './ui-server-config.interface';
1515
import { MediaViewerConfig } from './media-viewer-config.interface';

src/config/config.util.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { environment } from '../environments/environment.production';
22
import { extendEnvironmentWithAppConfig } from './config.util';
33
import { DefaultAppConfig } from './default-app-config';
4-
import { HandleThemeConfig } from './theme.model';
4+
import { HandleThemeConfig } from './theme.config';
55

66
describe('Config Util', () => {
77
describe('extendEnvironmentWithAppConfig', () => {

src/config/config.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { environment } from '../environments/environment';
55
import { hasNoValue } from '../app/shared/empty.util';
66

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

1111
/**

0 commit comments

Comments
 (0)