Hide attachment list when attachments are empty

When attachment uploading is forbidden and attachments are empty,
currently there is an empty 'Files' legend that may be surprising.

We can hide it by deciding whether we should show it when:

- Uploading is allowed
- At least one attachment exists
pull/6489/head
Oliver Günther 6 years ago
parent f42101d65d
commit e7fa06a68e
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 6
      frontend/src/app/components/attachments/attachments.component.ts
  2. 2
      frontend/src/app/components/attachments/attachments.html
  3. 3
      frontend/src/app/modules/hal/resources/mixins/attachable-mixin.ts

@ -110,6 +110,12 @@ export class AttachmentsComponent implements OnInit, OnDestroy {
this.$formElement.off('submit.attachment-component'); this.$formElement.off('submit.attachment-component');
} }
// Only show attachment list when allow uploading is set
// or when at least one attachment exists
public showAttachments() {
return this.allowUploading || _.get(this.resource, 'attachments.count', 0) > 0;
}
private destroyRemovedAttachments() { private destroyRemovedAttachments() {
let missingAttachments = _.differenceBy(this.initialAttachments, let missingAttachments = _.differenceBy(this.initialAttachments,
this.resource.attachments.elements, this.resource.attachments.elements,

@ -1,4 +1,4 @@
<fieldset class="form--fieldset"> <fieldset class="form--fieldset" *ngIf="showAttachments()">
<legend class="form--fieldset-legend"> <legend class="form--fieldset-legend">
{{ text.attachments }} {{ text.attachments }}
</legend> </legend>

@ -81,6 +81,8 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {
.then(() => { .then(() => {
if (!!this.attachmentsBackend) { if (!!this.attachmentsBackend) {
this.updateAttachments(); this.updateAttachments();
} else {
this.attachments.count = Math.max(this.attachments.count - 1, 0);
} }
}) })
.catch((error:any) => { .catch((error:any) => {
@ -108,6 +110,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {
if (!!this.attachmentsBackend && !this.isNew) { if (!!this.attachmentsBackend && !this.isNew) {
this.updateAttachments(); this.updateAttachments();
} else { } else {
this.attachments.count += result.length;
result.forEach(r => { result.forEach(r => {
this.attachments.elements.push(r.response); this.attachments.elements.push(r.response);
}); });

Loading…
Cancel
Save