11//#region imports
2- import { Component , OnInit , AfterViewInit , OnDestroy } from '@angular/core' ;
2+ import { Component , OnInit , OnDestroy } from '@angular/core' ;
33import { EventLog } from '../../types/EventLog' ;
44import { PowershellService } from '../../services/powershell/powershell.service' ;
5- import { NzModalRef } from 'ng-zorro-antd' ;
5+ import { NzModalRef , NzModalService } from 'ng-zorro-antd' ;
66import { Subscription , fromEvent } from 'rxjs' ;
77import { map , debounceTime } from 'rxjs/operators' ;
8+ import { PowershellCommands } from '../../services/powershell/powershell-commands' ;
89//#endregion imports
910
1011@Component ( {
@@ -14,10 +15,10 @@ import { map, debounceTime } from 'rxjs/operators';
1415export class LogSelectionComponent implements OnInit , OnDestroy {
1516
1617 //#region Constructor & Properties
17- constructor ( private psService : PowershellService
18- , private modal : NzModalRef
19- ) { }
20- private _searchSubscription : Subscription ;
18+ constructor ( private modalService : NzModalService
19+ , private modal : NzModalRef ) { }
20+
21+ private _searchInputSub : Subscription ;
2122
2223 public loading : boolean = true ;
2324 private _logers : EventLog [ ] = [ ] ;
@@ -29,27 +30,27 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
2930
3031 //#region Component Methods
3132 ngOnInit ( ) : void {
32- this . search ( ) ;
33+ this . _search ( ) ;
3334 this . _setupSearch ( ) ;
3435 }
3536
3637 ngOnDestroy ( ) : void {
37- if ( ! ! this . _searchSubscription ) this . _searchSubscription . unsubscribe ( ) ;
38+ if ( ! ! this . _searchInputSub ) this . _searchInputSub . unsubscribe ( ) ;
3839 }
3940 //#endregion Component Methods
4041
4142
4243 //#region Implementation
4344 private _setupSearch ( ) :void {
44- if ( ! ! this . _searchSubscription ) return ;
45+ if ( ! ! this . _searchInputSub ) return ;
4546
4647 const target = document . getElementById ( 'searchInput' ) ;
4748 if ( ! target ) {
4849 setTimeout ( ( ) => this . _setupSearch ( ) , 300 ) ;
4950 return ;
5051 }
5152
52- this . _searchSubscription = fromEvent ( target , 'keyup' )
53+ this . _searchInputSub = fromEvent ( target , 'keyup' )
5354 . pipe (
5455 map ( ( e : any ) => e . target . value )
5556 , debounceTime ( 300 )
@@ -60,14 +61,22 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
6061 } ) ;
6162 }
6263
63- private search ( ) : void {
64+ private _search ( ) : void {
65+ this . _logers = [ ] ;
6466 this . loading = true ;
65- this . psService . getEventLogs ( this . remoteComputer )
67+ PowershellCommands . getEventLogs ( this . remoteComputer )
6668 . then ( ( evs : EventLog [ ] ) => {
6769 this . _logers = evs ;
6870 this . loading = false ;
6971 this . _applyFiltering ( ) ;
70- } ) ;
72+ } )
73+ . catch ( ( e : Error ) => {
74+ this . modalService . error ( {
75+ nzTitle : 'Something went wrong'
76+ , nzContent : 'press "apply" button to retry'
77+ } ) ;
78+ } )
79+ . finally ( ( ) => this . loading = false ) ;
7180 }
7281
7382 private _applyFiltering ( ) : void {
@@ -78,9 +87,13 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
7887
7988
8089 //#region UiCallbacks
81- public onItemSelected ( item : EventLog ) : void {
90+ public UiOnItemSelected ( item : EventLog ) : void {
8291 this . modal . close ( item ) ;
8392 }
93+
94+ public UiOnSearchClicked ( ) : void {
95+ this . _search ( ) ;
96+ }
8497 //#endregion UiCallbacks
8598
8699}
0 commit comments