import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core"; import { AlertController, ModalController, ViewWillEnter, ViewWillLeave, } from "@ionic/angular"; import { Connect2frameService } from "../../services/connect2frame.service"; import { CountService } from "../../services/count.service"; import { TranslateService } from "@ngx-translate/core"; import { container } from "../../models/container.model"; @Component({ selector: "counting-page", templateUrl: "./counting-page.component.html", styleUrls: ["./counting-page.component.scss"], }) export class CountingPage implements OnInit, OnChanges, OnDestroy, ViewWillEnter, ViewWillLeave { @Input("article") article: string; @Input("newOrUsed") newOrUsed: string; @Input("orderedValue") orderedValue: number; @Input("normPacking") normPacking: number; @Input("container") container: string; constructor( public frameConnector: Connect2frameService, public countService: CountService, public alertCtrl: AlertController, private translateService: TranslateService, private modalCtrl: ModalController ) {} ionViewWillEnter() { console.log(this.article, this.newOrUsed, this.orderedValue); this.countService.currentCount.Packing = this.orderedValue; this.frameConnector.countService.containers = []; this.frameConnector.countService.containers.push(new container(1, 0)); this.frameConnector.countService.selectedContainer = this.frameConnector.countService.containers[0]; } ionViewWillLeave() {} ngOnInit() {} ngOnDestroy() { this.frameConnector.disconnect(); this.frameConnector.resetFrame(); this.countService.resetUI(); this.countService.resetContainers(); } //Opens alert containing options on how the user wants to connect to a BT Device async choosePairingMethod() { if (this.frameConnector.IsEnabled && !this.frameConnector.IsConnected) { this.alertCtrl .create({ header: this.translateService.instant("CONNECT TO FRAME"), message: this.translateService.instant("SELECT PAIRING METHOD"), buttons: [ { text: this.translateService.instant("SELECT FROM LIST"), role: "confirm", handler: () => { this.frameConnector.scan(); }, }, ], }) .then((alert) => { alert.present(); }); } if (this.frameConnector.IsConnected) { this.frameConnector.disconnect(); } } //Resets the UI, disconnects the Frame, but doesnt reset the Frame allthough the Frame gets reset every time someone connects to it. resetNoSave() { /* this.alertCtrl.create({ header: this.translateService.instant("RESET_METHOD_H"), message: this.translateService.instant("RESET_METHOD_M"), buttons: [ { text: this.translateService.instant("RESET_EVERYTHING"), handler: ()=>{ this.frameConnector.resetFrame(); this.countService.resetUI(); this.countService.resetContainers(); } }, { text: this.translateService.instant("RESET_CURRENT_CONTAINER"), handler: ()=>{ this.frameConnector.resetCurrentContainer(); } }, { text: this.translateService.instant("CANCEL"), handler: ()=>{} } ] }).then(alert=>{ alert.present(); }); */ this.frameConnector.resetFrame(); this.countService.resetUI(); this.countService.resetContainers(); } //Resets the UI and the Frame, saves current Values in Pouch resetSave() { this.frameConnector.countService.selectedContainer.save(); this.modalCtrl.dismiss({ ReturnValue: this.countService.currentCount.Return, }); this.frameConnector.resetFrame(); this.countService.resetUI(); } ngOnChanges() {} closeFrameNoData() { this.frameConnector .disconnect() .then(() => { this.modalCtrl.dismiss({ ReturnValue: null }); }) .catch(() => { this.modalCtrl.dismiss({ ReturnValue: null}); }); } }