Skip to content

Commit

Permalink
feat(attachments): u#3728 download attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Sep 7, 2023
1 parent edb0439 commit fc4943b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Copyright (c) 2023-present Kaleidos INC
.row {
block-size: var(--spacing-32);
padding-block: var(--spacing-4);

&:hover {
background-color: var(--color-gray20);
border-radius: var(--spacing-4);
cursor: pointer;
}
}

.name-column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
(confirm)="onConfirmDeleteFile()">
<tg-ui-dtable-row
class="row"
data-test="attachment-row">
data-test="attachment-row"
(click)="downloadAttachment()">
<tg-ui-dtable-cell
class="name-column"
[attr.title]="attachment.name">
Expand Down Expand Up @@ -53,6 +54,7 @@
</tg-ui-dtable-cell>
<tg-ui-dtable-cell class="actions-column">
<a
#download
[download]="attachment.name"
[href]="attachment.file"
target="_blank"
Expand All @@ -75,7 +77,7 @@
[tgUiTooltip]="t('attachments.delete')"
[tgUiTooltipStaysOpenOnHover]="false"
tgUiTooltipPosition="bottom-right"
(click)="deleteAttachment()"
(click)="deleteAttachment($event)"
icon="trash"
type="button"></button>
</tg-ui-dtable-cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
* Copyright (c) 2023-present Kaleidos INC
*/

import { Component, Input, OnChanges, inject } from '@angular/core';
import {
Component,
ElementRef,
Input,
OnChanges,
ViewChild,
inject,
} from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslocoModule } from '@ngneat/transloco';
import { TuiButtonModule, TuiSvgModule } from '@taiga-ui/core';
Expand Down Expand Up @@ -51,6 +58,9 @@ export class AttachmentComponent implements OnChanges {
@Input()
public canEdit = true;

@ViewChild('download', { read: ElementRef })
public download!: ElementRef<HTMLElement>;

public extension = 'paperclip';
public state = inject(AttachmentsState);
#initUndo$ = new Subject<void>();
Expand Down Expand Up @@ -103,7 +113,8 @@ export class AttachmentComponent implements OnChanges {
return 'progress' in attachment;
};

public deleteAttachment() {
public deleteAttachment(event: Event) {
event.stopPropagation();
this.#initUndo$.next();
}

Expand All @@ -113,6 +124,10 @@ export class AttachmentComponent implements OnChanges {
}
}

public downloadAttachment() {
this.download.nativeElement.click();
}

public ngOnChanges() {
this.calculateExtension();
}
Expand Down

0 comments on commit fc4943b

Please sign in to comment.