Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #110 from friendsofagape/Paratext_Sync_Restored
Browse files Browse the repository at this point in the history
Paratext sync is working
  • Loading branch information
joelthe1 authored Jan 7, 2020
2 parents 15f8437 + 355821f commit 25124ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "autographa-live",
"description": "A Bible translation editor for everyone. Now live.",
"version": "0.1.0-beta.7",
"version": "0.1.0-beta.8",
"main": "public/electron.js",
"author": "Friends of Agape <mathew.joel@protonmail.com>",
"license": "GPL-3.0",
Expand Down
26 changes: 9 additions & 17 deletions src/components/ProjectListRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ProjectListRow extends React.Component {
// });
}
selectBook = (projId, bookId, obj) => {
// console.log(projId, bookId, obj.target.checked)
if(obj.target.checked) {
this.state.selectedBook.push(bookId)
AutographaStore.paratextBook[projId] = this.state.selectedBook
Expand Down Expand Up @@ -101,10 +100,10 @@ class ProjectListRow extends React.Component {
let chapterNodes = xmlDoc.evaluate("//chapter", xmlDoc, null, XPathResult.ANY_TYPE, null);
let verseNodes = xmlDoc.evaluate("//verse", xmlDoc, null, XPathResult.ANY_TYPE, null);
let currChapter=chapterNodes.iterateNext();
book[currChapter.attributes["number"].value] = []
book[currChapter.attributes["number"].value] = [];
let currVerse = verseNodes.iterateNext();
while(currVerse){
if(currVerse.attributes["number"].value === 1 && book[currChapter.attributes["number"].value].length !== 0){
if(currVerse.attributes["number"].value == 1 && book[currChapter.attributes["number"].value].length != 0){
currChapter = chapterNodes.iterateNext();
book[currChapter.attributes["number"].value] = [];
}
Expand Down Expand Up @@ -151,23 +150,22 @@ class ProjectListRow extends React.Component {
}
}
//get bookIndex from const
let bookCode = booksCodes.findIndex((book) => book === bookId)

let bookCode = booksCodes.findIndex((book) => book === bookId);
db.get((bookCode + 1).toString()).then((doc) => {
for (let i = 0; i < doc.chapters.length; i++) {
for (let j = 1; j <= Object.keys(book).length; j++) {
if (j === doc.chapters[i].chapter) {
var versesLen = Math.min(book[j].length, doc.chapters[i].verses.length);
for (let k = 0; k < versesLen; k++) {
var verseNum = book[j][k].verse_number;
var versesLen = Math.min(book[j].length, doc.chapters[i].verses.length);
for (let k = 0; k < versesLen; k++) {
var verseNum = book[j][k].verse_number;
doc.chapters[i].verses[verseNum - 1].verse = book[j][k].verse;
book[j][k] = undefined;
}
//check for extra verses in the imported usfm here.
break;
}
}
}
}
db.put(doc).then((response) => {
this.resetLoader();
//swal({AutographaStore.currentTrans["btn-import"], AutographaStore.currentTrans["label-imported-book"], "success");
Expand All @@ -190,7 +188,6 @@ class ProjectListRow extends React.Component {
swal(AutographaStore.currentTrans["dynamic-msg-error"], AutographaStore.currentTrans["dynamic-msg-went-wrong"], "error");
});
});
// console.log(book)
})
}
});
Expand Down Expand Up @@ -224,7 +221,6 @@ class ProjectListRow extends React.Component {
this.resetLoader();
await swal(currentTrans["btn-import"], this.makeSyncReport(importedBooks), "success");
} catch(err) {
console.log(err);
this.resetLoader();
await swal(currentTrans["dynamic-msg-error"], currentTrans["dynamic-msg-went-wrong"], "error");
}
Expand Down Expand Up @@ -268,7 +264,6 @@ class ProjectListRow extends React.Component {
this.resetLoader();
await swal(currentTrans["dynamic-msg-book-exported"], this.makeSyncReport(writtenBookIds), "success");
} catch(err) {
console.log(err);
this.resetLoader();
await swal(currentTrans["dynamic-msg-error"], currentTrans["dynamic-msg-went-wrong"], "error");
}
Expand Down Expand Up @@ -317,14 +312,13 @@ class ProjectListRow extends React.Component {
let parser = new xml2js.Parser();
parser.parseString(bookRevision, (err, result) => {
let revision = result.RevisionInfo.ChapterInfo[0].$.revision;
let bookIndex = booksCodes.findIndex((book) => book === bookId)
let bookIndex = booksCodes.findIndex((book) => book === bookId);
db.get((bookIndex + 1).toString()).then( async (doc) => {
let xmlBook = fs.readFileSync(`${app.getPath('userData')}/paratext_projects/${projectName}/${bookId.toUpperCase()}.xml`, 'utf8');
const xmlDoc = new DOMParser().parseFromString(xmlBook,"text/xml");
if (xmlDoc.evaluate) {
let chapterNodes = xmlDoc.evaluate("//chapter", xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
let verseNodes = xmlDoc.evaluate("//verse", xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

let currChapter=chapterNodes.snapshotItem(0);
book[currChapter.attributes["number"].value-1] = [];
let currVerse = verseNodes.snapshotItem(0);
Expand All @@ -333,13 +327,12 @@ class ProjectListRow extends React.Component {

while(v < verseNodes.snapshotLength){
v++;
if(currVerse.attributes["number"].value === 1 && book[currChapter.attributes["number"].value-1].length !== 0){
if(currVerse.attributes["number"].value == 1 && book[currChapter.attributes["number"].value-1].length != 0){
i++;
currChapter = chapterNodes.snapshotItem(i);
book[currChapter.attributes["number"].value-1] = [];
}
let verse = doc.chapters[currChapter.attributes["number"].value-1].verses[currVerse.attributes["number"].value-1];

if(!currVerse.nextSibling){
currVerse.insertAdjacentText('afterend',verse.verse);
}
Expand All @@ -356,7 +349,6 @@ class ProjectListRow extends React.Component {
}
book[currChapter.attributes["number"].value-1].push({verse_number: currVerse.attributes["number"].value, verse: currVerse.nextSibling !== null ? (currVerse.nextSibling.data !== undefined ? currVerse.nextSibling.data : "") : ""})
currVerse = verseNodes.snapshotItem(v);

}
try{
_this.props.syncAdapter.updateBookData(projectId, bookId, revision, xmlDoc.getElementsByTagName("usx")[0].outerHTML);
Expand Down

0 comments on commit 25124ef

Please sign in to comment.