@kit-data-manager/pid-component
Version:
The PID-Component is a web component that can be used to evaluate and display FAIR Digital Objects, PIDs, ORCiDs, and possibly other identifiers in a user-friendly way. It is easily extensible to support other identifier types.
139 lines (138 loc) • 8.25 kB
JavaScript
/*!
*
* Copyright 2024 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { h } from "@stencil/core";
import { GenericIdentifierType } from "../../utils/GenericIdentifierType";
import { ORCIDInfo } from "./ORCIDInfo";
import { FoldableItem } from "../../utils/FoldableItem";
import { FoldableAction } from "../../utils/FoldableAction";
export class ORCIDType extends GenericIdentifierType {
constructor() {
super(...arguments);
this.affiliationAt = new Date(Date.now());
this.showAffiliation = true;
}
get data() {
return JSON.stringify(this._orcidInfo.toObject());
}
hasCorrectFormat() {
return ORCIDInfo.isORCiD(this.value);
}
async init(data) {
if (data !== undefined) {
this._orcidInfo = ORCIDInfo.fromJSON(data);
console.debug('reload ORCIDInfo from data', this._orcidInfo);
}
else {
this._orcidInfo = await ORCIDInfo.getORCiDInfo(this.value);
console.debug('load ORCIDInfo from API', this._orcidInfo);
}
if (this.settings) {
for (const i of this.settings) {
switch (i['name']) {
case 'affiliationAt':
this.affiliationAt = new Date(i['value']);
break;
case 'showAffiliation':
this.showAffiliation = i['value'];
break;
}
}
}
this.items.push(new FoldableItem(0, 'ORCiD', this._orcidInfo.orcid, 'ORCiD is a free service for researchers to distinguish themselves by creating a unique personal identifier.', 'https://orcid.org', undefined, true));
try {
const familyName = this._orcidInfo.familyName;
if (familyName) {
new FoldableItem(1, 'Family Name', this._orcidInfo.familyName, 'The family name of the person.');
}
}
catch (e) {
console.log('Failed to obtain family name from ORCiD record.', e);
}
try {
const givenNames = this._orcidInfo.givenNames;
if (givenNames) {
new FoldableItem(2, 'Given Names', this._orcidInfo.givenNames.toString(), 'The given names of the person.');
}
}
catch (e) {
console.log('Failed to obtain given names from ORCiD record.', e);
}
this.actions.push(new FoldableAction(0, 'Open ORCiD profile', `https://orcid.org/${this._orcidInfo.orcid}`, 'primary'));
try {
const affiliations = this._orcidInfo.getAffiliationsAt(new Date(Date.now()));
for (const data of affiliations) {
const affiliation = this._orcidInfo.getAffiliationAsString(data);
if (affiliation !== undefined && affiliation.length > 2)
this.items.push(new FoldableItem(50, 'Current Affiliation', affiliation, 'The current affiliation of the person.', undefined, undefined, false));
}
}
catch (e) {
console.log('Failed to obtain affiliations from ORCiD record.', e);
}
if (this._orcidInfo.getAffiliationsAt(this.affiliationAt) !== this._orcidInfo.getAffiliationsAt(new Date()) &&
this.affiliationAt.toLocaleDateString('en-US') !== new Date().toLocaleDateString('en-US')) {
const affiliationsThen = this._orcidInfo.getAffiliationsAt(this.affiliationAt);
for (const data of affiliationsThen) {
const affiliation = this._orcidInfo.getAffiliationAsString(data);
this.items.push(new FoldableItem(49, 'Affiliation at ' +
this.affiliationAt.toLocaleDateString('en-US', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
}), affiliation, 'The affiliation of the person at the given date.', undefined, undefined, false));
}
}
if (this._orcidInfo.emails) {
const primary = this._orcidInfo.emails.filter(email => email.primary)[0];
const other = this._orcidInfo.emails.filter(email => !email.primary);
if (primary) {
this.items.push(new FoldableItem(20, 'Primary E-Mail address', primary.email, 'The primary e-mail address of the person.'));
this.actions.push(new FoldableAction(0, 'Send E-Mail', `mailto:${primary.email}`, 'secondary'));
}
if (other.length > 0)
this.items.push(new FoldableItem(70, 'Other E-Mail addresses', other.map(email => email.email).join(', '), 'All other e-mail addresses of the person.'));
if (this._orcidInfo.preferredLocale)
this.items.push(new FoldableItem(25, 'Preferred Language', this._orcidInfo.preferredLocale, 'The preferred locale/language of the person.'));
for (const url of this._orcidInfo.researcherUrls) {
this.items.push(new FoldableItem(100, url.name, url.url, 'A link to a website specified by the person.'));
}
if (this._orcidInfo.keywords.length > 50)
this.items.push(new FoldableItem(60, 'Keywords', this._orcidInfo.keywords.map(keyword => keyword.content).join(', '), 'Keywords specified by the person.', undefined, undefined, false));
if (this._orcidInfo.biography)
this.items.push(new FoldableItem(200, 'Biography', this._orcidInfo.biography, 'The biography of the person.', undefined, undefined, false));
if (this._orcidInfo.country)
this.items.push(new FoldableItem(30, 'Country', this._orcidInfo.country, 'The country of the person.'));
}
}
isResolvable() {
return this._orcidInfo.ORCiDJSON !== undefined;
}
renderPreview() {
return (h("span", { class: 'inline-flex items-center font-mono flex-nowrap align-top' }, h("svg", { version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 256 256", class: 'h-5 p-0.5 mr-1 flex-none items-center' }, h("style", { type: "text/css" }, `.st0{fill:#A6CE39;}`, `.st1{fill:#FFFFFF;}`), h("path", { class: "st0", d: "M256,128c0,70.7-57.3,128-128,128C57.3,256,0,198.7,0,128C0,57.3,57.3,0,128,0C198.7,0,256,57.3,256,128z" }), h("g", null, h("path", { class: "st1", d: "M86.3,186.2H70.9V79.1h15.4v48.4V186.2z" }), h("path", { class: "st1", d: "M108.9,79.1h41.6c39.6,0,57,28.3,57,53.6c0,27.5-21.5,53.6-56.8,53.6h-41.8V79.1z M124.3,172.4h24.5\n c34.9,0,42.9-26.5,42.9-39.7c0-21.5-13.7-39.7-43.7-39.7h-23.7V172.4z" }), h("path", { class: "st1", d: "M88.7,56.8c0,5.5-4.5,10.1-10.1,10.1c-5.6,0-10.1-4.6-10.1-10.1c0-5.6,4.5-10.1,10.1-10.1\n C84.2,46.7,88.7,51.3,88.7,56.8z" }))), h("span", { class: 'flex-none px-1 items-center' }, this._orcidInfo.familyName, ", ", this._orcidInfo.givenNames, ' ', this.showAffiliation && this._orcidInfo.getAffiliationsAt(new Date()).length > 0
? `(${this._orcidInfo.getAffiliationAsString(this._orcidInfo.getAffiliationsAt(new Date())[0], false)}${this._orcidInfo.getAffiliationsAt(this.affiliationAt).length > 0 &&
this.affiliationAt.toLocaleDateString() !== new Date().toLocaleDateString() &&
this._orcidInfo.getAffiliationsAt(this.affiliationAt)[0].organization !== this._orcidInfo.getAffiliationsAt(new Date())[0].organization
? `, then: ${this._orcidInfo.getAffiliationsAt(this.affiliationAt)[0].organization}`
: ''})`
: '')));
}
getSettingsKey() {
return 'ORCIDType';
}
}
//# sourceMappingURL=ORCIDType.js.map