Retraction improvements

- Fix list download logic
- Close bar when clicking "View Item"
- Don't show "Move to Trash" if item isn't editable
- Download new list if cached version differs from client
- Reduce height of notification bar
- Switch to a slightly darker red
This commit is contained in:
Dan Stillman 2019-06-07 08:21:15 -04:00
parent 75b38caf6f
commit 47164edea6
6 changed files with 39 additions and 22 deletions

View file

@ -2392,7 +2392,7 @@
= Zotero.getString('retraction.banner'); = Zotero.getString('retraction.banner');
var deleteButton = this._id('retraction-header-delete-button'); var deleteButton = this._id('retraction-header-delete-button');
if (!this.item.deleted) { if (!this.item.deleted && this.item.editable) {
deleteButton.hidden = false; deleteButton.hidden = false;
deleteButton.textContent = Zotero.getString('pane.items.trash.title'); deleteButton.textContent = Zotero.getString('pane.items.trash.title');
deleteButton.onclick = function () { deleteButton.onclick = function () {
@ -2400,7 +2400,6 @@
this.item.saveTx(); this.item.saveTx();
}.bind(this); }.bind(this);
} }
// Already in trash
else { else {
deleteButton.hidden = true; deleteButton.hidden = true;
} }

View file

@ -28,9 +28,11 @@ Zotero.Retractions = {
TYPE_PMID: 'p', TYPE_PMID: 'p',
TYPE_NAMES: ['DOI', 'PMID'], TYPE_NAMES: ['DOI', 'PMID'],
_initialized: false,
_version: 1, _version: 1,
_cacheFile: null, _cacheFile: null,
_cacheVersion: null,
_cacheETag: null, _cacheETag: null,
_cacheDOIPrefixLength: null, _cacheDOIPrefixLength: null,
_cachePMIDPrefixLength: null, _cachePMIDPrefixLength: null,
@ -63,10 +65,12 @@ Zotero.Retractions = {
var itemIDs = await Zotero.DB.columnQueryAsync("SELECT itemID FROM retractedItems"); var itemIDs = await Zotero.DB.columnQueryAsync("SELECT itemID FROM retractedItems");
this._retractedItems = new Set(itemIDs); this._retractedItems = new Set(itemIDs);
// TEMP this._initialized = true;
Zotero.Schema.schemaUpdatePromise.then(() => {
this.updateFromServer(); // If no cache file or it was created with a different version, download list at startup
}); if (!this._cacheETag || this._cacheVersion != this._version) {
Zotero.Schema.schemaUpdatePromise.then(() => this.updateFromServer());
}
}, },
/** /**
@ -203,7 +207,11 @@ Zotero.Retractions = {
} }
}, 1000), }, 1000),
updateFromServer: async function () { updateFromServer: Zotero.serial(async function () {
if (!this._initialized) {
return;
}
// Download list // Download list
var headers = {}; var headers = {};
if (this._cacheETag) { if (this._cacheETag) {
@ -240,11 +248,11 @@ Zotero.Retractions = {
} }
} }
// Get possible local matches // Get all keys and compute prefixes to check for possible matches
var prefixStrings = new Set([ var prefixStrings = new Set([
...Object.keys(this._keyItems[this.TYPE_DOI]) ...Array.from(this._keyItems[this.TYPE_DOI].keys())
.map(x => this.TYPE_DOI + x.substr(0, doiPrefixLength)), .map(x => this.TYPE_DOI + x.substr(0, doiPrefixLength)),
...Object.keys(this._keyItems[this.TYPE_PMID]) ...Array.from(this._keyItems[this.TYPE_PMID].keys())
.map(x => this.TYPE_PMID + x.substr(0, pmidPrefixLength)) .map(x => this.TYPE_PMID + x.substr(0, pmidPrefixLength))
]); ]);
var prefixesToSend = new Set(); var prefixesToSend = new Set();
@ -272,8 +280,8 @@ Zotero.Retractions = {
// TODO: Diff list // TODO: Diff list
await this._downloadPossibleMatches([...prefixesToSend]); await this._downloadPossibleMatches([...prefixesToSend]);
await this._cacheList(list, etag, doiPrefixLength, pmidPrefixLength); await this._saveCacheFile(list, etag, doiPrefixLength, pmidPrefixLength);
}, }),
/** /**
* @return {Number[]} - Array of added item ids * @return {Number[]} - Array of added item ids
@ -298,7 +306,9 @@ Zotero.Retractions = {
let ids = this._keyItems[this.TYPE_DOI].get(row.doi); let ids = this._keyItems[this.TYPE_DOI].get(row.doi);
if (ids) { if (ids) {
for (let id of ids) { for (let id of ids) {
addedItemIDs.add(id); if (!this._retractedItems.has(id)) {
addedItemIDs.add(id);
}
await this._addEntry(id, row); await this._addEntry(id, row);
} }
} }
@ -307,7 +317,9 @@ Zotero.Retractions = {
let ids = this._keyItems[this.TYPE_PMID].get(row.pmid.toString()); let ids = this._keyItems[this.TYPE_PMID].get(row.pmid.toString());
if (ids) { if (ids) {
for (let id of ids) { for (let id of ids) {
addedItemIDs.add(id); if (!this._retractedItems.has(id)) {
addedItemIDs.add(id);
}
await this._addEntry(id, row); await this._addEntry(id, row);
} }
} }
@ -537,6 +549,7 @@ Zotero.Retractions = {
}, },
_processCacheData: function (data) { _processCacheData: function (data) {
this._cacheVersion = data.version;
this._cacheETag = data.etag; this._cacheETag = data.etag;
this._cacheDOIPrefixLength = data.doiPrefixLength; this._cacheDOIPrefixLength = data.doiPrefixLength;
this._cachePMIDPrefixLength = data.pmidPrefixLength; this._cachePMIDPrefixLength = data.pmidPrefixLength;

View file

@ -1127,7 +1127,12 @@ Zotero.Schema = new function(){
yield Zotero.DB.waitForTransaction(); yield Zotero.DB.waitForTransaction();
} }
yield Zotero.Retractions.updateFromServer(); try {
yield Zotero.Retractions.updateFromServer();
}
catch (e) {
Zotero.logError(e);
}
// Get the last timestamp we got from the server // Get the last timestamp we got from the server
var lastUpdated = yield this.getDBVersion('repository'); var lastUpdated = yield this.getDBVersion('repository');

View file

@ -4767,6 +4767,7 @@ var ZoteroPane = new function()
// Pick the first item we find in the current library, or just pick one at random // Pick the first item we find in the current library, or just pick one at random
var item = items.find(item => item.libraryID == libraryID) || items[0]; var item = items.find(item => item.libraryID == libraryID) || items[0];
this.selectItem(item.id); this.selectItem(item.id);
this.hideRetractionBanner();
}.bind(this); }.bind(this);
close.onclick = function () { close.onclick = function () {

View file

@ -50,7 +50,7 @@
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 1.5em 1em; padding: 1.5em 1em;
background: #ea3232; background: #d93425;
color: white; color: white;
font-weight: bold; font-weight: bold;
} }

View file

@ -732,11 +732,11 @@
#retracted-items-banner { #retracted-items-banner {
display: flex; display: flex;
justify-content: center; justify-content: center;
background: #ea3232; background: #d93425;
line-height: 2.5em; line-height: 2.2em;
font-weight: bold; font-weight: bold;
color: white; color: white;
font-size: 16px; font-size: 13.5px;
text-align: center; text-align: center;
padding: 0 2em; padding: 0 2em;
position: relative; position: relative;
@ -759,10 +759,9 @@
#retracted-items-close { #retracted-items-close {
position: absolute; position: absolute;
cursor: pointer; cursor: pointer;
top: 3px; top: -2px;
right: 9px; right: 9px;
font-size: 28px; font-size: 22px;
line-height: 28px;
} }
/* BEGIN 2X BLOCK -- DO NOT EDIT MANUALLY -- USE 2XIZE */ /* BEGIN 2X BLOCK -- DO NOT EDIT MANUALLY -- USE 2XIZE */