From c3ececdde714ab880b1918d41adb718c74d1fc8a Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 9 Jun 2022 19:22:23 +0200 Subject: [PATCH] [CST-5668] Retrieve item from route data --- .../orcid-auth/orcid-auth.component.html | 140 +++++++++--------- .../orcid-auth/orcid-auth.component.ts | 12 +- .../orcid-page/orcid-page.component.html | 4 +- .../orcid-page/orcid-page.component.ts | 55 +++++-- .../orcid-sync/orcid-setting.component.ts | 40 +++-- 5 files changed, 146 insertions(+), 105 deletions(-) diff --git a/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.html b/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.html index 8e538b66aa..12b13c433c 100644 --- a/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.html +++ b/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.html @@ -1,71 +1,77 @@
- - - -
- -
-
-
-
- - -
-
-
{{ 'person.page.orcid.granted-authorizations'| translate }}
-
-
-
    -
  • {{getAuthorizationDescription(auth) | translate}}
  • -
+ + + +
+ +
+
+
+
+ + +
+
+
{{ 'person.page.orcid.granted-authorizations'| translate }}
+
+
+
    +
  • {{getAuthorizationDescription(auth) | translate}}
  • +
+
+
+
+
+
{{ 'person.page.orcid.missing-authorizations'| translate }}
+
+
+
+ {{'person.page.orcid.no-missing-authorizations-message' | translate}}
+
+ {{'person.page.orcid.missing-authorizations-message' | translate}} +
    +
  • {{getAuthorizationDescription(auth) | translate }}
  • +
+
-
-
{{ 'person.page.orcid.missing-authorizations'| translate }}
-
-
-
- {{'person.page.orcid.no-missing-authorizations-message' | translate}} -
-
- {{'person.page.orcid.missing-authorizations-message' | translate}} -
    -
  • {{getAuthorizationDescription(auth) | translate }}
  • -
-
-
-
-
-
-
- {{ 'person.page.orcid.remove-orcid-message' | translate}} -
-
-
- - -
-
- - - -
-
orcid-logo
-
{{ getOrcidNotLinkedMessage() | async }}
-
-
-
- -
-
-
-
\ No newline at end of file +
+
+
+ {{ 'person.page.orcid.remove-orcid-message' | translate}} +
+
+
+ + +
+
+ + + +
+
orcid-logo
+
{{ getOrcidNotLinkedMessage() | async }}
+
+
+
+ +
+
+
+
diff --git a/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.ts b/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.ts index 0f368ada2f..aa234648f0 100644 --- a/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.ts +++ b/src/app/item-page/orcid-page/orcid-auth/orcid-auth.component.ts @@ -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([]); 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) => { - this.item = data.payload; - }); } ngOnInit() { diff --git a/src/app/item-page/orcid-page/orcid-page.component.html b/src/app/item-page/orcid-page/orcid-page.component.html index 296d5468c5..c105ba6127 100644 --- a/src/app/item-page/orcid-page/orcid-page.component.html +++ b/src/app/item-page/orcid-page/orcid-page.component.html @@ -6,5 +6,5 @@
- - + + diff --git a/src/app/item-page/orcid-page/orcid-page.component.ts b/src/app/item-page/orcid-page/orcid-page.component.ts index 3c464596b1..122c199f61 100644 --- a/src/app/item-page/orcid-page/orcid-page.component.ts +++ b/src/app/item-page/orcid-page/orcid-page.component.ts @@ -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) => { - 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), + 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); } diff --git a/src/app/item-page/orcid-page/orcid-sync/orcid-setting.component.ts b/src/app/item-page/orcid-page/orcid-sync/orcid-setting.component.ts index 00a6018892..2429ac2e43 100644 --- a/src/app/item-page/orcid-page/orcid-sync/orcid-setting.component.ts +++ b/src/app/item-page/orcid-page/orcid-sync/orcid-setting.component.ts @@ -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) => { - 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) => { + if (profileRD.hasSucceeded) { + return this.researcherProfileService.updateByOrcidOperations(profileRD.payload, operations).pipe( + getFirstCompletedRemoteData() + ); + } else { + return of(profileRD); + } + }), + ).subscribe((remoteData: RemoteData) => { 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; } - }