All files / app/codeCharta/state/effects/nodeContextMenu/highlightButtons highlightButtons.component.ts

100% Statements 18/18
100% Branches 3/3
100% Functions 5/5
100% Lines 17/17

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 514x   4x 4x 4x                 4x           3x 3x       7x 7x         1x       1x       7x 2x     5x 5x 2x     3x      
import { Component, Input, OnChanges, SimpleChanges } from "@angular/core"
import { CodeMapNode } from "../../../../codeCharta.model"
import { IdToBuildingService } from "../../../../services/idToBuilding/idToBuilding.service"
import { ThreeSceneService } from "../../../../ui/codeMap/threeViewer/threeSceneService"
import { MatButton } from "@angular/material/button"
 
@Component({
    selector: "cc-highlight-buttons",
    templateUrl: "./highlightButtons.component.html",
    styleUrls: ["../nodeContextMenuButton.component.scss"],
    standalone: true,
    imports: [MatButton]
})
export class HighlightButtonsComponent implements OnChanges {
    @Input() codeMapNode: Pick<CodeMapNode, "id">
 
    isHighlighted: boolean
 
    constructor(
        private threeSceneService: ThreeSceneService,
        private idToBuilding: IdToBuildingService
    ) {}
 
    ngOnChanges(changes: SimpleChanges): void {
        if (changes.codeMapNode) {
            this.isHighlighted = this.calculateIsHighlighted()
        }
    }
 
    addNodeToConstantHighlight() {
        this.threeSceneService.addNodeAndChildrenToConstantHighlight(this.codeMapNode)
    }
 
    removeNodeFromConstantHighlight() {
        this.threeSceneService.removeNodeAndChildrenFromConstantHighlight(this.codeMapNode)
    }
 
    private calculateIsHighlighted() {
        if (!this.codeMapNode) {
            return false
        }
 
        const codeMapBuilding = this.idToBuilding.get(this.codeMapNode.id)
        if (!codeMapBuilding) {
            return false
        }
 
        return this.threeSceneService.getConstantHighlight().has(codeMapBuilding.id)
    }
}