Skip to content

Commit 475f776

Browse files
committed
[log-selection] adds remove EventLog functionality
1 parent 568db42 commit 475f776

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
[nzLoading]="loading"
2424
>
2525
<ng-template #itemRef let-item>
26-
<li nz-list-item [nzActions]="[opAction]" [nzContent]="item.log + ' ('+ item.entries +')'" nzNoFlex></li>
27-
<ng-template #opAction><a (click)="UiOnItemSelected(item)">select</a></ng-template>
26+
<li nz-list-item [nzActions]="[deleteAction, selectAction]" [nzContent]="item.log + ' ('+ item.entries +')'" nzNoFlex></li>
27+
<ng-template #deleteAction><a (click)="UiOnRemoveItemClicked(item)" style="color: #E89999;">remove</a></ng-template>
28+
<ng-template #selectAction><a (click)="UiOnItemSelected(item)">select</a></ng-template>
2829
</ng-template>
29-
</nz-list>
30+
</nz-list>

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NzModalRef, NzModalService } from 'ng-zorro-antd';
55
import { Subscription, fromEvent } from 'rxjs';
66
import { map, debounceTime } from 'rxjs/operators';
77
import { PowershellCommands } from '../../services/powershell/powershell-commands';
8+
import { GlobalUtils } from '../../services/global-utils';
89
//#endregion imports
910

1011
@Component({
@@ -82,6 +83,23 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
8283
this.logers = this._logers.filter(l => !this._searchValue || l.log.toLowerCase().indexOf(this._searchValue) >=0);
8384
}
8485

86+
87+
private _removeEventLog(item: EventLog) {
88+
this.loading = true;
89+
PowershellCommands.removeEventLog(item)
90+
.then(() => {
91+
this._search();
92+
})
93+
.catch(ex => {
94+
console.log(ex);
95+
this.modalService.error({
96+
nzTitle: 'Something went wrong'
97+
,nzContent: 'please try again'
98+
});
99+
})
100+
.finally(() => this.loading = false);
101+
}
102+
85103
//#endregion Implementation
86104

87105

@@ -100,6 +118,27 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
100118
public UiOnSearchClicked(): void {
101119
this._search();
102120
}
121+
122+
public UiOnRemoveItemClicked(item: EventLog): void {
123+
GlobalUtils.runningAsAdmin()
124+
.then((res:boolean) => {
125+
if (!res) {
126+
this.modalService.error({
127+
nzTitle: 'Error'
128+
,nzContent: 'Run the app as admin to execute this action'
129+
});
130+
return;
131+
}
132+
133+
this.modalService.confirm({
134+
nzTitle: `Remove EventLog ${item.log} ?`
135+
,nzCancelText: 'Cancel'
136+
,nzOkText: 'Yes'
137+
,nzOkType: 'danger'
138+
,nzOnOk: () => this._removeEventLog(item)
139+
});
140+
});
141+
}
103142
//#endregion UiCallbacks
104143

105144
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export class PowershellCommands {
1212
return PsCommandExecutor.executeCommand(command, false);
1313
}
1414

15+
16+
static removeEventLog(eventLog: EventLog): Promise<string> {
17+
let command = `Remove-EventLog -LogName "${eventLog.log}"`;
18+
if (eventLog.computerName) command += ` -ComputerName "${eventLog.computerName}"`;
19+
20+
return PsCommandExecutor.executeCommand(command, false);
21+
}
22+
1523
//#region Event Log Sources
1624
public static eventLogSources(eventLog: EventLog): Promise<string[]> {
1725
let command = `Get-EventLog -LogName "${eventLog.log}"`;

0 commit comments

Comments
 (0)