From 1f26a7b6341e4abf6d3e3fa57cb6377bbd24b9b9 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 30 Mar 2020 12:57:33 +0200 Subject: [PATCH] Show the policies for each bundle and bitstream within the item --- resources/i18n/en.json5 | 2 + .../item-authorizations.component.html | 12 +- .../item-authorizations.component.ts | 106 ++++++++++++++++-- 3 files changed, 111 insertions(+), 9 deletions(-) diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index b350d2c979..e85c374779 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -745,6 +745,8 @@ + "item.edit.authorizations.heading": "With this editor you can view and alter the policies of an item, plus alter policies of individual item components: bundles and bitstreams. Briefly, an item is a container of bundles, and bundles are containers of bitstreams. Containers usually have ADD/REMOVE/READ/WRITE policies, while bitstreams only have READ/WRITE policies.", + "item.edit.authorizations.title": "Edit item's Policies", diff --git a/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.html b/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.html index 4ddf939631..cb22d93868 100644 --- a/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.html +++ b/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.html @@ -1,3 +1,13 @@
- + + + + + + + +
+ diff --git a/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts b/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts index 21971a09d5..e241166a47 100644 --- a/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts +++ b/src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts @@ -1,17 +1,24 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { Observable } from 'rxjs'; -import { flatMap, map } from 'rxjs/operators'; +import { Observable, of as observableOf, Subscription } from 'rxjs'; +import { catchError, filter, first, flatMap, map, take } from 'rxjs/operators'; import { ResourcePolicyService } from '../../../core/resource-policy/resource-policy.service'; import { PaginatedList } from '../../../core/data/paginated-list'; import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; -import { RemoteData } from '../../../core/data/remote-data'; import { Item } from '../../../core/shared/item.model'; import { followLink } from '../../../shared/utils/follow-link-config.model'; import { LinkService } from '../../../core/cache/builders/link.service'; import { Bundle } from '../../../core/shared/bundle.model'; +import { hasValue, isNotEmpty } from '../../../shared/empty.util'; +import { Bitstream } from '../../../core/shared/bitstream.model'; +import { FindListOptions } from '../../../core/data/request.models'; + +interface BundleBitstreamsMapEntry { + id: string; + bitstreams: Observable> +} @Component({ selector: 'ds-item-authorizations', @@ -20,11 +27,35 @@ import { Bundle } from '../../../core/shared/bundle.model'; /** * Component that handles the item Authorizations */ -export class ItemAuthorizationsComponent implements OnInit { +export class ItemAuthorizationsComponent implements OnInit, OnDestroy { - private bundles$: Observable>>; + public bundleBitstreamsMap: Map>> = new Map>>(); + + /** + * The list of bundle for the item + * @type {Observable>} + */ + private bundles$: Observable>; + + /** + * The target editing item + * @type {Observable} + */ private item$: Observable; + /** + * Array to track all subscriptions and unsubscribe them onDestroy + * @type {Array} + */ + private subs: Subscription[] = []; + + /** + * Initialize instance variables + * + * @param {LinkService} linkService + * @param {ResourcePolicyService} resourcePolicyService + * @param {ActivatedRoute} route + */ constructor( private linkService: LinkService, private resourcePolicyService: ResourcePolicyService, @@ -32,15 +63,74 @@ export class ItemAuthorizationsComponent implements OnInit { ) { } + /** + * Initialize the component, setting up the bundle and bitstream within the item + */ ngOnInit(): void { this.item$ = this.route.data.pipe( map((data) => data.item), getFirstSucceededRemoteDataPayload(), - map((item: Item) => this.linkService.resolveLink(item, followLink('bundles'))) + map((item: Item) => this.linkService.resolveLink( + item, + followLink('bundles', new FindListOptions(), true, followLink('bitstreams')) + )) ) as Observable; - this.bundles$ = this.item$.pipe(flatMap((item: Item) => item.bundles)); + this.bundles$ = this.item$.pipe( + filter((item: Item) => isNotEmpty(item.bundles)), + flatMap((item: Item) => item.bundles), + getFirstSucceededRemoteDataPayload(), + catchError(() => observableOf(new PaginatedList(null, []))) + ); + this.subs.push( + this.bundles$.pipe( + take(1), + flatMap((list: PaginatedList) => list.page), + map((bundle: Bundle) => ({ id: bundle.id, bitstreams: this.getBundleBitstreams(bundle) })) + ).subscribe((entry: BundleBitstreamsMapEntry) => { + this.bundleBitstreamsMap.set(entry.id, entry.bitstreams) + }) + ) } + /** + * Return the item's UUID + */ + getItemUUID(): Observable { + return this.item$.pipe( + map((item: Item) => item.id), + first((UUID: string) => isNotEmpty(UUID)) + ) + } + + /** + * Return all item's bundles + * + * @return an observable that emits all item's bundles + */ + getItemBundles(): Observable> { + return this.bundles$ + } + + /** + * Return all bundle's bitstreams + * + * @return an observable that emits all item's bundles + */ + private getBundleBitstreams(bundle: Bundle): Observable> { + return bundle.bitstreams.pipe( + getFirstSucceededRemoteDataPayload(), + catchError(() => observableOf(new PaginatedList(null, []))) + ) + } + + /** + * Unsubscribe from all subscriptions + */ + ngOnDestroy(): void { + this.subs + .filter((subscription) => hasValue(subscription)) + .forEach((subscription) => subscription.unsubscribe()) + } }