mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
added new decorator for metadata representations
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
export enum Context {
|
||||
Undefined = 'undefined',
|
||||
SearchList = 'searchList',
|
||||
SearchGrid = 'searchGrid',
|
||||
Submission = 'submission',
|
||||
|
@@ -1,11 +1,9 @@
|
||||
import { hasNoValue, hasValue } from '../empty.util';
|
||||
import { MetadataRepresentationType } from '../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||
|
||||
export const DEFAULT_ITEM_TYPE = 'Default';
|
||||
export const DEFAULT_VIEW_MODE = ViewMode.ListElement;
|
||||
export const NO_REPRESENTATION_TYPE = MetadataRepresentationType.None;
|
||||
export const DEFAULT_REPRESENTATION_TYPE = MetadataRepresentationType.PlainText;
|
||||
|
||||
|
||||
const map = new Map();
|
||||
|
||||
@@ -13,23 +11,16 @@ const map = new Map();
|
||||
* Decorator used for rendering simple item pages by type and viewMode (and optionally a representationType)
|
||||
* @param type
|
||||
* @param viewMode
|
||||
* @param representationType
|
||||
*/
|
||||
export function rendersItemType(type: string, viewMode: string, representationType?: MetadataRepresentationType) {
|
||||
export function rendersItemType(type: string, viewMode: string) {
|
||||
return function decorator(component: any) {
|
||||
if (hasNoValue(map.get(viewMode))) {
|
||||
map.set(viewMode, new Map());
|
||||
}
|
||||
if (hasNoValue(map.get(viewMode).get(type))) {
|
||||
map.get(viewMode).set(type, new Map());
|
||||
if (hasValue(map.get(viewMode).get(type))) {
|
||||
throw new Error(`There can't be more than one component to render Metadata of type "${type}" in view mode "${viewMode}"`);
|
||||
}
|
||||
if (hasNoValue(representationType)) {
|
||||
representationType = NO_REPRESENTATION_TYPE;
|
||||
}
|
||||
if (hasValue(map.get(viewMode).get(type).get(representationType))) {
|
||||
throw new Error(`There can't be more than one component to render Metadata of type "${type}" in view mode "${viewMode}" with representation type "${representationType}"`);
|
||||
}
|
||||
map.get(viewMode).get(type).set(representationType, component);
|
||||
map.get(viewMode).set(type, component);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,24 +28,13 @@ export function rendersItemType(type: string, viewMode: string, representationTy
|
||||
* Get the component used for rendering an item by type and viewMode (and optionally a representationType)
|
||||
* @param type
|
||||
* @param viewMode
|
||||
* @param representationType
|
||||
*/
|
||||
export function getComponentByItemType(type: string, viewMode: string, representationType?: MetadataRepresentationType) {
|
||||
if (hasNoValue(representationType)) {
|
||||
representationType = NO_REPRESENTATION_TYPE;
|
||||
}
|
||||
export function getComponentByItemType(type: string, viewMode: string) {
|
||||
if (hasNoValue(map.get(viewMode))) {
|
||||
viewMode = DEFAULT_VIEW_MODE;
|
||||
}
|
||||
if (hasNoValue(map.get(viewMode).get(type))) {
|
||||
type = DEFAULT_ITEM_TYPE;
|
||||
}
|
||||
let representationComponent = map.get(viewMode).get(type).get(representationType);
|
||||
if (hasNoValue(representationComponent)) {
|
||||
representationComponent = map.get(viewMode).get(type).get(DEFAULT_REPRESENTATION_TYPE);
|
||||
}
|
||||
if (hasNoValue(representationComponent)) {
|
||||
representationComponent = map.get(viewMode).get(type).get(NO_REPRESENTATION_TYPE);
|
||||
}
|
||||
return representationComponent;
|
||||
return map.get(viewMode).get(type);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ export class ItemTypeSwitcherComponent implements OnInit {
|
||||
/**
|
||||
* The item or metadata to determine the component for
|
||||
*/
|
||||
@Input() object: Item | SearchResult<Item> | MetadataRepresentation;
|
||||
@Input() object: Item | SearchResult<Item>;
|
||||
|
||||
/**
|
||||
* The preferred view-mode to display
|
||||
@@ -50,11 +50,6 @@ export class ItemTypeSwitcherComponent implements OnInit {
|
||||
* @returns {string}
|
||||
*/
|
||||
private getComponent(): string {
|
||||
if (hasValue((this.object as any).representationType)) {
|
||||
const metadataRepresentation = this.object as MetadataRepresentation;
|
||||
return getComponentByItemType(metadataRepresentation.itemType, this.viewMode, metadataRepresentation.representationType);
|
||||
}
|
||||
|
||||
let item: Item;
|
||||
if (hasValue((this.object as any).indexableObject)) {
|
||||
const searchResult = this.object as ItemSearchResult;
|
||||
|
@@ -0,0 +1,44 @@
|
||||
import { MetadataRepresentationType } from '../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { hasNoValue, hasValue } from '../empty.util';
|
||||
import { Context } from '../../core/shared/context.model';
|
||||
import { DEFAULT_ITEM_TYPE } from '../items/item-type-decorator';
|
||||
|
||||
const map = new Map();
|
||||
|
||||
export const DEFAULT_REPRESENTATION_TYPE = MetadataRepresentationType.PlainText;
|
||||
export const DEFAULT_CONTEXT = Context.Undefined;
|
||||
|
||||
export function metadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT) {
|
||||
return function decorator(component: any) {
|
||||
if (hasNoValue(map.get(entityType))) {
|
||||
map.set(entityType, new Map());
|
||||
}
|
||||
|
||||
if (hasNoValue(map.get(entityType).get(mdRepresentationType))) {
|
||||
map.get(entityType).set(mdRepresentationType, new Map());
|
||||
}
|
||||
|
||||
if (hasValue(map.get(entityType).get(mdRepresentationType).get(context))) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
export function getMetadataRepresentationComponent(entityType: string, mdRepresentationType: MetadataRepresentationType, context: Context = DEFAULT_CONTEXT) {
|
||||
if (hasNoValue(entityType) || hasNoValue(map.get(entityType))) {
|
||||
entityType = DEFAULT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
if (hasNoValue(map.get(entityType).get(mdRepresentationType))) {
|
||||
mdRepresentationType = DEFAULT_REPRESENTATION_TYPE;
|
||||
}
|
||||
|
||||
let representationComponent = map.get(entityType).get(mdRepresentationType).get(context);
|
||||
|
||||
if (hasNoValue(representationComponent)) {
|
||||
representationComponent = map.get(entityType).get(mdRepresentationType).get(DEFAULT_REPRESENTATION_TYPE);
|
||||
}
|
||||
|
||||
return representationComponent;
|
||||
}
|
Reference in New Issue
Block a user