[CST-5668] Retrieve item from route data

This commit is contained in:
Giuseppe Digilio
2022-06-09 19:22:23 +02:00
parent b03c73e0c5
commit c3ececdde7
5 changed files with 146 additions and 105 deletions

View File

@@ -1,71 +1,77 @@
<div class="container custom-accordion mb-4">
<ngb-accordion activeIds="auth">
<ngb-panel title="{{'person.orcid.registry.auth' | translate}}" id="auth">
<ng-template ngbPanelContent>
<div class="container">
<ng-container *ngIf="isLinkedToOrcid(); then orcidLinked; else orcidNotLinked"></ng-container>
</div>
</ng-template>
</ngb-panel>
</ngb-accordion>
<ng-template #orcidLinked>
<div class="row mt-3">
<div *ngIf="getOrcidAuthorizations().length > 0" class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.granted-authorizations'| translate }}</div>
<div class="card-body">
<div class="container">
<ul>
<li *ngFor="let auth of getOrcidAuthorizations()"> {{getAuthorizationDescription(auth) | translate}} </li>
</ul>
<ngb-accordion activeIds="auth">
<ngb-panel title="{{'person.orcid.registry.auth' | translate}}" id="auth">
<ng-template ngbPanelContent>
<div class="container">
<ng-container *ngIf="isLinkedToOrcid(); then orcidLinked; else orcidNotLinked"></ng-container>
</div>
</ng-template>
</ngb-panel>
</ngb-accordion>
<ng-template #orcidLinked>
<div class="row mt-3">
<div *ngIf="getOrcidAuthorizations().length > 0" class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.granted-authorizations'| translate }}</div>
<div class="card-body">
<div class="container">
<ul>
<li *ngFor="let auth of getOrcidAuthorizations()"> {{getAuthorizationDescription(auth) | translate}} </li>
</ul>
</div>
</div>
</div>
<div class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.missing-authorizations'| translate }}</div>
<div class="card-body">
<div class="container">
<div *ngIf="( missingAuthorizations$ | async ).length === 0" class="p-3 mb-2 alert alert-success rounded">
{{'person.page.orcid.no-missing-authorizations-message' | translate}}
</div>
<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>
</ul>
</div>
</div>
</div>
<div class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.missing-authorizations'| translate }}</div>
<div class="card-body">
<div class="container">
<div *ngIf="( missingAuthorizations$ | async ).length === 0" class="p-3 mb-2 alert alert-success rounded">
{{'person.page.orcid.no-missing-authorizations-message' | translate}}
</div>
<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>
</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">
{{ '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>
<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>
</div>
</ng-template>
<ng-template #orcidNotLinked>
<div class="row">
<div class="col-2"><img alt="orcid-logo" src="../../../../assets/images/orcid.logo.icon.svg"/></div>
<div class="alert alert-info col">{{ getOrcidNotLinkedMessage() | async }}</div>
</div>
<div class="row">
<div class="col-md">
<button class="btn btn-primary float-right" (click)="linkOrcid()">
<i class="fas fa-link"></i>
{{'person.page.orcid.link' | translate}}
</button>
</div>
</div>
</ng-template>
</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">
{{ '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>
<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>
</div>
</ng-template>
<ng-template #orcidNotLinked>
<div class="row">
<div class="col-2"><img alt="orcid-logo" src="../../../../assets/images/orcid.logo.icon.svg"/></div>
<div class="alert alert-info col">{{ getOrcidNotLinkedMessage() | async }}</div>
</div>
<div class="row">
<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}}
</button>
</div>
</div>
</ng-template>
</div>

View File

@@ -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() {

View File

@@ -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>

View File

@@ -1,37 +1,64 @@
import {Component, Inject} from '@angular/core';
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 {RemoteData} from '../../core/data/remote-data';
import {Item} from '../../core/shared/item.model';
import {getItemPageRoute} from '../item-page-routing-paths';
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 { 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);
}

View File

@@ -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;
}
}