Skip to content

Commit

Permalink
119915: Changed the dspace.entity.type textarea with a select to prev…
Browse files Browse the repository at this point in the history
…ent incorrect values
  • Loading branch information
alexandrevryghem committed Oct 30, 2024
1 parent 2ba3f0b commit 77b66a5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
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,32 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DsoEditMetadataEntityFieldComponent } from './dso-edit-metadata-entity-field.component';
import { EntityTypeDataServiceStub } from '../../../../shared/testing/entity-type-data.service.stub';
import { EntityTypeDataService } from '../../../../core/data/entity-type-data.service';

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,38 @@
import { Component, OnInit } 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 { EntityTypeDataService } from '../../../../core/data/entity-type-data.service';
import { Observable } from 'rxjs';
import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators';
import { ItemType } from '../../../../core/shared/item-relationships/item-type.model';
import { AbstractDsoEditMetadataValueFieldComponent } from '../abstract-dso-edit-metadata-value-field.component';

/**
* 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
Expand Up @@ -3,4 +3,5 @@
*/
export enum EditMetadataValueFieldType {
PLAIN_TEXT = 'PLAIN_TEXT',
ENTITY_TYPE = 'ENTITY_TYPE',
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export class DsoEditMetadataValueComponent implements OnInit, OnChanges {
* Retrieves the {@link EditMetadataValueFieldType} to be displayed for the current field while in edit mode.
*/
getFieldType(): EditMetadataValueFieldType {
if (this.mdField === 'dspace.entity.type') {
return EditMetadataValueFieldType.ENTITY_TYPE;
}
return EditMetadataValueFieldType.PLAIN_TEXT;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/dso-shared/dso-shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { ThemedDsoEditMetadataComponent } from './dso-edit-metadata/themed-dso-e
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';
import { DsoEditMetadataEntityFieldComponent } from './dso-edit-metadata/dso-edit-metadata-value-field/dso-edit-metadata-entity-field/dso-edit-metadata-entity-field.component';

const ENTRY_COMPONENTS = [
DsoEditMetadataTextFieldComponent,
DsoEditMetadataEntityFieldComponent,
];

@NgModule({
Expand Down
19 changes: 19 additions & 0 deletions src/app/shared/testing/entity-type-data.service.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FindListOptions } from '../../core/data/find-list-options.model';
import { FollowLinkConfig } from '../utils/follow-link-config.model';
import { ItemType } from '../../core/shared/item-relationships/item-type.model';
import { Observable } from 'rxjs';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
import { createPaginatedList } from './utils.test';

/**
* Stub class {@link EntityTypeDataService}
*/
export class EntityTypeDataServiceStub {

public findAll(_options?: FindListOptions, _useCachedVersionIfAvailable?: boolean, _reRequestOnStale?: boolean, ..._linksToFollow: FollowLinkConfig<ItemType>[]): Observable<RemoteData<PaginatedList<ItemType>>> {
return createSuccessfulRemoteDataObject$(createPaginatedList());
}

}

0 comments on commit 77b66a5

Please sign in to comment.