Skip to content

Commit

Permalink
118944: Embed the accessStatus link on collection, browse, recent ite…
Browse files Browse the repository at this point in the history
…m submissions & the item page related items & delete tab when enabled
  • Loading branch information
alexandrevryghem committed Oct 11, 2024
1 parent 4af8899 commit b709ee0
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/app/collection-page/collection-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { AuthorizationDataService } from '../core/data/feature-authorization/aut
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { getCollectionPageRoute } from './collection-page-routing-paths';
import { redirectOn4xx } from '../core/shared/authorized.operators';
import { BROWSE_LINKS_TO_FOLLOW } from '../core/browse/browse.service';
import { getBrowseLinksToFollow } from '../core/browse/browse.service';
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
import { APP_CONFIG, AppConfig } from '../../../src/config/app-config.interface';

Expand Down Expand Up @@ -115,7 +115,7 @@ export class CollectionPageComponent implements OnInit {
pagination: currentPagination,
sort: currentSort,
dsoTypes: [DSpaceObjectType.ITEM]
}), null, true, true, ...BROWSE_LINKS_TO_FOLLOW)
}), null, true, true, ...getBrowseLinksToFollow())
.pipe(toDSpaceObjectListRD()) as Observable<RemoteData<PaginatedList<Item>>>;
}),
startWith(undefined) // Make sure switching pages shows loading component
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/breadcrumbs/item-breadcrumb.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ItemDataService } from '../data/item-data.service';
import { Item } from '../shared/item.model';
import { DSOBreadcrumbResolver } from './dso-breadcrumb.resolver';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../item-page/item.resolver';
import { getItemPageLinksToFollow } from '../../item-page/item.resolver';

/**
* The class that resolves the BreadcrumbConfig object for an Item
Expand All @@ -23,6 +23,6 @@ export class ItemBreadcrumbResolver extends DSOBreadcrumbResolver<Item> {
* Requesting them as embeds will limit the number of requests
*/
get followLinks(): FollowLinkConfig<Item>[] {
return ITEM_PAGE_LINKS_TO_FOLLOW;
return getItemPageLinksToFollow();
}
}
12 changes: 0 additions & 12 deletions src/app/core/browse/browse.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { of as observableOf } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { RequestService } from '../data/request.service';
import { BrowseEntrySearchOptions } from './browse-entry-search-options.model';
import { BrowseService } from './browse.service';
Expand All @@ -20,7 +18,6 @@ describe('BrowseService', () => {
let scheduler: TestScheduler;
let service: BrowseService;
let requestService: RequestService;
let rdbService: RemoteDataBuildService;

const browsesEndpointURL = 'https://rest.api/browses';
const halService: any = new HALEndpointServiceStub(browsesEndpointURL);
Expand Down Expand Up @@ -118,7 +115,6 @@ describe('BrowseService', () => {
halService,
browseDefinitionDataService,
hrefOnlyDataService,
rdbService
);
}

Expand All @@ -130,11 +126,9 @@ describe('BrowseService', () => {

beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true));
rdbService = getMockRemoteDataBuildService();
service = initTestService();
spyOn(halService, 'getEndpoint').and
.returnValue(hot('--a-', { a: browsesEndpointURL }));
spyOn(rdbService, 'buildList').and.callThrough();
});

it('should call BrowseDefinitionDataService to create the RemoteData Observable', () => {
Expand All @@ -151,9 +145,7 @@ describe('BrowseService', () => {

beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true));
rdbService = getMockRemoteDataBuildService();
service = initTestService();
spyOn(rdbService, 'buildList').and.callThrough();
});

