[CST-5676] Implemented bitstream-breadcrumbs.service

This commit is contained in:
Giuseppe Digilio
2022-04-28 15:41:25 +02:00
parent b8904f5fe1
commit 393a4a3d40
5 changed files with 109 additions and 86 deletions

View File

@@ -11,6 +11,8 @@ import { ResourcePolicyEditComponent } from '../shared/resource-policies/edit/re
import { BitstreamAuthorizationsComponent } from './bitstream-authorizations/bitstream-authorizations.component';
import { LegacyBitstreamUrlResolver } from './legacy-bitstream-url.resolver';
import { BitstreamBreadcrumbResolver } from '../core/breadcrumbs/bitstream-breadcrumb.resolver';
import { BitstreamBreadcrumbsService } from '../core/breadcrumbs/bitstream-breadcrumbs.service';
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
const EDIT_BITSTREAM_PATH = ':id/edit';
const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
@@ -26,8 +28,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
path: 'handle/:prefix/:suffix/:filename',
component: BitstreamDownloadPageComponent,
resolve: {
bitstream: LegacyBitstreamUrlResolver,
breadcrumb: BitstreamBreadcrumbResolver
bitstream: LegacyBitstreamUrlResolver
},
},
{
@@ -35,8 +36,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
path: ':prefix/:suffix/:sequence_id/:filename',
component: BitstreamDownloadPageComponent,
resolve: {
bitstream: LegacyBitstreamUrlResolver,
breadcrumb: BitstreamBreadcrumbResolver
bitstream: LegacyBitstreamUrlResolver
},
},
{
@@ -44,8 +44,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
path: ':id/download',
component: BitstreamDownloadPageComponent,
resolve: {
bitstream: BitstreamPageResolver,
breadcrumb: BitstreamBreadcrumbResolver
bitstream: BitstreamPageResolver
},
},
{
@@ -53,7 +52,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
component: EditBitstreamPageComponent,
resolve: {
bitstream: BitstreamPageResolver,
breadcrumb: BitstreamBreadcrumbResolver
breadcrumb: BitstreamBreadcrumbResolver,
},
canActivate: [AuthenticatedGuard]
},
@@ -64,8 +63,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
{
path: 'create',
resolve: {
resourcePolicyTarget: ResourcePolicyTargetResolver,
breadcrumb: BitstreamBreadcrumbResolver
resourcePolicyTarget: ResourcePolicyTargetResolver
},
component: ResourcePolicyCreateComponent,
data: { title: 'resource-policies.create.page.title', showBreadcrumbs: true }
@@ -73,17 +71,17 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
{
path: 'edit',
resolve: {
resourcePolicy: ResourcePolicyResolver,
breadcrumb: BitstreamBreadcrumbResolver
breadcrumb: I18nBreadcrumbResolver,
resourcePolicy: ResourcePolicyResolver
},
component: ResourcePolicyEditComponent,
data: { title: 'resource-policies.edit.page.title', showBreadcrumbs: true }
data: { breadcrumbKey: 'item.edit', title: 'resource-policies.edit.page.title', showBreadcrumbs: true }
},
{
path: '',
resolve: {
bitstream: BitstreamPageResolver,
breadcrumb: BitstreamBreadcrumbResolver
breadcrumb: BitstreamBreadcrumbResolver,
},
component: BitstreamAuthorizationsComponent,
data: { title: 'bitstream.edit.authorizations.title', showBreadcrumbs: true }
@@ -94,7 +92,8 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
],
providers: [
BitstreamPageResolver,
BitstreamBreadcrumbResolver
BitstreamBreadcrumbResolver,
BitstreamBreadcrumbsService
]
})
export class BitstreamPageRoutingModule {

View File

@@ -17,7 +17,7 @@ import { Bundle } from '../core/shared/bundle.model';
followLink('parentCommunity', {},
followLink('parentCommunity'))
),
followLink('bundle'),
followLink('bundle', {}, followLink('item')),
followLink('thumbnail')
];

View File

