Skip to content

Commit 793a437

Browse files
committed
Add sft-summary section. Move getNbxDocumentText to gx-util as getDocumentText.
1 parent 1e82017 commit 793a437

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

bbox/bbox.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ function createOverlay(type, rectangle, elementMap, gxObject) {
2222
};
2323
}
2424

25-
function findNbxDocumentText(doc, docId) {
26-
if (doc.documents) {
27-
if (!docId) {
28-
docId = "nbx";
29-
}
30-
for (let document of documents) {
31-
if (document.id === docId) {
32-
return document.text;
33-
}
34-
}
35-
}
36-
return null;
37-
}
38-
3925
/**
4026
* Add highlight boxes and corresponding text markers to the image viewer, as found in the given GedcomX document.
4127
* A map is returned with key = local HTML element "id" for each highlight created; and value = "id" of the GedcomX object it came from.
@@ -302,7 +288,7 @@ function overlayBoxes(viewer, doc, sessionId) {
302288
}
303289

304290
// Add bounding boxes for all words. (Do this before names, dates and places, so that those will be on top)
305-
addNbxBoxes(boxes, markers, findNbxDocumentText(doc));
291+
addNbxBoxes(boxes, markers, findDocumentText(doc));
306292

307293
if (doc.persons) {
308294
for (let person of doc.persons) {

gx-util.js

+14
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ function getSourceDocument(doc, mainSourceDescription) {
315315
return document;
316316
}
317317

318+
function findDocumentText(doc, docId) {
319+
if (doc.documents) {
320+
if (!docId) {
321+
docId = "nbx";
322+
}
323+
for (let document of doc.documents) {
324+
if (document.id === docId) {
325+
return document.text;
326+
}
327+
}
328+
}
329+
return null;
330+
}
331+
318332
/**
319333
* Create an object with {x, y, width, height}, either from those four values, or four a comma-seprated string containing those four values.
320334
* @param x1OrRectangle - Either an x coordinate, or a string with "x,y,width,height" all in them.

gx-view.css

+18
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,22 @@ pre {
6363

6464
.section-drop-hover {
6565
background-color: #e4fffb;
66+
}
67+
68+
.hanging-indent {
69+
padding-left: 22px;
70+
text-indent: -22px;
71+
margin-bottom: 0;
72+
}
73+
74+
.sft-relationship {
75+
color: #015b46;
76+
}
77+
78+
.sft-person {
79+
color: #0000b7;
80+
}
81+
82+
.sft-tag {
83+
color: #6c854e;
6684
}

index.html

+27-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,27 @@
209209
}
210210
}
211211

212+
function getSftSummaryHtml(doc) {
213+
let summary = findDocumentText(doc, "sftPrediction");
214+
if (summary) {
215+
let lines = summary.split("\n");
216+
let html = "";
217+
for (let line of lines) {
218+
if (line.startsWith("relationship ")) {
219+
line = line.replace(/^(relationship) /, "<span class='sft-relationship'>$1</span> ");
220+
line = line.replace(/ (pe[0-9]+)/g, " <span class='sft-person'>$1</span>");
221+
}
222+
else if (line.startsWith("pe")) {
223+
line = line.replace(/^(pe[0-9]*) /, "<span class='sft-person'>$1</span> ")
224+
}
225+
line = line.replace(/ (_[^ ]*)/g, " <span class='sft-tag'>$1</span>");
226+
html += "<p class='hanging-indent'>" + line + "</p>";
227+
}
228+
return html;
229+
}
230+
return null;
231+
}
232+
212233
/**
213234
* Having made a change to the given record, update the display of it.
214235
*
@@ -250,6 +271,11 @@
250271
$("#source-viewer").show();
251272
}
252273

274+
let sftSummaryHtml = getSftSummaryHtml(doc);
275+
if (sftSummaryHtml) {
276+
$("#sft-summary").html(sftSummaryHtml);
277+
}
278+
253279
function getImageLink(doc) {
254280
// todo: Include coordinates and handle multiple images.
255281
// let imageArksAndRectangles = getImageArks(doc);
@@ -2675,7 +2701,7 @@
26752701
<div id="source-file" class="pt-4"></div>
26762702
<div id="gx-editor" class="pt-2"></div>
26772703
<div><span id="image-link">IMAGE LINK</span>&nbsp;&nbsp;<span id="nbx-link">ENTITY VIEWER</span></div>
2678-
2704+
<div id="sft-summary"></div>
26792705
</div>
26802706
</div>
26812707
<div class="col-8 pt-4">

nbx/nbx.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
window.opener.entityChildWindow = document;
2828
let doc = window.opener.getCurrentGx();
2929
doc = fixGedcomx(doc);
30-
nbxText = findNbxDocumentText(doc, "relexPostRules");
30+
nbxText = findDocumentText(doc, "relexPostRules");
3131
if (!nbxText) {
32-
nbxText = findNbxDocumentText(doc, "nbx");
32+
nbxText = findDocumentText(doc, "nbx");
3333
if (nbxText) {
3434
// Remove bounding boxes.
3535
nbxText = nbxText.replace(/\[[0-9]*,[0-9]*:[0-9]*,[0-9]*] /g, "");

0 commit comments

Comments
 (0)