diff --git a/config/environment.default.js b/config/environment.default.js
index 387b2bb48a..c4f63fe596 100644
--- a/config/environment.default.js
+++ b/config/environment.default.js
@@ -155,5 +155,13 @@ module.exports = {
edit: {
undoTimeout: 10000 // 10 seconds
}
- }
+ },
+ themes: [
+ {
+ name: 'Preview Release',
+ cssClass: 'preview-release'
+ }
+ ]
+
+
};
diff --git a/package.json b/package.json
index 1f75da6c8b..ebcaafc932 100644
--- a/package.json
+++ b/package.json
@@ -224,6 +224,7 @@
"webpack-bundle-analyzer": "^2.13.1",
"webpack-dev-middleware": "3.2.0",
"webpack-dev-server": "^3.1.5",
+ "webpack-import-glob-loader": "^1.6.3",
"webpack-merge": "4.1.4",
"webpack-node-externals": "1.7.2"
}
diff --git a/src/app/+home-page/home-page.component.default.scss b/src/app/+home-page/home-page.component.default.scss
new file mode 100644
index 0000000000..177ab29848
--- /dev/null
+++ b/src/app/+home-page/home-page.component.default.scss
@@ -0,0 +1,3 @@
+:host {
+ color: red;
+}
\ No newline at end of file
diff --git a/src/app/+home-page/home-page.component.scss b/src/app/+home-page/home-page.component.scss
index da97dd7a62..20c152008f 100644
--- a/src/app/+home-page/home-page.component.scss
+++ b/src/app/+home-page/home-page.component.scss
@@ -1 +1,2 @@
-@import '../../styles/variables.scss';
+@import './home-page.component.default';
+@import './themes/*';
diff --git a/src/app/+home-page/themes/home-page.component.preview-release.scss b/src/app/+home-page/themes/home-page.component.preview-release.scss
new file mode 100644
index 0000000000..4cca79d1b3
--- /dev/null
+++ b/src/app/+home-page/themes/home-page.component.preview-release.scss
@@ -0,0 +1,3 @@
+:host-context(.preview-release) {
+ color: green;
+}
\ No newline at end of file
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 898208db80..b6b0e202df 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -1,5 +1,5 @@
-
-
+
+
;
collapsedSidebarWidth: Observable
;
totalSidebarWidth: Observable;
+ theme: Observable= of({} as any);
constructor(
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
@@ -60,8 +64,10 @@ export class AppComponent implements OnInit, AfterViewInit {
private routeService: RouteService,
private cssService: CSSVariableService,
private menuService: MenuService,
- private windowService: HostWindowService
+ private windowService: HostWindowService,
+ private themeService: ThemeService
) {
+
// Load all the languages that are defined as active from the config file
translate.addLangs(config.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
@@ -83,10 +89,15 @@ export class AppComponent implements OnInit, AfterViewInit {
console.info(config);
}
this.storeCSSVariables();
-
}
ngOnInit() {
+ const availableThemes: Theme[] = this.config.themes;
+ if (isNotEmpty(availableThemes)) {
+ this.themeService.setCurrentTheme(availableThemes[0]);
+ }
+ this.theme = this.themeService.getCurrentTheme();
+
const env: string = this.config.production ? 'Production' : 'Development';
const color: string = this.config.production ? 'red' : 'green';
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
diff --git a/src/app/core/core.effects.ts b/src/app/core/core.effects.ts
index bb25c49a7a..94669cac31 100644
--- a/src/app/core/core.effects.ts
+++ b/src/app/core/core.effects.ts
@@ -1,4 +1,3 @@
-
import { ObjectCacheEffects } from './cache/object-cache.effects';
import { UUIDIndexEffects } from './index/index.effects';
import { RequestEffects } from './data/request.effects';
@@ -6,6 +5,7 @@ import { AuthEffects } from './auth/auth.effects';
import { JsonPatchOperationsEffects } from './json-patch/json-patch-operations.effects';
import { ServerSyncBufferEffects } from './cache/server-sync-buffer.effects';
import { ObjectUpdatesEffects } from './data/object-updates/object-updates.effects';
+import { ThemeEffects } from './theme/theme.effects';
export const coreEffects = [
RequestEffects,
@@ -14,5 +14,6 @@ export const coreEffects = [
AuthEffects,
JsonPatchOperationsEffects,
ServerSyncBufferEffects,
- ObjectUpdatesEffects
+ ObjectUpdatesEffects,
+ ThemeEffects
];
diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts
index 6550435aa3..4160a73cb4 100644
--- a/src/app/core/core.module.ts
+++ b/src/app/core/core.module.ts
@@ -81,6 +81,7 @@ import { DSOChangeAnalyzer } from './data/dso-change-analyzer.service';
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
import { DefaultChangeAnalyzer } from './data/default-change-analyzer.service';
import { SearchService } from '../+search-page/search-service/search.service';
+import { ThemeService } from './theme/theme.service';
import { RoleService } from './roles/role.service';
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
@@ -170,6 +171,7 @@ const PROVIDERS = [
MenuService,
ObjectUpdatesService,
SearchService,
+ ThemeService,
MyDSpaceGuard,
RoleService,
TaskResponseParsingService,
diff --git a/src/app/core/core.reducers.ts b/src/app/core/core.reducers.ts
index c93b4bf44b..74e1323aa1 100644
--- a/src/app/core/core.reducers.ts
+++ b/src/app/core/core.reducers.ts
@@ -13,6 +13,7 @@ import {
objectUpdatesReducer,
ObjectUpdatesState
} from './data/object-updates/object-updates.reducer';
+import { themeReducer, ThemeState } from './theme/theme.reducer';
export interface CoreState {
'cache/object': ObjectCacheState,
@@ -21,6 +22,7 @@ export interface CoreState {
'data/request': RequestState,
'index': MetaIndexState,
'auth': AuthState,
+ 'theme': ThemeState
'json/patch': JsonPatchOperationsState
}
@@ -31,5 +33,6 @@ export const coreReducers: ActionReducerMap = {
'data/request': requestReducer,
'index': indexReducer,
'auth': authReducer,
+ 'theme': themeReducer,
'json/patch': jsonPatchOperationsReducer
};
diff --git a/src/app/core/theme/theme.actions.ts b/src/app/core/theme/theme.actions.ts
new file mode 100644
index 0000000000..550a53c91d
--- /dev/null
+++ b/src/app/core/theme/theme.actions.ts
@@ -0,0 +1,37 @@
+/**
+ * The list of ObjectUpdatesAction type definitions
+ */
+import { type } from '../../shared/ngrx/type';
+import { Action } from '@ngrx/store';
+import { Theme } from '../../../config/theme.inferface';
+
+export const ThemeActionTypes = {
+ SET: type('dspace/core/theme/SET'),
+};
+
+/* tslint:disable:max-classes-per-file */
+
+/**
+ * An ngrx action to set a the repository's current theme
+ */
+export class SetThemeAction implements Action {
+ type = ThemeActionTypes.SET;
+ payload: {
+ theme: Theme
+ };
+
+ /**
+ * Create a new SetThemeAction
+ *
+ * @param theme
+ * the theme configuration to change the current theme to
+ */
+ constructor(
+ theme: Theme
+ ) {
+ this.payload = { theme };
+ }
+}
+
+export type ThemeAction
+ = SetThemeAction;
diff --git a/src/app/core/theme/theme.effects.ts b/src/app/core/theme/theme.effects.ts
new file mode 100644
index 0000000000..f03b356b78
--- /dev/null
+++ b/src/app/core/theme/theme.effects.ts
@@ -0,0 +1,25 @@
+import { Inject, Injectable } from '@angular/core';
+import { Action, Store } from '@ngrx/store';
+import { Actions, Effect } from '@ngrx/effects';
+import { CoreState } from '../core.reducers';
+import { SetThemeAction } from './theme.actions';
+import { GLOBAL_CONFIG, GlobalConfig } from '../../../config';
+import { Theme } from '../../../config/theme.inferface';
+import { isNotEmpty } from '../../shared/empty.util';
+import { asyncScheduler, defer, Observable, of as observableOf } from 'rxjs';
+
+@Injectable()
+export class ThemeEffects {
+
+ // @Effect() setInitialTheme: Observable = defer(() => {
+ // console.log('set theme');
+ // const availableThemes: Theme[] = this.config.themes;
+ // if (isNotEmpty(availableThemes)) {
+ // return observableOf(new SetThemeAction(availableThemes[0]), asyncScheduler);
+ // }
+ // });
+ //
+ // constructor(private actions: Actions, private store: Store, @Inject(GLOBAL_CONFIG) public config: GlobalConfig) {
+ // console.log("theme effects");
+ // }
+}
diff --git a/src/app/core/theme/theme.reducer.ts b/src/app/core/theme/theme.reducer.ts
new file mode 100644
index 0000000000..fb3e0eb7b8
--- /dev/null
+++ b/src/app/core/theme/theme.reducer.ts
@@ -0,0 +1,19 @@
+import { Theme } from '../../../config/theme.inferface';
+import { ThemeAction, ThemeActionTypes } from './theme.actions';
+
+export interface ThemeState {
+ theme: Theme
+}
+
+// Object.create(null) ensures the object has no default js properties (e.g. `__proto__`)
+const initialState = Object.create(null);
+
+export function themeReducer(state = initialState, action: ThemeAction): ThemeState {
+ switch (action.type) {
+ case ThemeActionTypes.SET: {
+ const newState = Object.assign({}, state, { theme: action.payload.theme });
+ console.log(newState);
+ return newState;
+ }
+ }
+}
diff --git a/src/app/core/theme/theme.service.ts b/src/app/core/theme/theme.service.ts
new file mode 100644
index 0000000000..998fe6b856
--- /dev/null
+++ b/src/app/core/theme/theme.service.ts
@@ -0,0 +1,33 @@
+import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
+import { coreSelector, CoreState } from '../core.reducers';
+import { Inject, Injectable } from '@angular/core';
+import { Theme } from '../../../config/theme.inferface';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+import { ThemeState } from './theme.reducer';
+import { SetThemeAction } from './theme.actions';
+
+function themeStateSelector(): MemoizedSelector {
+ return createSelector(coreSelector, (state: CoreState) => state['theme']);
+}
+
+/**
+ * Service that dispatches to and reads from the Theme state in the store
+ */
+@Injectable()
+export class ThemeService {
+ constructor(private store: Store) {
+
+ }
+
+ public getCurrentTheme(): Observable {
+ return this.store.pipe(
+ select(themeStateSelector()),
+ map((state: ThemeState) => state.theme)
+ );
+ }
+
+ public setCurrentTheme(theme: Theme): void {
+ return this.store.dispatch(new SetThemeAction(theme));
+ }
+}
\ No newline at end of file
diff --git a/src/config/global-config.interface.ts b/src/config/global-config.interface.ts
index d83ec6e4d8..22b4b0500f 100644
--- a/src/config/global-config.interface.ts
+++ b/src/config/global-config.interface.ts
@@ -8,6 +8,7 @@ import { FormConfig } from './form-config.interfaces';
import {LangConfig} from './lang-config.interface';
import { BrowseByConfig } from './browse-by-config.interface';
import { ItemPageConfig } from './item-page-config.interface';
+import { Theme } from './theme.inferface';
export interface GlobalConfig extends Config {
ui: ServerConfig;
@@ -25,4 +26,5 @@ export interface GlobalConfig extends Config {
languages: LangConfig[];
browseBy: BrowseByConfig;
item: ItemPageConfig;
+ themes: Theme[];
}
diff --git a/src/config/theme.inferface.ts b/src/config/theme.inferface.ts
new file mode 100644
index 0000000000..dc5a870f6e
--- /dev/null
+++ b/src/config/theme.inferface.ts
@@ -0,0 +1,6 @@
+import { Config } from './config.interface';
+
+export interface Theme extends Config {
+ name: string;
+ cssClass: string;
+}
diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js
index 7fb4656a15..3dac48b1e2 100644
--- a/webpack/webpack.common.js
+++ b/webpack/webpack.common.js
@@ -22,10 +22,11 @@ module.exports = {
module: "empty"
},
module: {
- rules: [{
- test: /\.ts$/,
- loader: '@ngtools/webpack'
- },
+ rules: [
+ {
+ test: /\.ts$/,
+ loader: '@ngtools/webpack'
+ },
{
test: /\.css$/,
use: [{
@@ -52,19 +53,20 @@ module.exports = {
{
test: /\.scss$/,
exclude: [/node_modules/,
- path.resolve(__dirname, '..', 'src/styles/_exposed_variables.scss')
+ path.resolve(__dirname, '..', 'src/styles/_exposed_variables.scss')
],
- use: [{
- loader: 'to-string-loader',
- options: {
- sourceMap: true
- }
- }, {
- loader: 'raw-loader',
- options: {
- sourceMap: true
- }
- },
+ use: [
+ {
+ loader: 'to-string-loader',
+ options: {
+ sourceMap: true
+ }
+ }, {
+ loader: 'raw-loader',
+ options: {
+ sourceMap: true
+ }
+ },
{
loader: 'resolve-url-loader',
options: {
@@ -76,7 +78,8 @@ module.exports = {
options: {
sourceMap: true
}
- }
+ },
+ 'webpack-import-glob-loader'
]
},
{
diff --git a/yarn.lock b/yarn.lock
index 50cf67c8d8..42bfd33486 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -10939,6 +10939,12 @@ webpack-dev-server@^3.1.5:
webpack-log "^2.0.0"
yargs "12.0.1"
+webpack-import-glob-loader@^1.6.3:
+ version "1.6.3"
+ resolved "https://registry.yarnpkg.com/webpack-import-glob-loader/-/webpack-import-glob-loader-1.6.3.tgz#1b1de573f49c2c2afdb814dc13b44b2111b2ea7b"
+ dependencies:
+ glob "^5.0.15"
+
webpack-log@^1.0.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-1.2.0.tgz#a4b34cda6b22b518dbb0ab32e567962d5c72a43d"