Add collectionID
option to EditorInstance.createNoteFromAnnotations()
For adding a standalone note to the current collection
This commit is contained in:
parent
b24c7577ec
commit
894309d061
5 changed files with 28 additions and 11 deletions
|
@ -497,7 +497,12 @@ var ZoteroContextPane = new function () {
|
|||
if (!annotations.length) {
|
||||
return;
|
||||
}
|
||||
var note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, child && attachment.parentID);
|
||||
var note = await Zotero.EditorInstance.createNoteFromAnnotations(
|
||||
annotations,
|
||||
{
|
||||
parentID: child && attachment.parentID
|
||||
}
|
||||
);
|
||||
|
||||
_updateAddToNote();
|
||||
|
||||
|
|
|
@ -1212,10 +1212,12 @@ class EditorInstance {
|
|||
* Create note from annotations
|
||||
*
|
||||
* @param {Zotero.Item[]} annotations
|
||||
* @param {Integer} parentID Creates standalone note if not provided
|
||||
* @param {Object} options
|
||||
* @param {Integer} options.parentID - Creates standalone note if not provided
|
||||
* @param {Integer} options.collectionID - Only valid if parentID not provided
|
||||
* @returns {Promise<Zotero.Item>}
|
||||
*/
|
||||
static async createNoteFromAnnotations(annotations, parentID) {
|
||||
static async createNoteFromAnnotations(annotations, { parentID, collectionID } = {}) {
|
||||
if (!annotations.length) {
|
||||
throw new Error("No annotations provided");
|
||||
}
|
||||
|
@ -1236,7 +1238,12 @@ class EditorInstance {
|
|||
|
||||
let note = new Zotero.Item('note');
|
||||
note.libraryID = annotations[0].libraryID;
|
||||
note.parentID = parentID;
|
||||
if (parentID) {
|
||||
note.parentID = parentID;
|
||||
}
|
||||
else if (collectionID) {
|
||||
note.addToCollection(collectionID);
|
||||
}
|
||||
await note.saveTx();
|
||||
let editorInstance = new EditorInstance();
|
||||
editorInstance._item = note;
|
||||
|
|
|
@ -4962,7 +4962,12 @@ var ZoteroPane = new function()
|
|||
if (!annotations.length) {
|
||||
return;
|
||||
}
|
||||
var note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, attachment.parentID);
|
||||
var note = await Zotero.EditorInstance.createNoteFromAnnotations(
|
||||
annotations,
|
||||
{
|
||||
parentID: attachment.parentID
|
||||
}
|
||||
);
|
||||
if (!skipSelect) {
|
||||
await this.selectItem(note.id);
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ describe("Create a note from annotations from multiple items and attachments", f
|
|||
annotations.push(annotation1);
|
||||
let annotation2 = await createAnnotation('highlight', attachment);
|
||||
annotations.push(annotation2);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, null);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations);
|
||||
assert.equal(note.note.split('test.pdf').length - 1, 1);
|
||||
assert.equal(note.note.split(annotation1.annotationText).length - 1, 1);
|
||||
assert.equal(note.note.split(annotation2.annotationText).length - 1, 1);
|
||||
|
@ -428,7 +428,7 @@ describe("Create a note from annotations from multiple items and attachments", f
|
|||
annotations.push(annotation1);
|
||||
let annotation2 = await createAnnotation('highlight', attachment2);
|
||||
annotations.push(annotation2);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, null);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations);
|
||||
assert.equal(note.note.split('test.pdf').length - 1, 2);
|
||||
assert.equal(note.note.split('>' + item.getField('title') + '<').length - 1, 0);
|
||||
assert.equal(note.note.split(annotation1.annotationText).length - 1, 1);
|
||||
|
@ -445,7 +445,7 @@ describe("Create a note from annotations from multiple items and attachments", f
|
|||
annotations.push(annotation1);
|
||||
let annotation2 = await createAnnotation('highlight', attachment2);
|
||||
annotations.push(annotation2);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, null);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations);
|
||||
assert.equal(note.note.split('test.pdf').length - 1, 0);
|
||||
assert.equal(note.note.split('>' + item1.getField('title') + '<').length - 1, 1);
|
||||
assert.equal(note.note.split('>' + item2.getField('title') + '<').length - 1, 1);
|
||||
|
@ -468,7 +468,7 @@ describe("Create a note from annotations from multiple items and attachments", f
|
|||
annotations.push(annotation3);
|
||||
let annotation4 = await createAnnotation('highlight', attachment3);
|
||||
annotations.push(annotation4);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations, null);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations(annotations);
|
||||
Zotero.debug(note.note);
|
||||
assert.equal(note.note.split('test.pdf').length - 1, 2);
|
||||
assert.equal(note.note.split('>' + item1.getField('title') + '<').length - 1, 1);
|
||||
|
|
|
@ -608,7 +608,7 @@ describe("Zotero.Items", function () {
|
|||
await item2.saveTx();
|
||||
let attachment2 = await importPDFAttachment(item2);
|
||||
let annotation2 = await createAnnotation('highlight', attachment2);
|
||||
let annotation2Note = await Zotero.EditorInstance.createNoteFromAnnotations([annotation2], item2.id);
|
||||
let annotation2Note = await Zotero.EditorInstance.createNoteFromAnnotations([annotation2], { parentID: item2.id });
|
||||
|
||||
assert.include(annotation2Note.getNote(), attachment2.key);
|
||||
|
||||
|
@ -651,7 +651,7 @@ describe("Zotero.Items", function () {
|
|||
for (let filename of attachmentFilenames) {
|
||||
let attachment = await importFileAttachment(filename, { parentID: item2.id });
|
||||
let annotation = await createAnnotation('highlight', attachment);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations([annotation], item2.id);
|
||||
let note = await Zotero.EditorInstance.createNoteFromAnnotations([annotation], { parentID: item2.id });
|
||||
attachments2.push(attachment);
|
||||
annotations2.push(annotation);
|
||||
notes2.push(note);
|
||||
|
|
Loading…
Reference in a new issue