import { Component , OnInit } from "@angular/core" ; import { UserSettingsService } from "../shared/services/user-settings/user-settings.service" ; import { ConfirmDialogDataModel } from "../shared/dialogs/confirm-dialog/confirm-dialog-data.model" ; import { ConfirmDialogComponent } from "../shared/dialogs/confirm-dialog/confirm-dialog.component" ; import { MatDialog , MatSnackBar } from "@angular/material" ; import { SyncService } from "../shared/services/sync/sync.service" ; import { AthleteService } from "../shared/services/athlete/athlete.service" ; @ Component ( { selector : "app-advanced-menu" , templateUrl : "./advanced-menu.component.html" , styleUrls : [ "./advanced-menu.component.scss" ] } ) export class AdvancedMenuComponent implements OnInit { constructor ( public userSettingsService , public athleteService , public syncService , public dialog , public snackBar ) { } public ngOnInit ( ) { } public onSyncedBackupClear ( ) { const data = { title : "Clear your athlete synced data" , content : "Are you sure to perform this action? You will be able to re-import synced data through backup file " + "or a new re-synchronization." } ; const dialogRef = this . dialog . open ( ConfirmDialogComponent , { minWidth : ConfirmDialogComponent . MIN_WIDTH , maxWidth : ConfirmDialogComponent . MAX_WIDTH , data : data } ) ; const afterClosedSubscription = dialogRef . afterClosed ( ) . subscribe ( ( confirm ) => { if ( confirm ) { this . syncService . clearSyncedData ( ) . then ( ( ) => { afterClosedSubscription . unsubscribe ( ) ; location . reload ( ) ; } , error => { this . snackBar . open ( error , "Close" ) ; } ) ; } } ) ; } public onPluginCacheClear ( ) { const data = { title : "Clear the plugin cache" , content : "This will remove caches of the plugin including display preferences (e.g. app theme chosen). You will not loose your synced data, athlete settings, zones settings or global settings." } ; const dialogRef = this . dialog . open ( ConfirmDialogComponent , { minWidth : ConfirmDialogComponent . MIN_WIDTH , maxWidth : ConfirmDialogComponent . MAX_WIDTH , data : data } ) ; const afterClosedSubscription = dialogRef . afterClosed ( ) . subscribe ( ( confirm ) => { if ( confirm ) { localStorage . clear ( ) ; this . userSettingsService . clearLocalStorageOnNextLoad ( ) . then ( ( ) => { this . snackBar . open ( "Plugin cache has been cleared" , "Reload App" ) . afterDismissed ( ) . toPromise ( ) . then ( ( ) => { location . reload ( ) ; } ) ; afterClosedSubscription . unsubscribe ( ) ; } ) ; } } ) ; } public onZoneSettingsReset ( ) { const data = { title : "Reset zones" , content : "This will reset only your zones to defaults. Are you sure to perform this action?" } ; const dialogRef = this . dialog . open ( ConfirmDialogComponent , { minWidth : ConfirmDialogComponent . MIN_WIDTH , maxWidth : ConfirmDialogComponent . MAX_WIDTH , data : data } ) ; const afterClosedSubscription = dialogRef . afterClosed ( ) . subscribe ( ( confirm ) => { if ( confirm ) { Promise . all ( [ this . userSettingsService . reset ( ) , this . userSettingsService . clearLocalStorageOnNextLoad ( ) ] ) . then ( ( ) => { this . snackBar . open ( "Zones settings have been reset" , "Close" ) ; afterClosedSubscription . unsubscribe ( ) ; } ) ; } } ) ; } public onUserSettingsReset ( ) { const data = { title : "Reset settings" , content : "This will reset your settings to defaults including: dated athlete settings, zones settings and global settings. Are you sure to perform this action?" } ; const dialogRef = this . dialog . open ( ConfirmDialogComponent , { minWidth : ConfirmDialogComponent . MIN_WIDTH , maxWidth : ConfirmDialogComponent . MAX_WIDTH , data : data } ) ; const afterClosedSubscription = dialogRef . afterClosed ( ) . subscribe ( ( confirm ) => { if ( confirm ) { Promise . all ( [ this . userSettingsService . reset ( ) , this . athleteService . resetSettings ( ) , this . userSettingsService . clearLocalStorageOnNextLoad ( ) ] ) . then ( ( ) => { this . snackBar . open ( "Settings have been reset" , "Close" ) ; afterClosedSubscription . unsubscribe ( ) ; } ) ; } } ) ; } }