Support wikidata IDs in GND-ID column (automatic linking to wikidata.org)

pull/52/head
Kai Labusch 5 years ago
parent 023fd82f5d
commit e2f6c4f4f1

@ -192,10 +192,19 @@ function setupInterface(data, file, urls) {
$("#table td:contains('I-TODO')").addClass('ner_todo'); $("#table td:contains('I-TODO')").addClass('ner_todo');
} }
function makeTdEditable(td) { function fillStandardTd(td, content) {
td.text(content);
}
function fillEntityDisambiguationTd(td, content) {
}
function makeTdEditable(td, content) {
let tableInfo = $(td).data('tableInfo');
editingTd = { editingTd = {
data: td.innerHTML, data: data.data[tableInfo.nRow][tableInfo.column],
finish: finish:
function (isOk) { function (isOk) {
@ -203,9 +212,7 @@ function setupInterface(data, file, urls) {
let newValue = $('#edit-area').val(); let newValue = $('#edit-area').val();
$(td).html(newValue); tableInfo.fillAction($(td), newValue);
let tableInfo = $(td).data('tableInfo');
data.data[tableInfo.nRow][tableInfo.column] = newValue; data.data[tableInfo.nRow][tableInfo.column] = newValue;
@ -214,7 +221,7 @@ function setupInterface(data, file, urls) {
updateTable(); updateTable();
} }
else { else {
$(td).html(editingTd.data); tableInfo.fillAction($(td), editingTd.data);
} }
editingTd = null; editingTd = null;
$(td).focus(); $(td).focus();
@ -226,7 +233,7 @@ function setupInterface(data, file, urls) {
textArea.style.height = td.clientHeight + 'px'; textArea.style.height = td.clientHeight + 'px';
textArea.id = 'edit-area'; textArea.id = 'edit-area';
$(textArea).val($(td).html()); $(textArea).val(data.data[tableInfo.nRow][tableInfo.column]);
$(td).html(''); $(td).html('');
$(td).append(textArea); $(td).append(textArea);
textArea.focus(); textArea.focus();
@ -321,15 +328,15 @@ function setupInterface(data, file, urls) {
function makeLineSplitMerge(td) { function makeLineSplitMerge(td) {
let tableInfo = $(td).data('tableInfo');
editingTd = { editingTd = {
data: td.innerHTML, data: data.data[tableInfo.nRow][tableInfo.column],
finish: function(action, isOk) { finish: function(action, isOk) {
$(td).html(editingTd.data); $(td).html(editingTd.data);
$(td).addClass('editable'); $(td).addClass('editable');
let tableInfo = $(td).data('tableInfo');
editingTd = null; editingTd = null;
tableEditAction(tableInfo.nRow, action) tableEditAction(tableInfo.nRow, action)
@ -355,15 +362,16 @@ function setupInterface(data, file, urls) {
function makeTagEdit(td) { function makeTagEdit(td) {
let tableInfo = $(td).data('tableInfo');
editingTd = { editingTd = {
data: td.innerHTML, data: data.data[tableInfo.nRow][tableInfo.column],
finish: function(isOk) { finish: function(isOk) {
let tableInfo = $(td).data('tableInfo');
data.data[tableInfo.nRow][tableInfo.column] = editingTd.data; data.data[tableInfo.nRow][tableInfo.column] = editingTd.data;
$(td).html(editingTd.data); tableInfo.fillAction($(td), data.data[tableInfo.nRow][tableInfo.column])
$(td).addClass('editable'); $(td).addClass('editable');
editingTd = null; editingTd = null;
@ -510,6 +518,7 @@ function setupInterface(data, file, urls) {
if (do_not_display.has(column)) return if (do_not_display.has(column)) return
let clickAction = function() { console.log('Do something different');} let clickAction = function() { console.log('Do something different');}
let fillAction = function(td, content) { td.text(content); };
if (column == 'No.') { if (column == 'No.') {
clickAction = makeLineSplitMerge; clickAction = makeLineSplitMerge;
@ -519,6 +528,28 @@ function setupInterface(data, file, urls) {
clickAction = makeTdEditable; clickAction = makeTdEditable;
listener.simple_combo('enter', function() { $(td).click(); }); listener.simple_combo('enter', function() { $(td).click(); });
if (column == 'GND-ID') {
fillAction =
function(td,content) {
if (String(content).match(/^Q[0-9]+$/g) == null) {
td.text(content);
}
else {
td.html("");
var link = $('<a href="https://www.wikidata.org/wiki/' + content + '">' +
content + "</a>")
link.click(
function(event) {
event.stopPropagation();
}
);
td.append(link);
}
}
}
} }
if ((column == 'NE-TAG') || (column == 'NE-EMB')) { if ((column == 'NE-TAG') || (column == 'NE-EMB')) {
@ -555,8 +586,14 @@ function setupInterface(data, file, urls) {
} }
td.attr('tabindex', 0). td.attr('tabindex', 0).
text(content). data('tableInfo',
data('tableInfo', { 'nRow': nRow, 'column': column , 'clickAction': clickAction }) {'nRow': nRow,
'column': column ,
'clickAction': clickAction,
'fillAction': fillAction
});
fillAction(td,content);
row.append(td); row.append(td);
}); });
@ -621,7 +658,9 @@ function setupInterface(data, file, urls) {
tableInfo.nRow = nRow; tableInfo.nRow = nRow;
td.text(content).data('tableInfo', tableInfo); td.data('tableInfo', tableInfo);
tableInfo.fillAction(td, content);
pColumn++; pColumn++;
}); });

Loading…
Cancel
Save