import { OnInit, Input, Component, NgZone } from "@angular/core"; import { StpConfigureService } from "../stp-configure.service"; import { MainPageService } from "../../../main-page/main-page.service"; import { ExtensionInterface } from "../../../models/viewer/ExtensionInterface.model"; @Component({ selector: 'arms-configure', templateUrl: './arms-configure.component.html', styleUrls: ['./arms-configure.component.scss', '../stp-configure.component.scss'] }) export class ArmsConfigureComponent implements OnInit { @Input() extensionInterface: ExtensionInterface; public armData = []; public profileData: any; public dirOptions = []; public releaseCodeOptions = []; public isVariantChoosen: boolean = false; @Input() set ExtensionInterface(value: ExtensionInterface) { this.extensionInterface = value; if (this.extensionInterface !== null) { this.extensionInterface.loadingCompleated.subscribe(() => { this.zone.run(() => { this.loadVariantData(); this.isVariantChoosen = this.extensionInterface.isVariantChoosen; }); }); } } constructor(private stpConfigureService: StpConfigureService, private mainPageService: MainPageService, private zone: NgZone) { } ngOnInit(): void { this.mainPageService.loadAllReleases().subscribe((response) => { this.releaseCodeOptions = response; }); } loadVariantData(): void { if (!this.extensionInterface.verifyArmDefinitionForProfileConfiguration(1)) { this.extensionInterface.resetConnectorCrossSectionsConfig(); this.saveConfiguration(); } this.profileData = this.extensionInterface.getConnectorCrossSectionsConfig(); } showArmsConfiguration() { this.dirOptions = this.extensionInterface.getPossibleArmDirections(); this.armData = this.extensionInterface.getArms(); } armDirectionChanged(arm, event) { this.extensionInterface.changeArmDirection(arm, event.id); this.saveConfiguration(); this.saveVariantConfiguration(); } removeArm(arm) { this.extensionInterface.removeArmDefintion(arm); this.armData = this.extensionInterface.getArms(); this.saveConfiguration(); this.saveVariantConfiguration(); } addEmptyArm() { this.extensionInterface.createEmptyArm(); this.armData = this.extensionInterface.getArms(); } saveConfiguration() { const data = this.extensionInterface.prepareFullConnectorConfiguration(); this.stpConfigureService.saveConnectorConfiguration(data).subscribe((response) => { }); } saveVariantConfiguration() { const data = this.extensionInterface.getConnectorCrossSectionsConfig(); this.stpConfigureService.saveConnectorVariantConfiguration(data).subscribe((response) => { }); } releaseCodeChanged(index, event) { if (this.profileData.armData[index].borderBeam) { const armsToChange = this.checkForSiblings(this.armData[index]); armsToChange.forEach(arm => { this.profileData.armData.find(x => x.armId === arm.id).releaseId = event; }); } else { this.profileData.armData[index].releaseId = event; } this.saveVariantConfiguration(); } isBorderValueChanged(index) { const state = this.profileData.armData[index].borderBeam; const armsToChange = this.checkForSiblings(this.armData[index]); this.profileData.armData.forEach(arm => { arm.borderBeam = false; }); armsToChange.forEach(arm => { this.profileData.armData.find(x => x.armId === arm.id).borderBeam = state; }); this.saveVariantConfiguration(); } checkForSiblings(arm) { const arms = []; for (let i = 0; i < this.armData.length; i++) { if (this.armData[i].dirObj[0].text === arm.dirObj[0].text) { arms.push(this.armData[i]); } } return arms; } }