import { Component , OnInit , Injector } from '@angular/core' ; import { CachingServiceProxy , EntityDtoOfString , WebLogServiceProxy , CacheDto } from '@shared/service-proxies/service-proxies' ; import { escape as _escape } from 'lodash-es' ; import { PagedListingComponentBase , PagedRequestDto , } from '@shared/common/paged-listing-component-base' ; import { finalize } from 'rxjs/operators' ; import { FileDownloadService } from '@shared/utils/file-download.service' ; @ Component ( { selector : 'app-maintenance' , templateUrl : './maintenance.component.html' , styleUrls : [ './maintenance.component.less' ] , } ) export class MaintenanceComponent extends PagedListingComponentBase < CacheDto > implements OnInit { logs : any = '' ; constructor ( injector , private cacheService , private _webLogService , private _fileDownloadService ) { super ( injector ) ; } ngOnInit ( ) { this . refresh ( ) ; this . getWebLogs ( ) ; } protected fetchDataList ( request , pageNumber , finishedCallback ) { this . cacheService . getAllCaches ( ) . pipe ( finalize ( finishedCallback ) ) . subscribe ( result => { this . dataList = result . items ; } ) ; } clearCache ( cacheName ) { const input = new EntityDtoOfString ( ) ; input . id = cacheName ; this . cacheService . clearCache ( input ) . subscribe ( ( ) => { this . notify . success ( this . l ( 'CacheSuccessfullyCleared' ) ) ; } ) ; } clearAllCaches ( ) { this . cacheService . clearAllCaches ( ) . subscribe ( ( ) => { this . notify . success ( this . l ( 'AllCachesSuccessfullyCleared' ) ) ; } ) ; } getWebLogs ( ) { this . _webLogService . getLatestWebLogs ( ) . subscribe ( result => { this . logs = result . latestWebLogLines ; } ) ; } downloadWebLogs = function ( ) { this . _webLogService . downloadWebLogs ( ) . subscribe ( result => { this . _fileDownloadService . downloadTempFile ( result ) ; } ) ; } ; getLogClass ( log ) { if ( log . startsWith ( 'DEBUG' ) ) { return 'badge badge-grey' ; } if ( log . startsWith ( 'INFO' ) ) { return 'badge badge-success' ; } if ( log . startsWith ( 'WARN' ) ) { return 'badge badge-warning' ; } if ( log . startsWith ( 'ERROR' ) || log . startsWith ( 'FATAL' ) ) { return 'badge badge-error' ; } return '' ; } getLogType ( log ) { if ( log . startsWith ( 'DEBUG' ) ) { return 'DEBUG' ; } if ( log . startsWith ( 'INFO' ) ) { return 'INFO' ; } if ( log . startsWith ( 'WARN' ) ) { return 'WARN' ; } if ( log . startsWith ( 'ERROR' ) ) { return 'ERROR' ; } if ( log . startsWith ( 'FATAL' ) ) { return 'FATAL' ; } return '' ; } getRawLogContent ( log ) { return _escape ( log ) . replace ( 'DEBUG' , '' ) . replace ( 'INFO' , '' ) . replace ( 'WARN' , '' ) . replace ( 'ERROR' , '' ) . replace ( 'FATAL' , '' ) ; } }