Skip to content

Commit

Permalink
Merge branch 'w2p-119915_made-edit-metadata-tab-fields-dynamic_contri…
Browse files Browse the repository at this point in the history
…bute-7.6'

# Conflicts:
#	src/app/core/shared/context.model.ts
#	src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-field-values/dso-edit-metadata-field-values.component.ts
#	src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.html
#	src/app/dso-shared/dso-edit-metadata/dso-edit-metadata-value/dso-edit-metadata-value.component.ts
#	src/app/dso-shared/dso-edit-metadata/dso-edit-metadata.component.ts
#	src/app/dso-shared/dso-shared.module.ts
#	src/app/shared/testing/entity-type-data.service.stub.ts
  • Loading branch information
alexandrevryghem committed Oct 28, 2024
2 parents 13cbcd3 + 4703bae commit acf80db
Show file tree
Hide file tree
Showing 21 changed files with 497 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/app/core/shared/context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ export enum Context {
Bitstream = 'bitstream',

CoarNotify = 'coarNotify',

/**
* The Edit Metadata field Context values that are used in the Edit Item Metadata tab.
*/
AddMetadata = 'addMetadata',
EditMetadata = 'editMetadata',
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 *ngFor="let mdValue of form.fields[mdField]; let idx = index" role="presentation"
[dso]="dso"
[context]="Context.EditMetadata"
[mdField]="mdField"
[mdValue]="mdValue"
[mdField]="mdField"
[dsoType]="dsoType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Observable,
} from 'rxjs';

import { Context } from '../../../core/shared/context.model';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import {
DsoEditMetadataChangeType,
Expand Down Expand Up @@ -81,6 +82,8 @@ export class DsoEditMetadataFieldValuesComponent {
*/
public DsoEditMetadataChangeTypeEnum = DsoEditMetadataChangeType;

public readonly Context = Context;

/**
* Drop a value into a new position
* Update the form's value array for the current field to match the dropped position
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Component,
EventEmitter,
Input,
Output,
} from '@angular/core';

import { Context } from '../../../core/shared/context.model';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { DsoEditMetadataValue } from '../dso-edit-metadata-form';
import { EditMetadataValueFieldType } from './dso-edit-metadata-field-type.enum';

@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();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<select class="form-control" [(ngModel)]="mdValue?.newValue.value" (ngModelChange)="confirm.emit(false)">
<option *ngFor="let entity of (entities$ | async)" [value]="entity.label === 'none' ? undefined : entity.label">
{{ entity.label }}
</option>
</select>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
ComponentFixture,
TestBed,
} from '@angular/core/testing';

import { EntityTypeDataService } from '../../../../core/data/entity-type-data.service';
import { EntityTypeDataServiceStub } from '../../../../shared/testing/entity-type-data.service.stub';
import { DsoEditMetadataEntityFieldComponent } from './dso-edit-metadata-entity-field.component';

describe('DsoEditMetadataEntityFieldComponent', () => {
let component: DsoEditMetadataEntityFieldComponent;
let fixture: ComponentFixture<DsoEditMetadataEntityFieldComponent>;

let entityTypeService: EntityTypeDataServiceStub;

beforeEach(async () => {
entityTypeService = new EntityTypeDataServiceStub();

await TestBed.configureTestingModule({
declarations: [
DsoEditMetadataEntityFieldComponent,
],
providers: [
{ provide: EntityTypeDataService, useValue: entityTypeService },
],
}).compileComponents();

fixture = TestBed.createComponent(DsoEditMetadataEntityFieldComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Component,
OnInit,
} from '@angular/core';
import { Observable } from 'rxjs';

import { EntityTypeDataService } from '../../../../core/data/entity-type-data.service';
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators';
import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component';
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
import { editMetadataValueFieldComponent } from '../dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field.decorator';

/**
* The component used to gather input for entity-type metadata fields
*/
@Component({
selector: 'ds-dso-edit-metadata-entity-field',
templateUrl: './dso-edit-metadata-entity-field.component.html',
styleUrls: ['./dso-edit-metadata-entity-field.component.scss'],
})
@editMetadataValueFieldComponent(EditMetadataValueFieldType.ENTITY_TYPE)
export class DsoEditMetadataEntityFieldComponent extends AbstractDsoEditMetadataValueFieldComponent implements OnInit {

/**
* List of all the existing entity types
*/
entities$: Observable<ItemType[]>;

constructor(
protected entityTypeService: EntityTypeDataService,
) {
super();
}

ngOnInit(): void {
this.entities$ = this.entityTypeService.findAll({ elementsPerPage: 100, currentPage: 1 }).pipe(
getFirstSucceededRemoteListPayload(),
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* The edit metadata field tab types
*/
export enum EditMetadataValueFieldType {
PLAIN_TEXT = 'PLAIN_TEXT',
ENTITY_TYPE = 'ENTITY_TYPE',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<textarea [(ngModel)]="mdValue?.newValue.value"
[dsDebounce]="300"
(onDebounce)="confirm.emit(false)"
class="form-control"
rows="5">
</textarea>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';

import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component';
import { EditMetadataValueFieldType } from '../dso-edit-metadata-field-type.enum';
import { editMetadataValueFieldComponent } from '../dso-edit-metadata-value-field-loader/dso-edit-metadata-value-field.decorator';

/**
* 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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ng-template dsDsoEditMetadataValueFieldDirective></ng-template>
Loading

0 comments on commit acf80db

Please sign in to comment.