Skip to content

Commit 2ba3f0b

Browse files
119915: Retrieve the edit metadata field dynamically
1 parent 404ccd9 commit 2ba3f0b

18 files changed

Lines changed: 388 additions & 4 deletions

src/app/core/shared/context.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ export enum Context {
3939
MyDSpaceValidation = 'mydspaceValidation',
4040

4141
Bitstream = 'bitstream',
42+
43+
/**
44+
* The Edit Metadata field Context values that are used in the Edit Item Metadata tab.
45+
*/
46+
AddMetadata = 'addMetadata',
47+
EditMetadata = 'editMetadata',
4248
}

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-field-values/dso-edit-metadata-field-values.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<ds-dso-edit-metadata-value-headers role="presentation" [dsoType]="dsoType"></ds-dso-edit-metadata-value-headers>
33
<ds-dso-edit-metadata-value *ngFor="let mdValue of form.fields[mdField]; let idx = index" role="presentation"
44
[dso]="dso"
5+
[context]="Context.EditMetadata"
6+
[mdField]="mdField"
57
[mdValue]="mdValue"
68
[dsoType]="dsoType"
79
[saving$]="saving$"

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-field-values/dso-edit-metadata-field-values.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Observable } from 'rxjs/internal/Observable';
44
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
55
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
66
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
7+
import { Context } from '../../../core/shared/context.model';
78

89
@Component({
910
selector: 'ds-dso-edit-metadata-field-values',
@@ -57,6 +58,8 @@ export class DsoEditMetadataFieldValuesComponent {
5758
*/
5859
public DsoEditMetadataChangeTypeEnum = DsoEditMetadataChangeType;
5960

61+
public readonly Context = Context;
62+
6063
/**
6164
* Drop a value into a new position
6265
* Update the form's value array for the current field to match the dropped position
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, Input, Output, EventEmitter } from '@angular/core';
2+
import { Context } from '../../../core/shared/context.model';
3+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
4+
import { EditMetadataValueFieldType } from './dso-edit-metadata-field-type.enum';
5+
import { DsoEditMetadataValue } from '../dso-edit-metadata-form';
6+
7+
@Component({
8+
selector: 'ds-dso-edit-metadata-entity-field',
9+
template: '',
10+
})
11+
export abstract class AbstractDsoEditMetadataValueFieldComponent {
12+
13+
/**
14+
* The optional context
15+
*/
16+
@Input() context: Context;
17+
18+
/**
19+
* The {@link DSpaceObject}
20+
*/
21+
@Input() dso: DSpaceObject;
22+
23+
/**
24+
* The type of the DSO, used to determines i18n messages
25+
*/
26+
@Input() dsoType: string;
27+
28+
/**
29+
* The type of the field
30+
*/
31+
@Input() type: EditMetadataValueFieldType;
32+
33+
/**
34+
* The metadata field
35+
*/
36+
@Input() mdField: string;
37+
38+
/**
39+
* Editable metadata value to show
40+
*/
41+
@Input() mdValue: DsoEditMetadataValue;
42+
43+
/**
44+
* Emits when the user clicked confirm
45+
*/
46+
@Output() confirm: EventEmitter<boolean> = new EventEmitter();
47+
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The edit metadata field tab types
3+
*/
4+
export enum EditMetadataValueFieldType {
5+
PLAIN_TEXT = 'PLAIN_TEXT',
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<textarea [(ngModel)]="mdValue?.newValue.value"
2+
[dsDebounce]="300"
3+
(onDebounce)="confirm.emit(false)"
4+
class="form-control"
5+
rows="5">
6+
</textarea>

src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-text-field/dso-edit-metadata-text-field.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { DsoEditMetadataTextFieldComponent } from './dso-edit-metadata-text-field.component';
3+
4+
describe('DsoEditMetadataTextFieldComponent', () => {
5+
let component: DsoEditMetadataTextFieldComponent;
6+
let fixture: ComponentFixture<DsoEditMetadataTextFieldComponent>;
7+
8+
beforeEach(async () => {
9+
await TestBed.configureTestingModule({
10+
declarations: [
11+
DsoEditMetadataTextFieldComponent,
12+
],
13+
}).compileComponents();
14+
15+
fixture = TestBed.createComponent(DsoEditMetadataTextFieldComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component } from '@angular/core';
2+
import { editMetadataValueFieldComponent } from '../dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field.decorator';
3+
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
4+
import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component';
5+
6+
/**
7+
* The component used to gather input for plain-text metadata fields
8+
*/
9+
@Component({
10+
selector: 'ds-dso-edit-metadata-text-field',
11+
templateUrl: './dso-edit-metadata-text-field.component.html',
12+
styleUrls: ['./dso-edit-metadata-text-field.component.scss'],
13+
})
14+
@editMetadataValueFieldComponent(EditMetadataValueFieldType.PLAIN_TEXT)
15+
export class DsoEditMetadataTextFieldComponent extends AbstractDsoEditMetadataValueFieldComponent {
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ng-template dsDsoEditMetadataValueFieldDirective></ng-template>

0 commit comments

Comments
 (0)