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() {
|
get empty() {
|
||||||
return !this._attachment || !this._attachment.numAnnotations();
|
return !this._attachment
|
||||||
|
|| !this._attachment.isFileAttachment()
|
||||||
|
|| !this._attachment.numAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
get contextRow() {
|
get contextRow() {
|
||||||
|
@ -155,11 +157,14 @@ import { getCSSItemTypeIcon } from 'components/icons';
|
||||||
this._label.textContent = this._attachment.getField('title');
|
this._label.textContent = this._attachment.getField('title');
|
||||||
|
|
||||||
this._body.replaceChildren();
|
this._body.replaceChildren();
|
||||||
|
|
||||||
|
if (this._attachment.isFileAttachment()) {
|
||||||
for (let annotation of this._attachment.getAnnotations()) {
|
for (let annotation of this._attachment.getAnnotations()) {
|
||||||
let row = document.createXULElement('annotation-row');
|
let row = document.createXULElement('annotation-row');
|
||||||
row.annotation = annotation;
|
row.annotation = annotation;
|
||||||
this._body.append(row);
|
this._body.append(row);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!this._listenerAdded) {
|
if (!this._listenerAdded) {
|
||||||
this._body.addEventListener('transitionend', () => {
|
this._body.addEventListener('transitionend', () => {
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
this._item = item;
|
this._item = item;
|
||||||
this._body.replaceChildren();
|
this._body.replaceChildren();
|
||||||
if (item) {
|
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.addRow(attachment);
|
||||||
}
|
}
|
||||||
this.updateCount();
|
this.updateCount();
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
set inTrash(inTrash) {
|
set inTrash(inTrash) {
|
||||||
this._inTrash = inTrash;
|
this._inTrash = inTrash;
|
||||||
for (let row of this._body.children) {
|
for (let row of this._body.children) {
|
||||||
row.contextRow = this._isContext(row.attachment);
|
this._updateRowAttributes(row, row.attachment);
|
||||||
}
|
}
|
||||||
this.updateCount();
|
this.updateCount();
|
||||||
}
|
}
|
||||||
|
@ -124,11 +124,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
addRow(attachment) {
|
addRow(attachment) {
|
||||||
if (attachment.deleted && !this._inTrash) return;
|
|
||||||
|
|
||||||
let row = document.createXULElement('attachment-row');
|
let row = document.createXULElement('attachment-row');
|
||||||
row.attachment = attachment;
|
this._updateRowAttributes(row, attachment);
|
||||||
row.contextRow = this._isContext(attachment);
|
|
||||||
|
|
||||||
let inserted = false;
|
let inserted = false;
|
||||||
for (let existingRow of this._body.children) {
|
for (let existingRow of this._body.children) {
|
||||||
|
@ -156,8 +153,12 @@
|
||||||
this._section.open = true;
|
this._section.open = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
_isContext(attachment) {
|
_updateRowAttributes(row, attachment) {
|
||||||
return this._inTrash && !this._item.deleted && !attachment.deleted;
|
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);
|
customElements.define("attachments-box", AttachmentsBox);
|
||||||
|
|
|
@ -3,6 +3,10 @@ attachment-row {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 2px;
|
gap: 2px;
|
||||||
|
|
||||||
|
&[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
& > .head {
|
& > .head {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -39,7 +43,7 @@ attachment-row {
|
||||||
fill: var(--fill-tertiary);
|
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
|
// TODO This color is used in virtualized-table - probably want to change to something theme-defined
|
||||||
color: gray;
|
color: gray;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue