From b5e1394fce6aed7dc4f142358049c7d9f5539df8 Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Mon, 4 May 2020 17:38:31 +0200 Subject: [PATCH] 65272: Post-merge fixes --- .../edit-item-template-page.component.ts | 2 +- .../item-template-page.resolver.ts | 3 ++- .../models/normalized-template-item.model.ts | 22 ------------------ src/app/core/data/data.service.ts | 11 +++++++-- .../core/data/item-template-data.service.ts | 23 +++++++++++-------- src/app/core/shared/template-item.model.ts | 10 ++++++-- .../shared/template-item.resource-type.ts | 9 ++++++++ 7 files changed, 42 insertions(+), 38 deletions(-) delete mode 100644 src/app/core/cache/models/normalized-template-item.model.ts create mode 100644 src/app/core/shared/template-item.resource-type.ts diff --git a/src/app/+collection-page/edit-item-template-page/edit-item-template-page.component.ts b/src/app/+collection-page/edit-item-template-page/edit-item-template-page.component.ts index 0170ab620b..d4b49ef280 100644 --- a/src/app/+collection-page/edit-item-template-page/edit-item-template-page.component.ts +++ b/src/app/+collection-page/edit-item-template-page/edit-item-template-page.component.ts @@ -26,7 +26,7 @@ export class EditItemTemplatePageComponent implements OnInit { } ngOnInit(): void { - this.collectionRD$ = this.route.data.pipe(first(), map((data) => data.collection)); + this.collectionRD$ = this.route.parent.data.pipe(first(), map((data) => data.dso)); } /** diff --git a/src/app/+collection-page/edit-item-template-page/item-template-page.resolver.ts b/src/app/+collection-page/edit-item-template-page/item-template-page.resolver.ts index 07ccfd9eee..919e131836 100644 --- a/src/app/+collection-page/edit-item-template-page/item-template-page.resolver.ts +++ b/src/app/+collection-page/edit-item-template-page/item-template-page.resolver.ts @@ -6,6 +6,7 @@ import { ItemTemplateDataService } from '../../core/data/item-template-data.serv import { Observable } from 'rxjs/internal/Observable'; import { find } from 'rxjs/operators'; import { hasValue } from '../../shared/empty.util'; +import { followLink } from '../../shared/utils/follow-link-config.model'; /** * This class represents a resolver that requests a specific collection's item template before the route is activated @@ -23,7 +24,7 @@ export class ItemTemplatePageResolver implements Resolve> { * or an error if something went wrong */ resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable> { - return this.itemTemplateService.findByCollectionID(route.params.id).pipe( + return this.itemTemplateService.findByCollectionID(route.params.id, followLink('templateItemOf')).pipe( find((RD) => hasValue(RD.error) || RD.hasSucceeded), ); } diff --git a/src/app/core/cache/models/normalized-template-item.model.ts b/src/app/core/cache/models/normalized-template-item.model.ts deleted file mode 100644 index 7a3259d74d..0000000000 --- a/src/app/core/cache/models/normalized-template-item.model.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { inheritSerialization, deserialize } from 'cerialize'; - -import { mapsTo, relationship } from '../builders/build-decorators'; -import { TemplateItem } from '../../shared/template-item.model'; -import { NormalizedItem } from './normalized-item.model'; -import { Collection } from '../../shared/collection.model'; - -/** - * Normalized model class for a DSpace Template Item - */ -@mapsTo(TemplateItem) -@inheritSerialization(NormalizedItem) -export class NormalizedTemplateItem extends NormalizedItem { - - /** - * The Collection that this item is a template for - */ - @deserialize - @relationship(Collection, false) - templateItemOf: string; - -} diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 0860bc5915..ff228e08fc 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -75,6 +75,13 @@ export abstract class DataService implements UpdateDa * @returns {Observable} */ getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable { + return this.getEndpoint(); + } + + /** + * Get the base endpoint for all requests + */ + protected getEndpoint(): Observable { return this.halService.getEndpoint(this.linkPath); } @@ -238,7 +245,7 @@ export abstract class DataService implements UpdateDa * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved */ getIDHrefObs(resourceID: string, ...linksToFollow: Array>): Observable { - return this.getBrowseEndpoint().pipe( + return this.getEndpoint().pipe( map((endpoint: string) => this.getIDHref(endpoint, resourceID, ...linksToFollow))); } @@ -395,7 +402,7 @@ export abstract class DataService implements UpdateDa */ create(dso: T, parentUUID?: string): Observable> { const requestId = this.requestService.generateRequestId(); - const endpoint$ = this.getBrowseEndpoint().pipe( + const endpoint$ = this.getEndpoint().pipe( isNotEmptyOperator(), distinctUntilChanged(), map((endpoint: string) => parentUUID ? `${endpoint}?parent=${parentUUID}` : endpoint) diff --git a/src/app/core/data/item-template-data.service.ts b/src/app/core/data/item-template-data.service.ts index aaa664d7ec..69e7ae91b1 100644 --- a/src/app/core/data/item-template-data.service.ts +++ b/src/app/core/data/item-template-data.service.ts @@ -8,7 +8,6 @@ import { Observable } from 'rxjs/internal/Observable'; import { DSOChangeAnalyzer } from './dso-change-analyzer.service'; import { RequestService } from './request.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; -import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; import { Store } from '@ngrx/store'; import { CoreState } from '../core.reducers'; import { ObjectCacheService } from '../cache/object-cache.service'; @@ -18,6 +17,8 @@ import { HttpClient } from '@angular/common/http'; import { BrowseService } from '../browse/browse.service'; import { CollectionDataService } from './collection-data.service'; import { switchMap } from 'rxjs/operators'; +import { BundleDataService } from './bundle-data.service'; +import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; /* tslint:disable:max-classes-per-file */ /** @@ -41,7 +42,6 @@ class DataServiceImpl extends ItemDataService { constructor( protected requestService: RequestService, protected rdbService: RemoteDataBuildService, - protected dataBuildService: NormalizedObjectBuildService, protected store: Store, protected bs: BrowseService, protected objectCache: ObjectCacheService, @@ -49,8 +49,9 @@ class DataServiceImpl extends ItemDataService { protected notificationsService: NotificationsService, protected http: HttpClient, protected comparator: DSOChangeAnalyzer, + protected bundleService: BundleDataService, protected collectionService: CollectionDataService) { - super(requestService, rdbService, dataBuildService, store, bs, objectCache, halService, notificationsService, http, comparator); + super(requestService, rdbService, store, bs, objectCache, halService, notificationsService, http, comparator, bundleService); } /** @@ -96,10 +97,11 @@ class DataServiceImpl extends ItemDataService { /** * Set the collection ID and send a find by ID request * @param collectionID + * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved */ - findByCollectionID(collectionID: string): Observable> { + findByCollectionID(collectionID: string, ...linksToFollow: Array>): Observable> { this.setCollectionEndpoint(collectionID); - return super.findById(collectionID); + return super.findById(collectionID, ...linksToFollow); } /** @@ -119,7 +121,7 @@ class DataServiceImpl extends ItemDataService { */ deleteByCollectionID(item: Item, collectionID: string): Observable { this.setRegularEndpoint(); - return super.delete(item); + return super.delete(item.uuid); } } @@ -136,7 +138,6 @@ export class ItemTemplateDataService implements UpdateDataService { constructor( protected requestService: RequestService, protected rdbService: RemoteDataBuildService, - protected dataBuildService: NormalizedObjectBuildService, protected store: Store, protected bs: BrowseService, protected objectCache: ObjectCacheService, @@ -144,8 +145,9 @@ export class ItemTemplateDataService implements UpdateDataService { protected notificationsService: NotificationsService, protected http: HttpClient, protected comparator: DSOChangeAnalyzer, + protected bundleService: BundleDataService, protected collectionService: CollectionDataService) { - this.dataService = new DataServiceImpl(requestService, rdbService, dataBuildService, store, bs, objectCache, halService, notificationsService, http, comparator, collectionService); + this.dataService = new DataServiceImpl(requestService, rdbService, store, bs, objectCache, halService, notificationsService, http, comparator, bundleService, collectionService); } /** @@ -165,9 +167,10 @@ export class ItemTemplateDataService implements UpdateDataService { /** * Find an item template by collection ID * @param collectionID + * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved */ - findByCollectionID(collectionID: string): Observable> { - return this.dataService.findByCollectionID(collectionID); + findByCollectionID(collectionID: string, ...linksToFollow: Array>): Observable> { + return this.dataService.findByCollectionID(collectionID, ...linksToFollow); } /** diff --git a/src/app/core/shared/template-item.model.ts b/src/app/core/shared/template-item.model.ts index ef60c6906e..bfcf941e41 100644 --- a/src/app/core/shared/template-item.model.ts +++ b/src/app/core/shared/template-item.model.ts @@ -1,18 +1,24 @@ +import { inheritSerialization } from 'cerialize'; import { Item } from './item.model'; import { Observable } from 'rxjs/internal/Observable'; import { RemoteData } from '../data/remote-data'; import { Collection } from './collection.model'; -import { ResourceType } from './resource-type'; +import { ITEM_TEMPLATE } from './template-item.resource-type'; +import { link, typedObject } from '../cache/builders/build-decorators'; +import { COLLECTION } from './collection.resource-type'; /** * Class representing a DSpace Template Item */ +@typedObject +@inheritSerialization(Item) export class TemplateItem extends Item { - static type = new ResourceType('itemtemplate'); + static type = ITEM_TEMPLATE; /** * The Collection that this item is a template for */ + @link(COLLECTION) templateItemOf: Observable>; } diff --git a/src/app/core/shared/template-item.resource-type.ts b/src/app/core/shared/template-item.resource-type.ts new file mode 100644 index 0000000000..06692d8cc7 --- /dev/null +++ b/src/app/core/shared/template-item.resource-type.ts @@ -0,0 +1,9 @@ +import { ResourceType } from './resource-type'; + +/** + * The resource type for TemplateItem. + * + * Needs to be in a separate file to prevent circular + * dependencies in webpack. + */ +export const ITEM_TEMPLATE = new ResourceType('itemtemplate');