Skip to content

Commit

Permalink
Merge pull request #1182 from atmire/w2p-79327_Fix-item-level-statistics
Browse files Browse the repository at this point in the history
Fix item-level statistics pages
  • Loading branch information
tdonohue authored May 24, 2021
2 parents 8daf52e + 579f98d commit f85a5e6
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 45 deletions.
36 changes: 36 additions & 0 deletions e2e/src/item-statistics/item-statistics.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ProtractorPage } from './item-statistics.po';
import { browser } from 'protractor';
import { UIURLCombiner } from '../../../src/app/core/url-combiner/ui-url-combiner';

describe('protractor Item statics', () => {
let page: ProtractorPage;

beforeEach(() => {
page = new ProtractorPage();
});

it('should contain element ds-item-page when navigating when navigating to an item page', () => {
page.navigateToItemPage();
expect<any>(page.elementTagExists('ds-item-page')).toEqual(true);
expect<any>(page.elementTagExists('ds-item-statistics-page')).toEqual(false);
});

it('should redirect to the entity page when navigating to an item page', () => {
page.navigateToItemPage();
expect(browser.getCurrentUrl()).toEqual(new UIURLCombiner(page.ENTITYPAGE).toString());
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMSTATISTICSPAGE).toString());
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMPAGE).toString());
});

it('should contain element ds-item-statistics-page when navigating when navigating to an item statistics page', () => {
page.navigateToItemStatisticsPage();
expect<any>(page.elementTagExists('ds-item-statistics-page')).toEqual(true);
expect<any>(page.elementTagExists('ds-item-page')).toEqual(false);
});
it('should contain the item statistics page url when navigating to an item statistics page', () => {
page.navigateToItemStatisticsPage();
expect(browser.getCurrentUrl()).toEqual(new UIURLCombiner(page.ITEMSTATISTICSPAGE).toString());
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ENTITYPAGE).toString());
expect(browser.getCurrentUrl()).not.toEqual(new UIURLCombiner(page.ITEMPAGE).toString());
});
});
18 changes: 18 additions & 0 deletions e2e/src/item-statistics/item-statistics.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { browser, element, by } from 'protractor';

export class ProtractorPage {
ITEMPAGE = '/items/e98b0f27-5c19-49a0-960d-eb6ad5287067';
ENTITYPAGE = '/entities/publication/e98b0f27-5c19-49a0-960d-eb6ad5287067';
ITEMSTATISTICSPAGE = '/statistics/items/e98b0f27-5c19-49a0-960d-eb6ad5287067';

navigateToItemPage() {
return browser.get(this.ITEMPAGE);
}
navigateToItemStatisticsPage() {
return browser.get(this.ITEMSTATISTICSPAGE);
}

elementTagExists(tag: string) {
return element(by.tagName(tag)).isPresent();
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
},
"private": true,
"resolutions": {
"minimist": "^1.2.5"
"minimist": "^1.2.5",
"webdriver-manager": "^12.1.8"
},
"dependencies": {
"@angular/animations": "~10.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
44 changes: 9 additions & 35 deletions src/app/+item-page/item-page.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,24 @@ 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';
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);
}

/**
Expand All @@ -47,12 +32,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);
Expand All @@ -66,11 +46,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$;
}
}
61 changes: 61 additions & 0 deletions src/app/+item-page/item.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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';

/**
* 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$;
}
}
2 changes: 1 addition & 1 deletion 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-page.resolver';
import { ITEM_PAGE_LINKS_TO_FOLLOW } from '../../+item-page/item.resolver';

/**
* The class that resolves the BreadcrumbConfig object for an Item
Expand Down
6 changes: 3 additions & 3 deletions src/app/statistics-page/statistics-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { RouterModule } from '@angular/router';
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
import { I18nBreadcrumbsService } from '../core/breadcrumbs/i18n-breadcrumbs.service';
import { StatisticsPageModule } from './statistics-page.module';
import { ItemPageResolver } from '../+item-page/item-page.resolver';
import { CollectionPageResolver } from '../+collection-page/collection-page.resolver';
import { CommunityPageResolver } from '../+community-page/community-page.resolver';
import { ThemedCollectionStatisticsPageComponent } from './collection-statistics-page/themed-collection-statistics-page.component';
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: [
Expand All @@ -34,7 +34,7 @@ import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed
{
path: `items/:id`,
resolve: {
scope: ItemPageResolver,
scope: ItemResolver,
breadcrumb: I18nBreadcrumbResolver
},
data: {
Expand Down Expand Up @@ -75,7 +75,7 @@ import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed
I18nBreadcrumbsService,
CollectionPageResolver,
CommunityPageResolver,
ItemPageResolver
ItemResolver
]
})
export class StatisticsPageRoutingModule {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11933,10 +11933,10 @@ webdriver-js-extender@2.1.0:
"@types/selenium-webdriver" "^3.0.0"
selenium-webdriver "^3.0.1"

webdriver-manager@^12.1.7:
version "12.1.7"
resolved "https://registry.yarnpkg.com/webdriver-manager/-/webdriver-manager-12.1.7.tgz#ed4eaee8f906b33c146e869b55e850553a1b1162"
integrity sha512-XINj6b8CYuUYC93SG3xPkxlyUc3IJbD6Vvo75CVGuG9uzsefDzWQrhz0Lq8vbPxtb4d63CZdYophF8k8Or/YiA==
webdriver-manager@^12.1.7, webdriver-manager@^12.1.8:
version "12.1.8"
resolved "https://registry.yarnpkg.com/webdriver-manager/-/webdriver-manager-12.1.8.tgz#5e70e73eaaf53a0767d5745270addafbc5905fd4"
integrity sha512-qJR36SXG2VwKugPcdwhaqcLQOD7r8P2Xiv9sfNbfZrKBnX243iAkOueX1yAmeNgIKhJ3YAT/F2gq6IiEZzahsg==
dependencies:
adm-zip "^0.4.9"
chalk "^1.1.1"
Expand Down

0 comments on commit f85a5e6

Please sign in to comment.