import { Component } from '@angular/core' ; import { Device } from '@ionic-native/device' ; import { NavController , ViewController , Platform } from 'ionic-angular' ; import { barcodeFormatModel } from '../../models/barcode-format.model' ; import { requestModelHelo } from '../../models/request.model' ; import { ServerProvider } from '../../providers/server' ; import { SelectScanningModePage } from '../scan-session/select-scanning-mode/select-scanning-mode' ; import { Config } from './../../providers/config' ; import { Settings } from './../../providers/settings' ; import { AppVersion } from '@ionic-native/app-version' ; import { Insomnia } from '@ionic-native/insomnia' ; import { Utils } from '../../providers/utils' ; import { TranslateService } from '@ngx-translate/core' ; @ Component ( { selector : 'page-settings' , templateUrl : 'settings.html' } ) export class SettingsPage { public deviceName : string ; public scanSessionName : string ; public scanSessionFilter : string ; public continueModeTimeout = Config . DEFAULT_CONTINUE_MODE_TIMEOUT ; public repeatInterval = Config . DEFAULT_REPEAT_INVERVAL ; public availableContinueModeTimeouts = Array . from ( Array ( 30 ) . keys ( ) ) ; public availableRepeatIntervals = [ ] ; public scanMode = '' ; public duplicateBarcodeChoice : 'ask' | 'accept' | 'discard' = 'ask' ; public alwaysUseDefaultScanSessionName = false ; public alwaysUseCameraForScanSessionName = false ; public preferFrontCamera = false ; public torchOn = false ; public keepDisplayOn = false ; public enableBeep = true ; public enableVibrationFeedback = true ; public openScanOnStart = false ; private changesSaved = false ; public quantityType : string = 'number' ; public barcodeFormats : barcodeFormatModel [ ] = barcodeFormatModel . supportedBarcodeFormats ; public enableLimitBarcodeFormats : boolean = false ; public static SCAN_MODE_LABELS : any = { } ; public static DUPLICATE_BARCODE_LABELS : any = { } ; constructor ( public viewCtrl , public navCtrl , public settings , private serverProvider , public appVersion , private device , public platform , private insomnia , private translateService ) { for ( let i = 0 ; i <= 15000 ; i += 250 ) { this . availableRepeatIntervals . push ( i ) ; } SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_ASK ] = '' ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_CONTINUE ] = '' ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_SINGLE ] = '' ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_ENTER_MAUALLY ] = '' ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'ask' ] = '' ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'accept' ] = '' ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'discard' ] = '' ; } async ngOnInit ( ) { SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_ASK ] = this . translateService . instant ( 'askEveryTimeLabel' ) ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_CONTINUE ] = this . translateService . instant ( 'continuousModeLabel' ) ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_SINGLE ] = this . translateService . instant ( 'singleModeLabel' ) ; SettingsPage . SCAN_MODE_LABELS [ SelectScanningModePage . SCAN_MODE_ENTER_MAUALLY ] = this . translateService . instant ( 'enterManuallyLabel' ) ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'ask' ] = this . translateService . instant ( 'askLabel' ) ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'accept' ] = this . translateService . instant ( 'acceptLabel' ) ; SettingsPage . DUPLICATE_BARCODE_LABELS [ 'discard' ] = this . translateService . instant ( 'discardLabel' ) ; } ionViewDidLoad ( ) { this . settings . getContinueModeTimeout ( ) . then ( seconds => { if ( seconds ) { this . continueModeTimeout = seconds ; } } ) ; this . settings . getDefaultMode ( ) . then ( scanMode => { if ( scanMode ) { this . scanMode = scanMode ; } } ) ; this . settings . getDuplicateBarcodeChoice ( ) . then ( duplicateBarcodeChoice => { if ( duplicateBarcodeChoice ) { this . duplicateBarcodeChoice = duplicateBarcodeChoice ; } } ) ; this . settings . getDeviceName ( ) . then ( deviceName => { this . deviceName = deviceName ; } ) ; this . settings . getScanSessionName ( ) . then ( scanSessionName => { this . scanSessionName = scanSessionName ; } ) ; this . settings . getScanSessionFilter ( ) . then ( scanSessionFilter => { this . scanSessionFilter = scanSessionFilter ; } ) ; this . settings . getRepeatInterval ( ) . then ( repeatInterval => { if ( repeatInterval != null ) { this . repeatInterval = repeatInterval ; } } ) ; this . settings . getBarcodeFormats ( ) . then ( barcodeFormats => { this . barcodeFormats = barcodeFormats ; } ) ; this . settings . getEnableLimitBarcodeFormats ( ) . then ( enableLimitBarcodeFormats => { this . enableLimitBarcodeFormats = enableLimitBarcodeFormats ; } ) ; this . settings . getAlwaysUseDefaultScanSessionName ( ) . then ( alwaysUseDefaultScanSessionName => { this . alwaysUseDefaultScanSessionName = alwaysUseDefaultScanSessionName ; } ) ; this . settings . getAlwaysUseCameraForScanSessionName ( ) . then ( alwaysUseCameraForScanSessionName => { this . alwaysUseCameraForScanSessionName = alwaysUseCameraForScanSessionName ; } ) ; this . settings . getPreferFrontCamera ( ) . then ( preferFrontCamera => { this . preferFrontCamera = preferFrontCamera ; } ) ; this . settings . getTorchOn ( ) . then ( torchOn => { this . torchOn = torchOn ; } ) ; this . settings . getKeepDisplayOn ( ) . then ( keepDisplayOn => { this . keepDisplayOn = keepDisplayOn ; } ) ; this . settings . getEnableBeep ( ) . then ( enableBeep => { this . enableBeep = enableBeep ; } ) ; this . settings . getEnableVibrationFeedback ( ) . then ( enableVibrationFeedback => { this . enableVibrationFeedback = enableVibrationFeedback ; } ) ; this . settings . getOpenScanOnStart ( ) . then ( openScanOnStart => { this . openScanOnStart = openScanOnStart ; } ) ; deprecated this . settings . getQuantityType ( ) . then ( quantityType => { if ( quantityType ) { this . quantityType = quantityType ; } } ) ; } ionViewWillLeave ( ) { if ( ! this . changesSaved ) { this . saveChanges ( ) ; } } dismiss ( ) { this . changesSaved = true ; this . saveChanges ( ) ; this . viewCtrl . dismiss ( ) ; } async saveChanges ( ) { this . settings . setContinueModeTimeout ( this . continueModeTimeout ) ; this . settings . setRepeatInterval ( this . repeatInterval ) ; this . settings . setDefaultMode ( this . scanMode ) ; this . settings . setDuplicateBarcodeChoice ( this . duplicateBarcodeChoice ) ; this . settings . setDeviceName ( this . deviceName ) ; this . settings . setScanSessionName ( this . scanSessionName ) ; this . settings . setScanSessionFilter ( this . scanSessionFilter ) ; this . settings . setAlwaysUseDefaultScanSessionName ( this . alwaysUseDefaultScanSessionName ) ; this . settings . setAlwaysUseCameraForScanSessionName ( this . alwaysUseCameraForScanSessionName ) ; this . settings . setPreferFrontCamera ( this . preferFrontCamera ) ; this . settings . setTorchOn ( this . torchOn ) ; this . settings . setKeepDisplayOn ( this . keepDisplayOn ) ; this . settings . setEnableBeep ( this . enableBeep ) ; this . settings . setEnableVibrationFeedback ( this . enableVibrationFeedback ) ; this . settings . setOpenScanOnStart ( this . openScanOnStart ) ; this . settings . setBarcodeFormats ( this . barcodeFormats ) ; this . settings . setEnableLimitBarcodeFormats ( this . enableLimitBarcodeFormats ) ; this . settings . setQuantityType ( this . quantityType ) ; if ( this . keepDisplayOn ) { this . insomnia . keepAwake ( ) ; } else { this . insomnia . allowSleepAgain ( ) ; } this . serverProvider . send ( new requestModelHelo ( ) . fromObject ( { version : await this . appVersion . getVersionNumber ( ) , deviceName : this . deviceName , deviceId : this . device . uuid } ) ) ; } public getScanModeList ( ) { return [ SelectScanningModePage . SCAN_MODE_ASK , SelectScanningModePage . SCAN_MODE_CONTINUE , SelectScanningModePage . SCAN_MODE_SINGLE , SelectScanningModePage . SCAN_MODE_ENTER_MAUALLY , ] ; } public getScanModeName ( scanMode ) { return SettingsPage . SCAN_MODE_LABELS [ scanMode ] ; } public duplicateBarcodeChoiceName ( choice ) { return SettingsPage . DUPLICATE_BARCODE_LABELS [ choice ] ; } }