All files / app/codeCharta/ui/customConfigs/addCustomConfigButton/addCustomConfigDialog/downloadAndPurgeConfigs downloadAndPurgeConfigs.component.ts

100% Statements 21/21
100% Branches 2/2
100% Functions 4/4
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 5310x 10x 10x 10x 10x 10x 10x 10x                 10x 10x   10x     10x       3x 3x 1x           1x     2x               2x 2x 1x          
import { Component, OnInit } from "@angular/core"
import { ErrorDialogComponent } from "../../../../dialogs/errorDialog/errorDialog.component"
import { ConfirmationDialogComponent } from "../../../../dialogs/confirmationDialog/confirmationDialog.component"
import { CustomConfigHelper } from "../../../../../util/customConfigHelper"
import { MatDialog } from "@angular/material/dialog"
import { validateLocalStorageSize } from "./validateLocalStorageSize"
import { downloadAndCollectPurgeableConfigs } from "./downloadAndCollectPurgeableConfigs"
import { MatButton } from "@angular/material/button"
 
@Component({
    selector: "cc-download-and-purge-configs",
    templateUrl: "./downloadAndPurgeConfigs.component.html",
    styleUrl: "./downloadAndPurgeConfigs.component.scss",
    standalone: true,
    imports: [MatButton]
})
export class DownloadAndPurgeConfigsComponent implements OnInit {
    isLocalStorageSizeValid = true
 
    constructor(private dialog: MatDialog) {}
 
    ngOnInit(): void {
        this.isLocalStorageSizeValid = validateLocalStorageSize()
    }
 
    showPurgeConfirmDialog() {
        const purgeableConfigs = downloadAndCollectPurgeableConfigs()
        if (purgeableConfigs.size === 0) {
            this.dialog.open(ErrorDialogComponent, {
                data: {
                    title: "Download Error",
                    message: "Could not download and purge old configs automatically! Please try it by yourself."
                }
            })
            return
        }
 
        const dialogReference = this.dialog.open(ConfirmationDialogComponent, {
            panelClass: "cc-confirmation-dialog",
            data: {
                title: "Confirm to purge old Configs",
                message: "Are you sure to delete old Configs now?"
            }
        })
 
        dialogReference.afterClosed().subscribe(confirmation => {
            if (confirmation) {
                CustomConfigHelper.deleteCustomConfigs([...purgeableConfigs])
            }
        })
    }
}