Skip to content

Commit 3ef92d1

Browse files
committed
clear log implementation
1 parent 98a0ab0 commit 3ef92d1

5 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/app/components/event-viewer/event-viewer.component.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
<nz-content>
88
<!-- Refersh Button -->
9-
<div *ngIf="viewModel.hasNew" style="margin-left:5px; margin-bottom: 10px;">
10-
<button (click)="uiOnRefreshClicked()" nz-button nzType="primary" [nzSize]="'default'" nzShape="circle">
9+
<div style="margin-left:5px; margin-bottom: 10px;">
10+
<button (click)="uiOnClearClicked()" nz-button nzType="primary" [nzSize]="'default'" nzShape="circle">
11+
<i nz-icon nzType="delete"></i>
12+
</button>
13+
14+
<button *ngIf="viewModel.hasNew" (click)="uiOnRefreshClicked()" nz-button nzType="primary" [nzSize]="'default'" nzShape="circle">
1115
<i nz-icon nzType="issues-close"></i>
1216
</button>
1317
</div>
1418

15-
16-
1719
<!-- Main List-->
1820
<nz-collapse>
1921
<nz-collapse-panel *ngFor="let event of viewModel.events"

src/app/components/event-viewer/event-viewer.component.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Constants } from '../../types/Constants';
88
import { filter } from 'rxjs/operators';
99
import { EventFiltersVm } from '../../types/viewmodels/EventFiltersVm';
1010
import { EventLog } from '../../types/EventLog';
11+
import { NzModalService } from 'ng-zorro-antd';
1112
//#endregion imports
1213

1314
@Component({
@@ -16,7 +17,7 @@ import { EventLog } from '../../types/EventLog';
1617
})
1718
export class EventViewerComponent implements OnInit, OnDestroy {
1819
//#region Constructor & Properties
19-
constructor(private psService: PowershellService) { }
20+
constructor(private psService: PowershellService, private modalService: NzModalService) { }
2021

2122
@Input()
2223
public eventLog: EventLog;
@@ -77,6 +78,11 @@ export class EventViewerComponent implements OnInit, OnDestroy {
7778
this.viewModel.hasNew = true;
7879
this.unreadEventsUpdated.emit(true);
7980
}
81+
82+
private _clearEvents(): void {
83+
this.psService.clearEventLog(this.eventLog)
84+
.then(() => this._refreshList());
85+
}
8086
//#endregion Implementation
8187

8288

@@ -88,6 +94,16 @@ export class EventViewerComponent implements OnInit, OnDestroy {
8894
public uiOnMoreClicked(): void {
8995
this._showNextItems();
9096
}
97+
98+
public uiOnClearClicked(): void {
99+
this.modalService.confirm({
100+
nzTitle: `Clear all events from ${this.eventLog.log}?`
101+
,nzCancelText: 'Cancel'
102+
,nzOkText: 'Yes'
103+
,nzOkType: 'danger'
104+
,nzOnOk: () => this._clearEvents()
105+
});
106+
}
91107
//#endregion UiCallbacks
92108
}
93109

src/app/services/powershell/powershell-command-executor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Shell from 'node-powershell';
2-
import { GlobalUtils } from '../global-utils';
32

43
export class PsCommandExecutor {
54
private static _ps: Shell;
@@ -19,7 +18,7 @@ export class PsCommandExecutor {
1918
return this._ps.addCommand(command)
2019
.then(() => this._ps.invoke())
2120
.catch(e => {
22-
console.log(e);
21+
console.error(e);
2322
this._initShell();
2423
return '';
2524
});

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ import { PsCommandExecutor } from "./powershell-command-executor";
55

66
export class PowershellCommands {
77

8+
static clearEventLog(eventLog: EventLog): Promise<string> {
9+
let command = `Clear-EventLog -LogName "${eventLog.log}"`;
10+
if (eventLog.computerName) command += ` -ComputerName "${eventLog.computerName}"`;
11+
12+
return PsCommandExecutor.executeCommand(command);
13+
}
14+
815
//#region Event Log
916
public static getEventLogs(computerName: string): Promise<EventLog[]> {
1017
let command = 'Get-EventLog';
11-
if (computerName) command += ` -ComputerName ${computerName}`;
18+
if (computerName) command += ` -ComputerName "${computerName}"`;
1219
command += ' -List';
1320

1421
return PsCommandExecutor.executeCommand(command)
@@ -44,7 +51,7 @@ export class PowershellCommands {
4451
let command = `Get-EventLog -LogName "${eventLog.log}"`;
4552
if (eventLog.computerName) command += ` -ComputerName "${eventLog.computerName}"`;
4653
if (after) command += ` -After "${after}"`;
47-
if (newest) command += ` -Newest "${newest}"`;
54+
if (newest) command += ` -Newest ${newest}`;
4855

4956
command += ' ' + PowershellCommands.selectEvent;
5057
return PsCommandExecutor.executeCommand(command)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ export class PowershellService {
2626
public onNewEvents$(eventLog: EventLog, filters:EventFiltersVm): Observable<Event[]> {
2727
return new PowershellMonitor(eventLog, filters).observable$;
2828
}
29+
30+
public clearEventLog(eventLog: EventLog): Promise<string> {
31+
return PowershellCommands.clearEventLog(eventLog);
32+
}
2933
//#endregion Public Api
3034
}

0 commit comments

Comments
 (0)