Skip to content

Commit 09ee7b8

Browse files
committed
Merge branch 'master' into OCA-to-LinkML
2 parents f6e9e85 + 2609ed2 commit 09ee7b8

13 files changed

+530
-129
lines changed

lib/DataHarmonizer.js

+115-33
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.
@@ -1046,6 +1071,7 @@ class DataHarmonizer {
10461071

10471072
let style = `
10481073
body {
1074+
background-color:#fff;
10491075
font-family: arial;
10501076
margin:5% 5% 5% 5%;
10511077
}
@@ -1080,17 +1106,19 @@ class DataHarmonizer {
10801106
let row_html = '';
10811107
for (const section of this.sections) {
10821108
row_html += `<tr class="section">
1083-
<td colspan="${this.columnHelpEntries.length}"><h3>${
1109+
<td colspan="${this.columnHelpEntries.length-1}"><h3>${
10841110
section.title || section.name
10851111
}</h3></td>
10861112
</tr>
10871113
`;
10881114
for (const slot of section.children) {
10891115
const slot_dict = this.getCommentDict(slot);
10901116

1117+
const slot_uri = this.renderSemanticID(slot_dict.slot_uri);
1118+
10911119
row_html += '<tr>';
10921120
if (this.columnHelpEntries.includes('column')) {
1093-
row_html += `<td class="label">${slot_dict.title}</td>`;
1121+
row_html += `<td class="label">${slot_dict.title}<br>${slot_uri}</td>`;
10941122
}
10951123
if (this.columnHelpEntries.includes('description')) {
10961124
row_html += `<td>${slot_dict.description}</td>`;
@@ -1102,38 +1130,62 @@ class DataHarmonizer {
11021130
row_html += `<td>${slot_dict.examples}</td>`;
11031131
}
11041132
if (this.columnHelpEntries.includes('menus')) {
1105-
row_html += ` <td>${slot_dict.sources || ''}</td>`;
1133+
row_html += ` <td>${slot_dict.menus || ''}</td>`;
11061134
}
11071135
row_html += '</tr>';
11081136
}
11091137
}
11101138

1139+
// Note this may include more enumerations than exist in a given template.
1140+
let enum_html = ``;
1141+
for (const key of Object.keys(this.schema.enums).sort()) {
1142+
const enumeration = this.schema.enums[key];
1143+
let title = enumeration.title != enumeration.name ? enumeration.title : '';
1144+
enum_html += `<tr class="section">
1145+
<td colspan="2" id="${enumeration.name}">${enumeration.name}</td>
1146+
<td colspan="2" style="font-size:1.2rem;">"${title}"<br>${this.renderSemanticID(enumeration.enum_uri)}</td>
1147+
</tr>`;
1148+
1149+
for (const item_key in enumeration.permissible_values) {
1150+
const item = enumeration.permissible_values[item_key];
1151+
let text = item.text != item_key ? item.text : '';
1152+
enum_html += `<tr>
1153+
<td>${this.renderSemanticID(item.meaning)}</td>
1154+
<td>${item_key}</td>
1155+
<td>${text}</td>
1156+
<td></td>
1157+
</tr>`;
1158+
}
1159+
}
1160+
11111161
var win = window.open(
11121162
'',
11131163
'Reference',
1114-
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600'
1164+
'toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600'
11151165
);
11161166

1117-
win.document.head.innerHTML = `
1118-
<meta charset="utf-8">
1119-
<title>${i18next.t('reference_guide_title')} "${
1167+
win.document.open(); // For reloads
1168+
win.document.write(`<!DOCTYPE html>
1169+
<html lang="en">
1170+
<head>
1171+
<meta charset="utf-8">
1172+
<title>${i18next.t('reference_guide_title')} "${
11201173
schema_template.title || schema_template.name
11211174
}" template</title>
1122-
<meta name="description" content="${schema_template.description || ''}">
1123-
<style>${style}</style>
1124-
`;
1125-
1126-
win.document.body.innerHTML = `
1127-
<div>
1175+
<meta name="description" content="${schema_template.description || ''}">
1176+
<style>${style}</style>
1177+
</head>
1178+
<body>
1179+
<div>
11281180
<h2>${i18next.t('reference_guide_title')} "${
11291181
schema_template.title || schema_template.name
11301182
}" template</h2>
1131-
<hr size="2"/>
1183+
<hr/>
11321184
<p>${schema_template.description || ''}</p>
11331185
11341186
<table>
1135-
<thead>
1136-
<tr>
1187+
<thead>
1188+
<tr>
11371189
${
11381190
this.columnHelpEntries.includes('column')
11391191
? `<th class="label">${i18next.t('help-sidebar__column')}</th>`
@@ -1161,16 +1213,25 @@ class DataHarmonizer {
11611213
? `<th class="data_status">${i18next.t('help-sidebar__menus')}</th>`
11621214
: ''
11631215
}
1164-
</tr>
1165-
</thead>
1166-
<tbody>
1167-
${row_html}
1168-
</tbody>
1169-
</table>
1216+
</tr>
1217+
</thead>
1218+
<tbody>
1219+
${row_html}
1220+
</tbody>
1221+
</table>
11701222
</div>
1171-
</body>
1172-
</html>
1173-
`;
1223+
<div>
1224+
<table>
1225+
<thead>
1226+
<tr class="section">
1227+
<th colspan="4">${i18next.t('help-picklists')}</th>
1228+
</tr>
1229+
</thead>
1230+
<tbody>${enum_html}</tbody>
1231+
</table>
1232+
</div>
1233+
</body>
1234+
</html>`);
11741235
return false;
11751236
}
11761237

@@ -1455,8 +1516,8 @@ class DataHarmonizer {
14551516
// Close current dialog and switch to error message
14561517
//$('specify-headers-modal').modal('hide');
14571518
//$('#unmapped-headers-modal').modal('hide');
1458-
const errMsg = `The template for the loaded file has a configuration error:<br/>
1459-
<strong>${parent.title}</strong><br/>
1519+
const errMsg = `The template for the loaded file has a configuration error:<br>
1520+
<strong>${parent.title}</strong><br>
14601521
This is a field that has no parent, or a section that has no fields.`;
14611522
$('#unmapped-headers-list').html(errMsg);
14621523
$('#unmapped-headers-modal').modal('show');
@@ -1868,6 +1929,14 @@ class DataHarmonizer {
18681929
)}</strong>: ${field.title || field.name}</p>`;
18691930
}
18701931

1932+
// Requires markup treatment of URLS.
1933+
const slot_uri = this.renderSemanticID(field.slot_uri);
1934+
if (field.slot_uri && this.columnHelpEntries.includes('slot_uri')) {
1935+
ret += `<p><strong data-i18n="help-sidebar__column">${i18next.t(
1936+
'help-sidebar__slot_uri'
1937+
)}</strong>: ${slot_uri}</p>`;
1938+
}
1939+
18711940
if (field.description && this.columnHelpEntries.includes('description')) {
18721941
ret += `<p><strong data-i18n="help-sidebar__description">${i18next.t(
18731942
'help-sidebar__description'
@@ -1907,10 +1976,12 @@ class DataHarmonizer {
19071976
let guide = {
19081977
title: field.title,
19091978
name: field.name,
1910-
description: field.description || '',
1979+
slot_uri: field.slot_uri,
1980+
description: urlToClickableAnchor(field.description) || '',
19111981
guidance: '',
19121982
examples: '',
19131983
sources: '',
1984+
menus: ''
19141985
};
19151986

19161987
let guidance = [];
@@ -1955,7 +2026,13 @@ class DataHarmonizer {
19552026
guidance.push(i18next.t('reference_guide_msg_unique_record'));
19562027
}
19572028
if (field.sources && field.sources.length) {
1958-
let sources = [];
2029+
let menus = [];
2030+
for (const item of field.sources) {
2031+
menus.push('<a href="#'+ item + '" target="Reference">' + item +'</a>');
2032+
}
2033+
guide.menus = '<ul><li>' + menus.join('</li><li>') + '</li></ul>';
2034+
/*
2035+
// List null value menu items directly
19592036
for (const [, item] of Object.entries(field.sources)) {
19602037
// List null value menu items directly
19612038
if (item === 'NullValueMenu') {
@@ -1967,7 +2044,8 @@ class DataHarmonizer {
19672044
sources.push(item);
19682045
}
19692046
}
1970-
guide.sources = '<ul><li>' + sources.join('</li>\n<li>') + '</li></ul>';
2047+
*/
2048+
guide.sources = '<ul><li>' + field.sources.join('</li><li>') + '</li></ul>';
19712049
}
19722050
if (field.multivalued) {
19732051
guidance.push(i18next.t('reference_guide_msg_more_than_one_selection'));
@@ -1979,6 +2057,10 @@ class DataHarmonizer {
19792057
})
19802058
.join('\n');
19812059

2060+
// Makes full URIs that aren't in markup into <a href>
2061+
if (guide.guidance)
2062+
guide.guidance = urlToClickableAnchor(guide.guidance);
2063+
19822064
if (field.examples && field.examples.length) {
19832065
let examples = [];
19842066
let first_item = true;
@@ -1994,9 +2076,9 @@ class DataHarmonizer {
19942076

19952077
if (first_item === true) {
19962078
first_item = false;
1997-
examples += '<ul><li>' + i18next.t(item.value) + '</li>\n';
2079+
examples += '<ul><li>' + i18next.t(item.value) + '</li>';
19982080
} else {
1999-
examples += '<li>' + i18next.t(item.value) + '</li>\n';
2081+
examples += '<li>' + i18next.t(item.value) + '</li>';
20002082
}
20012083
}
20022084
guide.examples = examples + '</ul>';

lib/Toolbar.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ class Toolbar {
313313

314314
updateTemplateOptions() {
315315
this.$selectTemplate.empty();
316-
for (const [schema_name, schema_obj] of Object.entries(this.menu)) {
316+
//for (const [schema_name, schema_obj] of Object.entries(this.menu)) {
317+
for (const schema_obj of Object.values(this.menu)) {
317318
const templates = schema_obj['templates'];
318319
for (const [template_name, template_obj] of Object.entries(templates)) {
319320
let path = schema_obj.folder + '/' + template_name;
@@ -817,6 +818,10 @@ class Toolbar {
817818
for (const dh in this.context.dhs) {
818819
this.context.dhs[dh].renderReference();
819820
}
821+
// Prevents another popup on repeated click if user focuses away from
822+
// previous popup.
823+
return false;
824+
820825
}
821826

822827
showError(prefix, message) {

lib/toolbar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
>
182182
<a
183183
class="dropdown-item"
184-
target="_blank"
184+
target="Reference"
185185
href=""
186186
id="help_reference"
187187
data-i18n="help_reference"

lib/utils/content.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const urlToClickableAnchor = (string) => {
5353
'g'
5454
);
5555
// Replace the URL with an anchor tag in the string
56-
string = string.replace(regex, `<a href="${escapedURL}">${escapedURL}</a>`);
56+
string = string.replace(regex, `<a href="${escapedURL}" target="_blank">${escapedURL}</a>`);
5757
});
5858

5959
return string;

0 commit comments

Comments
 (0)