From eb865e2625dc1de3f1ab21fe05cd5337aecc23da Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 17 Feb 2021 14:56:32 -0500 Subject: [PATCH] =?UTF-8?q?setAttachmentPageIndex()=20=E2=86=92=20setAttac?= =?UTF-8?q?hmentLastPageIndex()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome/content/zotero/xpcom/data/item.js | 24 ++++++++++++------------ test/tests/itemTest.js | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 30a3d4cc34..93e0d010d9 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3269,12 +3269,12 @@ for (let name of ['lastProcessedModificationTime']) { } -Zotero.Item.prototype.getAttachmentPageIndex = function () { +Zotero.Item.prototype.getAttachmentLastPageIndex = function () { if (!this.isFileAttachment()) { - throw new Error("getAttachmentPageIndex() can only be called on file attachments"); + throw new Error("getAttachmentLastPageIndex() can only be called on file attachments"); } - var id = this._getPageIndexSettingKey(); + var id = this._getLastPageIndexSettingKey(); var val = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, id); if (val !== null && typeof val != 'number' || val != parseInt(val)) { Zotero.logError(`Setting contains an invalid attachment page index ('${val}') -- discarding`); @@ -3283,17 +3283,17 @@ Zotero.Item.prototype.getAttachmentPageIndex = function () { return val; }; -Zotero.Item.prototype.setAttachmentPageIndex = async function (val) { +Zotero.Item.prototype.setAttachmentLastPageIndex = async function (val) { if (!this.isFileAttachment()) { - throw new Error("setAttachmentPageIndex() can only be called on file attachments"); + throw new Error("setAttachmentLastPageIndex() can only be called on file attachments"); } if (typeof val != 'number' || val != parseInt(val)) { Zotero.debug(val, 2); - throw new Error(`setAttachmentPageIndex() must be passed an integer`); + throw new Error(`setAttachmentLastPageIndex() must be passed an integer`); } - var id = this._getPageIndexSettingKey(); + var id = this._getLastPageIndexSettingKey(); if (val === null) { return Zotero.SyncedSettings.clear(id); } @@ -3304,11 +3304,11 @@ Zotero.Item.prototype.setAttachmentPageIndex = async function (val) { /** * Get the key for the item's pageIndex synced setting * - * E.g., 'pageIndex_u_ABCD2345' or 'pageIndex_g123_ABCD2345' + * E.g., 'lastPageIndex_u_ABCD2345' or 'lastPageIndex_g123_ABCD2345' */ -Zotero.Item.prototype._getPageIndexSettingKey = function () { +Zotero.Item.prototype._getLastPageIndexSettingKey = function () { var library = Zotero.Libraries.get(this.libraryID); - var id = 'pageIndex_'; + var id = 'lastPageIndex_'; switch (library.libraryType) { case 'user': id += 'u'; @@ -3319,7 +3319,7 @@ Zotero.Item.prototype._getPageIndexSettingKey = function () { break; default: - throw new Error(`Can't get page index id for ${library.libraryType} item`); + throw new Error(`Can't get last page index key for ${library.libraryType} item`); } id += "_" + this.key; return id; @@ -4608,7 +4608,7 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) { env.notifierData[this.id].storageDeleteLog = this.isStoredFileAttachment(); if (this.isFileAttachment()) { - let id = this._getPageIndexSettingKey(); + let id = this._getLastPageIndexSettingKey(); yield Zotero.SyncedSettings.clear(Zotero.Libraries.userLibraryID, id); } } diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 7fe9f82320..5fb44e97f8 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1206,34 +1206,34 @@ describe("Zotero.Item", function () { describe("Attachment Page Index", function () { - describe("#getAttachmentPageIndex()", function () { + describe("#getAttachmentLastPageIndex()", function () { it("should get the page index", async function () { var attachment = await importFileAttachment('test.pdf'); - assert.isNull(attachment.getAttachmentPageIndex()); - await attachment.setAttachmentPageIndex(2); - assert.equal(2, attachment.getAttachmentPageIndex()); + assert.isNull(attachment.getAttachmentLastPageIndex()); + await attachment.setAttachmentLastPageIndex(2); + assert.equal(2, attachment.getAttachmentLastPageIndex()); }); it("should throw an error if called on a regular item", async function () { var item = createUnsavedDataObject('item'); assert.throws( - () => item.getAttachmentPageIndex(), - "getAttachmentPageIndex() can only be called on file attachments" + () => item.getAttachmentLastPageIndex(), + "getAttachmentLastPageIndex() can only be called on file attachments" ); }); it("should discard invalid page index", async function () { var attachment = await importFileAttachment('test.pdf'); - var id = attachment._getPageIndexSettingKey(); + var id = attachment._getLastPageIndexSettingKey(); await Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, id, '"1"'); - assert.isNull(attachment.getAttachmentPageIndex()); + assert.isNull(attachment.getAttachmentLastPageIndex()); }); }); it("should be cleared when item is deleted", async function () { var attachment = await importFileAttachment('test.pdf'); - await attachment.setAttachmentPageIndex(2); - var id = attachment._getPageIndexSettingKey(); + await attachment.setAttachmentLastPageIndex(2); + var id = attachment._getLastPageIndexSettingKey(); assert.equal(2, Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, id)); await attachment.eraseTx(); assert.isNull(Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, id));