mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
119915: Retrieve the edit metadata field dynamically
This commit is contained in:
@@ -39,4 +39,10 @@ export enum Context {
|
|||||||
MyDSpaceValidation = 'mydspaceValidation',
|
MyDSpaceValidation = 'mydspaceValidation',
|
||||||
|
|
||||||
Bitstream = 'bitstream',
|
Bitstream = 'bitstream',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Edit Metadata field Context values that are used in the Edit Item Metadata tab.
|
||||||
|
*/
|
||||||
|
AddMetadata = 'addMetadata',
|
||||||
|
EditMetadata = 'editMetadata',
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
<ds-dso-edit-metadata-value-headers role="presentation" [dsoType]="dsoType"></ds-dso-edit-metadata-value-headers>
|
<ds-dso-edit-metadata-value-headers role="presentation" [dsoType]="dsoType"></ds-dso-edit-metadata-value-headers>
|
||||||
<ds-dso-edit-metadata-value *ngFor="let mdValue of form.fields[mdField]; let idx = index" role="presentation"
|
<ds-dso-edit-metadata-value *ngFor="let mdValue of form.fields[mdField]; let idx = index" role="presentation"
|
||||||
[dso]="dso"
|
[dso]="dso"
|
||||||
|
[context]="Context.EditMetadata"
|
||||||
|
[mdField]="mdField"
|
||||||
[mdValue]="mdValue"
|
[mdValue]="mdValue"
|
||||||
[dsoType]="dsoType"
|
[dsoType]="dsoType"
|
||||||
[saving$]="saving$"
|
[saving$]="saving$"
|
||||||
|
@@ -4,6 +4,7 @@ import { Observable } from 'rxjs/internal/Observable';
|
|||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||||
|
import { Context } from '../../../core/shared/context.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dso-edit-metadata-field-values',
|
selector: 'ds-dso-edit-metadata-field-values',
|
||||||
@@ -57,6 +58,8 @@ export class DsoEditMetadataFieldValuesComponent {
|
|||||||
*/
|
*/
|
||||||
public DsoEditMetadataChangeTypeEnum = DsoEditMetadataChangeType;
|
public DsoEditMetadataChangeTypeEnum = DsoEditMetadataChangeType;
|
||||||
|
|
||||||
|
public readonly Context = Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop a value into a new position
|
* Drop a value into a new position
|
||||||
* Update the form's value array for the current field to match the dropped position
|
* Update the form's value array for the current field to match the dropped position
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||||
|
import { Context } from '../../../core/shared/context.model';
|
||||||
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
|
import { EditMetadataValueFieldType } from './dso-edit-metadata-field-type.enum';
|
||||||
|
import { DsoEditMetadataValue } from '../dso-edit-metadata-form';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-dso-edit-metadata-entity-field',
|
||||||
|
template: '',
|
||||||
|
})
|
||||||
|
export abstract class AbstractDsoEditMetadataValueFieldComponent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The optional context
|
||||||
|
*/
|
||||||
|
@Input() context: Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link DSpaceObject}
|
||||||
|
*/
|
||||||
|
@Input() dso: DSpaceObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the DSO, used to determines i18n messages
|
||||||
|
*/
|
||||||
|
@Input() dsoType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the field
|
||||||
|
*/
|
||||||
|
@Input() type: EditMetadataValueFieldType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The metadata field
|
||||||
|
*/
|
||||||
|
@Input() mdField: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editable metadata value to show
|
||||||
|
*/
|
||||||
|
@Input() mdValue: DsoEditMetadataValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits when the user clicked confirm
|
||||||
|
*/
|
||||||
|
@Output() confirm: EventEmitter<boolean> = new EventEmitter();
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* The edit metadata field tab types
|
||||||
|
*/
|
||||||
|
export enum EditMetadataValueFieldType {
|
||||||
|
PLAIN_TEXT = 'PLAIN_TEXT',
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
<textarea [(ngModel)]="mdValue?.newValue.value"
|
||||||
|
[dsDebounce]="300"
|
||||||
|
(onDebounce)="confirm.emit(false)"
|
||||||
|
class="form-control"
|
||||||
|
rows="5">
|
||||||
|
</textarea>
|
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { DsoEditMetadataTextFieldComponent } from './dso-edit-metadata-text-field.component';
|
||||||
|
|
||||||
|
describe('DsoEditMetadataTextFieldComponent', () => {
|
||||||
|
let component: DsoEditMetadataTextFieldComponent;
|
||||||
|
let fixture: ComponentFixture<DsoEditMetadataTextFieldComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [
|
||||||
|
DsoEditMetadataTextFieldComponent,
|
||||||
|
],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(DsoEditMetadataTextFieldComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,16 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { editMetadataValueFieldComponent } from '../dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field.decorator';
|
||||||
|
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
|
||||||
|
import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component used to gather input for plain-text metadata fields
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-dso-edit-metadata-text-field',
|
||||||
|
templateUrl: './dso-edit-metadata-text-field.component.html',
|
||||||
|
styleUrls: ['./dso-edit-metadata-text-field.component.scss'],
|
||||||
|
})
|
||||||
|
@editMetadataValueFieldComponent(EditMetadataValueFieldType.PLAIN_TEXT)
|
||||||
|
export class DsoEditMetadataTextFieldComponent extends AbstractDsoEditMetadataValueFieldComponent {
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
<ng-template dsDsoEditMetadataValueFieldDirective></ng-template>
|
@@ -0,0 +1,149 @@
|
|||||||
|
import { Component, Input, ViewChild, ComponentRef, OnInit, OnChanges, OnDestroy, SimpleChanges, ViewContainerRef, Output, EventEmitter } from '@angular/core';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { Context } from '../../../../core/shared/context.model';
|
||||||
|
import { ThemeService } from '../../../../shared/theme-support/theme.service';
|
||||||
|
import { DsoEditMetadataValueFieldLoaderDirective } from './dso-edit-metadata-value-field-loader.directive';
|
||||||
|
import { hasNoValue, hasValue, isNotEmpty } from '../../../../shared/empty.util';
|
||||||
|
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
|
||||||
|
import { getDsoEditMetadataValueFieldComponent } from './dso-edit-metadata-value-field.decorator';
|
||||||
|
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
|
||||||
|
import { DsoEditMetadataValue } from '../../dso-edit-metadata-form';
|
||||||
|
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-dso-edit-metadata-value-field-loader',
|
||||||
|
templateUrl: './dso-edit-metadata-value-field-loader.component.html',
|
||||||
|
})
|
||||||
|
export class DsoEditMetadataValueFieldLoaderComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The optional context
|
||||||
|
*/
|
||||||
|
@Input() context: Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link DSpaceObject}
|
||||||
|
*/
|
||||||
|
@Input() dso: DSpaceObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the DSO, used to determines i18n messages
|
||||||
|
*/
|
||||||
|
@Input() dsoType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the field
|
||||||
|
*/
|
||||||
|
@Input() type: EditMetadataValueFieldType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The metadata field
|
||||||
|
*/
|
||||||
|
@Input() mdField: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editable metadata value to show
|
||||||
|
*/
|
||||||
|
@Input() mdValue: DsoEditMetadataValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits when the user clicked confirm
|
||||||
|
*/
|
||||||
|
@Output() confirm: EventEmitter<boolean> = new EventEmitter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directive to determine where the dynamic child component is located
|
||||||
|
*/
|
||||||
|
@ViewChild(DsoEditMetadataValueFieldLoaderDirective, { static: true }) componentDirective: DsoEditMetadataValueFieldLoaderDirective;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reference to the dynamic component
|
||||||
|
*/
|
||||||
|
protected compRef: ComponentRef<Component>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||||
|
*/
|
||||||
|
protected subs: Subscription[] = [];
|
||||||
|
|
||||||
|
protected inAndOutputNames: (keyof this)[] = [
|
||||||
|
'context',
|
||||||
|
'dso',
|
||||||
|
'dsoType',
|
||||||
|
'type',
|
||||||
|
'mdField',
|
||||||
|
'mdValue',
|
||||||
|
'confirm',
|
||||||
|
];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
protected themeService: ThemeService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public getComponent(): GenericConstructor<Component> {
|
||||||
|
return getDsoEditMetadataValueFieldComponent(this.type, this.context, this.themeService.getThemeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the dynamic child component
|
||||||
|
*/
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.instantiateComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whenever the inputs change, update the inputs of the dynamic component
|
||||||
|
*/
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (hasNoValue(this.compRef)) {
|
||||||
|
// sometimes the component has not been initialized yet, so it first needs to be initialized
|
||||||
|
// before being called again
|
||||||
|
this.instantiateComponent(changes);
|
||||||
|
} else {
|
||||||
|
// if an input or output has changed
|
||||||
|
if (this.inAndOutputNames.some((name: any) => hasValue(changes[name]))) {
|
||||||
|
this.connectInputsAndOutputs();
|
||||||
|
if (this.compRef?.instance && 'ngOnChanges' in this.compRef.instance) {
|
||||||
|
(this.compRef.instance as any).ngOnChanges(changes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subs
|
||||||
|
.filter((subscription: Subscription) => hasValue(subscription))
|
||||||
|
.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||||
|
}
|
||||||
|
|
||||||
|
public instantiateComponent(changes?: SimpleChanges): void {
|
||||||
|
const component: GenericConstructor<Component> = this.getComponent();
|
||||||
|
const viewContainerRef: ViewContainerRef = this.componentDirective.viewContainerRef;
|
||||||
|
viewContainerRef.clear();
|
||||||
|
this.compRef = viewContainerRef.createComponent(
|
||||||
|
component, {
|
||||||
|
index: 0,
|
||||||
|
injector: undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (hasValue(changes)) {
|
||||||
|
this.ngOnChanges(changes);
|
||||||
|
} else {
|
||||||
|
this.connectInputsAndOutputs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect the in and outputs of this component to the dynamic component,
|
||||||
|
* to ensure they're in sync
|
||||||
|
*/
|
||||||
|
protected connectInputsAndOutputs(): void {
|
||||||
|
if (isNotEmpty(this.inAndOutputNames) && hasValue(this.compRef) && hasValue(this.compRef.instance)) {
|
||||||
|
this.inAndOutputNames.filter((name: any) => this[name] !== undefined).forEach((name: any) => {
|
||||||
|
this.compRef.instance[name] = this[name];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
import {
|
||||||
|
Directive,
|
||||||
|
ViewContainerRef,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directive used as a hook to know where to inject the dynamic loaded component
|
||||||
|
*/
|
||||||
|
@Directive({
|
||||||
|
selector: '[dsDsoEditMetadataValueFieldDirective]',
|
||||||
|
})
|
||||||
|
export class DsoEditMetadataValueFieldLoaderDirective {
|
||||||
|
constructor(
|
||||||
|
public viewContainerRef: ViewContainerRef,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
import { hasNoValue, hasValue } from '../../../../shared/empty.util';
|
||||||
|
import { Context } from '../../../../core/shared/context.model';
|
||||||
|
import { resolveTheme, DEFAULT_THEME, DEFAULT_CONTEXT, } from '../../../../shared/object-collection/shared/listable-object/listable-object.decorator';
|
||||||
|
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
|
||||||
|
|
||||||
|
export const map = new Map();
|
||||||
|
|
||||||
|
export const DEFAULT_EDIT_METADATA_FIELD_TYPE = EditMetadataValueFieldType.PLAIN_TEXT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decorator function to store edit metadata field mapping
|
||||||
|
*
|
||||||
|
* @param type The edit metadata field type
|
||||||
|
* @param context The optional context the component represents
|
||||||
|
* @param theme The optional theme for the component
|
||||||
|
*/
|
||||||
|
export function editMetadataValueFieldComponent(type: EditMetadataValueFieldType, context: Context = DEFAULT_CONTEXT, theme = DEFAULT_THEME) {
|
||||||
|
return function decorator(component: any) {
|
||||||
|
if (hasNoValue(map.get(type))) {
|
||||||
|
map.set(type, new Map());
|
||||||
|
}
|
||||||
|
if (hasNoValue(map.get(type).get(context))) {
|
||||||
|
map.get(type).set(context, new Map());
|
||||||
|
}
|
||||||
|
map.get(type).get(context).set(theme, component);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter to retrieve a matching component by entity type, metadata representation and context
|
||||||
|
*
|
||||||
|
* @param type The edit metadata field type
|
||||||
|
* @param context The context to match
|
||||||
|
* @param theme the theme to match
|
||||||
|
*/
|
||||||
|
export function getDsoEditMetadataValueFieldComponent(type: EditMetadataValueFieldType, context: Context = DEFAULT_CONTEXT, theme = DEFAULT_THEME) {
|
||||||
|
if (type) {
|
||||||
|
const mapForEntity = map.get(type);
|
||||||
|
if (hasValue(mapForEntity)) {
|
||||||
|
const contextMap = mapForEntity.get(context);
|
||||||
|
if (hasValue(contextMap)) {
|
||||||
|
const match = resolveTheme(contextMap, theme);
|
||||||
|
if (hasValue(match)) {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
if (hasValue(contextMap.get(DEFAULT_THEME))) {
|
||||||
|
return contextMap.get(DEFAULT_THEME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasValue(mapForEntity.get(DEFAULT_CONTEXT)) && hasValue(mapForEntity.get(DEFAULT_CONTEXT).get(DEFAULT_THEME))) {
|
||||||
|
return mapForEntity.get(DEFAULT_CONTEXT).get(DEFAULT_THEME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map.get(DEFAULT_EDIT_METADATA_FIELD_TYPE).get(DEFAULT_CONTEXT).get(DEFAULT_THEME);
|
||||||
|
}
|
@@ -3,8 +3,15 @@
|
|||||||
[ngClass]="{ 'ds-warning': mdValue.reordered || mdValue.change === DsoEditMetadataChangeTypeEnum.UPDATE, 'ds-danger': mdValue.change === DsoEditMetadataChangeTypeEnum.REMOVE, 'ds-success': mdValue.change === DsoEditMetadataChangeTypeEnum.ADD, 'h-100': isOnlyValue }">
|
[ngClass]="{ 'ds-warning': mdValue.reordered || mdValue.change === DsoEditMetadataChangeTypeEnum.UPDATE, 'ds-danger': mdValue.change === DsoEditMetadataChangeTypeEnum.REMOVE, 'ds-success': mdValue.change === DsoEditMetadataChangeTypeEnum.ADD, 'h-100': isOnlyValue }">
|
||||||
<div class="flex-grow-1 ds-flex-cell ds-value-cell d-flex align-items-center" *ngVar="(mdRepresentation$ | async) as mdRepresentation" role="cell">
|
<div class="flex-grow-1 ds-flex-cell ds-value-cell d-flex align-items-center" *ngVar="(mdRepresentation$ | async) as mdRepresentation" role="cell">
|
||||||
<div class="dont-break-out preserve-line-breaks" *ngIf="!mdValue.editing && !mdRepresentation">{{ mdValue.newValue.value }}</div>
|
<div class="dont-break-out preserve-line-breaks" *ngIf="!mdValue.editing && !mdRepresentation">{{ mdValue.newValue.value }}</div>
|
||||||
<textarea class="form-control" rows="5" *ngIf="mdValue.editing && !mdRepresentation" [(ngModel)]="mdValue.newValue.value"
|
<ng-container *ngVar="fieldType">
|
||||||
[dsDebounce]="300" (onDebounce)="confirm.emit(false)"></textarea>
|
<ds-dso-edit-metadata-value-field-loader *ngIf="mdValue.editing && !mdRepresentation"
|
||||||
|
[context]="context"
|
||||||
|
[mdValue]="mdValue"
|
||||||
|
[type]="fieldType"
|
||||||
|
(confirm)="confirm.emit($event)"
|
||||||
|
class="w-100">
|
||||||
|
</ds-dso-edit-metadata-value-field-loader>
|
||||||
|
</ng-container>
|
||||||
<div class="d-flex" *ngIf="mdRepresentation">
|
<div class="d-flex" *ngIf="mdRepresentation">
|
||||||
<a class="mr-2" target="_blank" [routerLink]="mdRepresentationItemRoute$ | async">{{ mdRepresentationName$ | async }}</a>
|
<a class="mr-2" target="_blank" [routerLink]="mdRepresentationItemRoute$ | async">{{ mdRepresentationName$ | async }}</a>
|
||||||
<ds-themed-type-badge [object]="mdRepresentation"></ds-themed-type-badge>
|
<ds-themed-type-badge [object]="mdRepresentation"></ds-themed-type-badge>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, OnChanges } from '@angular/core';
|
||||||
import { DsoEditMetadataChangeType, DsoEditMetadataValue } from '../dso-edit-metadata-form';
|
import { DsoEditMetadataChangeType, DsoEditMetadataValue } from '../dso-edit-metadata-form';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import {
|
import {
|
||||||
@@ -12,6 +12,8 @@ import { map } from 'rxjs/operators';
|
|||||||
import { getItemPageRoute } from '../../../item-page/item-page-routing-paths';
|
import { getItemPageRoute } from '../../../item-page/item-page-routing-paths';
|
||||||
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
|
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
|
||||||
import { EMPTY } from 'rxjs/internal/observable/empty';
|
import { EMPTY } from 'rxjs/internal/observable/empty';
|
||||||
|
import { EditMetadataValueFieldType } from '../dso-edit-metadata-value-field/dso-edit-metadata-field-type.enum';
|
||||||
|
import { Context } from '../../../core/shared/context.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dso-edit-metadata-value',
|
selector: 'ds-dso-edit-metadata-value',
|
||||||
@@ -21,13 +23,21 @@ import { EMPTY } from 'rxjs/internal/observable/empty';
|
|||||||
/**
|
/**
|
||||||
* Component displaying a single editable row for a metadata value
|
* Component displaying a single editable row for a metadata value
|
||||||
*/
|
*/
|
||||||
export class DsoEditMetadataValueComponent implements OnInit {
|
export class DsoEditMetadataValueComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
|
@Input() context: Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The parent {@link DSpaceObject} to display a metadata form for
|
* The parent {@link DSpaceObject} to display a metadata form for
|
||||||
* Also used to determine metadata-representations in case of virtual metadata
|
* Also used to determine metadata-representations in case of virtual metadata
|
||||||
*/
|
*/
|
||||||
@Input() dso: DSpaceObject;
|
@Input() dso: DSpaceObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The metadata field that is being edited
|
||||||
|
*/
|
||||||
|
@Input() mdField: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editable metadata value to show
|
* Editable metadata value to show
|
||||||
*/
|
*/
|
||||||
@@ -97,6 +107,8 @@ export class DsoEditMetadataValueComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
mdRepresentationName$: Observable<string | null>;
|
mdRepresentationName$: Observable<string | null>;
|
||||||
|
|
||||||
|
fieldType: EditMetadataValueFieldType;
|
||||||
|
|
||||||
constructor(protected relationshipService: RelationshipDataService,
|
constructor(protected relationshipService: RelationshipDataService,
|
||||||
protected dsoNameService: DSONameService) {
|
protected dsoNameService: DSONameService) {
|
||||||
}
|
}
|
||||||
@@ -105,6 +117,12 @@ export class DsoEditMetadataValueComponent implements OnInit {
|
|||||||
this.initVirtualProperties();
|
this.initVirtualProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (changes.mdField) {
|
||||||
|
this.fieldType = this.getFieldType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise potential properties of a virtual metadata value
|
* Initialise potential properties of a virtual metadata value
|
||||||
*/
|
*/
|
||||||
@@ -123,4 +141,12 @@ export class DsoEditMetadataValueComponent implements OnInit {
|
|||||||
map((mdRepresentation: ItemMetadataRepresentation) => mdRepresentation ? this.dsoNameService.getName(mdRepresentation) : null),
|
map((mdRepresentation: ItemMetadataRepresentation) => mdRepresentation ? this.dsoNameService.getName(mdRepresentation) : null),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the {@link EditMetadataValueFieldType} to be displayed for the current field while in edit mode.
|
||||||
|
*/
|
||||||
|
getFieldType(): EditMetadataValueFieldType {
|
||||||
|
return EditMetadataValueFieldType.PLAIN_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,8 @@
|
|||||||
<div role="table">
|
<div role="table">
|
||||||
<ds-dso-edit-metadata-value-headers role="presentation" [dsoType]="dsoType"></ds-dso-edit-metadata-value-headers>
|
<ds-dso-edit-metadata-value-headers role="presentation" [dsoType]="dsoType"></ds-dso-edit-metadata-value-headers>
|
||||||
<ds-dso-edit-metadata-value [dso]="dso"
|
<ds-dso-edit-metadata-value [dso]="dso"
|
||||||
|
[context]="Context.AddMetadata"
|
||||||
|
[mdField]="newMdField"
|
||||||
[mdValue]="form.newValue"
|
[mdValue]="form.newValue"
|
||||||
[dsoType]="dsoType"
|
[dsoType]="dsoType"
|
||||||
[saving$]="savingOrLoadingFieldValidation$"
|
[saving$]="savingOrLoadingFieldValidation$"
|
||||||
|
@@ -22,6 +22,7 @@ import { ArrayMoveChangeAnalyzer } from '../../core/data/array-move-change-analy
|
|||||||
import { DATA_SERVICE_FACTORY } from '../../core/data/base/data-service.decorator';
|
import { DATA_SERVICE_FACTORY } from '../../core/data/base/data-service.decorator';
|
||||||
import { GenericConstructor } from '../../core/shared/generic-constructor';
|
import { GenericConstructor } from '../../core/shared/generic-constructor';
|
||||||
import { HALDataService } from '../../core/data/base/hal-data-service.interface';
|
import { HALDataService } from '../../core/data/base/hal-data-service.interface';
|
||||||
|
import { Context } from '../../core/shared/context.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dso-edit-metadata',
|
selector: 'ds-dso-edit-metadata',
|
||||||
@@ -105,6 +106,8 @@ export class DsoEditMetadataComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
dsoUpdateSubscription: Subscription;
|
dsoUpdateSubscription: Subscription;
|
||||||
|
|
||||||
|
public readonly Context = Context;
|
||||||
|
|
||||||
constructor(protected route: ActivatedRoute,
|
constructor(protected route: ActivatedRoute,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected translateService: TranslateService,
|
protected translateService: TranslateService,
|
||||||
|
@@ -7,12 +7,20 @@ import { DsoEditMetadataValueComponent } from './dso-edit-metadata/dso-edit-meta
|
|||||||
import { DsoEditMetadataHeadersComponent } from './dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component';
|
import { DsoEditMetadataHeadersComponent } from './dso-edit-metadata/dso-edit-metadata-headers/dso-edit-metadata-headers.component';
|
||||||
import { DsoEditMetadataValueHeadersComponent } from './dso-edit-metadata/dso-edit-metadata-value-headers/dso-edit-metadata-value-headers.component';
|
import { DsoEditMetadataValueHeadersComponent } from './dso-edit-metadata/dso-edit-metadata-value-headers/dso-edit-metadata-value-headers.component';
|
||||||
import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-edit-metadata.component';
|
import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-edit-metadata.component';
|
||||||
|
import { DsoEditMetadataValueFieldLoaderComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field-loader.component';
|
||||||
|
import { DsoEditMetadataTextFieldComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-text-field/dso-edit-metadata-text-field.component';
|
||||||
|
import { DsoEditMetadataValueFieldLoaderDirective } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field-loader.directive';
|
||||||
|
|
||||||
|
const ENTRY_COMPONENTS = [
|
||||||
|
DsoEditMetadataTextFieldComponent,
|
||||||
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
SharedModule,
|
SharedModule,
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
|
...ENTRY_COMPONENTS,
|
||||||
DsoEditMetadataComponent,
|
DsoEditMetadataComponent,
|
||||||
ThemedDsoEditMetadataComponent,
|
ThemedDsoEditMetadataComponent,
|
||||||
MetadataFieldSelectorComponent,
|
MetadataFieldSelectorComponent,
|
||||||
@@ -20,6 +28,8 @@ import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-e
|
|||||||
DsoEditMetadataValueComponent,
|
DsoEditMetadataValueComponent,
|
||||||
DsoEditMetadataHeadersComponent,
|
DsoEditMetadataHeadersComponent,
|
||||||
DsoEditMetadataValueHeadersComponent,
|
DsoEditMetadataValueHeadersComponent,
|
||||||
|
DsoEditMetadataValueFieldLoaderComponent,
|
||||||
|
DsoEditMetadataValueFieldLoaderDirective,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
DsoEditMetadataComponent,
|
DsoEditMetadataComponent,
|
||||||
@@ -30,6 +40,9 @@ import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-e
|
|||||||
DsoEditMetadataHeadersComponent,
|
DsoEditMetadataHeadersComponent,
|
||||||
DsoEditMetadataValueHeadersComponent,
|
DsoEditMetadataValueHeadersComponent,
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
...ENTRY_COMPONENTS,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class DsoSharedModule {
|
export class DsoSharedModule {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user