|
1 | 1 | console.log("ror.js.."); |
2 | 2 | var rorSelector = "span[data-cvoc-protocol='ror']"; |
3 | 3 | var rorInputSelector = "input[data-cvoc-protocol='ror']"; |
4 | | -var rorRetrievalUrl = "https://api.ror.org/v1/organizations"; |
| 4 | +var rorRetrievalUrl = "https://api.ror.org/v2/organizations"; |
5 | 5 | var rorIdStem = "https://ror.org/"; |
6 | 6 | var rorPrefix = "ror"; |
7 | 7 | //Max chars that displays well for a child field |
@@ -62,12 +62,19 @@ function expandRors() { |
62 | 62 | }, |
63 | 63 | success: function(ror, status) { |
64 | 64 | // If found, construct the HTML for display |
65 | | - var name = ror.name; |
66 | | - var altNames = ror.acronyms; |
| 65 | + // Find the display name (type: "ror_display" or "label") |
| 66 | + const displayName = ror.names.find(n => |
| 67 | + n.types && (n.types.includes("ror_display") || n.types.includes("label")) |
| 68 | + )?.value || ror.id; |
| 69 | + |
| 70 | + // Find all acronyms |
| 71 | + const acronyms = ror.names |
| 72 | + .filter(n => n.types && n.types.includes("acronym")) |
| 73 | + .map(n => n.value); |
67 | 74 |
|
68 | | - $(rorElement).html(getRorDisplayHtml(name, rorIdStem + id, altNames, false, true)); |
| 75 | + $(rorElement).html(getRorDisplayHtml(displayName, rorIdStem + id, acronyms, false, true)); |
69 | 76 | //Store values in localStorage to avoid repeating calls to CrossRef |
70 | | - storeValue(rorPrefix, id, name + "#" + altNames); |
| 77 | + storeValue(rorPrefix, id, displayName + "#" + acronyms.join(',')); |
71 | 78 | }, |
72 | 79 | failure: function(jqXHR, textStatus, errorThrown) { |
73 | 80 | // Generic logging - don't need to do anything if 404 (leave |
@@ -190,14 +197,34 @@ function updateRorInputs() { |
190 | 197 | // Sort the list |
191 | 198 | // Prioritize active orgs |
192 | 199 | .sort((a, b) => Number(b.status === 'active') - Number(a.status === 'active')) |
| 200 | + // Extract display name and acronyms from the names array |
| 201 | + .map(org => { |
| 202 | + // Find the display name (type: "ror_display" or "label") |
| 203 | + const displayName = org.names.find(n => |
| 204 | + n.types && (n.types.includes("ror_display") || n.types.includes("label")) |
| 205 | + )?.value || org.id; |
| 206 | + |
| 207 | + // Find all acronyms |
| 208 | + const acronyms = org.names |
| 209 | + .filter(n => n.types && n.types.includes("acronym")) |
| 210 | + .map(n => n.value); |
| 211 | + |
| 212 | + return { |
| 213 | + ...org, |
| 214 | + name: displayName, |
| 215 | + acronyms: acronyms |
| 216 | + }; |
| 217 | + }) |
193 | 218 | // Prioritize those with this acronym |
194 | | - .sort((a, b) => Number(b.acronyms.includes(params.term)) - Number(a.acronyms.includes(params.term))) |
| 219 | + .sort((a, b) => Number(b.acronyms.some(acr => acr === params.term)) - |
| 220 | + Number(a.acronyms.some(acr => acr === params.term))) |
195 | 221 | // Prioritize previously used entries |
196 | | - .sort((a, b) => Number(getValue(rorPrefix, b['id'].replace(rorIdStem, '')).name != null) - Number(getValue(rorPrefix, a['id'].replace(rorIdStem, '')).name != null)) |
| 222 | + .sort((a, b) => Number(getValue(rorPrefix, b['id'].replace(rorIdStem, '')).name != null) - |
| 223 | + Number(getValue(rorPrefix, a['id'].replace(rorIdStem, '')).name != null)) |
197 | 224 | .map( |
198 | 225 | function(x) { |
199 | 226 | return { |
200 | | - text: x.name + ", " + x.id.replace(rorIdStem, '') + ', ' + x.acronyms, |
| 227 | + text: x.name + ", " + x.id.replace(rorIdStem, '') + ', ' + x.acronyms.join(','), |
201 | 228 | id: x.id |
202 | 229 | } |
203 | 230 | }) |
@@ -236,9 +263,18 @@ function updateRorInputs() { |
236 | 263 | 'Accept': 'application/json' |
237 | 264 | }, |
238 | 265 | success: function(ror, status) { |
239 | | - var name = ror.name; |
| 266 | + // Find the display name (type: "ror_display" or "label") |
| 267 | + const displayName = ror.names.find(n => |
| 268 | + n.types && (n.types.includes("ror_display") || n.types.includes("label")) |
| 269 | + )?.value || ror.id; |
| 270 | + |
| 271 | + // Find all acronyms |
| 272 | + const acronyms = ror.names |
| 273 | + .filter(n => n.types && n.types.includes("acronym")) |
| 274 | + .map(n => n.value); |
| 275 | + |
240 | 276 | //Display the name and id number in the selection menu |
241 | | - var text = name + ", " + ror.id.replace(rorIdStem, '') + ', ' + ror.acronyms; |
| 277 | + var text = displayName + ", " + ror.id.replace(rorIdStem, '') + ', ' + acronyms.join(','); |
242 | 278 | var newOption = new Option(text, id, true, true); |
243 | 279 | $('#' + selectId).append(newOption).trigger('change'); |
244 | 280 | }, |
|
0 commit comments