@@ -1,22 +1,11 @@
import { Injectable } from '@angular/core';
import { DSOBreadcrumbsService } from './dso-breadcrumbs.service';
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { Bitstream } from '../shared/bitstream.model';
import { BitstreamDataService } from '../data/bitstream-data.service';
import { BITSTREAM_PAGE_LINKS_TO_FOLLOW, BUNDLE_PAGE_LINKS_TO_FOLLOW } from 'src/app/bitstream-page/bitstream-page.resolver';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { BreadcrumbConfig } from 'src/app/breadcrumbs/breadcrumb/breadcrumb-config.model';
import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../shared/operators';
import { map, switchMap } from 'rxjs/operators';
import { hasValue } from 'src/app/shared/empty.util';
import { BITSTREAM_PAGE_LINKS_TO_FOLLOW } from '../../bitstream-page/bitstream-page.resolver';
import { DSOBreadcrumbResolver } from './dso-breadcrumb.resolver';
import { BundleDataService } from '../data/bundle-data.service';
import { Bundle } from '../shared/bundle.model';
import { ItemDataService } from '../data/item-data.service';
import { Item } from '../shared/item.model';
import { ITEM_PAGE_LINKS_TO_FOLLOW } from 'src/app/item-page/item.resolver';
import { DSpaceObject } from '../shared/dspace-object.model';
import { BitstreamBreadcrumbsService } from './bitstream-breadcrumbs.service';
/**
* The class that resolves the BreadcrumbConfig object for an Item
@@ -24,69 +13,19 @@ import { DSpaceObject } from '../shared/dspace-object.model';
@Injectable({
providedIn: 'root'
})
export class BitstreamBreadcrumbResolver extends DSOBreadcrumbResolver<Item> {
export class BitstreamBreadcrumbResolver extends DSOBreadcrumbResolver<Bitstream> {
constructor(
protected breadcrumbService: DSOBreadcrumbsService,
protected bitstreamService: BitstreamDataService,
protected dataService: ItemDataService
) {
protected breadcrumbService: BitstreamBreadcrumbsService, protected dataService: BitstreamDataService) {
super(breadcrumbService, dataService);
}
/**
* Method for resolving a breadcrumb config object
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
* @returns BitstreamBreadcrumbConfig object
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<BreadcrumbConfig<Item>> {
const uuid = route.params.id;
return this.bitstreamService.findById(uuid, true, false, ...this.bfollowLinks).pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
switchMap((bitstream: Bitstream) => {
if (hasValue(bitstream)) {
return bitstream.bundle.pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
switchMap((bundle: Bundle) => {
if (hasValue(bundle)) {
return bundle.item.pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
map((item: Item) => {
if (hasValue(item)) {
console.log(item);
const fullPath = state.url;
const url = fullPath.substr(0, fullPath.indexOf(uuid)) + uuid;
return {provider: this.breadcrumbService, key: item, url: url};
} else {
return undefined;
}
})
);
} else {
return of(undefined);
}
})
);
} else {
return of(undefined);
}
})
);
}
/**
* Method that returns the follow links to already resolve
* 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
*/
get followLinks(): FollowLinkConfig<Item>[] {
return ITEM_PAGE_LINKS_TO_FOLLOW;
get followLinks(): FollowLinkConfig<Bitstream>[] {
return BITSTREAM_PAGE_LINKS_TO_FOLLOW;
}
get bfollowLinks(): FollowLinkConfig<Bitstream>[] {
return [followLink('bundle', followLink('item'))];
}
}

View File

@@ -0,0 +1,85 @@
import { Injectable } from '@angular/core';
import { Observable, of as observableOf } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
import { DSONameService } from './dso-name.service';
import { ChildHALResource } from '../shared/child-hal-resource.model';
import { LinkService } from '../cache/builders/link.service';
import { DSpaceObject } from '../shared/dspace-object.model';
import { RemoteData } from '../data/remote-data';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { getDSORoute } from '../../app-routing-paths';
import { DSOBreadcrumbsService } from './dso-breadcrumbs.service';
import { BitstreamDataService } from '../data/bitstream-data.service';
import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../shared/operators';
import { Bitstream } from '../shared/bitstream.model';
import { Bundle } from '../shared/bundle.model';
import { Item } from '../shared/item.model';
import { BITSTREAM_PAGE_LINKS_TO_FOLLOW } from '../../bitstream-page/bitstream-page.resolver';
/**
* Service to calculate DSpaceObject breadcrumbs for a single part of the route
*/
@Injectable({
providedIn: 'root'
})
export class BitstreamBreadcrumbsService extends DSOBreadcrumbsService {
constructor(
protected bitstreamService: BitstreamDataService,
protected linkService: LinkService,
protected dsoNameService: DSONameService
) {
super(linkService, dsoNameService);
}
/**
* Method to recursively calculate the breadcrumbs
* This method returns the name and url of the key and all its parent DSOs recursively, top down
* @param key The key (a DSpaceObject) used to resolve the breadcrumb
* @param url The url to use as a link for this breadcrumb
*/
getBreadcrumbs(key: ChildHALResource & DSpaceObject, url: string): Observable<Breadcrumb[]> {
const label = this.dsoNameService.getName(key);
const crumb = new Breadcrumb(label, url);
return this.getOwningItem(key.uuid).pipe(
switchMap((parentRD: RemoteData<ChildHALResource & DSpaceObject>) => {
if (isNotEmpty(parentRD) && hasValue(parentRD.payload)) {
const parent = parentRD.payload;
return super.getBreadcrumbs(parent, getDSORoute(parent));
}
return observableOf([]);
}),
map((breadcrumbs: Breadcrumb[]) => [...breadcrumbs, crumb])
);
}
getOwningItem(uuid: string): Observable<RemoteData<Item>> {
return this.bitstreamService.findById(uuid, true, true, ...BITSTREAM_PAGE_LINKS_TO_FOLLOW).pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
switchMap((bitstream: Bitstream) => {
if (hasValue(bitstream)) {
return bitstream.bundle.pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
switchMap((bundle: Bundle) => {
if (hasValue(bundle)) {
return bundle.item.pipe(
getFirstCompletedRemoteData(),
);
} else {
return observableOf(undefined);
}
})
);
} else {
return observableOf(undefined);
}
})
);
}
}

View File

@@ -20,8 +20,8 @@ import { getDSORoute } from '../../app-routing-paths';
})
export class DSOBreadcrumbsService implements BreadcrumbsProviderService<ChildHALResource & DSpaceObject> {
constructor(
private linkService: LinkService,
private dsoNameService: DSONameService
protected linkService: LinkService,
protected dsoNameService: DSONameService
) {
}