mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Add support for dynamic themes
This commit is contained in:
@@ -6,15 +6,17 @@ export const map = new Map();
|
||||
|
||||
export const DEFAULT_ENTITY_TYPE = 'Publication';
|
||||
export const DEFAULT_REPRESENTATION_TYPE = MetadataRepresentationType.PlainText;
|
||||
export const DEFAULT_CONTEXT = Context.Undefined;
|
||||
export const DEFAULT_CONTEXT = Context.Any;
|
||||
export const DEFAULT_THEME = '*';
|
||||
|
||||
/**
|
||||
* Decorator function to store metadata representation mapping
|
||||
* @param entityType The entity type the component represents
|
||||
* @param mdRepresentationType The metadata representation type the component represents
|
||||
* @param context The optional context the component represents
|
||||
* @param theme The optional theme for the component
|
||||
*/
|
||||
export function metadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT) {
|
||||
export function metadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT, theme = DEFAULT_THEME) {
|
||||
return function decorator(component: any) {
|
||||
if (hasNoValue(map.get(entityType))) {
|
||||
map.set(entityType, new Map());
|
||||
@@ -23,10 +25,14 @@ export function metadataRepresentationComponent(entityType: string, mdRepresenta
|
||||
map.get(entityType).set(mdRepresentationType, new Map());
|
||||
}
|
||||
|
||||
if (hasValue(map.get(entityType).get(mdRepresentationType).get(context))) {
|
||||
if (hasNoValue(map.get(entityType).get(mdRepresentationType).get(context))) {
|
||||
map.get(entityType).get(mdRepresentationType).set(context, new Map());
|
||||
}
|
||||
|
||||
if (hasValue(map.get(entityType).get(mdRepresentationType).get(context).get(theme))) {
|
||||
throw new Error(`There can't be more than one component to render Entity of type "${entityType}" in MetadataRepresentation "${mdRepresentationType}" with context "${context}"`);
|
||||
}
|
||||
map.get(entityType).get(mdRepresentationType).set(context, component);
|
||||
map.get(entityType).get(mdRepresentationType).get(context).set(theme, component);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,22 +41,32 @@ export function metadataRepresentationComponent(entityType: string, mdRepresenta
|
||||
* @param entityType The entity type to match
|
||||
* @param mdRepresentationType The metadata representation to match
|
||||
* @param context The context to match
|
||||
* @param theme the theme to match
|
||||
*/
|
||||
export function getMetadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT) {
|
||||
export function getMetadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT, theme = DEFAULT_THEME) {
|
||||
const mapForEntity = map.get(entityType);
|
||||
if (hasValue(mapForEntity)) {
|
||||
const entityAndMDRepMap = mapForEntity.get(mdRepresentationType);
|
||||
if (hasValue(entityAndMDRepMap)) {
|
||||
if (hasValue(entityAndMDRepMap.get(context))) {
|
||||
return entityAndMDRepMap.get(context);
|
||||
const contextMap = entityAndMDRepMap.get(context);
|
||||
if (hasValue(contextMap)) {
|
||||
if (hasValue(contextMap.get(theme))) {
|
||||
return contextMap.get(theme);
|
||||
}
|
||||
if (hasValue(contextMap.get(DEFAULT_THEME))) {
|
||||
return contextMap.get(DEFAULT_THEME);
|
||||
}
|
||||
}
|
||||
if (hasValue(entityAndMDRepMap.get(DEFAULT_CONTEXT))) {
|
||||
return entityAndMDRepMap.get(DEFAULT_CONTEXT);
|
||||
if (hasValue(entityAndMDRepMap.get(DEFAULT_CONTEXT)) &&
|
||||
hasValue(entityAndMDRepMap.get(DEFAULT_CONTEXT).get(DEFAULT_THEME))) {
|
||||
return entityAndMDRepMap.get(DEFAULT_CONTEXT).get(DEFAULT_THEME);
|
||||
}
|
||||
}
|
||||
if (hasValue(mapForEntity.get(DEFAULT_REPRESENTATION_TYPE))) {
|
||||
return mapForEntity.get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT);
|
||||
if (hasValue(mapForEntity.get(DEFAULT_REPRESENTATION_TYPE)) &&
|
||||
hasValue(mapForEntity.get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT)) &&
|
||||
hasValue(mapForEntity.get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT).get(DEFAULT_THEME))) {
|
||||
return mapForEntity.get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT).get(DEFAULT_THEME);
|
||||
}
|
||||
}
|
||||
return map.get(DEFAULT_ENTITY_TYPE).get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT);
|
||||
return map.get(DEFAULT_ENTITY_TYPE).get(DEFAULT_REPRESENTATION_TYPE).get(DEFAULT_CONTEXT).get(DEFAULT_THEME);
|
||||
}
|
||||
|
Reference in New Issue
Block a user