[CST-5338] ORCID Settings added.

This commit is contained in:
Pratik Rajkotiya
2022-04-13 17:54:29 +05:30
parent cc08a2829e
commit dd4ff5e40c
5 changed files with 225 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ import { ThemedFileSectionComponent } from './simple/field-components/file-secti
import { OrcidAuthComponent } from './orcid-page/orcid-auth/orcid-auth.component'; import { OrcidAuthComponent } from './orcid-page/orcid-auth/orcid-auth.component';
import { OrcidPageComponent } from './orcid-page/orcid-page.component'; import { OrcidPageComponent } from './orcid-page/orcid-page.component';
import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
import { OrcidSettingComponent } from './orcid-page/orcid-sync/orcid-setting.component';
const ENTRY_COMPONENTS = [ const ENTRY_COMPONENTS = [
@@ -71,7 +72,8 @@ const DECLARATIONS = [
MiradorViewerComponent, MiradorViewerComponent,
VersionPageComponent, VersionPageComponent,
OrcidPageComponent, OrcidPageComponent,
OrcidAuthComponent OrcidAuthComponent,
OrcidSettingComponent
]; ];
@NgModule({ @NgModule({

View File

@@ -1 +1,2 @@
<ds-orcid-auth></ds-orcid-auth> <ds-orcid-auth></ds-orcid-auth>
<ds-orcid-setting></ds-orcid-setting>

View File

@@ -0,0 +1,82 @@
<div class="container custom-accordion mb-4">
<ngb-accordion activeIds="setting">
<ngb-panel title="{{'person.orcid.sync.setting' | translate}}" id="setting">
<ng-template ngbPanelContent>
<div class="container">
<form #f="ngForm" (ngSubmit)="onSubmit(f.form)">
<div class="row alert alert-info">
{{ 'person.page.orcid.synchronization-mode-message' | translate}}
</div>
<div class="row">
<div class="card m-2 p-0 col-md">
<div class="card-header">{{ 'person.page.orcid.synchronization-mode'| translate }}</div>
<div class="card-body">
<div class="container">
<div class="form-group row">
<label for="syncMode">{{ 'person.page.orcid.synchronization-mode.label'| translate }}</label>
<select class="form-control" [(ngModel)]="currentSyncMode" name="syncMode" id="syncMode" required>
<option *ngFor="let syncMode of syncModes" [value]="syncMode.value">{{ syncMode.label | translate }}</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.publications-preferences'| translate }}</div>
<div class="card-body">
<div class="m-3">
<div class="form-group" >
<div *ngFor="let option of syncPublicationOptions" class="row form-check">
<input type="radio" [(ngModel)]="currentSyncPublications"
name="syncPublications" id="publicationOption_{{option.value}}" [value]="option.value" required >
<label for="publicationOption_{{option.value}}" class="ml-2">{{option.label | translate}}</label>
</div>
</div>
</div>
</div>
</div>
<div class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.funding-preferences'| translate }}</div>
<div class="card-body">
<div class="m-3">
<div class="form-group" >
<div *ngFor="let option of syncFundingOptions" class="row form-check">
<input type="radio" [(ngModel)]="currentSyncFundings"
name="syncFundings" id="fundingOption_{{option.value}}" [value]="option.value" required >
<label for="fundingOption_{{option.value}}" class="ml-2">{{option.label | translate}}</label>
</div>
</div>
</div>
</div>
</div>
<div class="card m-2 col-md p-0">
<div class="card-header">{{ 'person.page.orcid.profile-preferences'| translate }}</div>
<div class="card-body">
<div class="m-3">
<div class="form-group" >
<div *ngFor="let option of syncProfileOptions" class="row form-check">
<input type="checkbox" [(ngModel)]="option.checked"
name="syncProfile_{{option.value}}" id="profileOption_{{option.value}}" [value]="option.value" >
<label for="profileOption_{{option.value}}" class="ml-2">{{option.label | translate}}</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md">
<button type="submit" class="btn btn-primary float-right m-2">
<i class="fas fa-edit"></i>
{{ 'person.page.orcid.save.preference.changes' | translate }}
</button>
</div>
</div>
</form>
</div>
</ng-template>
</ngb-panel>
</ngb-accordion>
</div>

View File

@@ -0,0 +1,139 @@
import { Component, 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 { 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 { NotificationsService } from '../../../shared/notifications/notifications.service';
@Component({
selector: 'ds-orcid-setting',
templateUrl: './orcid-setting.component.html',
styleUrls: ['./orcid-setting.component.scss']
})
export class OrcidSettingComponent implements OnInit {
messagePrefix = 'person.page.orcid';
currentSyncMode: string;
currentSyncPublications: string;
currentSyncFundings: string;
syncModes: { value: string, label: string }[];
syncPublicationOptions: { value: string, label: string }[];
syncFundingOptions: {value: string, label: string}[];
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
) {
this.itemService.findById(this.route.snapshot.paramMap.get('id'), true, true).pipe(getFirstCompletedRemoteData()).subscribe((data: RemoteData<Item>) => {
this.item = data.payload;
});
}
ngOnInit() {
this.syncModes = [
{
label: this.messagePrefix + '.synchronization-mode.batch',
value: 'BATCH'
},
{
label: this.messagePrefix + '.synchronization-mode.manual',
value: 'MANUAL'
}
];
this.syncPublicationOptions = ['DISABLED', 'ALL']
.map((value) => {
return {
label: this.messagePrefix + '.sync-publications.' + value.toLowerCase(),
value: value,
};
});
this.syncFundingOptions = ['DISABLED', 'ALL']
.map((value) => {
return {
label: this.messagePrefix + '.sync-fundings.' + value.toLowerCase(),
value: value,
};
});
const syncProfilePreferences = this.item.allMetadataValues('cris.orcid.sync-profile');
this.syncProfileOptions = ['AFFILIATION', 'EDUCATION', 'BIOGRAPHICAL', 'IDENTIFIERS']
.map((value) => {
return {
label: this.messagePrefix + '.sync-profile.' + value.toLowerCase(),
value: value,
checked: syncProfilePreferences.includes(value)
};
});
this.currentSyncMode = this.getCurrentPreference('cris.orcid.sync-mode', ['BATCH, MANUAL'], 'MANUAL');
this.currentSyncPublications = this.getCurrentPreference('cris.orcid.sync-publications', ['DISABLED', 'ALL'], 'DISABLED');
this.currentSyncFundings = this.getCurrentPreference('cris.orcid.sync-fundings', ['DISABLED', 'ALL'], 'DISABLED');
}
onSubmit(form: FormGroup) {
const operations: Operation[] = [];
this.fillOperationsFor(operations, '/orcid/mode', form.value.syncMode);
this.fillOperationsFor(operations, '/orcid/publications', form.value.syncPublications);
this.fillOperationsFor(operations, '/orcid/fundings', form.value.syncFundings);
const syncProfileValue = this.syncProfileOptions
.map((syncProfileOption => syncProfileOption.value))
.filter((value) => form.value['syncProfile_' + value])
.join(',');
this.fillOperationsFor(operations, '/orcid/profile', syncProfileValue);
if (operations.length === 0) {
return;
}
this.researcherProfileService.findById(this.item.firstMetadata('cris.owner').authority).pipe(
switchMap((profile) => this.researcherProfileService.patch(profile, operations)),
getFinishedRemoteData()
).subscribe((remoteData) => {
if (remoteData.isSuccess) {
this.notificationsService.success(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.success'));
} else {
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.synchronization-settings-update.error'));
}
});
}
fillOperationsFor(operations: Operation[], path: string, currentValue: string) {
operations.push({
path: path,
op: 'replace',
value: currentValue
});
}
getCurrentPreference(metadataField: string, allowedValues: string[], defaultValue: string): string {
const currentPreference = this.item.firstMetadataValue(metadataField);
return (currentPreference && allowedValues.includes(currentPreference)) ? currentPreference : defaultValue;
}
}