import { OnInit, Component, Input, NgZone } from "@angular/core"; import { MainPageService } from "../../main-page.service"; import { StpConfigureService } from "../stp-configure.service"; import { ExtensionInterface } from "../../../models/viewer/ExtensionInterface.model"; @Component({ selector: 'profiles-configure', templateUrl: './profiles-configure.component.html', styleUrls: ['./profiles-configure.component.scss', '../stp-configure.component.scss'] }) export class ProfilesConfigureComponent implements OnInit { private extensionInterface: ExtensionInterface; public profileData: any; public crossSectionOptions = []; public armData = []; public dirOptions = []; public releaseCodeOptions = []; public currentChoosenArmGroup: number = 1; @Input() set ExtensionInterface(value: ExtensionInterface) { this.extensionInterface = value; if (this.extensionInterface !== null) { this.extensionInterface.loadingCompleated.subscribe(() => { this.zone.run(() => { this.showProfilesConfiguration(); }); }); } } constructor(private mainPageService: MainPageService, private stpConfigureService: StpConfigureService, private zone: NgZone ) { this.profileData = { armGroups: [{ arms: [] }] }; } ngOnInit(): void { this.mainPageService.loadAllCrossSections().subscribe((allCrossSections) => { this.crossSectionOptions.splice(0, this.crossSectionOptions.length);//clear array for (var j = 0; j < allCrossSections.length; j++) { var crossSection = allCrossSections[j]; this.crossSectionOptions.push({ id: crossSection._id, text: crossSection.name }); } }); } saveConfiguration() { const data = this.extensionInterface.getConnectorCrossSectionsConfig(); this.stpConfigureService.saveConnectorVariantConfiguration(data).subscribe(() => { }); } showProfilesConfiguration(): void { if (!this.extensionInterface.verifyArmDefinitionForProfileConfiguration(this.currentChoosenArmGroup)) { this.extensionInterface.resetConnectorCrossSectionsConfig(); this.saveConfiguration(); } this.profileData = this.extensionInterface.getConnectorCrossSectionsConfig(); this.extensionInterface.showConnectorCrossSections(this.currentChoosenArmGroup); } addCrossSection(arm) { this.extensionInterface.createEmptyConnectorCrossSection(arm, this.currentChoosenArmGroup); this.profileData = this.extensionInterface.getConnectorCrossSectionsConfig(); } removeCrossSection(arm, crossSection) { var ind = arm.crossSections.indexOf(crossSection); arm.crossSections.splice(ind, 1); this.extensionInterface.removeCrossSectionForArm(arm, crossSection); this.saveConfiguration(); } crossSectionChanged(arm, crossSection, event) { crossSection.crossSectionId = event.id; crossSection.crossSectionName = event.text; this.extensionInterface.changeShownCrossSection(arm, crossSection, this.currentChoosenArmGroup); this.saveConfiguration(); } showCrossSection(arm, crossSection) { this.extensionInterface.changeShownCrossSection(arm, crossSection, this.currentChoosenArmGroup); } rotationChanged(arm, crossSection, angle) { if (angle !== 0) crossSection.allow0rotation = false; if (angle !== 90) crossSection.allow90rotation = false; if (angle !== 180) crossSection.allow180rotation = false; if (angle !== 270) crossSection.allow270rotation = false; crossSection.rotationAngle = angle / 180 * Math.PI; this.extensionInterface.changeShownCrossSection(arm, crossSection, this.currentChoosenArmGroup); this.saveConfiguration(); } hideCrossSections() { this.extensionInterface.hideConnectorCrossSections(); } addNewArmGroup(newGroupName) { this.extensionInterface.createEmptyArmGroup(newGroupName); this.saveConfiguration(); this.currentChoosenArmGroup = this.profileData.armGroups.length; this.showProfilesConfiguration(); } removeCurrentArmGroup() { if (this.currentChoosenArmGroup !== 1) { const groupToRemove = this.profileData.armGroups[this.currentChoosenArmGroup - 1]; this.extensionInterface.removeArmGroup(groupToRemove); this.saveConfiguration(); if (this.profileData.armGroups[this.currentChoosenArmGroup - 1] === undefined) { this.currentChoosenArmGroup = this.currentChoosenArmGroup - 1; } this.showProfilesConfiguration(); } } onGroupChange() { this.showProfilesConfiguration(); } }