Update and improve attachment-row initialization
- Actually show un-deleted rows as context rows within trash - Add all rows, hide ones that shouldn't be shown - Check whether attachment is file before calling getAnnotations() - Fixes errors on update and new link attachments being shown as empty rows
This commit is contained in:
parent
e4b329bffc
commit
c78739bf2f
3 changed files with 24 additions and 14 deletions
|
@ -106,7 +106,9 @@ import { getCSSItemTypeIcon } from 'components/icons';
|
|||
}
|
||||
|
||||
get empty() {
|
||||
return !this._attachment || !this._attachment.numAnnotations();
|
||||
return !this._attachment
|
||||
|| !this._attachment.isFileAttachment()
|
||||
|| !this._attachment.numAnnotations();
|
||||
}
|
||||
|
||||
get contextRow() {
|
||||
|
@ -155,10 +157,13 @@ import { getCSSItemTypeIcon } from 'components/icons';
|
|||
this._label.textContent = this._attachment.getField('title');
|
||||
|
||||
this._body.replaceChildren();
|
||||
for (let annotation of this._attachment.getAnnotations()) {
|
||||
let row = document.createXULElement('annotation-row');
|
||||
row.annotation = annotation;
|
||||
this._body.append(row);
|
||||
|
||||
if (this._attachment.isFileAttachment()) {
|
||||
for (let annotation of this._attachment.getAnnotations()) {
|
||||
let row = document.createXULElement('annotation-row');
|
||||
row.annotation = annotation;
|
||||
this._body.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._listenerAdded) {
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
this._item = item;
|
||||
this._body.replaceChildren();
|
||||
if (item) {
|
||||
for (let attachment of Zotero.Items.get(item.getAttachments())) {
|
||||
for (let attachment of Zotero.Items.get(item.getAttachments(true))) {
|
||||
this.addRow(attachment);
|
||||
}
|
||||
this.updateCount();
|
||||
|
@ -74,7 +74,7 @@
|
|||
set inTrash(inTrash) {
|
||||
this._inTrash = inTrash;
|
||||
for (let row of this._body.children) {
|
||||
row.contextRow = this._isContext(row.attachment);
|
||||
this._updateRowAttributes(row, row.attachment);
|
||||
}
|
||||
this.updateCount();
|
||||
}
|
||||
|
@ -124,11 +124,8 @@
|
|||
}
|
||||
|
||||
addRow(attachment) {
|
||||
if (attachment.deleted && !this._inTrash) return;
|
||||
|
||||
let row = document.createXULElement('attachment-row');
|
||||
row.attachment = attachment;
|
||||
row.contextRow = this._isContext(attachment);
|
||||
this._updateRowAttributes(row, attachment);
|
||||
|
||||
let inserted = false;
|
||||
for (let existingRow of this._body.children) {
|
||||
|
@ -156,8 +153,12 @@
|
|||
this._section.open = true;
|
||||
};
|
||||
|
||||
_isContext(attachment) {
|
||||
return this._inTrash && !this._item.deleted && !attachment.deleted;
|
||||
_updateRowAttributes(row, attachment) {
|
||||
let hidden = !this._inTrash && attachment.deleted;
|
||||
let context = this._inTrash && !this._item.deleted && !attachment.deleted;
|
||||
row.attachment = attachment;
|
||||
row.hidden = hidden;
|
||||
row.contextRow = context;
|
||||
}
|
||||
}
|
||||
customElements.define("attachments-box", AttachmentsBox);
|
||||
|
|
|
@ -2,6 +2,10 @@ attachment-row {
|
|||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
|
||||
&[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
& > .head {
|
||||
display: flex;
|
||||
|
@ -39,7 +43,7 @@ attachment-row {
|
|||
fill: var(--fill-tertiary);
|
||||
}
|
||||
|
||||
&.context > .head .title {
|
||||
&.context > .head .label {
|
||||
// TODO This color is used in virtualized-table - probably want to change to something theme-defined
|
||||
color: gray;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue