Skip to content

Commit dad9d6b

Browse files
committed
split source table into source and annotations
1 parent cf92189 commit dad9d6b

1 file changed

Lines changed: 116 additions & 43 deletions

File tree

previewers/betatest/js/refiqdacore.js

Lines changed: 116 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -266,68 +266,141 @@ function parseData2(data) {
266266
}
267267

268268

269-
if (xmlDoc.getElementsByTagName("Sources")[0]) {
269+
if (xmlDoc.getElementsByTagName("Sources")[0]) {
270270
let sources = xmlDoc.getElementsByTagName("Sources")[0].childNodes;
271271
if (sources != null && sources.length > 0) {
272-
$('#filterby').append($('<option/>').prop('value', 'Sources').text('Sources'));
273-
let sourceBlock = $('<div/>').width(tableWidth).appendTo($(".preview"));
274-
sourceBlock.append($("<h2/>").html("Sources"));
275-
let sourceTable = createTable("Sources", "Name", "Type", "Selection", "Codes").appendTo(sourceBlock);
276-
sourceTable.addClass("sourcetable compact stripe");
277-
272+
273+
// First pass: collect annotations and whole documents separately
274+
let annotationRows = [];
275+
let sourceRows = [];
276+
278277
for (let source of sources) {
279278
if (source.nodeName.endsWith("Source")) {
280279
sourceMap.set(source.getAttribute("guid"), source);
281-
let tr = null;
280+
282281
let sourceMatches = source.getAttribute("creatingUser") + source.getAttribute("modifyingUser");
283-
284-
285282
let selections = getSelections(source);
283+
286284
if (selections != null && selections.length != 0) {
287285
selections.forEach(function(selection) {
288286
let selectionMatches = sourceMatches + selection.getAttribute("creatingUser") + selection.getAttribute("modifyingUser");
289287
selectionMatches = selectionMatches + getCodeRelatedGUIDs(selection);
290-
tr = addRow(sourceTable, createSourceReference(source, zipUrl), selection.nodeName, selection.getAttribute("name"), getCodeNames(selection));
291-
tr.attr('data-guid', selection.getAttribute("guid"));
292-
tr.attr('data-matches', selectionMatches);
288+
289+
let rowData = {
290+
sourceRef: createSourceReference(source, zipUrl),
291+
type: selection.nodeName,
292+
name: selection.getAttribute("name"),
293+
codes: getCodeNames(selection),
294+
guid: selection.getAttribute("guid"),
295+
matches: selectionMatches
296+
};
297+
298+
// Check if this is a PDFSelection or PlainTextSelection
299+
if (selection.nodeName === "PDFSelection" || selection.nodeName === "PlainTextSelection") {
300+
annotationRows.push(rowData);
301+
} else {
302+
sourceRows.push(rowData);
303+
}
293304
});
294305
}
295-
//else {
296-
tr = addRow(sourceTable, createSourceReference(source, zipUrl), source.nodeName, "Whole Document", "");
297-
tr.attr('data-guid', source.getAttribute("guid"));
298-
tr.attr('data-matches', sourceMatches);
299-
//}
306+
307+
// Add whole document entry to sources
308+
sourceRows.push({
309+
sourceRef: createSourceReference(source, zipUrl),
310+
type: source.nodeName,
311+
name: "Whole Document",
312+
codes: "",
313+
guid: source.getAttribute("guid"),
314+
matches: sourceMatches
315+
});
300316
}
301-
302317
}
303-
sourceDataTable = $(".sourcetable").DataTable({
304-
select: $('#filterby').val() == 'Sources'
305-
});
306-
if (typeof downloadFile === 'function') {
307-
$("a[data-entry-index]").click(downloadFile);
308-
$("a[data-entry-index]").each(function() { console.log('Here: ' + $(this).attr('data-entry-index')) });
309-
$('.sourcetable').on('draw.dt', function() {
310-
console.log("Draw!!!!");
311-
$("a[data-entry-index]").each(function() { console.log('There: ' + $(this).attr('data-entry-index')) });
312-
$("a[data-entry-index]").off('click');
318+
319+
// Create Annotations table if there are any annotations
320+
if (annotationRows.length > 0) {
321+
$('#filterby').append($('<option/>').prop('value', 'Annotations').text('Annotations'));
322+
323+
let annotationBlock = $('<div/>').width(tableWidth).appendTo($(".preview"));
324+
annotationBlock.append($("<h2/>").html("Annotations"));
325+
let annotationTable = createTable("Annotations", "Name", "Type", "Selection", "Codes").appendTo(annotationBlock);
326+
annotationTable.addClass("annotationtable compact stripe");
327+
328+
annotationRows.forEach(function(rowData) {
329+
let tr = addRow(annotationTable, rowData.sourceRef, rowData.type, rowData.name, rowData.codes);
330+
tr.attr('data-guid', rowData.guid);
331+
tr.attr('data-matches', rowData.matches);
332+
});
333+
334+
var annotationDataTable = $(".annotationtable").DataTable({
335+
select: $('#filterby').val() == 'Annotations'
336+
});
337+
338+
if (typeof downloadFile === 'function') {
313339
$("a[data-entry-index]").click(downloadFile);
340+
$('.annotationtable').on('draw.dt', function() {
341+
$("a[data-entry-index]").off('click');
342+
$("a[data-entry-index]").click(downloadFile);
343+
});
344+
}
345+
346+
tables.push(annotationDataTable);
347+
annotationDataTable.on('select deselect', function(e, dt, type, indexes) {
348+
if (type === 'row') {
349+
var data = annotationDataTable.rows(indexes).data().pluck('id');
350+
annotationDataTable[type](indexes).nodes().to$().addClass('custom-selected');
351+
console.log('uG: ' + annotationDataTable[type](indexes).nodes().to$().attr('data-guid'));
352+
console.log(annotationDataTable.rows({ selected: true }).count());
353+
console.log("clearing sG in annotation");
354+
selectedGUIDs = new Array();
355+
annotationDataTable.rows({ selected: true }).nodes().to$().each(function(index, element) { selectedGUIDs.push(element.dataset.guid) });
356+
selectedGUIDs.forEach(guid => { console.log('Added ' + guid); });
357+
tables.filter(function(curTable) { return curTable !== annotationDataTable }).forEach(table => { table.draw() });
358+
}
314359
});
315360
}
316-
tables.push(sourceDataTable);
317-
sourceDataTable.on('select deselect', function(e, dt, type, indexes) {
318-
if (type === 'row') {
319-
var data = sourceDataTable.rows(indexes).data().pluck('id');
320-
sourceDataTable[type](indexes).nodes().to$().addClass('custom-selected');
321-
console.log('uG: ' + sourceDataTable[type](indexes).nodes().to$().attr('data-guid'));
322-
console.log(sourceDataTable.rows({ selected: true }).count());
323-
console.log("clearing sG in source");
324-
selectedGUIDs = new Array();
325-
sourceDataTable.rows({ selected: true }).nodes().to$().each(function(index, element) { selectedGUIDs.push(element.dataset.guid) });
326-
selectedGUIDs.forEach(guid => { console.log('Added ' + guid); });
327-
// do something with the ID of the selected items
328-
tables.filter(function(curTable) { return curTable !== sourceDataTable }).forEach(table => { table.draw() });
361+
362+
// Create Sources table if there are any sources
363+
if (sourceRows.length > 0) {
364+
$('#filterby').append($('<option/>').prop('value', 'Sources').text('Sources'));
365+
366+
let sourceBlock = $('<div/>').width(tableWidth).appendTo($(".preview"));
367+
sourceBlock.append($("<h2/>").html("Sources"));
368+
let sourceTable = createTable("Sources", "Name", "Type", "Selection", "Codes").appendTo(sourceBlock);
369+
sourceTable.addClass("sourcetable compact stripe");
370+
371+
sourceRows.forEach(function(rowData) {
372+
let tr = addRow(sourceTable, rowData.sourceRef, rowData.type, rowData.name, rowData.codes);
373+
tr.attr('data-guid', rowData.guid);
374+
tr.attr('data-matches', rowData.matches);
375+
});
376+
377+
sourceDataTable = $(".sourcetable").DataTable({
378+
select: $('#filterby').val() == 'Sources'
379+
});
380+
381+
if (typeof downloadFile === 'function') {
382+
$("a[data-entry-index]").click(downloadFile);
383+
$('.sourcetable').on('draw.dt', function() {
384+
$("a[data-entry-index]").off('click');
385+
$("a[data-entry-index]").click(downloadFile);
386+
});
329387
}
330-
});
388+
389+
tables.push(sourceDataTable);
390+
sourceDataTable.on('select deselect', function(e, dt, type, indexes) {
391+
if (type === 'row') {
392+
var data = sourceDataTable.rows(indexes).data().pluck('id');
393+
sourceDataTable[type](indexes).nodes().to$().addClass('custom-selected');
394+
console.log('uG: ' + sourceDataTable[type](indexes).nodes().to$().attr('data-guid'));
395+
console.log(sourceDataTable.rows({ selected: true }).count());
396+
console.log("clearing sG in source");
397+
selectedGUIDs = new Array();
398+
sourceDataTable.rows({ selected: true }).nodes().to$().each(function(index, element) { selectedGUIDs.push(element.dataset.guid) });
399+
selectedGUIDs.forEach(guid => { console.log('Added ' + guid); });
400+
tables.filter(function(curTable) { return curTable !== sourceDataTable }).forEach(table => { table.draw() });
401+
}
402+
});
403+
}
331404
}
332405
}
333406

0 commit comments

Comments
 (0)