Skip to content

Commit b2906e5

Browse files
committed
[log-selection] 5 sec timeout & error handling
1 parent 2c8fbaa commit b2906e5

4 files changed

Lines changed: 30 additions & 21 deletions

File tree

src/app/components/log-selection/log-selection.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<input type="text" nz-input placeholder="connect to remote computer" [(ngModel)]="remoteComputer" />
1212
</nz-input-group>
1313
<ng-template #suffixButton>
14-
<button (click)="search()" nz-button nzType="primary" nzSearch>Apply</button>
14+
<button (click)="UiOnSearchClicked()" nz-button nzType="primary" nzSearch>Apply</button>
1515
</ng-template>
1616

1717

@@ -24,6 +24,6 @@
2424
>
2525
<ng-template #itemRef let-item>
2626
<li nz-list-item [nzActions]="[opAction]" [nzContent]="item.log + ' ('+ item.entries +')'" nzNoFlex></li>
27-
<ng-template #opAction><a (click)="onItemSelected(item)">select</a></ng-template>
27+
<ng-template #opAction><a (click)="UiOnItemSelected(item)">select</a></ng-template>
2828
</ng-template>
2929
</nz-list>
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//#region imports
2-
import { Component, OnInit, AfterViewInit, OnDestroy } from '@angular/core';
2+
import { Component, OnInit, OnDestroy } from '@angular/core';
33
import { EventLog } from '../../types/EventLog';
44
import { PowershellService } from '../../services/powershell/powershell.service';
5-
import { NzModalRef } from 'ng-zorro-antd';
5+
import { NzModalRef, NzModalService } from 'ng-zorro-antd';
66
import { Subscription, fromEvent } from 'rxjs';
77
import { 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';
1415
export 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
}

src/app/services/powershell/powershell-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class PowershellCommands {
1818
if (computerName) command += ` -ComputerName "${computerName}"`;
1919
command += ' -List';
2020

21-
return PsCommandExecutor.executeCommand(command)
21+
return PsCommandExecutor.executeCommand(command, 5)
2222
.then(output => PowershellCommands._parseEventViewersList(output))
2323
.then(events => {
2424
events.forEach(e => e.computerName = computerName);

src/app/services/powershell/powershell.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import { EventFiltersVm } from '../../types/viewmodels/EventFiltersVm';
1212
export class PowershellService {
1313
//#region Public Api
1414

15-
public getEventLogs(computerName: string): Promise<EventLog[]> {
16-
return PowershellCommands.getEventLogs(computerName);
17-
}
18-
1915
public getEvents(
2016
eventLog: EventLog
2117
, filters:EventFiltersVm): Promise<Event[]> {

0 commit comments

Comments
 (0)