mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5307] claim item added.
This commit is contained in:
@@ -28,4 +28,6 @@ export enum FeatureID {
|
||||
CanCreateVersion = 'canCreateVersion',
|
||||
CanViewUsageStatistics = 'canViewUsageStatistics',
|
||||
CanSendFeedback = 'canSendFeedback',
|
||||
ShowClaimItem = 'showClaimItem',
|
||||
CanClaimItem = 'canClaimItem',
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@
|
||||
<div class="pl-2">
|
||||
<ds-dso-page-edit-button [pageRoute]="itemPageRoute$ | async" [dso]="item"
|
||||
[tooltipMsg]="'item.page.edit'"></ds-dso-page-edit-button>
|
||||
<button class="edit-button btn btn-dark btn-sm" *ngIf="(isClaimable() | async)" (click)="claim()"> {{"item.page.claim.button" | translate }} </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="simple-view-link my-3" *ngIf="!fromWfi">
|
||||
@@ -42,4 +43,4 @@
|
||||
</div>
|
||||
<ds-error *ngIf="itemRD?.hasFailed" message="{{'error.item' | translate}}"></ds-error>
|
||||
<ds-loading *ngIf="itemRD?.isLoading" message="{{'loading.item' | translate}}"></ds-loading>
|
||||
</div>
|
||||
</div>
|
@@ -16,6 +16,10 @@ import { hasValue } from '../../shared/empty.util';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
import { Location } from '@angular/common';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
|
||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,8 +52,11 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
||||
items: ItemDataService,
|
||||
authService: AuthService,
|
||||
authorizationService: AuthorizationDataService,
|
||||
translate: TranslateService,
|
||||
notificationsService: NotificationsService,
|
||||
researcherProfileService: ResearcherProfileService,
|
||||
private _location: Location) {
|
||||
super(route, router, items, authService, authorizationService);
|
||||
super(route, router, items, authService, authorizationService, translate, notificationsService, researcherProfileService);
|
||||
}
|
||||
|
||||
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
||||
|
@@ -1,20 +1,26 @@
|
||||
import { map } from 'rxjs/operators';
|
||||
import { map, mergeMap, take, tap } from 'rxjs/operators';
|
||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
|
||||
import { fadeInOut } from '../../shared/animations/fade';
|
||||
import { getAllSucceededRemoteDataPayload, redirectOn4xx } from '../../core/shared/operators';
|
||||
import { getAllSucceededRemoteDataPayload, getFirstSucceededRemoteData, redirectOn4xx } from '../../core/shared/operators';
|
||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
import { getItemPageRoute } from '../item-page-routing-paths';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
|
||||
import { ResearcherProfile } from '../../core/profile/model/researcher-profile.model';
|
||||
import { isNotUndefined } from '../../shared/empty.util';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -55,13 +61,27 @@ export class ItemPageComponent implements OnInit {
|
||||
*/
|
||||
isAdmin$: Observable<boolean>;
|
||||
|
||||
itemUrl: string;
|
||||
|
||||
public claimable$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
public isProcessing$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private items: ItemDataService,
|
||||
private authService: AuthService,
|
||||
private authorizationService: AuthorizationDataService
|
||||
) { }
|
||||
private authorizationService: AuthorizationDataService,
|
||||
private translate: TranslateService,
|
||||
private notificationsService: NotificationsService,
|
||||
private researcherProfileService: ResearcherProfileService
|
||||
) {
|
||||
this.route.data.pipe(
|
||||
map((data) => data.dso as RemoteData<Item>)
|
||||
).subscribe((data: RemoteData<Item>) => {
|
||||
this.itemUrl = data?.payload?.self
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
@@ -77,5 +97,56 @@ export class ItemPageComponent implements OnInit {
|
||||
);
|
||||
|
||||
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
|
||||
|
||||
this.authorizationService.isAuthorized(FeatureID.ShowClaimItem, this.itemUrl).pipe(
|
||||
take(1)
|
||||
).subscribe((isAuthorized: boolean) => {
|
||||
this.claimable$.next(isAuthorized)
|
||||
});
|
||||
}
|
||||
|
||||
claim() {
|
||||
this.isProcessing$.next(true);
|
||||
|
||||
this.authorizationService.isAuthorized(FeatureID.CanClaimItem, this.itemUrl).pipe(
|
||||
take(1)
|
||||
).subscribe((isAuthorized: boolean) => {
|
||||
if (!isAuthorized) {
|
||||
this.notificationsService.warning(this.translate.get('researcherprofile.claim.not-authorized'));
|
||||
this.isProcessing$.next(false);
|
||||
} else {
|
||||
this.createFromExternalSource();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
createFromExternalSource() {
|
||||
this.researcherProfileService.createFromExternalSource(this.itemUrl).pipe(
|
||||
tap((rd: any) => {
|
||||
if (!rd.hasSucceeded) {
|
||||
this.isProcessing$.next(false);
|
||||
}
|
||||
}),
|
||||
getFirstSucceededRemoteData(),
|
||||
mergeMap((rd: RemoteData<ResearcherProfile>) => {
|
||||
return this.researcherProfileService.findRelatedItemId(rd.payload);
|
||||
}))
|
||||
.subscribe((id: string) => {
|
||||
if (isNotUndefined(id)) {
|
||||
this.notificationsService.success(this.translate.get('researcherprofile.success.claim.title'),
|
||||
this.translate.get('researcherprofile.success.claim.body'));
|
||||
this.claimable$.next(false);
|
||||
this.isProcessing$.next(false);
|
||||
} else {
|
||||
this.notificationsService.error(
|
||||
this.translate.get('researcherprofile.error.claim.title'),
|
||||
this.translate.get('researcherprofile.error.claim.body'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isClaimable(): Observable<boolean> {
|
||||
return this.claimable$;
|
||||
}
|
||||
}
|
||||
|
@@ -2130,6 +2130,8 @@
|
||||
|
||||
"item.page.version.hasDraft": "A new version cannot be created because there is an inprogress submission in the version history",
|
||||
|
||||
"item.page.claim.button": "Claim",
|
||||
|
||||
"item.preview.dc.identifier.uri": "Identifier:",
|
||||
|
||||
"item.preview.dc.contributor.author": "Authors:",
|
||||
|
Reference in New Issue
Block a user