Skip to content

Commit c50a510

Browse files
committed
Adjustment to get uri's to show right in guidance
and in description fields. One tweak to prevent click to get popup Reference Guide from triggering new tab instance of DH in browser.
1 parent e15e90f commit c50a510

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

lib/DataHarmonizer.js

+44-3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class DataHarmonizer {
125125
);
126126
this.columnHelpEntries = options.columnHelpEntries || [
127127
'column',
128+
'slot_uri',
128129
'description',
129130
'guidance',
130131
'examples',
@@ -176,7 +177,7 @@ class DataHarmonizer {
176177
(field) => field.title === field_reference
177178
);
178179
$('#field-description-text').html(
179-
urlToClickableAnchor(this.getComment(field))
180+
this.getComment(field)
180181
);
181182
$('#field-description-modal').modal('show');
182183
});
@@ -1037,6 +1038,30 @@ class DataHarmonizer {
10371038
hotInstance.render(); // Render the table to apply changes
10381039
}
10391040

1041+
renderSemanticID(curieOrURI, as_markup = false) {
1042+
if (curieOrURI) {
1043+
if (curieOrURI.toLowerCase().startsWith('http')) {
1044+
if (as_markup)
1045+
return `[${curieOrURI}](${curieOrURI})`;
1046+
1047+
return `<a href="${curieOrURI}" target="_blank">${curieOrURI}</a>`;
1048+
}
1049+
else if (curieOrURI.includes(':')) {
1050+
const [prefix, reference] = curieOrURI.split(':',2);
1051+
if (prefix && reference && (prefix in this.schema.prefixes)) {
1052+
// Lookup curie
1053+
let url = this.schema.prefixes[prefix]['prefix_reference'] + reference;
1054+
if (as_markup)
1055+
return `[${curieOrURI}](${url})`;
1056+
return `<a href="${url}" target="_blank">${curieOrURI}</a>`;
1057+
}
1058+
else
1059+
return `${curieOrURI}`;
1060+
}
1061+
}
1062+
return '';
1063+
}
1064+
10401065
/**
10411066
* Presents reference guide in a popup.
10421067
* @param {String} mystyle simple css stylesheet commands to override default.
@@ -1088,9 +1113,11 @@ class DataHarmonizer {
10881113
for (const slot of section.children) {
10891114
const slot_dict = this.getCommentDict(slot);
10901115

1116+
const slot_uri = this.renderSemanticID(slot_dict.slot_uri);
1117+
10911118
row_html += '<tr>';
10921119
if (this.columnHelpEntries.includes('column')) {
1093-
row_html += `<td class="label">${slot_dict.title}</td>`;
1120+
row_html += `<td class="label">${slot_dict.title}<br/>${slot_uri}</td>`;
10941121
}
10951122
if (this.columnHelpEntries.includes('description')) {
10961123
row_html += `<td>${slot_dict.description}</td>`;
@@ -1868,6 +1895,15 @@ class DataHarmonizer {
18681895
)}</strong>: ${field.title || field.name}</p>`;
18691896
}
18701897

1898+
// Requires markup treatment of URLS. Issue: this is getting rendered
1899+
// wrong.
1900+
const slot_uri = this.renderSemanticID(field.slot_uri, true);
1901+
if (field.slot_uri && this.columnHelpEntries.includes('slot_uri')) {
1902+
ret += `<p><strong data-i18n="help-sidebar__column">${i18next.t(
1903+
'help-sidebar__slot_uri'
1904+
)}</strong>: ${slot_uri}</p>`;
1905+
}
1906+
18711907
if (field.description && this.columnHelpEntries.includes('description')) {
18721908
ret += `<p><strong data-i18n="help-sidebar__description">${i18next.t(
18731909
'help-sidebar__description'
@@ -1907,7 +1943,8 @@ class DataHarmonizer {
19071943
let guide = {
19081944
title: field.title,
19091945
name: field.name,
1910-
description: field.description || '',
1946+
slot_uri: field.slot_uri,
1947+
description: urlToClickableAnchor(field.description) || '',
19111948
guidance: '',
19121949
examples: '',
19131950
sources: '',
@@ -1979,6 +2016,10 @@ class DataHarmonizer {
19792016
})
19802017
.join('\n');
19812018

2019+
// Makes full URIs that aren't in markup into <a href>
2020+
if (guide.guidance)
2021+
guide.guidance = urlToClickableAnchor(guide.guidance);
2022+
19822023
if (field.examples && field.examples.length) {
19832024
let examples = [];
19842025
let first_item = true;

lib/Toolbar.js

+4
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,10 @@ class Toolbar {
818818
for (const dh in this.context.dhs) {
819819
this.context.dhs[dh].renderReference();
820820
}
821+
// Prevents another popup on repeated click if user focuses away from
822+
// previous popup.
823+
return false;
824+
821825
}
822826

823827
showError(prefix, message) {

web/translations/translations.json

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@
223223
"en": "Column",
224224
"fr": "Colonne"
225225
},
226+
"help-sidebar__slot_uri": {
227+
"en": "Semantic ID",
228+
"fr": "ID sémantique"
229+
},
226230
"help-sidebar__description": {
227231
"en": "Description",
228232
"fr": "Description"

0 commit comments

Comments
 (0)