diff --git a/src/app/shared/object-select/item-select/item-select.component.html b/src/app/shared/object-select/item-select/item-select.component.html index 110434969a..719a2f5493 100644 --- a/src/app/shared/object-select/item-select/item-select.component.html +++ b/src/app/shared/object-select/item-select/item-select.component.html @@ -17,17 +17,17 @@ - - + + - + {{ dsoNameService.getName(collection) }} - {{item.firstMetadataValue(['dc.contributor.author', 'dc.creator', 'dc.contributor.*'])}} - {{ dsoNameService.getName(item) }} + {{selectItem.dso.firstMetadataValue(['dc.contributor.author', 'dc.creator', 'dc.contributor.*'])}} + {{ dsoNameService.getName(selectItem.dso) }} diff --git a/src/app/shared/object-select/item-select/item-select.component.spec.ts b/src/app/shared/object-select/item-select/item-select.component.spec.ts index 5131060cb2..fabd45e484 100644 --- a/src/app/shared/object-select/item-select/item-select.component.spec.ts +++ b/src/app/shared/object-select/item-select/item-select.component.spec.ts @@ -184,15 +184,16 @@ describe('ItemSelectComponent', () => { beforeEach(() => { comp.featureId = FeatureID.CanManageMappings; spyOn(authorizationDataService, 'isAuthorized').and.returnValue(of(false)); + comp.ngOnInit(); }); - it('should disable the checkbox', waitForAsync(() => { + it('should disable the checkbox', waitForAsync(async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const checkbox = fixture.debugElement.query(By.css('input.item-checkbox')).nativeElement; - expect(authorizationDataService.isAuthorized).toHaveBeenCalled(); - expect(checkbox.disabled).toBeTrue(); - }); + await fixture.whenStable(); + + const checkbox = fixture.debugElement.query(By.css('input.item-checkbox')).nativeElement; + expect(authorizationDataService.isAuthorized).toHaveBeenCalled(); + expect(checkbox.disabled).toBeTrue(); })); }); }); diff --git a/src/app/shared/object-select/item-select/item-select.component.ts b/src/app/shared/object-select/item-select/item-select.component.ts index dd0266ff83..e9ec817cf0 100644 --- a/src/app/shared/object-select/item-select/item-select.component.ts +++ b/src/app/shared/object-select/item-select/item-select.component.ts @@ -1,14 +1,13 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; -import { ObjectSelectService } from '../object-select.service'; import { ObjectSelectComponent } from '../object-select/object-select.component'; import { hasValueOperator, isNotEmpty } from '../../empty.util'; import { Observable } from 'rxjs'; import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators'; import { map } from 'rxjs/operators'; import { getItemPageRoute } from '../../../item-page/item-page-routing-paths'; -import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; -import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; +import { PaginatedList } from '../../../core/data/paginated-list.model'; +import { DSpaceObjectSelect } from '../object-select.model'; @Component({ selector: 'ds-item-select', @@ -18,7 +17,7 @@ import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; /** * A component used to select items from a specific list and returning the UUIDs of the selected items */ -export class ItemSelectComponent extends ObjectSelectComponent { +export class ItemSelectComponent extends ObjectSelectComponent implements OnInit { /** * Whether or not to hide the collection column @@ -27,35 +26,25 @@ export class ItemSelectComponent extends ObjectSelectComponent { hideCollection = false; /** - * The routes to the items their pages - * Key: Item ID - * Value: Route to item page + * Collection of all the data that is used to display the {@link Item} in the HTML. + * By collecting this data here it doesn't need to be recalculated on evey change detection. */ - itemPageRoutes$: Observable<{ - [itemId: string]: string - }>; - - constructor( - protected objectSelectService: ObjectSelectService, - protected authorizationService: AuthorizationDataService, - public dsoNameService: DSONameService, - ) { - super(objectSelectService, authorizationService); - } + selectItems$: Observable[]>; ngOnInit(): void { super.ngOnInit(); if (!isNotEmpty(this.confirmButton)) { this.confirmButton = 'item.select.confirm'; } - this.itemPageRoutes$ = this.dsoRD$.pipe( + this.selectItems$ = this.dsoRD$.pipe( hasValueOperator(), getAllSucceededRemoteDataPayload(), - map((items) => { - const itemPageRoutes = {}; - items.page.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item)); - return itemPageRoutes; - }) + map((items: PaginatedList) => items.page.map((item: Item) => Object.assign(new DSpaceObjectSelect(), { + dso: item, + canSelect$: this.canSelect(item), + selected$: this.getSelected(item.id), + route: getItemPageRoute(item), + } as DSpaceObjectSelect))), ); } diff --git a/src/app/shared/object-select/object-select.model.ts b/src/app/shared/object-select/object-select.model.ts new file mode 100644 index 0000000000..329b419f46 --- /dev/null +++ b/src/app/shared/object-select/object-select.model.ts @@ -0,0 +1,29 @@ +import { Observable } from 'rxjs'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; + +/** + * Class used to collect all the data that that is used by the {@link ObjectSelectComponent} in the HTML. + */ +export class DSpaceObjectSelect { + + /** + * The {@link DSpaceObject} to display + */ + dso: T; + + /** + * Whether the {@link DSpaceObject} can be selected + */ + canSelect$: Observable; + + /** + * Whether the {@link DSpaceObject} is selected + */ + selected$: Observable; + + /** + * The {@link DSpaceObject}'s route + */ + route: string; + +} diff --git a/src/app/shared/object-select/object-select/object-select.component.ts b/src/app/shared/object-select/object-select/object-select.component.ts index 6fb795690d..cc38941fd9 100644 --- a/src/app/shared/object-select/object-select/object-select.component.ts +++ b/src/app/shared/object-select/object-select/object-select.component.ts @@ -9,6 +9,7 @@ import { SortOptions } from '../../../core/cache/models/sort-options.model'; import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; +import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; /** * An abstract component used to select DSpaceObjects from a specific list and returning the UUIDs of the selected DSpaceObjects @@ -17,7 +18,7 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model'; selector: 'ds-object-select-abstract', template: '' }) -export abstract class ObjectSelectComponent implements OnInit, OnDestroy { +export abstract class ObjectSelectComponent implements OnInit, OnDestroy { /** * A unique key used for the object select service @@ -88,8 +89,11 @@ export abstract class ObjectSelectComponent implements OnInit, OnDestro */ selectedIds$: Observable; - constructor(protected objectSelectService: ObjectSelectService, - protected authorizationService: AuthorizationDataService) { + constructor( + protected objectSelectService: ObjectSelectService, + protected authorizationService: AuthorizationDataService, + public dsoNameService: DSONameService, + ) { } ngOnInit(): void {