Various RTF Scan fixes

- Firefox 46 compatibility
- Async DB
- Stretched progress meters
This commit is contained in:
Dan Stillman 2016-04-15 04:20:09 -04:00
parent 08b3eed7da
commit c5716a395f
2 changed files with 13 additions and 10 deletions

View file

@ -143,7 +143,7 @@ var Zotero_RTFScan = new function() {
/** /**
* Scans file for citations, then proceeds to next wizard page. * Scans file for citations, then proceeds to next wizard page.
*/ */
function _scanRTF() { var _scanRTF = Zotero.Promise.coroutine(function* () {
// set up globals // set up globals
citations = []; citations = [];
citationItemIDs = {}; citationItemIDs = {};
@ -231,7 +231,7 @@ var Zotero_RTFScan = new function() {
} }
if(title) s.addCondition("title", "contains", title); if(title) s.addCondition("title", "contains", title);
s.addCondition("date", "is", date); s.addCondition("date", "is", date);
var ids = s.search(); var ids = yield s.search();
Zotero.debug("Mapped to "+ids); Zotero.debug("Mapped to "+ids);
citationItemIDs[citationString] = ids; citationItemIDs[citationString] = ids;
@ -239,11 +239,12 @@ var Zotero_RTFScan = new function() {
unmappedCitationsChildren.appendChild(_generateItem(citationString, "")); unmappedCitationsChildren.appendChild(_generateItem(citationString, ""));
unmappedCitationsItem.hidden = undefined; unmappedCitationsItem.hidden = undefined;
} else { // some mapping found } else { // some mapping found
var items = Zotero.Items.get(ids); var items = yield Zotero.Items.getAsync(ids);
if(items.length > 1) { if(items.length > 1) {
// check to see how well the author list matches the citation // check to see how well the author list matches the citation
var matchedItems = []; var matchedItems = [];
for(var i=0; i<items.length; i++) { for(var i=0; i<items.length; i++) {
yield items[i].loadDataType('creators');
if(_matchesItemCreators(creators, items[i])) matchedItems.push(items[i]); if(_matchesItemCreators(creators, items[i])) matchedItems.push(items[i]);
} }
@ -275,7 +276,7 @@ var Zotero_RTFScan = new function() {
// when scanning is complete, go to citations page // when scanning is complete, go to citations page
document.documentElement.canAdvance = true; document.documentElement.canAdvance = true;
document.documentElement.advance(); document.documentElement.advance();
} });
function _generateItem(citationString, itemName, accept) { function _generateItem(citationString, itemName, accept) {
var treeitem = document.createElement('treeitem'); var treeitem = document.createElement('treeitem');
@ -329,7 +330,7 @@ var Zotero_RTFScan = new function() {
function _matchesItemCreator(creator, itemCreator) { function _matchesItemCreator(creator, itemCreator) {
// make sure last name matches // make sure last name matches
var lowerLast = itemCreator.ref.lastName.toLowerCase(); var lowerLast = itemCreator.lastName.toLowerCase();
if(lowerLast != creator.substr(-lowerLast.length).toLowerCase()) return false; if(lowerLast != creator.substr(-lowerLast.length).toLowerCase()) return false;
// make sure first name matches, if it exists // make sure first name matches, if it exists
@ -341,12 +342,14 @@ var Zotero_RTFScan = new function() {
var m = initialRe.exec(firstName); var m = initialRe.exec(firstName);
if(m) { if(m) {
var initials = firstName.replace(/[^A-Z]/g, ""); var initials = firstName.replace(/[^A-Z]/g, "");
var itemInitials = [name[0].toUpperCase() for each (name in itemCreator.ref.firstName.split(/ +/g))].join(""); var itemInitials = itemCreator.firstName.split(/ +/g)
.map(name => name[0].toUpperCase())
.join("");
if(initials != itemInitials) return false; if(initials != itemInitials) return false;
} else { } else {
// not all initials; verify that the first name matches // not all initials; verify that the first name matches
var firstWord = firstName.substr(0, itemCreator.ref.firstName).toLowerCase(); var firstWord = firstName.substr(0, itemCreator.firstName).toLowerCase();
var itemFirstWord = itemCreator.ref.firstName.substr(0, itemCreator.ref.firstName.indexOf(" ")).toLowerCase(); var itemFirstWord = itemCreator.firstName.substr(0, itemCreator.firstName.indexOf(" ")).toLowerCase();
if(firstWord != itemFirstWord) return false; if(firstWord != itemFirstWord) return false;
} }
} }

View file

@ -45,7 +45,7 @@
<wizardpage id="scan-page" label="&zotero.rtfScan.scanPage.label;" <wizardpage id="scan-page" label="&zotero.rtfScan.scanPage.label;"
onpageshow="Zotero_RTFScan.scanPageShowing()"> onpageshow="Zotero_RTFScan.scanPageShowing()">
<description width="700">&zotero.rtfScan.scanPage.description;</description> <description width="700">&zotero.rtfScan.scanPage.description;</description>
<progressmeter id="progress-indicator" mode="undetermined" flex="1"/> <progressmeter id="progress-indicator" mode="undetermined"/>
</wizardpage> </wizardpage>
<wizardpage id="citations-page" label="&zotero.rtfScan.citationsPage.label;" <wizardpage id="citations-page" label="&zotero.rtfScan.citationsPage.label;"
@ -107,7 +107,7 @@
<wizardpage id="format-page" label="&zotero.rtfScan.formatPage.label;" <wizardpage id="format-page" label="&zotero.rtfScan.formatPage.label;"
onpageshow="Zotero_RTFScan.formatPageShowing()"> onpageshow="Zotero_RTFScan.formatPageShowing()">
<description width="700">&zotero.rtfScan.formatPage.description;</description> <description width="700">&zotero.rtfScan.formatPage.description;</description>
<progressmeter id="progress-indicator" mode="undetermined" flex="1"/> <progressmeter id="progress-indicator" mode="undetermined"/>
</wizardpage> </wizardpage>
<wizardpage id="complete-page" label="&zotero.rtfScan.completePage.label;"> <wizardpage id="complete-page" label="&zotero.rtfScan.completePage.label;">