All files / app/codeCharta/ui/customConfigs/customConfigList/customConfigItemGroup customConfigItemGroup.component.ts

94.59% Statements 35/37
90% Branches 9/10
100% Functions 6/6
94.44% Lines 34/36

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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 946x 6x   6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x                                             6x     16x 16x 16x     16x 16x 16x 16x       27x 15x 3x 1x     12x                   60x           4x 4x     1x 1x       1x                  
import { Component, Input, OnChanges, SimpleChanges, ViewChild } from "@angular/core"
import { CustomConfigHelper } from "../../../../util/customConfigHelper"
import { CustomConfigItemGroup } from "../../customConfigs.component"
import { ThreeCameraService } from "../../../codeMap/threeViewer/threeCamera.service"
import { ThreeMapControlsService } from "../../../codeMap/threeViewer/threeMapControls.service"
import { Store } from "@ngrx/store"
import { MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle } from "@angular/material/expansion"
import { ThreeRendererService } from "../../../codeMap/threeViewer/threeRenderer.service"
import { MatList, MatListItem } from "@angular/material/list"
import { MatDialogClose } from "@angular/material/dialog"
import { CustomConfigNoteDialogButtonComponent } from "../../customConfigNoteDialogButton/customConfigNoteDialogButton.component"
import { ApplyCustomConfigButtonComponent } from "./customConfigDescription/applyCustomConfigButton.component"
import { TitleCasePipe, KeyValuePipe } from "@angular/common"
import { TruncateTextPipe } from "../../../../util/pipes/truncateText.pipe"
import { CustomConfig2ApplicableMessage } from "./customConfig2ApplicableMessage.pipe"
import { FilterCustomConfigDataBySearchTermPipe } from "./customConfigDescription/filterCustomConfigDataBySearchTerm.pipe"
 
@Component({
    selector: "cc-custom-config-item-group",
    templateUrl: "./customConfigItemGroup.component.html",
    styleUrls: ["./customConfigItemGroup.component.scss"],
    standalone: true,
    imports: [
        MatExpansionPanel,
        MatExpansionPanelHeader,
        MatExpansionPanelTitle,
        MatList,
        MatListItem,
        MatDialogClose,
        CustomConfigNoteDialogButtonComponent,
        ApplyCustomConfigButtonComponent,
        TitleCasePipe,
        KeyValuePipe,
        TruncateTextPipe,
        CustomConfig2ApplicableMessage,
        FilterCustomConfigDataBySearchTermPipe
    ]
})
export class CustomConfigItemGroupComponent implements OnChanges {
    @Input() customConfigItemGroups: Map<string, CustomConfigItemGroup>
    @ViewChild("matExpansionPanel") matExpansionPanel: MatExpansionPanel
    @Input() searchTerm = ""
    expandedStates: { [key: string]: boolean } = {}
    manuallyToggled: Set<string> = new Set()
 
    constructor(
        private store: Store,
        private threeCameraService: ThreeCameraService,
        private threeOrbitControlsService: ThreeMapControlsService,
        private threeRendererService: ThreeRendererService
    ) {}
 
    ngOnChanges(changes: SimpleChanges): void {
        if (changes.searchTerm) {
            if (changes.searchTerm.currentValue.length > 0) {
                for (const groupKey of Object.keys(this.expandedStates)) {
                    this.expandedStates[groupKey] = true
                }
            } else {
                for (const groupKey of Object.keys(this.expandedStates)) {
                    Iif (!this.manuallyToggled.has(groupKey)) {
                        this.expandedStates[groupKey] = false
                    }
                }
            }
        }
    }
 
    isGroupExpanded(groupKey: string): boolean {
        return this.searchTerm.length > 0
            ? !this.manuallyToggled.has(groupKey) || this.expandedStates[groupKey]
            : this.expandedStates[groupKey] || false
    }
 
    toggleGroupExpansion(groupKey: string): void {
        this.expandedStates[groupKey] = !this.isGroupExpanded(groupKey)
        this.manuallyToggled.add(groupKey)
    }
    removeCustomConfig(configId: string, groupKey: string) {
        CustomConfigHelper.deleteCustomConfig(configId)
        this.expandedStates[groupKey] = true
    }
 
    applyCustomConfig(configId: string) {
        CustomConfigHelper.applyCustomConfig(
            configId,
            this.store,
            this.threeCameraService,
            this.threeOrbitControlsService,
            this.threeRendererService
        )
    }
}