blob: 48fde7921d59721301dfa8b6cc3f387e3a3d001e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { Component, Input } from '@angular/core';
import { Icons } from '~/app/shared/enum/icons.enum';
import { TextToDownloadService } from '~/app/shared/services/text-to-download.service';
@Component({
selector: 'cd-download-button',
templateUrl: './download-button.component.html',
styleUrls: ['./download-button.component.scss']
})
export class DownloadButtonComponent {
@Input() objectItem: object;
@Input() textItem: string;
@Input() fileName: any;
@Input() title = $localize`Download`;
icons = Icons;
constructor(private textToDownloadService: TextToDownloadService) {}
download(format?: string) {
this.fileName = `${this.fileName}_${new Date().toLocaleDateString()}`;
if (format === 'json') {
this.textToDownloadService.download(
JSON.stringify(this.objectItem, null, 2),
`${this.fileName}.json`
);
} else {
this.textToDownloadService.download(this.textItem, `${this.fileName}.txt`);
}
}
}
|