mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5668] Retrieve item from route data
This commit is contained in:
@@ -31,23 +31,29 @@
|
||||
<div *ngIf="( missingAuthorizations$ | async ).length > 0" class="p-3 mb-2 alert alert-warning rounded">
|
||||
{{'person.page.orcid.missing-authorizations-message' | translate}}
|
||||
<ul>
|
||||
<li *ngFor="let auth of ( ( missingAuthorizations$ | async ) )"> {{getAuthorizationDescription(auth) | translate }} </li>
|
||||
<li
|
||||
*ngFor="let auth of ( ( missingAuthorizations$ | async ) )"> {{getAuthorizationDescription(auth) | translate }} </li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="(onlyAdminCanDisconnectProfileFromOrcid() | async)" class="row mt-3 p-3 mb-2 bg-info text-white rounded d-flex justify-content-center">
|
||||
<div *ngIf="(onlyAdminCanDisconnectProfileFromOrcid() | async)"
|
||||
class="row mt-3 p-3 mb-2 bg-info text-white rounded d-flex justify-content-center">
|
||||
{{ 'person.page.orcid.remove-orcid-message' | translate}}
|
||||
</div>
|
||||
<div class="row" *ngIf="(ownerCanDisconnectProfileFromOrcid() | async)">
|
||||
<div class="col-md">
|
||||
<button type="submit" class="btn btn-danger float-right m-2" (click)="unlinkOrcid()" [disabled]=unlinkProcessing>
|
||||
<span *ngIf="!unlinkProcessing"><i class="fas fa-unlink"></i> {{ 'person.page.orcid.unlink' | translate }}</span>
|
||||
<span *ngIf="unlinkProcessing"><i class='fas fa-circle-notch fa-spin'></i> {{'person.page.orcid.unlink.processing' | translate}}</span>
|
||||
<button type="submit" class="btn btn-danger float-right m-2" (click)="unlinkOrcid()"
|
||||
[disabled]=unlinkProcessing>
|
||||
<span *ngIf="!unlinkProcessing"><i
|
||||
class="fas fa-unlink"></i> {{ 'person.page.orcid.unlink' | translate }}</span>
|
||||
<span *ngIf="unlinkProcessing"><i
|
||||
class='fas fa-circle-notch fa-spin'></i> {{'person.page.orcid.unlink.processing' | translate}}</span>
|
||||
</button>
|
||||
<button *ngIf="( missingAuthorizations$ | async ).length > 0" type="submit" class="btn btn-primary float-right m-2" (click)="linkOrcid()">
|
||||
<button *ngIf="( missingAuthorizations$ | async ).length > 0" type="submit"
|
||||
class="btn btn-primary float-right m-2" (click)="linkOrcid()">
|
||||
<span><i class="fas fa-check"></i> {{ 'person.page.orcid.grant-authorizations' | translate }}</span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -60,7 +66,7 @@
|
||||
<div class="alert alert-info col">{{ getOrcidNotLinkedMessage() | async }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<div class="col p-0">
|
||||
<button class="btn btn-primary float-right" (click)="linkOrcid()">
|
||||
<i class="fas fa-link"></i>
|
||||
{{'person.page.orcid.link' | translate}}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { Component, Inject, Input, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
@@ -19,12 +19,15 @@ import { NotificationsService } from '../../../shared/notifications/notification
|
||||
})
|
||||
export class OrcidAuthComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* The item for which showing the orcid settings
|
||||
*/
|
||||
@Input() item: Item;
|
||||
|
||||
missingAuthorizations$ = new BehaviorSubject<string[]>([]);
|
||||
|
||||
unlinkProcessing = false;
|
||||
|
||||
item: Item;
|
||||
|
||||
constructor(
|
||||
private configurationService: ConfigurationDataService,
|
||||
private researcherProfileService: ResearcherProfileService,
|
||||
@@ -34,9 +37,6 @@ export class OrcidAuthComponent implements OnInit {
|
||||
private route: ActivatedRoute,
|
||||
@Inject(NativeWindowService) private _window: NativeWindowRef,
|
||||
) {
|
||||
this.itemService.findById(this.route.snapshot.paramMap.get('id'), true, true).pipe(getFirstCompletedRemoteData()).subscribe((data: RemoteData<Item>) => {
|
||||
this.item = data.payload;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
@@ -6,5 +6,5 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ds-orcid-auth></ds-orcid-auth>
|
||||
<ds-orcid-setting *ngIf="isLinkedToOrcid()"></ds-orcid-setting>
|
||||
<ds-orcid-auth *ngIf="item" [item]="item"></ds-orcid-auth>
|
||||
<ds-orcid-setting *ngIf="item && isLinkedToOrcid()" [item]="item"></ds-orcid-setting>
|
||||
|
@@ -1,37 +1,64 @@
|
||||
import {Component, Inject} from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
|
||||
import {ItemDataService} from '../../core/data/item-data.service';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {NativeWindowRef, NativeWindowService} from '../../core/services/window.service';
|
||||
import {getFirstCompletedRemoteData} from '../../core/shared/operators';
|
||||
import { getFirstSucceededRemoteDataPayload } from '../../core/shared/operators';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { getItemPageRoute } from '../item-page-routing-paths';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
import { redirectOn4xx } from '../../core/shared/authorized.operators';
|
||||
|
||||
/**
|
||||
* A component that represents the orcid settings page
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-orcid-page',
|
||||
templateUrl: './orcid-page.component.html',
|
||||
styleUrls: ['./orcid-page.component.scss']
|
||||
})
|
||||
export class OrcidPageComponent {
|
||||
export class OrcidPageComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* The item for which showing the orcid settings
|
||||
*/
|
||||
item: Item;
|
||||
|
||||
constructor(
|
||||
private itemService: ItemDataService,
|
||||
private authService: AuthService,
|
||||
private researcherProfileService: ResearcherProfileService,
|
||||
private route: ActivatedRoute,
|
||||
@Inject(NativeWindowService) private _window: NativeWindowRef,
|
||||
private router: Router
|
||||
) {
|
||||
this.itemService.findById(this.route.snapshot.paramMap.get('id'), true, true).pipe(getFirstCompletedRemoteData()).subscribe((data: RemoteData<Item>) => {
|
||||
this.item = data.payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the item for which showing the orcid settings
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.route.data.pipe(
|
||||
map((data) => data.dso as RemoteData<Item>),
|
||||
redirectOn4xx(this.router, this.authService),
|
||||
getFirstSucceededRemoteDataPayload()
|
||||
).subscribe((item) => {
|
||||
this.item = item;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current item is linked to an ORCID profile.
|
||||
*
|
||||
* @returns the check result
|
||||
*/
|
||||
isLinkedToOrcid(): boolean {
|
||||
return this.researcherProfileService.isLinkedToOrcid(this.item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route to an item's page
|
||||
*/
|
||||
getItemPage(): string {
|
||||
return getItemPageRoute(this.item);
|
||||
}
|
||||
|
@@ -1,16 +1,18 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Operation } from 'fast-json-patch';
|
||||
import { of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from '../../../core/auth/auth.service';
|
||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { ResearcherProfileService } from '../../../core/profile/researcher-profile.service';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { getFinishedRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { ResearcherProfile } from '../../../core/profile/model/researcher-profile.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-orcid-setting',
|
||||
@@ -19,6 +21,11 @@ import { NotificationsService } from '../../../shared/notifications/notification
|
||||
})
|
||||
export class OrcidSettingComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* The item for which showing the orcid settings
|
||||
*/
|
||||
@Input() item: Item;
|
||||
|
||||
messagePrefix = 'person.page.orcid';
|
||||
|
||||
currentSyncMode: string;
|
||||
@@ -35,18 +42,12 @@ export class OrcidSettingComponent implements OnInit {
|
||||
|
||||
syncProfileOptions: { value: string, label: string, checked: boolean }[];
|
||||
|
||||
item: Item;
|
||||
|
||||
constructor(private researcherProfileService: ResearcherProfileService,
|
||||
protected translateService: TranslateService,
|
||||
private notificationsService: NotificationsService,
|
||||
public authService: AuthService,
|
||||
private route: ActivatedRoute,
|
||||
private itemService: ItemDataService
|
||||
public authService: AuthService
|
||||
) {
|
||||
this.itemService.findById(this.route.snapshot.paramMap.get('id'), true, true).pipe(getFirstCompletedRemoteData()).subscribe((data: RemoteData<Item>) => {
|
||||
this.item = data.payload;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -110,10 +111,18 @@ export class OrcidSettingComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
this.researcherProfileService.findById(this.item.firstMetadata('dspace.object.owner').authority).pipe(
|
||||
switchMap((profile) => this.researcherProfileService.patch(profile, operations)),
|
||||
getFinishedRemoteData()
|
||||
).subscribe((remoteData) => {
|
||||
this.researcherProfileService.findByRelatedItem(this.item).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
switchMap((profileRD: RemoteData<ResearcherProfile>) => {
|
||||
if (profileRD.hasSucceeded) {
|
||||
return this.researcherProfileService.updateByOrcidOperations(profileRD.payload, operations).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
);
|
||||
} else {
|
||||
return of(profileRD);
|
||||
}
|
||||
}),
|
||||
).subscribe((remoteData: RemoteData<ResearcherProfile>) => {
|
||||
if (remoteData.isSuccess) {
|
||||
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.success'));
|
||||
} else {
|
||||
@@ -135,5 +144,4 @@ export class OrcidSettingComponent implements OnInit {
|
||||
return (currentPreference && allowedValues.includes(currentPreference)) ? currentPreference : defaultValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user