Skip to content

Commit

Permalink
Merge pull request #14 from gdcc/fundregror
Browse files Browse the repository at this point in the history
Fundreg and ROR support - merged to make it easier to access for testing in IQSS/dataverse#9151
  • Loading branch information
qqmyers authored Oct 4, 2023
2 parents 6055e9a + fd42c37 commit bf2c440
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/config/CVocConf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,22 @@
"js-url":
{
"$id": "#/fieldconfig/properties/js-url",
"type": "string",
"title": "The Script URL",
"description": "The URL for the JavaScript that should be included in the page to support the connection of this field to the specified service",
"oneOf":[
{
"type": "string",
"title": "The Script URL",
"description": "The URL for the JavaScript that should be included in the page to support the connection of this field to the specified service"
},
{
"type": "array",
"title": "Script URLs",
"description": "The URLs for all the JavaScripts that should be included in the page to support the connection of this field to the specified service"
}
],
"examples":
[
"https://gdcc.github.io/dataverse-external-vocab-support/scripts/skosmos.js"
"https://gdcc.github.io/dataverse-external-vocab-support/scripts/skosmos.js",
["https://gdcc.github.io/dataverse-external-vocab-support/scripts/fundreg.js","https://gdcc.github.io/dataverse-external-vocab-support/scripts/cvocutils.js"]
]
},

Expand Down
36 changes: 36 additions & 0 deletions examples/config/grantNumberAgencyFundreg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"field-name": "grantNumberAgency",
"term-uri-field": "grantNumberAgency",
"js-url": ["/cvoc/js/fundreg.js","/cvoc/js/cvocutils.js"],
"protocol": "fundreg",
"retrieval-uri": "https://data.crossref.org/fundingdata/funder/{0}",
"allow-free-text": true,
"prefix": "http://dx.doi.org/10.13039/",
"managed-fields": {},
"languages":"",
"vocabs": {
"funders": {
"uriSpace": "http://dx.doi.org/10.13039/"
}
},
"retrieval-filtering": {
"@context": {
"termName": "https://schema.org/name",
"scheme": "http://www.w3.org/2004/02/skos/core#inScheme",
"lang": "@language",
"content": "@value"
},
"scheme": {
"pattern": "http://data.crossref.org/fundingdata/vocabulary"
},
"termName": {
"pattern": "{0}",
"params": ["/altLabel/Label=*/literalForm"]
},
"@type": {
"pattern": "https://schema.org/Organization"
}
}
}
]
36 changes: 36 additions & 0 deletions examples/config/rorAuthAffiliation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"field-name": "authorAffiliation",
"term-uri-field": "authorAffiliation",
"js-url": ["/cvoc/js/ror.js","/cvoc/js/cvocutils.js"],
"protocol": "ror",
"retrieval-uri": "https://api.ror.org/organizations/{0}",
"allow-free-text": true,
"prefix": "https://ror.org/",
"managed-fields": {},
"languages":"",
"vocabs": {
"rors": {
"uriSpace": "https://ror.org/"
}
},
"retrieval-filtering": {
"@context": {
"termName": "https://schema.org/name",
"scheme": "http://www.w3.org/2004/02/skos/core#inScheme",
"lang": "@language",
"content": "@value"
},
"scheme": {
"pattern": "http://www.grid.ac/ontology/"
},
"termName": {
"pattern": "{0}",
"params": ["/name"]
},
"@type": {
"pattern": "https://schema.org/Organization"
}
}
}
]
60 changes: 60 additions & 0 deletions scripts/cvocutils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//Common Methods - used in more than one script

// Put the text in a result that matches the term in a span with class
// select2-rendered__match that can be styled (e.g. bold)
function markMatch2(text, term) {
// Find where the match is
var match = text.toUpperCase().indexOf(term.toUpperCase());
var $result = $('<span></span>');
// If there is no match, move on
if (match < 0) {
return $result.text(text);
}

// Put in whatever text is before the match
$result.text(text.substring(0, match));

// Mark the match
var $match = $('<span class="select2-rendered__match"></span>');
$match.text(text.substring(match, match + term.length));

// Append the matching text
$result.append($match);

// Put in whatever is after the match
$result.append(text.substring(match + term.length));

return $result;
}

function storeValue(prefix, id, value) {
try {
if(localStorage.getItem(prefix + id)==null) {
// Store the most recent 1000 values across all scripts
//ToDo: Use IndexedDB to manage storage for each script separately and avoid impacting other tools using localStorage
if (localStorage.length > 1000) {
localStorage.removeItem(localStorage.key(0));
}
localStorage.setItem(prefix + id, value);
}
} catch (e) {
console.log("Problem using localStorage: " + e);
}
}

function getValue(prefix, id) {
try {
let altNames='';
let name = localStorage.getItem(prefix + id);
if(name !== null) {
let pos = name.indexOf('#');
if(pos > 0) {
altNames=name.substring(pos+1).split(',');
name=name.substring(0, pos);
}
}
return {name, altNames};
} catch (e) {
console.log("Problem getting value from localStorage: " + e);
}
}
Loading

0 comments on commit bf2c440

Please sign in to comment.