Rename 'area' annotations to 'image' annotations

This commit is contained in:
Dan Stillman 2020-09-04 19:39:19 -04:00
parent 05318b3021
commit 427a227370
6 changed files with 30 additions and 30 deletions

View file

@ -29,7 +29,7 @@ Zotero.Annotations = new function () {
// Keep in sync with items.js::loadAnnotations()
Zotero.defineProperty(this, 'ANNOTATION_TYPE_HIGHLIGHT', { value: 1 });
Zotero.defineProperty(this, 'ANNOTATION_TYPE_NOTE', { value: 2 });
Zotero.defineProperty(this, 'ANNOTATION_TYPE_AREA', { value: 3 });
Zotero.defineProperty(this, 'ANNOTATION_TYPE_IMAGE', { value: 3 });
this.toJSON = function (item) {
@ -43,7 +43,7 @@ Zotero.Annotations = new function () {
if (o.type == 'highlight') {
o.text = item.annotationText;
}
else if (o.type == 'area') {
else if (o.type == 'image') {
o.imageURL = item.annotationImageURL;
}
o.comment = item.annotationComment;

View file

@ -354,7 +354,7 @@ Zotero.Attachments = new function(){
/**
* Saves an image for a parent note or area annotation
* Saves an image for a parent note or image annotation
*
* @param {Object} params
* @param {Blob} params.blob - Image to save

View file

@ -3519,7 +3519,7 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex'])
if (currentType && currentType != value) {
throw new Error("Cannot change annotation type");
}
if (!['highlight', 'note', 'area'].includes(value)) {
if (!['highlight', 'note', 'image'].includes(value)) {
throw new Error(`Invalid annotation type '${value}'`);
}
break;
@ -3569,12 +3569,12 @@ for (let name of ['position']) {
*/
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', {
get: function () {
if (!this.isAreaAnnotation()) {
throw new Error("'annotationImageAttachment' is only valid for area annotations");
if (!this.isImageAnnotation()) {
throw new Error("'annotationImageAttachment' is only valid for image annotations");
}
var attachments = this.getAttachments();
if (!attachments.length) {
throw new Error("No attachments found for area annotation");
throw new Error("No attachments found for image annotation");
}
return Zotero.Items.get(attachments[0]);
}
@ -3586,12 +3586,12 @@ Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', {
*/
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageURL', {
get: function () {
if (!this.isAreaAnnotation()) {
throw new Error("'annotationImageURL' is only valid for area annotations");
if (!this.isImageAnnotation()) {
throw new Error("'annotationImageURL' is only valid for image annotations");
}
var attachments = this.getAttachments();
if (!attachments.length) {
throw new Error("No attachments found for area annotation");
throw new Error("No attachments found for image annotation");
}
var { libraryID, key } = Zotero.Items.getLibraryAndKeyFromID(attachments[0]);
@ -3624,8 +3624,8 @@ Zotero.Item.prototype.isAnnotation = function() {
*
* @return {Boolean}
**/
Zotero.Item.prototype.isAreaAnnotation = function() {
return this.isAnnotation() && this._getLatestField('annotationType') == 'area';
Zotero.Item.prototype.isImageAnnotation = function() {
return this.isAnnotation() && this._getLatestField('annotationType') == 'image';
}

View file

@ -527,8 +527,8 @@ Zotero.Items = function() {
type = 'note';
break;
case Zotero.Annotations.ANNOTATION_TYPE_AREA:
type = 'area';
case Zotero.Annotations.ANNOTATION_TYPE_IMAGE:
type = 'image';
break;
default:

View file

@ -47,9 +47,9 @@ describe("Zotero.Annotations", function() {
"dateModified": "2019-05-14 06:50:54"
};
var exampleArea = {
var exampleImage = {
"key": "QD32MQJF",
"type": "area",
"type": "image",
"isAuthor": true,
"imageURL": "zotero://attachment/library/items/LB417FR4",
"comment": "This is a comment",
@ -162,16 +162,16 @@ describe("Zotero.Annotations", function() {
await annotation.eraseTx();
});
it("should generate an object for an area", async function () {
it("should generate an object for an image", async function () {
var annotation = new Zotero.Item('annotation');
annotation.libraryID = attachment.libraryID;
annotation.key = exampleArea.key;
annotation.key = exampleImage.key;
await annotation.loadPrimaryData();
annotation.parentID = attachment.id;
annotation.annotationType = 'area';
annotation.annotationType = 'image';
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
annotation[itemProp] = exampleArea[prop];
annotation[itemProp] = exampleImage[prop];
}
await annotation.saveTx();
@ -189,13 +189,13 @@ describe("Zotero.Annotations", function() {
var json = Zotero.Annotations.toJSON(annotation);
assert.sameMembers(Object.keys(json), Object.keys(exampleArea));
for (let prop of Object.keys(exampleArea)) {
assert.sameMembers(Object.keys(json), Object.keys(exampleImage));
for (let prop of Object.keys(exampleImage)) {
if (prop == 'imageURL'
|| prop == 'dateModified') {
continue;
}
assert.deepEqual(json[prop], exampleArea[prop], `'${prop}' doesn't match`);
assert.deepEqual(json[prop], exampleImage[prop], `'${prop}' doesn't match`);
}
assert.equal(json.imageURL, `zotero://attachment/library/items/${imageAttachment.key}`);
@ -251,15 +251,15 @@ describe("Zotero.Annotations", function() {
}
});
it("should create an item from an area", async function () {
var annotation = await Zotero.Annotations.saveFromJSON(attachment, exampleArea);
it("should create an item from an image", async function () {
var annotation = await Zotero.Annotations.saveFromJSON(attachment, exampleImage);
// Note: Image is created separately using Zotero.Attachments.importEmbeddedImage()
assert.equal(annotation.key, exampleArea.key);
assert.equal(annotation.key, exampleImage.key);
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
assert.deepEqual(annotation[itemProp], exampleArea[prop], `'${prop}' doesn't match`);
assert.deepEqual(annotation[itemProp], exampleImage[prop], `'${prop}' doesn't match`);
}
});
});

View file

@ -1212,7 +1212,7 @@ describe("Zotero.Item", function () {
assert.throws(() => a.annotationText = "This is highlighted text.");
a = new Zotero.Item('annotation');
a.annotationType = 'area';
a.annotationType = 'image';
assert.throws(() => a.annotationText = "This is highlighted text.");
});
});
@ -1248,7 +1248,7 @@ describe("Zotero.Item", function () {
await annotation.saveTx();
});
it("should save an area annotation", async function () {
it("should save an image annotation", async function () {
// Create a Blob from a PNG
var path = OS.Path.join(getTestDataDirectory().path, 'test.png');
var imageData = await Zotero.File.getBinaryContentsAsync(path);
@ -1259,7 +1259,7 @@ describe("Zotero.Item", function () {
var annotation = new Zotero.Item('annotation');
annotation.parentID = attachment.id;
annotation.annotationType = 'area';
annotation.annotationType = 'image';
annotation.annotationSortIndex = '000015|0002431|000000.000';
annotation.annotationPosition = {
pageIndex: 123,