Skip to content

Commit 88d8e0a

Browse files
committed
Support rel. graph undo/redo for summary labeler.
Reorder parameters of buildRecord so undo parameter is second.
1 parent 5d02aa1 commit 88d8e0a

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

graph/graph.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,20 @@
5252
let isTree = false;
5353
if (url && url.includes(":")) {
5454
let matches = url.match(/.*1:1:(.*)/);
55-
if (matches) {
55+
if (matches) { // CDS/SLS record persona
5656
let personaId = matches[1];
5757
url = "https://api.familysearch.org/platform/records/personas/" + personaId + "?access_token=" + sessionId;
5858
}
5959
else {
6060
matches = url.match(/.*4:1:(.*)/);
61-
if (matches) {
61+
if (matches) { // Family Tree person
6262
let personId = matches[1];
6363
isTree = true;
6464
url = "https://api.familysearch.org/platform/tree/persons/" + personId + "?access_token=" + sessionId;
6565
}
6666
else {
6767
matches = url.match(/.*2:2:(.*)/);
68-
if (matches) {
69-
let personId = matches[1];
68+
if (matches) { // LLS "Genealogies" tree person
7069
isTree = true;
7170
url = url + "?access_token=" + sessionId;
7271
}
@@ -98,12 +97,13 @@
9897
});
9998

10099
/**
101-
* Redraw the chart with an updated GedcomX document.
102-
* Note that record.html has "updateRecord(doc)" as well, so we're using the same function name for both.
103-
* @param doc - GedcomX document to rebuild the chart with.
100+
* Having made a change to the given record, update the display of it.
101+
*
102+
* @param doc The record to update.
103+
* @param fromUndoLog - flag for whether this update is coming from the undo history, in which case the undo history should not be updated.
104104
*/
105-
function updateRecord(doc) {
106-
buildRelGraph(doc, prevRelChartOptions(currentRelChart));
105+
function updateRecord(doc, fromUndoLog) {
106+
buildRelGraph(doc, prevRelChartOptions(currentRelChart, fromUndoLog));
107107
}
108108
</script>
109109
</body>

graph/graph.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
* @param isDraggable - Flag for whether the rel chart should be draggable.
4545
* @returns {RelationshipChart}
4646
*/
47-
function buildGraph(gx, isEditable, prevChart, ignoreUndo, imgOverlayToGx, isDraggable) {
48-
return buildRelGraph(gx, prevChart ? prevRelChartOptions(prevChart): new ChartOptions({
47+
function buildGraph(gx, isEditable, prevChart, ignoreUndo, imgOverlayToGx = null, isDraggable = false) {
48+
return buildRelGraph(gx, prevChart ? prevRelChartOptions(prevChart, ignoreUndo): new ChartOptions({
4949
isEditable: isEditable,
5050
prevChart: prevChart,
5151
ignoreUndo: ignoreUndo,
@@ -74,6 +74,9 @@ function buildMultipleRelGraphs(gxRecordSet, chartOptions) {
7474
* @returns {RelationshipChart}
7575
*/
7676
function buildRelGraph(gx, chartOptions, relChartDiv='rel-chart') {
77+
if (!chartOptions && currentRelChart) {
78+
chartOptions = prevRelChartOptions(currentRelChart);
79+
}
7780
if (!chartOptions.imgOverlayToGx && chartOptions.prevChart) {
7881
chartOptions.imgOverlayToGx = chartOptions.prevChart.imgOverlayToGx; // in case this is non-null.
7982
}

graph/tree/TreeFetch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function receivePersons(gx, fetchSpecs) {
399399
// Draw or update the relationship chart with what we have so far
400400
if (currentRelChart) {
401401
currentRelChart.selectedPersonBoxes = []; // clear selections
402-
updateRecord(masterGx, null, false, true);
402+
updateRecord(masterGx, false, false, null, true);
403403
}
404404
else {
405405
buildRelGraph(masterGx, defaultChartOptions);

graph/view/RelationshipChart.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function ChartOptions({ prevChart= null,
4545
this.isUndo = isUndo;
4646
}
4747

48-
function prevRelChartOptions(prevRelChart, imgOverlayToGx, isUndo) {
48+
function prevRelChartOptions(prevRelChart, isUndo, imgOverlayToGx) {
4949
return new ChartOptions({
5050
prevChart : prevRelChart,
5151
imgOverlayToGx: imgOverlayToGx,
@@ -326,7 +326,7 @@ function initUndo(relChart, chartOptions) {
326326
relChart.gedcomxChangePosition = chartOptions.prevChart ? chartOptions.prevChart.gedcomxChangePosition : 0;
327327

328328
if (!chartOptions.isUndo) {
329-
relChart.gedcomxChangeHistory[relChart.gedcomxChangePosition++] = JSON.parse(JSON.stringify(relChart.relGraph.gx));
329+
relChart.gedcomxChangeHistory[relChart.gedcomxChangePosition++] = copyGedcomx(relChart.relGraph.gx);
330330
if (relChart.gedcomxChangePosition < relChart.gedcomxChangeHistory.length) {
331331
// Did a change after doing multiple "undos". So ignore the rest of the change history.
332332
relChart.gedcomxChangeHistory.length = relChart.gedcomxChangePosition;
@@ -337,14 +337,14 @@ function initUndo(relChart, chartOptions) {
337337
function undoGraph(relChart) {
338338
if (relChart && relChart.gedcomxChangePosition > 1) {
339339
let gx = copyGedcomx(relChart.gedcomxChangeHistory[--relChart.gedcomxChangePosition - 1]);
340-
buildRelGraph(gx, prevRelChartOptions(relChart, null, true));
340+
updateRecord(gx, true);
341341
}
342342
}
343343

344344
function redoGraph(relChart) {
345345
if (relChart && relChart.gedcomxChangePosition < relChart.gedcomxChangeHistory.length) {
346346
let gx = copyGedcomx(relChart.gedcomxChangeHistory[relChart.gedcomxChangePosition++]);
347-
buildRelGraph(gx, prevRelChartOptions(relChart, null, true));
347+
updateRecord(gx, true);
348348
}
349349
}
350350

index.html

+15-13
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,15 @@
202202
if ((key === 'Z' && e.shiftKey) || key === 'Y') {
203203
// Ctrl/Cmd-shift Z or Cmd-Y => Redo
204204
redoRecordSet();
205-
e.stopPropagation();
205+
// Prevent graph.js from receiving redo, since it is already taken care of.
206+
e.stopImmediatePropagation();
206207
e.preventDefault(); // Prevent browser from treating Cmd-Y as "Show all history".
207208
}
208209
else if (key === 'Z') { // lower-case z, no shift
209210
// Ctrl/Cmd-Z => Undo
210211
undoRecordSet();
211-
e.stopPropagation();
212+
// Prevent graph.js from receiving Cmd-Z and re-doing the undo
213+
e.stopImmediatePropagation();
212214
e.preventDefault();
213215
}
214216
}
@@ -218,13 +220,13 @@
218220
/**
219221
* Having made a change to the given record, update the display of it.
220222
*
221-
* @param doc The record to update.
222-
* @param url (optional) The url or filename of the record, if applicable. (Ignored if null)
223-
* @param editorAlreadyUpdated (optional) Flag for whether the 'editor' is already updated (avoids closing editor when it is being edited still).
224-
* @param isClean - flag for whether this is a fresh update of the record, so the dirty bit should be cleared rather than set (like usual).
225-
* @param fromUndoLog - flag for whether this update is coming from the undo history, in which case the undo history should not be updated.
223+
* @param doc The record to update.
224+
* @param fromUndoLog - flag for whether this update is coming from the undo history, in which case the undo history should not be updated.
225+
* @param editorAlreadyUpdated (optional) Flag for whether the 'editor' is already updated (avoids closing editor when it is being edited still).
226+
* @param url (optional) The url or filename of the record, if applicable. (Ignored if null)
227+
* @param isClean - flag for whether this is a fresh update of the record, so the dirty bit should be cleared rather than set (like usual).
226228
*/
227-
function updateRecord(doc, url, editorAlreadyUpdated, isClean, fromUndoLog) {
229+
function updateRecord(doc, fromUndoLog, editorAlreadyUpdated, url, isClean) {
228230
url = url ? url : currentUrl;
229231
currentUrl = url;
230232
if (doc.records && doc.records.length > 0) {
@@ -304,7 +306,7 @@
304306
updateSelectablePersons(doc, $("#copy-person-fact-target-persons"));
305307

306308
// Rebuild the relationship graph. Set global variable (defined in RelChartBuilder.js).
307-
relChart = buildGraph(doc, true, relChart, true);
309+
relChart = buildGraph(doc, true, relChart, fromUndoLog);
308310
}
309311

310312
/**
@@ -792,7 +794,7 @@
792794
if (relChart) {
793795
relChart = null; // avoid animation at beginning when switching to different records.
794796
}
795-
updateRecord(recordInfo.gxRecord, null, false, true);
797+
updateRecord(recordInfo.gxRecord, false, false, null, true);
796798
}
797799
}
798800

@@ -2730,7 +2732,7 @@
27302732
else if (backup.text) {
27312733
setRecordSourceDocument(backup.text, backup.filename);
27322734
}
2733-
updateRecord(backup.doc, backup.url, false, true, true);
2735+
updateRecord(backup.doc, true, false, backup.url, true);
27342736
$("#download-gx").attr("download", backup.filename ? backup.filename.replace(/(.txt|.nbx|.nbx.xml)?$/, ".gx.json") : "gx.json");
27352737
}
27362738

@@ -2739,7 +2741,7 @@
27392741
setRecordSourceDocument(null);
27402742
recordInfos = [];
27412743
currentRecordIndex = -1;
2742-
updateRecord({}, null, false, true);
2744+
updateRecord({}, false, false, null, true);
27432745
}
27442746
}
27452747

@@ -2807,7 +2809,7 @@
28072809
recordInfos = [];
28082810
currentRecordIndex = -1;
28092811
relChart = null; // clear out any previous RelationshipChart
2810-
updateRecord(makeEmptyRecord(), null, false, true);
2812+
updateRecord(makeEmptyRecord(), false, false, null, true);
28112813
for (let i = 0; i < files.length; i++) {
28122814
let f = files[i];
28132815
let reader = new FileReader();

split/time-machine.html

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<title>FamilySearch Time Machine</title>
66
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
77
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
8-
<!-- <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">-->
98
<script src="../gx-util.js"></script>
109
<script src="time-machine.js"></script>
1110
<link rel="stylesheet" type="text/css" href="time-machine.css">

summary/testSummary.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
* Redraw the chart with an updated GedcomX document.
5959
* Note that record.html has "updateRecord(doc)" as well, so we're using the same function name for both.
6060
* @param doc - GedcomX document to rebuild the chart with.
61+
* @param fromUndoLog - Flag for if the update is due to an undo/redo.
6162
*/
62-
function updateRecord(doc) {
63-
buildRelGraph(doc, prevRelChartOptions(currentRelChart));
63+
function updateRecord(doc, fromUndoLog) {
64+
buildRelGraph(doc, prevRelChartOptions(currentRelChart, fromUndoLog));
6465
}
6566
</script>
6667
</body>

0 commit comments

Comments
 (0)