import { OnInit, Input, Component, NgZone } from "@angular/core"; import { StpConfigureService } from "../stp-configure.service"; import { MainPageService } from "../../../main-page/main-page.service"; import { ShowViewerArgs } from "../../../models/viewer/ShowViewerArgs.model"; import { PipeRingVariantConfigModel } from "../../../models/parts/pipering-variant-config.model"; import { UnitsConverter } from "../../../shared/units-converter/units-converter"; import { PipeRingModel } from "../../../models/parts/pipering.model."; import { PiperingBossModel } from "../../../models/parts/pipering-boss.model"; @Component({ selector: 'pipering-configure', templateUrl: './pipering-configure.component.html', styleUrls: ['./pipering-configure.component.scss', '../stp-configure.component.scss'] }) export class PiperingConfigureComponent implements OnInit { @Input() args: ShowViewerArgs; private pipering: PipeRingModel[]; public piperingVariantConfig: PipeRingVariantConfigModel; public configDisplay: PipeRingVariantConfigModel; private unitsConverter = new UnitsConverter(); public selectedUnit: string = 'mm'; public piperingBossData: PiperingBossModel[] = []; @Input() set Args(value: ShowViewerArgs) { this.args = value; if (this.args !== null) { this.loadVariantData(); } } constructor(private stpConfigureService: StpConfigureService, private mainPageService: MainPageService, private zone: NgZone) { } ngOnInit(): void { this.piperingVariantConfig = new PipeRingVariantConfigModel(); this.configDisplay = new PipeRingVariantConfigModel(); } loadVariantData(): void { this.mainPageService.getPiperingVariantConfigurationData(this.args.variantId).subscribe((response) => { if ((response.isEmpty !== undefined) ? response.isEmpty : false) { this.createNewConfig(); } else { this.piperingVariantConfig = response; this.changeDisplayedUnits(); } }); this.mainPageService.loadAllPiperingBosses().subscribe((response) => { this.piperingBossData = response; }) } createNewConfig() { this.mainPageService.getSpecificPipering(this.args.itemId).subscribe((res) => { this.pipering = res; this.piperingVariantConfig = new PipeRingVariantConfigModel(); this.piperingVariantConfig._id = this.args.variantId; this.piperingVariantConfig.isStandard = !(this.pipering[0].piperingGroupId === 2 || this.pipering[0].piperingGroupId === 3); if (this.piperingVariantConfig.isStandard) { this.piperingVariantConfig.isCeiling = true; } this.piperingVariantConfig.isDouble = false; this.changeDisplayedUnits(); }); } preventKeys(event) { if (event.charCode === 45 || event.charCode === 69 || event.charCode === 101 || event.charCode === 43) { event.preventDefault(); } } saveVariantChanges() { this.changeElementUnitsToSI(); // this.piperingVariantConfig.bossReference = +this.piperingVariantConfig.bossReference; this.mainPageService.postPiperingVariantConfiguration(this.piperingVariantConfig).subscribe((response) => { }); } private changeDisplayedUnits() { const tempObject = new PipeRingVariantConfigModel(); tempObject._id = this.piperingVariantConfig._id; tempObject.isCeiling = this.piperingVariantConfig.isCeiling; tempObject.isFloor = this.piperingVariantConfig.isFloor; tempObject.isWall = this.piperingVariantConfig.isWall; tempObject.isDouble = this.piperingVariantConfig.isDouble; tempObject.isStandard = this.piperingVariantConfig.isStandard; tempObject.bossReference = (this.piperingVariantConfig.bossReference) ? null : this.piperingVariantConfig.bossReference.valueOf(); tempObject.threadedRods = this.piperingVariantConfig.threadedRods; if (this.piperingVariantConfig.clampingRangeMax !== null) { tempObject.clampingRangeMax = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.clampingRangeMax, this.selectedUnit, 4); } if (this.piperingVariantConfig.clampingRangeMin !== null) { tempObject.clampingRangeMin = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.clampingRangeMin, this.selectedUnit, 4); } if (this.piperingVariantConfig.centerToBoss !== null) { tempObject.centerToBoss = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.centerToBoss, this.selectedUnit, 4); } if (this.piperingVariantConfig.width !== null) { tempObject.width = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.width, this.selectedUnit, 4); } if (this.piperingVariantConfig.screwSpacing !== null) { tempObject.screwSpacing = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.screwSpacing, this.selectedUnit, 4); } if (this.piperingVariantConfig.depth !== null) { tempObject.depth = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.depth, this.selectedUnit, 4); } if (this.piperingVariantConfig.spacingBetween !== null) { tempObject.spacingBetween = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.spacingBetween, this.selectedUnit, 4); } if (this.piperingVariantConfig.spacingAbove !== null) { tempObject.spacingAbove = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.spacingAbove, this.selectedUnit, 4); } if (this.piperingVariantConfig.adjustmentLength !== null) { tempObject.adjustmentLength = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.adjustmentLength, this.selectedUnit, 4); } if (this.piperingVariantConfig.insulationThickness !== null) { tempObject.insulationThickness = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.insulationThickness, this.selectedUnit, 4); } if (this.piperingVariantConfig.externalDiameter !== null) { tempObject.externalDiameter = this.unitsConverter.convertFromSIToUnits( this.piperingVariantConfig.externalDiameter, this.selectedUnit, 4); } Object.assign(this.configDisplay, tempObject); } private changeElementUnitsToSI() { const tempObject = new PipeRingVariantConfigModel(); tempObject._id = this.configDisplay._id; tempObject.isCeiling = this.configDisplay.isCeiling; tempObject.isFloor = this.configDisplay.isFloor; tempObject.isWall = this.configDisplay.isWall; tempObject.isDouble = this.configDisplay.isDouble; tempObject.isStandard = this.configDisplay.isStandard; tempObject.bossReference = (this.piperingVariantConfig.bossReference) ? null : this.piperingVariantConfig.bossReference.valueOf(); tempObject.threadedRods = this.configDisplay.threadedRods; if (this.configDisplay.clampingRangeMax !== null) { tempObject.clampingRangeMax = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.clampingRangeMax, this.selectedUnit); } if (this.configDisplay.clampingRangeMin !== null) { tempObject.clampingRangeMin = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.clampingRangeMin, this.selectedUnit); } if (this.configDisplay.centerToBoss !== null) { tempObject.centerToBoss = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.centerToBoss, this.selectedUnit); } if (this.configDisplay.width !== null) { tempObject.width = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.width, this.selectedUnit); } if (this.configDisplay.screwSpacing !== null) { tempObject.screwSpacing = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.screwSpacing, this.selectedUnit); } if (this.configDisplay.depth !== null) { tempObject.depth = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.depth, this.selectedUnit); } if (this.configDisplay.spacingBetween !== null) { tempObject.spacingBetween = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.spacingBetween, this.selectedUnit); } if (this.configDisplay.spacingAbove !== null) { tempObject.spacingAbove = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.spacingAbove, this.selectedUnit); } if (this.configDisplay.adjustmentLength !== null) { tempObject.adjustmentLength = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.adjustmentLength, this.selectedUnit); } if (this.configDisplay.insulationThickness !== null) { tempObject.insulationThickness = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.insulationThickness, this.selectedUnit); } if (this.configDisplay.externalDiameter !== null) { tempObject.externalDiameter = this.unitsConverter.convertFromUnitsToSI( this.configDisplay.externalDiameter, this.selectedUnit); } Object.assign(this.piperingVariantConfig, tempObject); } mountingChange() { if (this.configDisplay.isDouble) { this.configDisplay.centerToBoss = null; this.configDisplay.adjustmentLength = null; } else { this.configDisplay.screwSpacing = null; } this.saveVariantChanges(); } }