import { ChangeDetectorRef , Component , OnInit } from '@angular/core' ; import { Settings } from '../../../classes/settings/settings' ; import { ModalController } from '@ionic/angular' ; import { UIAlert } from '../../../services/uiAlert' ; import { UIBrewStorage } from '../../../services/uiBrewStorage' ; import { UISettingsStorage } from '../../../services/uiSettingsStorage' ; import { ROASTING_MACHINE_ACTION } from '../../../enums/roasting-machine/roastingMachineAction' ; import { RoastingMachine } from '../../../classes/roasting-machine/roasting-machine' ; import { UIRoastingMachineStorage } from '../../../services/uiRoastingMachineStorage' ; import { RoastingMachineAddComponent } from './roasting-machine-add/roasting-machine-add.component' ; import ROASTING_MACHINE_TRACKING from '../../../data/tracking/roastingMachineTracking' ; import { UIAnalytics } from '../../../services/uiAnalytics' ; import { UIRoastingMachineHelper } from '../../../services/uiRoastingMachineHelper' ; @ Component ( { selector : 'app-roasting-machine' , templateUrl : './roasting-machine.page.html' , styleUrls : [ './roasting-machine.page.scss' ] , } ) export class RoastingMachinePage implements OnInit { public roastingMachines : Array < RoastingMachine > = [ ] ; public settings : Settings ; public segment : string = 'open' ; constructor ( public modalCtrl , private readonly changeDetectorRef , private readonly uiRoastingMachineStorage , private readonly uiAlert , private readonly uiBrewStorage , private readonly uiSettingsStorage , private readonly uiAnalytics , private readonly uiRoastingMachineHelper ) { } public ngOnInit ( ) { } public ionViewWillEnter ( ) { this . settings = this . uiSettingsStorage . getSettings ( ) ; this . loadRoastingMachines ( ) ; } public getActiveRoastingMachines ( ) { return this . roastingMachines . filter ( ( machine ) => ! machine . finished ) ; } public getArchivedMRoastingMachines ( ) { return this . roastingMachines . filter ( ( machine ) => machine . finished ) ; } public loadRoastingMachines ( ) { this . __initializeMills ( ) ; this . changeDetectorRef . detectChanges ( ) ; } public async roastingMachineAction ( action , roastingMachine ) { this . loadRoastingMachines ( ) ; } private __initializeMills ( ) { this . roastingMachines = this . uiRoastingMachineStorage . getAllEntries ( ) . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ; } public async add ( ) { await this . uiRoastingMachineHelper . addRoastingMachine ( ) ; this . loadRoastingMachines ( ) ; } }