describe('when getBrowseEntriesFor is called with a valid browse definition id', () => {
Expand Down Expand Up @@ -204,7 +196,6 @@ describe('BrowseService', () => {
describe('if getBrowseDefinitions fires', () => {
beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true));
rdbService = getMockRemoteDataBuildService();
service = initTestService();
spyOn(service, 'getBrowseDefinitions').and
.returnValue(hot('--a-', {
Expand Down Expand Up @@ -259,7 +250,6 @@ describe('BrowseService', () => {
describe('if getBrowseDefinitions doesn\'t fire', () => {
it('should return undefined', () => {
requestService = getMockRequestService(getRequestEntry$(true));
rdbService = getMockRemoteDataBuildService();
service = initTestService();
spyOn(service, 'getBrowseDefinitions').and
.returnValue(hot('----'));
Expand All @@ -277,9 +267,7 @@ describe('BrowseService', () => {
describe('getFirstItemFor', () => {
beforeEach(() => {
requestService = getMockRequestService();
rdbService = getMockRemoteDataBuildService();
service = initTestService();
spyOn(rdbService, 'buildList').and.callThrough();
});

describe('when getFirstItemFor is called with a valid browse definition id', () => {
Expand Down
19 changes: 12 additions & 7 deletions src/app/core/browse/browse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { distinctUntilChanged, map, startWith } from 'rxjs/operators';
import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../shared/empty.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { PaginatedList } from '../data/paginated-list.model';
import { RemoteData } from '../data/remote-data';
import { RequestService } from '../data/request.service';
Expand All @@ -24,11 +23,18 @@ import { HrefOnlyDataService } from '../data/href-only-data.service';
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { BrowseDefinitionDataService } from './browse-definition-data.service';
import { SortDirection } from '../cache/models/sort-options.model';
import { environment } from '../../../environments/environment';


export const BROWSE_LINKS_TO_FOLLOW: FollowLinkConfig<BrowseEntry | Item>[] = [
followLink('thumbnail')
];
export function getBrowseLinksToFollow(): FollowLinkConfig<BrowseEntry | Item>[] {
const followLinks = [
followLink('thumbnail'),
];
if (environment.item.showAccessStatuses) {
followLinks.push(followLink('accessStatus'));
}
return followLinks;
}

/**
* The service handling all browse requests
Expand All @@ -55,7 +61,6 @@ export class BrowseService {
protected halService: HALEndpointService,
private browseDefinitionDataService: BrowseDefinitionDataService,
private hrefOnlyDataService: HrefOnlyDataService,
private rdb: RemoteDataBuildService,
) {
}

Expand Down Expand Up @@ -105,7 +110,7 @@ export class BrowseService {
})
);
if (options.fetchThumbnail ) {
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$, {}, null, null, ...BROWSE_LINKS_TO_FOLLOW);
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$, {}, null, null, ...getBrowseLinksToFollow());
}
return this.hrefOnlyDataService.findListByHref<BrowseEntry>(href$);
}
Expand Down Expand Up @@ -153,7 +158,7 @@ export class BrowseService {
}),
);
if (options.fetchThumbnail) {
return this.hrefOnlyDataService.findListByHref<Item>(href$, {}, null, null, ...BROWSE_LINKS_TO_FOLLOW);
return this.hrefOnlyDataService.findListByHref<Item>(href$, {}, null, null, ...getBrowseLinksToFollow());
}
return this.hrefOnlyDataService.findListByHref<Item>(href$);
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/data/relationship-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FindListOptions } from './find-list-options.model';
import { testSearchDataImplementation } from './base/search-data.spec';
import { MetadataValue } from '../shared/metadata.models';
import { MetadataRepresentationType } from '../shared/metadata-representation/metadata-representation.model';
import { environment } from '../../../environments/environment.test';

describe('RelationshipDataService', () => {
let service: RelationshipDataService;
Expand Down Expand Up @@ -137,6 +138,7 @@ describe('RelationshipDataService', () => {
itemService,
null,
jasmine.createSpy('paginatedRelationsToItems').and.returnValue((v) => v),
environment,
);
}

Expand All @@ -152,7 +154,7 @@ describe('RelationshipDataService', () => {
});

describe('composition', () => {
const initService = () => new RelationshipDataService(null, null, null, null, null, null, null);
const initService = () => new RelationshipDataService(null, null, null, null, null, null, null, environment);

testSearchDataImplementation(initService);
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/data/relationship-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { MetadataRepresentation } from '../shared/metadata-representation/metada
import { MetadatumRepresentation } from '../shared/metadata-representation/metadatum/metadatum-representation.model';
import { ItemMetadataRepresentation } from '../shared/metadata-representation/item/item-metadata-representation.model';
import { DSpaceObject } from '../shared/dspace-object.model';
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';

const relationshipListsStateSelector = (state: AppState) => state.relationshipLists;

Expand Down Expand Up @@ -92,6 +93,7 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
protected itemService: ItemDataService,
protected appStore: Store<AppState>,
@Inject(PAGINATED_RELATIONS_TO_ITEMS_OPERATOR) private paginatedRelationsToItems: (thisId: string) => (source: Observable<RemoteData<PaginatedList<Relationship>>>) => Observable<RemoteData<PaginatedList<Item>>>,
@Inject(APP_CONFIG) private appConfig: AppConfig,
) {
super('relationships', requestService, rdbService, objectCache, halService, 15 * 60 * 1000);

Expand Down Expand Up @@ -264,7 +266,7 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* @param options
*/
getRelatedItemsByLabel(item: Item, label: string, options?: FindListOptions): Observable<RemoteData<PaginatedList<Item>>> {
let linksToFollow: FollowLinkConfig<Relationship>[] = itemLinksToFollow(options.fetchThumbnail);
let linksToFollow: FollowLinkConfig<Relationship>[] = itemLinksToFollow(options.fetchThumbnail, this.appConfig.item.showAccessStatuses);
linksToFollow.push(followLink('relationshipType'));

return this.getItemRelationshipsByLabel(item, label, options, true, true, ...linksToFollow).pipe(this.paginatedRelationsToItems(item.uuid));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export class RecentItemListComponent implements OnInit {
if (this.appConfig.browseBy.showThumbnails) {
linksToFollow.push(followLink('thumbnail'));
}
if (this.appConfig.item.showAccessStatuses) {
linksToFollow.push(followLink('accessStatus'));
}

this.itemRD$ = this.searchService.search(
new PaginatedSearchOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { environment } from '../../../../environments/environment';
import { getItemPageRoute } from '../../item-page-routing-paths';
import { getAllSucceededRemoteData } from '../../../core/shared/operators';
import { hasValue } from '../../../shared/empty.util';
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../item.resolver';
import { getItemPageLinksToFollow } from '../../item.resolver';
import { FieldUpdate } from '../../../core/data/object-updates/field-update.model';
import { FieldUpdates } from '../../../core/data/object-updates/field-updates.model';

Expand Down Expand Up @@ -72,7 +72,7 @@ export class AbstractItemUpdateComponent extends AbstractTrackableComponent impl
this.item = rd.payload;
}),
switchMap((rd: RemoteData<Item>) => {
return this.itemService.findByHref(rd.payload._links.self.href, true, true, ...ITEM_PAGE_LINKS_TO_FOLLOW);
return this.itemService.findByHref(rd.payload._links.self.href, true, true, ...getItemPageLinksToFollow());
}),
getAllSucceededRemoteData()
).subscribe((rd: RemoteData<Item>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ export class ItemDeleteComponent
this.linkService.resolveLinks(
relationship,
followLink('relationshipType'),
followLink('leftItem'),
followLink('rightItem'),
followLink('leftItem', undefined, followLink<Item>('accessStatus')),
followLink('rightItem', undefined, followLink<Item>('accessStatus')),
);
return relationship.relationshipType.pipe(
getFirstSucceededRemoteData(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ConfigurationProperty } from '../../../../core/shared/configuration-pro
import { Router } from '@angular/router';
import { RouterMock } from '../../../../shared/mocks/router.mock';
import { APP_CONFIG } from '../../../../../config/app-config.interface';
import { environment } from '../../../../../environments/environment.test';

let comp: EditRelationshipListComponent;
let fixture: ComponentFixture<EditRelationshipListComponent>;
Expand Down Expand Up @@ -202,11 +203,11 @@ describe('EditRelationshipListComponent', () => {
}))
});

const environmentUseThumbs = {
const environmentUseThumbs = Object.assign({}, environment, {
browseBy: {
showThumbnails: true
}
};
});

TestBed.configureTestingModule({
imports: [SharedModule, TranslateModule.forRoot()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
);

// this adds thumbnail images when required by configuration
let linksToFollow: FollowLinkConfig<Relationship>[] = itemLinksToFollow(this.fetchThumbnail);
let linksToFollow: FollowLinkConfig<Relationship>[] = itemLinksToFollow(this.fetchThumbnail, this.appConfig.item.showAccessStatuses);

this.subs.push(
observableCombineLatest([
Expand Down
27 changes: 17 additions & 10 deletions src/app/item-page/item.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ import { followLink, FollowLinkConfig } from '../shared/utils/follow-link-config
import { getFirstCompletedRemoteData } from '../core/shared/operators';
import { Store } from '@ngrx/store';
import { ResolvedAction } from '../core/resolving/resolver.actions';
import { environment } from '../../environments/environment';

/**
* The self links defined in this list are expected to be requested somewhere in the near future
* Requesting them as embeds will limit the number of requests
*/
export const ITEM_PAGE_LINKS_TO_FOLLOW: FollowLinkConfig<Item>[] = [
followLink('owningCollection', {},
followLink('parentCommunity', {},
followLink('parentCommunity'))
),
followLink('relationships'),
followLink('version', {}, followLink('versionhistory')),
followLink('thumbnail')
];
export function getItemPageLinksToFollow(): FollowLinkConfig<Item>[] {
const followLinks: FollowLinkConfig<Item>[] = [
followLink('owningCollection', {},
followLink('parentCommunity', {},
followLink('parentCommunity'))
),
followLink('relationships'),
followLink('version', {}, followLink('versionhistory')),
followLink('thumbnail'),
];
if (environment.item.showAccessStatuses) {
followLinks.push(followLink('accessStatus'));
}
return followLinks;
}

/**
* This class represents a resolver that requests a specific item before the route is activated
Expand All @@ -46,7 +53,7 @@ export class ItemResolver implements Resolve<RemoteData<Item>> {
const itemRD$ = this.itemService.findById(route.params.id,
true,
false,
...ITEM_PAGE_LINKS_TO_FOLLOW
...getItemPageLinksToFollow(),
).pipe(
getFirstCompletedRemoteData(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
const relationship$ = this.relationshipService.findById(this.value.virtualValue,
true,
true,
... itemLinksToFollow(this.fetchThumbnail)).pipe(
... itemLinksToFollow(this.fetchThumbnail, this.appConfig.item.showAccessStatuses)).pipe(
getAllSucceededRemoteData(),
getRemoteDataPayload());
this.relationshipValue$ = observableCombineLatest([this.item$.pipe(take(1)), relationship$]).pipe(
Expand Down
28 changes: 16 additions & 12 deletions src/app/shared/utils/relation-query.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { followLink, FollowLinkConfig } from './follow-link-config.model';
import { Relationship } from '../../core/shared/item-relationships/relationship.model';
import { Item } from '../../core/shared/item.model';

/**
* Get the query for looking up items by relation type
Expand All @@ -21,19 +22,22 @@ export function getFilterByRelation(relationType: string, itemUUID: string): str
}

/**
* Creates links to follow for the leftItem and rightItem. Links will include
* @param showThumbnail thumbnail image configuration
* @returns followLink array
* Creates links to follow for the leftItem and rightItem. Optionally additional links for `thumbnail` & `accessStatus`
* can be embedded as well.
*
* @param showThumbnail Whether the `thumbnail` needs to be embedded on the {@link Item}
* @param showAccessStatus Whether the `accessStatus` needs to be embedded on the {@link Item}
*/
export function itemLinksToFollow(showThumbnail: boolean): FollowLinkConfig<Relationship>[] {
let linksToFollow: FollowLinkConfig<Relationship>[];
export function itemLinksToFollow(showThumbnail: boolean, showAccessStatus: boolean): FollowLinkConfig<Relationship>[] {
const conditionalLinksToFollow: FollowLinkConfig<Item>[] = [];
if (showThumbnail) {
linksToFollow = [
followLink('leftItem',{}, followLink('thumbnail')),
followLink('rightItem',{}, followLink('thumbnail'))
];
} else {
linksToFollow = [followLink('leftItem'), followLink('rightItem')];
conditionalLinksToFollow.push(followLink<Item>('thumbnail'));
}
return linksToFollow;
if (showAccessStatus) {
conditionalLinksToFollow.push(followLink<Item>('accessStatus'));
}
return [
followLink('leftItem', undefined, ...conditionalLinksToFollow),
followLink('rightItem', undefined, ...conditionalLinksToFollow),
];
}

0 comments on commit b709ee0

Please sign in to comment.