All files / app/codeCharta/ui/export3DMapButton export3DMapButton.component.ts

100% Statements 29/29
100% Branches 3/3
100% Functions 6/6
100% Lines 28/28

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 53 54 55 56 57 58 59 60 61 62 63 64 654x 4x 4x 4x 4x 4x 4x 4x 4x 4x               4x   6x 6x 6x       2x 2x 1x       1x             2x   2x       2x 2x 1x 1x       1x 1x 1x               2x      
import { Component } from "@angular/core"
import { MatDialog } from "@angular/material/dialog"
import { Export3DMapDialogComponent } from "./export3DMapDialog/export3DMapDialog.component"
import { State, Store } from "@ngrx/store"
import { CcState, ColorMode } from "../../codeCharta.model"
import { colorModeSelector } from "../../state/store/dynamicSettings/colorMode/colorMode.selector"
import { take } from "rxjs"
import { ErrorDialogComponent } from "../dialogs/errorDialog/errorDialog.component"
import { setColorMode } from "../../state/store/dynamicSettings/colorMode/colorMode.actions"
import { ActionIconComponent } from "../actionIcon/actionIcon.component"
 
@Component({
    selector: "cc-export-3d-map-button",
    templateUrl: "./export3DMapButton.component.html",
    standalone: true,
    imports: [ActionIconComponent]
})
export class Export3DMapButtonComponent {
    constructor(
        private dialog: MatDialog,
        private state: State<CcState>,
        private store: Store<CcState>
    ) {}
 
    export3DMap() {
        const colorMode: ColorMode = this.state.getValue().dynamicSettings.colorMode
        if (colorMode !== ColorMode.absolute) {
            this.dialog.open(ErrorDialogComponent, {
                data: this.buildErrorDialog()
            })
        } else {
            this.dialog.open(Export3DMapDialogComponent, {
                panelClass: "cc-export-3D-map-dialog"
            })
        }
    }
 
    buildErrorDialog() {
        const title = "Map could not be exported"
        const message =
            "<p>3D map can only be exported when <strong>color mode</strong> is set to <strong>absolute</strong>.<br>" +
            '<i class="fa fa-info-circle"></i> You can change this under Color Metric Options ' +
            'or use "Change and continue" to directly change the color mode and continue.<p>'
 
        const resolveButtonText = "Change and continue"
        const resolveErrorCallback = () => {
            this.store.dispatch(setColorMode({ value: ColorMode.absolute }))
            this.store
                .select(colorModeSelector)
                .pipe(take(1))
                .subscribe(colorMode => {
                    if (colorMode === ColorMode.absolute) {
                        setTimeout(() => {
                            this.dialog.open(Export3DMapDialogComponent, {
                                panelClass: "cc-export-3D-map-dialog"
                            })
                        }, 100) //TODO: find a better way to wait for the colors to update without using setTimeout
                    }
                })
        }
 
        return { title, message, resolveErrorData: { buttonText: resolveButtonText, onResolveErrorClick: resolveErrorCallback } }
    }
}