Skip to content

Commit

Permalink
Fix empty list bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbo committed Feb 26, 2024
1 parent 5c04f96 commit 3da9916
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
4 changes: 4 additions & 0 deletions gx-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,9 @@ function normalizeDate(origDate) {
* @returns {*|*[]} - List of the given name, if any, or and empty list [] if the container or list are null.
*/
function getList(container, listName) {
if (container && container instanceof Map) {
let list = container.get(listName);
return list ? list : [];
}
return container && container.hasOwnProperty(listName) && container[listName] ? container[listName] : [];
}
46 changes: 27 additions & 19 deletions split/time-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ function fetchRelativesAndSources(changeLogMap, $status, context) {
url: sourceUrl,
success:function(gedcomx){
receiveSourceDescription(gedcomx, $status, context, fetching, sourceUrl, sourceMap);
},
error: function(jqXHR, textStatus, errorThrown) {
receiveSourceDescription(null, $status, context, fetching, sourceUrl, sourceMap)
}
});
}
Expand Down Expand Up @@ -281,10 +284,10 @@ class RelativeInfo {
* @param sourceMap - (Global) map of sourceUrl -> SourceInfo for that source (which is filled out here).
*/
function receiveSourceDescription(gedcomx, $status, context, fetching, sourceUrl, sourceMap) {
fetching.splice(fetching.indexOf(sourceUrl), 1);
if (gedcomx && "sourceDescriptions" in gedcomx && gedcomx.sourceDescriptions.length) {
let sourceInfo = sourceMap[sourceUrl];
sourceInfo.setSourceDescription(gedcomx.sourceDescriptions[0]);
fetching.splice(fetching.indexOf(sourceUrl), 1)
if (sourceInfo.personaArk.includes("ark:/61903/")) {
fetching.push(sourceInfo.personaArk);
// Got source description, which has the persona Ark, so now fetch that.
Expand All @@ -301,6 +304,9 @@ function receiveSourceDescription(gedcomx, $status, context, fetching, sourceUrl
url: sourceInfo.personaArk,
success: function (gedcomx) {
receivePersona(gedcomx, $status, context, fetching, sourceInfo);
},
error: function(jqXHR, textStatus, errorThrown) {
receivePersona(null, $status, context, fetching, sourceInfo);
}
});
}
Expand Down Expand Up @@ -412,19 +418,24 @@ function getRecordDate(gedcomx) {
}

function receivePersona(gedcomx, $status, context, fetching, sourceInfo) {
fixEventOrders(gedcomx);
sourceInfo.gedcomx = gedcomx;
if (!gedcomx) {
console.log("Persona " + sourceInfo.personaArk + " no longer exists (410 Gone). Skipping.");
}
else {
fixEventOrders(gedcomx);
sourceInfo.gedcomx = gedcomx;
let personaArk = getMainPersonaArk(gedcomx);
if (personaArk !== sourceInfo.personaArk) {
// This persona has been deprecated & forwarded or something, so update the 'ark' in sourceInfo to point to the new ark.
sourceInfo.personaArk = personaArk;
}
let person = findPersonInGx(gedcomx, personaArk);
sourceInfo.personId = person ? person.id : null;
sourceInfo.collectionName = getCollectionName(gedcomx);
sourceInfo.recordDate = getRecordDate(gedcomx);
sourceInfo.recordDateSortKey = sourceInfo.recordDate ? parseDateIntoNumber(sourceInfo.recordDate).toString() : null;
}
fetching.splice(fetching.indexOf(sourceInfo.personaArk), 1);
let personaArk = getMainPersonaArk(gedcomx);
if (personaArk !== sourceInfo.personaArk) {
// This persona has been deprecated & forwarded or something, so update the 'ark' in sourceInfo to point to the new ark.
sourceInfo.personaArk = personaArk;
}
let person = findPersonInGx(gedcomx, personaArk);
sourceInfo.personId = person ? person.id : null;
sourceInfo.collectionName = getCollectionName(gedcomx);
sourceInfo.recordDate = getRecordDate(gedcomx);
sourceInfo.recordDateSortKey = sourceInfo.recordDate ? parseDateIntoNumber(sourceInfo.recordDate).toString() : null;
if (fetching.length) {
setStatus($status, "Fetching " + fetching.length + "/" + Object.keys(sourceMap).length + " sources...");
}
Expand Down Expand Up @@ -2400,7 +2411,7 @@ function buildMergeRows(mergeNode, indent, maxIndent, isDupNode, mergeRows, shou
let mergeRow = new PersonRow(mergeNode, mergeNode.personId, mergeNode.gedcomx, indent, maxIndent, isDupNode, null, null);
mergeRows.push(mergeRow);
if (personSourcesMap) {
for (let sourceInfo of personSourcesMap.get(mergeNode.personId)) {
for (let sourceInfo of getList(personSourcesMap, mergeNode.personId)) {
let personaId = findPersonInGx(sourceInfo.gedcomx, shortenPersonArk(sourceInfo.personaArk)).id;
let personaRow = new PersonRow(null, personaId, sourceInfo.gedcomx, 0, 0, false, null, sourceInfo, mergeRow);
mergeRows.push(personaRow);
Expand Down Expand Up @@ -2919,11 +2930,8 @@ class Split {
}
function addRelationshipElements(gedcomx) {
function addChildrenElements(spouseId) {
let childRels = childrenMap.get(spouseId);
if (childRels) {
for (let childRel of childRels) {
addElement(childRel, TYPE_CHILD);
}
for (let childRel of getList(childrenMap, spouseId)) {
addElement(childRel, TYPE_CHILD);
}
}
// child-and-parents relationships in which the person is a child, i.e., containing the person's parents
Expand Down

0 comments on commit 3da9916

Please sign in to comment.