From 47164edea6c444c2cbdd8aa4a181e9f444162da5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 7 Jun 2019 08:21:15 -0400 Subject: [PATCH] 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 --- chrome/content/zotero/bindings/itembox.xml | 3 +- chrome/content/zotero/xpcom/retractions.js | 37 +++++++++++++++------- chrome/content/zotero/xpcom/schema.js | 7 +++- chrome/content/zotero/zoteroPane.js | 1 + chrome/skin/default/zotero/itemPane.css | 2 +- chrome/skin/default/zotero/overlay.css | 11 +++---- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index b25ce3e8c1..ac5c4b3fba 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -2392,7 +2392,7 @@ = Zotero.getString('retraction.banner'); var deleteButton = this._id('retraction-header-delete-button'); - if (!this.item.deleted) { + if (!this.item.deleted && this.item.editable) { deleteButton.hidden = false; deleteButton.textContent = Zotero.getString('pane.items.trash.title'); deleteButton.onclick = function () { @@ -2400,7 +2400,6 @@ this.item.saveTx(); }.bind(this); } - // Already in trash else { deleteButton.hidden = true; } diff --git a/chrome/content/zotero/xpcom/retractions.js b/chrome/content/zotero/xpcom/retractions.js index d210473a2f..199d7f87dc 100644 --- a/chrome/content/zotero/xpcom/retractions.js +++ b/chrome/content/zotero/xpcom/retractions.js @@ -28,9 +28,11 @@ Zotero.Retractions = { TYPE_PMID: 'p', TYPE_NAMES: ['DOI', 'PMID'], + _initialized: false, _version: 1, _cacheFile: null, + _cacheVersion: null, _cacheETag: null, _cacheDOIPrefixLength: null, _cachePMIDPrefixLength: null, @@ -63,10 +65,12 @@ Zotero.Retractions = { var itemIDs = await Zotero.DB.columnQueryAsync("SELECT itemID FROM retractedItems"); this._retractedItems = new Set(itemIDs); - // TEMP - Zotero.Schema.schemaUpdatePromise.then(() => { - this.updateFromServer(); - }); + this._initialized = true; + + // 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), - updateFromServer: async function () { + updateFromServer: Zotero.serial(async function () { + if (!this._initialized) { + return; + } + // Download list var headers = {}; 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([ - ...Object.keys(this._keyItems[this.TYPE_DOI]) + ...Array.from(this._keyItems[this.TYPE_DOI].keys()) .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)) ]); var prefixesToSend = new Set(); @@ -272,8 +280,8 @@ Zotero.Retractions = { // TODO: Diff list 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 @@ -298,7 +306,9 @@ Zotero.Retractions = { let ids = this._keyItems[this.TYPE_DOI].get(row.doi); if (ids) { for (let id of ids) { - addedItemIDs.add(id); + if (!this._retractedItems.has(id)) { + addedItemIDs.add(id); + } await this._addEntry(id, row); } } @@ -307,7 +317,9 @@ Zotero.Retractions = { let ids = this._keyItems[this.TYPE_PMID].get(row.pmid.toString()); if (ids) { for (let id of ids) { - addedItemIDs.add(id); + if (!this._retractedItems.has(id)) { + addedItemIDs.add(id); + } await this._addEntry(id, row); } } @@ -537,6 +549,7 @@ Zotero.Retractions = { }, _processCacheData: function (data) { + this._cacheVersion = data.version; this._cacheETag = data.etag; this._cacheDOIPrefixLength = data.doiPrefixLength; this._cachePMIDPrefixLength = data.pmidPrefixLength; diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index b916eafd66..81eb774b2f 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1127,7 +1127,12 @@ Zotero.Schema = new function(){ 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 var lastUpdated = yield this.getDBVersion('repository'); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 1c85eb8dd4..ff84045518 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4767,6 +4767,7 @@ var ZoteroPane = new function() // 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]; this.selectItem(item.id); + this.hideRetractionBanner(); }.bind(this); close.onclick = function () { diff --git a/chrome/skin/default/zotero/itemPane.css b/chrome/skin/default/zotero/itemPane.css index c8334ff21e..c8d9c64199 100644 --- a/chrome/skin/default/zotero/itemPane.css +++ b/chrome/skin/default/zotero/itemPane.css @@ -50,7 +50,7 @@ justify-content: space-between; align-items: center; padding: 1.5em 1em; - background: #ea3232; + background: #d93425; color: white; font-weight: bold; } diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css index 43163eba19..ee5ac83a65 100644 --- a/chrome/skin/default/zotero/overlay.css +++ b/chrome/skin/default/zotero/overlay.css @@ -732,11 +732,11 @@ #retracted-items-banner { display: flex; justify-content: center; - background: #ea3232; - line-height: 2.5em; + background: #d93425; + line-height: 2.2em; font-weight: bold; color: white; - font-size: 16px; + font-size: 13.5px; text-align: center; padding: 0 2em; position: relative; @@ -759,10 +759,9 @@ #retracted-items-close { position: absolute; cursor: pointer; - top: 3px; + top: -2px; right: 9px; - font-size: 28px; - line-height: 28px; + font-size: 22px; } /* BEGIN 2X BLOCK -- DO NOT EDIT MANUALLY -- USE 2XIZE */