mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
added different themes, issue with ngrx
This commit is contained in:
@@ -155,5 +155,13 @@ module.exports = {
|
|||||||
edit: {
|
edit: {
|
||||||
undoTimeout: 10000 // 10 seconds
|
undoTimeout: 10000 // 10 seconds
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
themes: [
|
||||||
|
{
|
||||||
|
name: 'Preview Release',
|
||||||
|
cssClass: 'preview-release'
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -224,6 +224,7 @@
|
|||||||
"webpack-bundle-analyzer": "^2.13.1",
|
"webpack-bundle-analyzer": "^2.13.1",
|
||||||
"webpack-dev-middleware": "3.2.0",
|
"webpack-dev-middleware": "3.2.0",
|
||||||
"webpack-dev-server": "^3.1.5",
|
"webpack-dev-server": "^3.1.5",
|
||||||
|
"webpack-import-glob-loader": "^1.6.3",
|
||||||
"webpack-merge": "4.1.4",
|
"webpack-merge": "4.1.4",
|
||||||
"webpack-node-externals": "1.7.2"
|
"webpack-node-externals": "1.7.2"
|
||||||
}
|
}
|
||||||
|
3
src/app/+home-page/home-page.component.default.scss
Normal file
3
src/app/+home-page/home-page.component.default.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
:host {
|
||||||
|
color: red;
|
||||||
|
}
|
@@ -1 +1,2 @@
|
|||||||
@import '../../styles/variables.scss';
|
@import './home-page.component.default';
|
||||||
|
@import './themes/*';
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
:host-context(.preview-release) {
|
||||||
|
color: green;
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<div class="outer-wrapper">
|
<div class="outer-wrapper" [ngClass]="(theme | async)?.cssClass">
|
||||||
<ds-admin-sidebar></ds-admin-sidebar>
|
<!--<ds-admin-sidebar></ds-admin-sidebar>-->
|
||||||
<div class="inner-wrapper" [@slideSidebarPadding]="{
|
<div class="inner-wrapper" [@slideSidebarPadding]="{
|
||||||
value: (!(sidebarVisible | async) ? 'hidden' : (slideSidebarOver | async) ? 'shown' : 'expanded'),
|
value: (!(sidebarVisible | async) ? 'hidden' : (slideSidebarOver | async) ? 'shown' : 'expanded'),
|
||||||
params: {collapsedSidebarWidth: (collapsedSidebarWidth | async), totalSidebarWidth: (totalSidebarWidth | async)}
|
params: {collapsedSidebarWidth: (collapsedSidebarWidth | async), totalSidebarWidth: (totalSidebarWidth | async)}
|
||||||
|
@@ -48,4 +48,3 @@ ds-admin-sidebar {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: $sidebar-z-index;
|
z-index: $sidebar-z-index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,8 +30,11 @@ import { MenuService } from './shared/menu/menu.service';
|
|||||||
import { MenuID } from './shared/menu/initial-menus-state';
|
import { MenuID } from './shared/menu/initial-menus-state';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { slideSidebarPadding } from './shared/animations/slide';
|
import { slideSidebarPadding } from './shared/animations/slide';
|
||||||
import { combineLatest as combineLatestObservable } from 'rxjs';
|
import { combineLatest as combineLatestObservable, of } from 'rxjs';
|
||||||
import { HostWindowService } from './shared/host-window.service';
|
import { HostWindowService } from './shared/host-window.service';
|
||||||
|
import { ThemeService } from './core/theme/theme.service';
|
||||||
|
import { Theme } from '../config/theme.inferface';
|
||||||
|
import { isNotEmpty } from './shared/empty.util';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-app',
|
selector: 'ds-app',
|
||||||
@@ -47,6 +50,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
slideSidebarOver: Observable<boolean>;
|
slideSidebarOver: Observable<boolean>;
|
||||||
collapsedSidebarWidth: Observable<string>;
|
collapsedSidebarWidth: Observable<string>;
|
||||||
totalSidebarWidth: Observable<string>;
|
totalSidebarWidth: Observable<string>;
|
||||||
|
theme: Observable<Theme>= of({} as any);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
|
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
|
||||||
@@ -60,8 +64,10 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
private routeService: RouteService,
|
private routeService: RouteService,
|
||||||
private cssService: CSSVariableService,
|
private cssService: CSSVariableService,
|
||||||
private menuService: MenuService,
|
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
|
// 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));
|
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);
|
console.info(config);
|
||||||
}
|
}
|
||||||
this.storeCSSVariables();
|
this.storeCSSVariables();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
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 env: string = this.config.production ? 'Production' : 'Development';
|
||||||
const color: string = this.config.production ? 'red' : 'green';
|
const color: string = this.config.production ? 'red' : 'green';
|
||||||
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
|
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import { ObjectCacheEffects } from './cache/object-cache.effects';
|
import { ObjectCacheEffects } from './cache/object-cache.effects';
|
||||||
import { UUIDIndexEffects } from './index/index.effects';
|
import { UUIDIndexEffects } from './index/index.effects';
|
||||||
import { RequestEffects } from './data/request.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 { JsonPatchOperationsEffects } from './json-patch/json-patch-operations.effects';
|
||||||
import { ServerSyncBufferEffects } from './cache/server-sync-buffer.effects';
|
import { ServerSyncBufferEffects } from './cache/server-sync-buffer.effects';
|
||||||
import { ObjectUpdatesEffects } from './data/object-updates/object-updates.effects';
|
import { ObjectUpdatesEffects } from './data/object-updates/object-updates.effects';
|
||||||
|
import { ThemeEffects } from './theme/theme.effects';
|
||||||
|
|
||||||
export const coreEffects = [
|
export const coreEffects = [
|
||||||
RequestEffects,
|
RequestEffects,
|
||||||
@@ -14,5 +14,6 @@ export const coreEffects = [
|
|||||||
AuthEffects,
|
AuthEffects,
|
||||||
JsonPatchOperationsEffects,
|
JsonPatchOperationsEffects,
|
||||||
ServerSyncBufferEffects,
|
ServerSyncBufferEffects,
|
||||||
ObjectUpdatesEffects
|
ObjectUpdatesEffects,
|
||||||
|
ThemeEffects
|
||||||
];
|
];
|
||||||
|
@@ -81,6 +81,7 @@ import { DSOChangeAnalyzer } from './data/dso-change-analyzer.service';
|
|||||||
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
|
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
|
||||||
import { DefaultChangeAnalyzer } from './data/default-change-analyzer.service';
|
import { DefaultChangeAnalyzer } from './data/default-change-analyzer.service';
|
||||||
import { SearchService } from '../+search-page/search-service/search.service';
|
import { SearchService } from '../+search-page/search-service/search.service';
|
||||||
|
import { ThemeService } from './theme/theme.service';
|
||||||
import { RoleService } from './roles/role.service';
|
import { RoleService } from './roles/role.service';
|
||||||
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
||||||
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
||||||
@@ -170,6 +171,7 @@ const PROVIDERS = [
|
|||||||
MenuService,
|
MenuService,
|
||||||
ObjectUpdatesService,
|
ObjectUpdatesService,
|
||||||
SearchService,
|
SearchService,
|
||||||
|
ThemeService,
|
||||||
MyDSpaceGuard,
|
MyDSpaceGuard,
|
||||||
RoleService,
|
RoleService,
|
||||||
TaskResponseParsingService,
|
TaskResponseParsingService,
|
||||||
|
@@ -13,6 +13,7 @@ import {
|
|||||||
objectUpdatesReducer,
|
objectUpdatesReducer,
|
||||||
ObjectUpdatesState
|
ObjectUpdatesState
|
||||||
} from './data/object-updates/object-updates.reducer';
|
} from './data/object-updates/object-updates.reducer';
|
||||||
|
import { themeReducer, ThemeState } from './theme/theme.reducer';
|
||||||
|
|
||||||
export interface CoreState {
|
export interface CoreState {
|
||||||
'cache/object': ObjectCacheState,
|
'cache/object': ObjectCacheState,
|
||||||
@@ -21,6 +22,7 @@ export interface CoreState {
|
|||||||
'data/request': RequestState,
|
'data/request': RequestState,
|
||||||
'index': MetaIndexState,
|
'index': MetaIndexState,
|
||||||
'auth': AuthState,
|
'auth': AuthState,
|
||||||
|
'theme': ThemeState
|
||||||
'json/patch': JsonPatchOperationsState
|
'json/patch': JsonPatchOperationsState
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,5 +33,6 @@ export const coreReducers: ActionReducerMap<CoreState> = {
|
|||||||
'data/request': requestReducer,
|
'data/request': requestReducer,
|
||||||
'index': indexReducer,
|
'index': indexReducer,
|
||||||
'auth': authReducer,
|
'auth': authReducer,
|
||||||
|
'theme': themeReducer,
|
||||||
'json/patch': jsonPatchOperationsReducer
|
'json/patch': jsonPatchOperationsReducer
|
||||||
};
|
};
|
||||||
|
37
src/app/core/theme/theme.actions.ts
Normal file
37
src/app/core/theme/theme.actions.ts
Normal file
@@ -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;
|
25
src/app/core/theme/theme.effects.ts
Normal file
25
src/app/core/theme/theme.effects.ts
Normal file
@@ -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<Action> = 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<CoreState>, @Inject(GLOBAL_CONFIG) public config: GlobalConfig) {
|
||||||
|
// console.log("theme effects");
|
||||||
|
// }
|
||||||
|
}
|
19
src/app/core/theme/theme.reducer.ts
Normal file
19
src/app/core/theme/theme.reducer.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
src/app/core/theme/theme.service.ts
Normal file
33
src/app/core/theme/theme.service.ts
Normal file
@@ -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<CoreState, ThemeState> {
|
||||||
|
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<CoreState>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCurrentTheme(): Observable<Theme> {
|
||||||
|
return this.store.pipe(
|
||||||
|
select(themeStateSelector()),
|
||||||
|
map((state: ThemeState) => state.theme)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setCurrentTheme(theme: Theme): void {
|
||||||
|
return this.store.dispatch(new SetThemeAction(theme));
|
||||||
|
}
|
||||||
|
}
|
@@ -8,6 +8,7 @@ import { FormConfig } from './form-config.interfaces';
|
|||||||
import {LangConfig} from './lang-config.interface';
|
import {LangConfig} from './lang-config.interface';
|
||||||
import { BrowseByConfig } from './browse-by-config.interface';
|
import { BrowseByConfig } from './browse-by-config.interface';
|
||||||
import { ItemPageConfig } from './item-page-config.interface';
|
import { ItemPageConfig } from './item-page-config.interface';
|
||||||
|
import { Theme } from './theme.inferface';
|
||||||
|
|
||||||
export interface GlobalConfig extends Config {
|
export interface GlobalConfig extends Config {
|
||||||
ui: ServerConfig;
|
ui: ServerConfig;
|
||||||
@@ -25,4 +26,5 @@ export interface GlobalConfig extends Config {
|
|||||||
languages: LangConfig[];
|
languages: LangConfig[];
|
||||||
browseBy: BrowseByConfig;
|
browseBy: BrowseByConfig;
|
||||||
item: ItemPageConfig;
|
item: ItemPageConfig;
|
||||||
|
themes: Theme[];
|
||||||
}
|
}
|
||||||
|
6
src/config/theme.inferface.ts
Normal file
6
src/config/theme.inferface.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { Config } from './config.interface';
|
||||||
|
|
||||||
|
export interface Theme extends Config {
|
||||||
|
name: string;
|
||||||
|
cssClass: string;
|
||||||
|
}
|
@@ -22,7 +22,8 @@ module.exports = {
|
|||||||
module: "empty"
|
module: "empty"
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [
|
||||||
|
{
|
||||||
test: /\.ts$/,
|
test: /\.ts$/,
|
||||||
loader: '@ngtools/webpack'
|
loader: '@ngtools/webpack'
|
||||||
},
|
},
|
||||||
@@ -54,7 +55,8 @@ module.exports = {
|
|||||||
exclude: [/node_modules/,
|
exclude: [/node_modules/,
|
||||||
path.resolve(__dirname, '..', 'src/styles/_exposed_variables.scss')
|
path.resolve(__dirname, '..', 'src/styles/_exposed_variables.scss')
|
||||||
],
|
],
|
||||||
use: [{
|
use: [
|
||||||
|
{
|
||||||
loader: 'to-string-loader',
|
loader: 'to-string-loader',
|
||||||
options: {
|
options: {
|
||||||
sourceMap: true
|
sourceMap: true
|
||||||
@@ -76,7 +78,8 @@ module.exports = {
|
|||||||
options: {
|
options: {
|
||||||
sourceMap: true
|
sourceMap: true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
'webpack-import-glob-loader'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -10939,6 +10939,12 @@ webpack-dev-server@^3.1.5:
|
|||||||
webpack-log "^2.0.0"
|
webpack-log "^2.0.0"
|
||||||
yargs "12.0.1"
|
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:
|
webpack-log@^1.0.1:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-1.2.0.tgz#a4b34cda6b22b518dbb0ab32e567962d5c72a43d"
|
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-1.2.0.tgz#a4b34cda6b22b518dbb0ab32e567962d5c72a43d"
|
||||||
|
Reference in New Issue
Block a user