]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / download-button / download-button.component.ts
diff --git a/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.ts b/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.ts
new file mode 100644 (file)
index 0000000..48fde79
--- /dev/null
@@ -0,0 +1,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`);
+    }
+  }
+}