import angular from 'angular' ; import { Component , OnInit } from 'angular-ts-decorators' ; import autobind from 'autobind-decorator' ; import { PlatformService } from '../../../shared/global-shared.interface' ; import { LogLevel } from '../../../shared/log/log.enum' ; import { LogService } from '../../../shared/log/log.service' ; import { UtilityService } from '../../../shared/utility/utility.service' ; import { RoutePath } from '../../app.enum' ; import { AppHelperService } from '../../shared/app-helper/app-helper.service' ; @ autobind @ Component ( { controllerAs : 'vm' , selector : 'issuesSettings' , styles : [ require ( './issues-settings.component.scss' ) ] , template : require ( './issues-settings.component.html' ) } ) export class IssuesSettingsComponent implements OnInit { Strings = require ( '../../../../../res/strings/en.json' ) ; appHelperSvc : AppHelperService ; logSvc : LogService ; platformSvc : PlatformService ; utilitySvc : UtilityService ; downloadLogCompletedMessage : string ; logSize : number ; savingLog = false ; static $inject = [ 'AppHelperService' , 'LogService' , 'PlatformService' , 'UtilityService' ] ; constructor ( AppHelperSvc , LogSvc , PlatformSvc , UtilitySvc ) { this . appHelperSvc = AppHelperSvc ; this . logSvc = LogSvc ; this . platformSvc = PlatformSvc ; this . utilitySvc = UtilitySvc ; } clearLog ( ) { this . logSvc . clear ( ) . then ( ( ) => { this . logSize = 0 ; } ) ; } downloadLog ( ) { this . savingLog = true ; this . saveLogFile ( ) . then ( ( filename ) => { if ( ! filename ) { return ; } this . downloadLogCompletedMessage = this . utilitySvc . isMobilePlatform ( this . platformSvc . platformName ) ? `${ this . platformSvc . getI18nString ( this . Strings . View . Settings . FileDownloaded ) }: ${ filename }` : '' ; } ) . finally ( ( ) => { this . savingLog = false ; this . appHelperSvc . focusOnElement ( '.btn-done' ) ; } ) ; } getLogFilename ( ) { const fileName = `xbs_log_${ this . utilitySvc . getDateTimeString ( new Date ( ) ) }.txt` ; return fileName ; } ngOnInit ( ) { this . logSvc . getLogEntries ( ) . then ( ( traceLogItems ) => { if ( angular . isUndefined ( traceLogItems ?? undefined ) ) { this . logSize = 0 ; return ; } this . logSize = new TextEncoder ( ) . encode ( traceLogItems . join ( ) ) . length ; } ) ; } saveLogFile ( ) { return this . logSvc . getLogEntries ( ) . then ( ( traceLogItems ) => { const log = traceLogItems . map ( ( traceLogItem ) => { let messageLogText = `${ new Date ( traceLogItem . timestamp ) . toISOString ( ) . replace ( /[A-Z]/g , ' ' ) . trim ( ) }\t` ; switch ( traceLogItem . level ) { case LogLevel . Error : messageLogText += '[error]\t' ; break ; case LogLevel . Warn : messageLogText += '[warn]\t' ; break ; case LogLevel . Trace : default : messageLogText += '[trace]\t' ; } messageLogText += traceLogItem . message ; return messageLogText ; } ) ; return this . platformSvc . downloadFile ( this . getLogFilename ( ) , log . join ( '\r\n' ) ) ; } ) ; } switchToHelpView ( ) { this . appHelperSvc . switchView ( RoutePath . Help ) ; } }