mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
79327: Fix item-level statistics pages
This commit is contained in:
@@ -15,9 +15,9 @@ import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { AbstractTrackableComponent } from '../../../shared/trackable/abstract-trackable.component';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { getItemPageRoute } from '../../item-page-routing-paths';
|
||||
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../item-page.resolver';
|
||||
import { getAllSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../item.resolver';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-abstract-item-update',
|
||||
|
@@ -12,31 +12,20 @@ import { ResolvedAction } from '../core/resolving/resolver.actions';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
import { getItemPageRoute } from './item-page-routing-paths';
|
||||
import { ItemResolver } from './item.resolver';
|
||||
|
||||
/**
|
||||
* 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', undefined, true, true, true,
|
||||
followLink('parentCommunity', undefined, true, true, true,
|
||||
followLink('parentCommunity'))
|
||||
),
|
||||
followLink('bundles', new FindListOptions(), true, true, true, followLink('bitstreams')),
|
||||
followLink('relationships'),
|
||||
followLink('version', undefined, true, true, true, followLink('versionhistory')),
|
||||
];
|
||||
|
||||
/**
|
||||
* This class represents a resolver that requests a specific item before the route is activated
|
||||
* This class represents a resolver that requests a specific item before the route is activated and will redirect to the
|
||||
* entity page
|
||||
*/
|
||||
@Injectable()
|
||||
export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
||||
export class ItemPageResolver extends ItemResolver {
|
||||
constructor(
|
||||
private itemService: ItemDataService,
|
||||
private store: Store<any>,
|
||||
private router: Router
|
||||
protected itemService: ItemDataService,
|
||||
protected store: Store<any>,
|
||||
protected router: Router
|
||||
) {
|
||||
super(itemService, store, router);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,12 +36,7 @@ export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
||||
* or an error if something went wrong
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
|
||||
const itemRD$ = this.itemService.findById(route.params.id,
|
||||
true,
|
||||
false,
|
||||
...ITEM_PAGE_LINKS_TO_FOLLOW
|
||||
).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
return super.resolve(route, state).pipe(
|
||||
map((rd: RemoteData<Item>) => {
|
||||
if (rd.hasSucceeded && hasValue(rd.payload)) {
|
||||
const itemRoute = getItemPageRoute(rd.payload);
|
||||
@@ -66,11 +50,5 @@ export class ItemPageResolver implements Resolve<RemoteData<Item>> {
|
||||
return rd;
|
||||
})
|
||||
);
|
||||
|
||||
itemRD$.subscribe((itemRD: RemoteData<Item>) => {
|
||||
this.store.dispatch(new ResolvedAction(state.url, itemRD.payload));
|
||||
});
|
||||
|
||||
return itemRD$;
|
||||
}
|
||||
}
|
||||
|
64
src/app/+item-page/item.resolver.ts
Normal file
64
src/app/+item-page/item.resolver.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { ItemDataService } from '../core/data/item-data.service';
|
||||
import { Item } from '../core/shared/item.model';
|
||||
import { followLink, FollowLinkConfig } from '../shared/utils/follow-link-config.model';
|
||||
import { FindListOptions } from '../core/data/request.models';
|
||||
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { ResolvedAction } from '../core/resolving/resolver.actions';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
import { getItemPageRoute } from './item-page-routing-paths';
|
||||
|
||||
/**
|
||||
* 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', undefined, true, true, true,
|
||||
followLink('parentCommunity', undefined, true, true, true,
|
||||
followLink('parentCommunity'))
|
||||
),
|
||||
followLink('bundles', new FindListOptions(), true, true, true, followLink('bitstreams')),
|
||||
followLink('relationships'),
|
||||
followLink('version', undefined, true, true, true, followLink('versionhistory')),
|
||||
];
|
||||
|
||||
/**
|
||||
* This class represents a resolver that requests a specific item before the route is activated
|
||||
*/
|
||||
@Injectable()
|
||||
export class ItemResolver implements Resolve<RemoteData<Item>> {
|
||||
constructor(
|
||||
protected itemService: ItemDataService,
|
||||
protected store: Store<any>,
|
||||
protected router: Router
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for resolving an item based on the parameters in the current route
|
||||
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
|
||||
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
|
||||
* @returns Observable<<RemoteData<Item>> Emits the found item based on the parameters in the current route,
|
||||
* or an error if something went wrong
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
|
||||
const itemRD$ = this.itemService.findById(route.params.id,
|
||||
true,
|
||||
false,
|
||||
...ITEM_PAGE_LINKS_TO_FOLLOW
|
||||
).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
);
|
||||
|
||||
itemRD$.subscribe((itemRD: RemoteData<Item>) => {
|
||||
this.store.dispatch(new ResolvedAction(state.url, itemRD.payload));
|
||||
});
|
||||
|
||||
return itemRD$;
|
||||
}
|
||||
}
|
@@ -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-page.resolver';
|
||||
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../+item-page/item.resolver';
|
||||
|
||||
/**
|
||||
* The class that resolves the BreadcrumbConfig object for an Item
|
||||
|
@@ -10,6 +10,7 @@ import { ThemedCollectionStatisticsPageComponent } from './collection-statistics
|
||||
import { ThemedCommunityStatisticsPageComponent } from './community-statistics-page/themed-community-statistics-page.component';
|
||||
import { ThemedItemStatisticsPageComponent } from './item-statistics-page/themed-item-statistics-page.component';
|
||||
import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed-site-statistics-page.component';
|
||||
import { ItemResolver } from '../+item-page/item.resolver';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -34,7 +35,7 @@ import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed
|
||||
{
|
||||
path: `items/:id`,
|
||||
resolve: {
|
||||
scope: ItemPageResolver,
|
||||
scope: ItemResolver,
|
||||
breadcrumb: I18nBreadcrumbResolver
|
||||
},
|
||||
data: {
|
||||
@@ -75,7 +76,7 @@ import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed
|
||||
I18nBreadcrumbsService,
|
||||
CollectionPageResolver,
|
||||
CommunityPageResolver,
|
||||
ItemPageResolver
|
||||
ItemResolver
|
||||
]
|
||||
})
|
||||
export class StatisticsPageRoutingModule {
|
||||
|
Reference in New Issue
Block a user