Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,542 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="container"> | ||
<ds-alert [type]="'alert-info'" [content]="'item.edit.authorizations.heading'"></ds-alert> | ||
<ds-resource-policies [resourceType]="'item'" [resourceUUID]="(getItemUUID() | async)"></ds-resource-policies> | ||
<ng-container *ngFor="let bundle of (getItemBundles() | async); trackById"> | ||
<ds-resource-policies [resourceType]="'bundle'" | ||
[resourceUUID]="bundle.id"></ds-resource-policies> | ||
<ng-container *ngFor="let bitstream of (bundleBitstreamsMap.get(bundle.id) | async)?.page; trackById"> | ||
<ds-resource-policies [resourceType]="'bitstream'" | ||
[resourceUUID]="bitstream.id"></ds-resource-policies> | ||
</ng-container> | ||
</ng-container> | ||
</div> | ||
|
9 changes: 9 additions & 0 deletions
9
src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ComponentFixture } from '@angular/core/testing'; | ||
|
||
import { ItemAuthorizationsComponent } from './item-authorizations.component'; | ||
|
||
describe('ItemAuthorizationsComponent', () => { | ||
// let comp: ItemAuthorizationsComponent; | ||
// let fixture: ComponentFixture<ItemAuthorizationsComponent>; | ||
|
||
}); |
148 changes: 148 additions & 0 deletions
148
src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
import { BehaviorSubject, 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, | ||
getFirstSucceededRemoteDataWithNotEmptyPayload | ||
} from '../../../core/shared/operators'; | ||
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 for a bundle's bitstream map entry | ||
*/ | ||
interface BundleBitstreamsMapEntry { | ||
id: string; | ||
bitstreams: Observable<PaginatedList<Bitstream>> | ||
} | ||
|
||
@Component({ | ||
selector: 'ds-item-authorizations', | ||
templateUrl: './item-authorizations.component.html' | ||
}) | ||
/** | ||
* Component that handles the item Authorizations | ||
*/ | ||
export class ItemAuthorizationsComponent implements OnInit, OnDestroy { | ||
|
||
public bundleBitstreamsMap: Map<string, Observable<PaginatedList<Bitstream>>> = new Map<string, Observable<PaginatedList<Bitstream>>>(); | ||
|
||
/** | ||
* The list of bundle for the item | ||
* @type {Observable<PaginatedList<Bundle>>} | ||
*/ | ||
private bundles$: BehaviorSubject<Bundle[]> = new BehaviorSubject<Bundle[]>([]); | ||
|
||
/** | ||
* The target editing item | ||
* @type {Observable<Item>} | ||
*/ | ||
private item$: Observable<Item>; | ||
|
||
/** | ||
* 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, | ||
private route: ActivatedRoute | ||
) { | ||
} | ||
|
||
/** | ||
* Initialize the component, setting up the bundle and bitstream within the item | ||
*/ | ||
ngOnInit(): void { | ||
this.item$ = this.route.data.pipe( | ||
map((data) => data.item), | ||
getFirstSucceededRemoteDataWithNotEmptyPayload(), | ||
map((item: Item) => this.linkService.resolveLink( | ||
item, | ||
followLink('bundles', new FindListOptions(), true, followLink('bitstreams')) | ||
)) | ||
) as Observable<Item>; | ||
|
||
const bundles$: Observable<PaginatedList<Bundle>> = this.item$.pipe( | ||
filter((item: Item) => isNotEmpty(item.bundles)), | ||
flatMap((item: Item) => item.bundles), | ||
getFirstSucceededRemoteDataWithNotEmptyPayload(), | ||
catchError(() => observableOf(new PaginatedList(null, []))) | ||
); | ||
|
||
this.subs.push( | ||
bundles$.pipe( | ||
take(1), | ||
map((list: PaginatedList<Bundle>) => list.page) | ||
).subscribe((bundles: Bundle[]) => { | ||
this.bundles$.next(bundles); | ||
}), | ||
bundles$.pipe( | ||
take(1), | ||
flatMap((list: PaginatedList<Bundle>) => 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<string> { | ||
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<Bundle[]> { | ||
return this.bundles$.asObservable(); | ||
} | ||
|
||
/** | ||
* Return all bundle's bitstreams | ||
* | ||
* @return an observable that emits all item's bundles | ||
*/ | ||
private getBundleBitstreams(bundle: Bundle): Observable<PaginatedList<Bitstream>> { | ||
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.