@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.
88 lines (87 loc) • 3.42 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 { PIDRecord } from "./PIDRecord";
import { PID } from "./PID";
import { PIDDataType } from "./PIDDataType";
import { h } from "@stencil/core";
import { GenericIdentifierType } from "../../utils/GenericIdentifierType";
import { FoldableItem } from "../../utils/FoldableItem";
import { FoldableAction } from "../../utils/FoldableAction";
export class HandleType extends GenericIdentifierType {
constructor() {
super(...arguments);
this._parts = [];
}
get data() {
return JSON.stringify(this._pidRecord.toObject());
}
hasCorrectFormat() {
return PID.isPID(this.value);
}
async init(data) {
if (data !== undefined) {
this._pidRecord = PIDRecord.fromJSON(data);
this._parts = await Promise.all([
{
text: this._pidRecord.pid.prefix,
nextExists: true,
},
{
text: this._pidRecord.pid.suffix,
nextExists: false,
},
]);
console.debug('reload PIDRecord from data', this._pidRecord);
}
else {
const pid = PID.getPIDFromString(this.value);
this._parts = [
{
text: pid.prefix,
nextExists: true,
},
{
text: pid.suffix,
nextExists: false,
},
];
this._pidRecord = await pid.resolve();
console.debug('load PIDRecord from API', this._pidRecord);
}
for (const value of this._pidRecord.values) {
if (value.type instanceof PIDDataType) {
this.items.push(new FoldableItem(0, value.type.name, value.data.value, value.type.description, value.type.redirectURL, value.type.regex));
}
}
this.actions.push(new FoldableAction(0, 'Open in FAIR-DOscope', `https://kit-data-manager.github.io/fairdoscope/?pid=${this._pidRecord.pid.toString()}`, 'primary'));
this.actions.push(new FoldableAction(0, 'View in Handle.net registry', `https://hdl.handle.net/${this._pidRecord.pid.toString()}`, 'secondary'));
return;
}
isResolvable() {
return this._pidRecord.values.length > 0;
}
renderPreview() {
return (h("span", { class: 'font-mono bg-inherit font-bold rounded-md' }, this._parts.map(element => {
return (h("span", { class: 'font-bold font-mono' }, h("color-highlight", { text: element.text }), h("span", { class: 'font-mono font-bold text-gray-800 mx-0.5' }, element.nextExists ? '/' : '')));
})));
}
getSettingsKey() {
return 'HandleType';
}
}
//# sourceMappingURL=HandleType.js.map