Skip to content

Commit 2005ccc

Browse files
committed
[log-selection] adds [log-creation] component inside modal
1 parent f5e7597 commit 2005ccc

10 files changed

Lines changed: 210 additions & 19 deletions

File tree

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
The format is based on [Keep a Changelog](http://keepachangelog.com/)
44
and this project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [0.1.2] 2020/07/28
7+
8+
### Added
9+
- **[log-creation]:** adds EventLog and EventSource creation functionality inside log-selection modal
10+
11+
### Changed
12+
13+
### Fixed
14+
15+
616

717
## [0.1.1] 2020/07/17
818

src/app/app.module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { AppComponent } from './app.component';
1717
import { MainComponent } from './components/main.component'
1818
import { EventViewerComponent } from './components/event-viewer/event-viewer.component';
1919
import { EventViewerFiltersComponent } from './components/event-viewer/event-viewer-filters/event-viewer-filters.component';
20-
import { LogSelectionComponent } from './components/log-selection/log-selection.component';
20+
import { EventLogsManagementComponent } from './components/event-logs-management-dialog/event-logs-management.component'
21+
import { LogSelectionComponent } from './components/event-logs-management-dialog/log-selection/log-selection.component';
22+
import { LogCreationComponent } from './components/event-logs-management-dialog/log-creation/log-creation.component';
2123
import { EventIconComponent } from './components/shared/event-icon/event-icon.component';
2224
import { EventEntryItemComponent } from './components/event-viewer/event-entry-item/event-entry-item.component';
2325
import { SidebarEventsComponent } from './components/sidebar-events/sidebar-events.component';
@@ -29,16 +31,18 @@ import { SidebarEventsComponent } from './components/sidebar-events/sidebar-even
2931
AppComponent
3032
,MainComponent
3133
,LogSelectionComponent
34+
,LogCreationComponent
3235

3336
,SidebarEventsComponent
3437
,EventViewerComponent
3538
,EventViewerFiltersComponent
39+
,EventLogsManagementComponent
3640

3741
,EventIconComponent
3842
,EventEntryItemComponent
3943
],
4044
entryComponents: [
41-
LogSelectionComponent //used inside dialog
45+
EventLogsManagementComponent //used inside dialog
4246
],
4347
imports: [
4448
BrowserModule,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<nz-tabset
2+
[nzAnimated]="false">
3+
<nz-tab nzTitle="Select EventLog">
4+
<log-selection
5+
(onLogSelected)="UiOnLogSelected($event)"
6+
></log-selection>
7+
</nz-tab>
8+
<nz-tab nzTitle="Add New">
9+
<log-creation
10+
(onEventSourceAdded)="UiOnEventLogAdded()"
11+
></log-creation>
12+
</nz-tab>
13+
</nz-tabset>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Component, ViewChild } from "@angular/core";
2+
import { NzModalRef } from "ng-zorro-antd";
3+
import { LogSelectionComponent } from "./log-selection/log-selection.component";
4+
5+
@Component({
6+
selector: 'event-logs-management',
7+
templateUrl: 'event-logs-management.component.html'
8+
})
9+
export class EventLogsManagementComponent {
10+
//#region Constructor - Input & Outputs
11+
constructor(private modal: NzModalRef) {}
12+
//#endregion Constructor - Input & Outputs
13+
14+
15+
//#region Component Properties
16+
@ViewChild(LogSelectionComponent,null) child:LogSelectionComponent;
17+
//#endregion Component Properties
18+
19+
20+
//#region Ui Events
21+
public UiOnLogSelected(info: any) : void {
22+
this.modal.close(info);
23+
}
24+
25+
public UiOnEventLogAdded(): void {
26+
this.child.refreshLogs();
27+
}
28+
//#endregion Ui Events
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<form nz-form>
2+
3+
<nz-form-item>
4+
<nz-form-label [nzSpan]="4" nzFor="logName">LogName</nz-form-label>
5+
<nz-form-control [nzSpan]="8">
6+
<input [(ngModel)]="UiVm.logName" type="text" nz-input placeholder="LogName" name="logName"/>
7+
</nz-form-control>
8+
</nz-form-item>
9+
10+
11+
<nz-form-item>
12+
<nz-form-label [nzSpan]="4" nzFor="source">Source</nz-form-label>
13+
<nz-form-control [nzSpan]="8">
14+
<input [(ngModel)]="UiVm.source" type="text" nz-input placeholder="Source" name="source" />
15+
</nz-form-control>
16+
</nz-form-item>
17+
18+
19+
20+
<nz-form-item>
21+
<nz-form-control [nzSpan]="8" [nzOffset]="4">
22+
<button (click)="UiOnAddClicked()" nz-button nzType="primary">Add</button>
23+
</nz-form-control>
24+
</nz-form-item>
25+
</form>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Component, Output, EventEmitter } from '@angular/core';
2+
import { NzModalService } from 'ng-zorro-antd';
3+
import { PowershellCommands } from '../../../services/powershell/powershell-commands';
4+
import { AppLogger } from '../../../services/AppLogger';
5+
import { GlobalUtils } from '../../../services/global-utils';
6+
7+
@Component({
8+
selector: 'log-creation',
9+
templateUrl: 'log-creation.component.html'
10+
})
11+
export class LogCreationComponent {
12+
//#region Constructor - Inputs & Outputs
13+
@Output()
14+
public onEventSourceAdded = new EventEmitter();
15+
16+
constructor(private modalService: NzModalService)
17+
{}
18+
//#endregion Constructor - Inputs & Outputs
19+
20+
21+
//#region Component Properties
22+
public UiVm = new ViewModel();
23+
//#endregion Component Properties
24+
25+
26+
//#region Implementation
27+
28+
private _addLogValidateInput(): boolean {
29+
if (!this.UiVm.logName) {
30+
this.modalService.error({
31+
nzTitle: 'Error'
32+
,nzContent: 'logName cannot be empty'
33+
});
34+
return false;
35+
}
36+
37+
if (!this.UiVm.source) {
38+
this.modalService.error({
39+
nzTitle: 'Error'
40+
,nzContent: 'source cannot be empty'
41+
});
42+
return false;
43+
}
44+
return true;
45+
}
46+
47+
private _addLog(): void {
48+
PowershellCommands.newEventLog(this.UiVm.logName, this.UiVm.source, null)
49+
.then((output: string) => {
50+
this.modalService.success({
51+
nzTitle: ''
52+
,nzContent: 'Event Log and Source created'
53+
});
54+
this.onEventSourceAdded.emit();
55+
this.UiVm = new ViewModel();
56+
})
57+
.catch((e: Error) => {
58+
AppLogger.getInstance().logError(e);
59+
this.modalService.error({
60+
nzTitle: 'Something went wrong'
61+
,nzContent: 'press "apply" button to retry'
62+
});
63+
});
64+
}
65+
//#endregion Implementation
66+
67+
68+
//#region Ui Events
69+
public UiOnAddClicked(): void {
70+
GlobalUtils.runningAsAdmin()
71+
.then((res:boolean) => {
72+
if (!res) {
73+
this.modalService.error({
74+
nzTitle: 'Error'
75+
,nzContent: 'Run the app as admin to execute this action'
76+
});
77+
return;
78+
}
79+
80+
if (!this._addLogValidateInput()) return;
81+
82+
this._addLog();
83+
});
84+
}
85+
//#endregion Ui Events
86+
}
87+
88+
89+
class ViewModel {
90+
public logName :string = '';
91+
public source :string = '';
92+
}

src/app/components/log-selection/log-selection.component.html renamed to src/app/components/event-logs-management-dialog/log-selection/log-selection.component.html

File renamed without changes.

src/app/components/log-selection/log-selection.component.ts renamed to src/app/components/event-logs-management-dialog/log-selection/log-selection.component.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//#region imports
2-
import { Component, OnInit, OnDestroy } from '@angular/core';
3-
import { EventLog } from '../../types/EventLog';
4-
import { NzModalRef, NzModalService } from 'ng-zorro-antd';
2+
import { Component, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
3+
import { EventLog } from '../../../types/EventLog';
4+
import { NzModalService } from 'ng-zorro-antd';
55
import { Subscription, fromEvent } from 'rxjs';
66
import { map, debounceTime } from 'rxjs/operators';
7-
import { PowershellCommands } from '../../services/powershell/powershell-commands';
8-
import { GlobalUtils } from '../../services/global-utils';
7+
import { PowershellCommands } from '../../../services/powershell/powershell-commands';
8+
import { GlobalUtils } from '../../../services/global-utils';
9+
import { AppLogger } from '../../../services/AppLogger';
910
//#endregion imports
1011

1112
@Component({
@@ -14,18 +15,27 @@ import { GlobalUtils } from '../../services/global-utils';
1415
})
1516
export class LogSelectionComponent implements OnInit, OnDestroy {
1617

17-
//#region Constructor & Properties
18-
constructor(private modalService: NzModalService
19-
, private modal: NzModalRef) { }
18+
//#region Constructor Input - Outputs
19+
@Output()
20+
public onLogSelected = new EventEmitter<any>();
21+
22+
constructor(private modalService: NzModalService) { }
23+
24+
public refreshLogs(): void {
25+
this._search();
26+
}
27+
//#endregion Constructor Input - Outputs
28+
2029

30+
//#region Component Variables
2131
private _searchInputSub: Subscription;
2232

2333
public loading: boolean= true;
2434
private _logers: EventLog[] = [];
2535
public logers: EventLog[] = [];
2636
private _searchValue: string = '';
2737
public remoteComputer: string = '';
28-
//#endregion Constructor & Properties
38+
//#endregion Component Variables
2939

3040

3141
//#region Component Methods
@@ -90,8 +100,8 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
90100
.then(() => {
91101
this._search();
92102
})
93-
.catch(ex => {
94-
console.log(ex);
103+
.catch(e => {
104+
AppLogger.getInstance().logError(e);
95105
this.modalService.error({
96106
nzTitle: 'Something went wrong'
97107
,nzContent: 'please try again'
@@ -109,9 +119,9 @@ export class LogSelectionComponent implements OnInit, OnDestroy {
109119
nzTitle: 'Which events to show?',
110120
nzContent: '',
111121
nzOkText: 'All events',
112-
nzOnOk: () => this.modal.close({eventLog: item, showOnlyNew:false}),
122+
nzOnOk: () => this.onLogSelected.emit({eventLog: item, showOnlyNew:false}),
113123
nzCancelText: 'New Only',
114-
nzOnCancel: () => this.modal.close({eventLog: item, showOnlyNew:true})
124+
nzOnCancel: () => this.onLogSelected.emit({eventLog: item, showOnlyNew:true})
115125
});
116126
}
117127

src/app/components/main.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { Component, OnInit } from '@angular/core';
33
import { EventLog } from '../types/EventLog';
44
import { NzModalService } from 'ng-zorro-antd';
5-
import { LogSelectionComponent } from './log-selection/log-selection.component';
5+
import { EventLogsManagementComponent } from './event-logs-management-dialog/event-logs-management.component';
6+
67
//#endregion imports
78

89
@Component({
@@ -30,7 +31,7 @@ export class MainComponent implements OnInit{
3031
//#region Implementation
3132
private _showSelectionDialog() {
3233
const modal = this.modalService.create({
33-
nzContent: LogSelectionComponent
34+
nzContent: EventLogsManagementComponent
3435
,nzClosable: false
3536
,nzFooter: null
3637
});

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

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

66
export class PowershellCommands {
77

8-
static clearEventLog(eventLog: EventLog): Promise<string> {
8+
public static newEventLog(logName: string, source: string, computerName: string): Promise<string> {
9+
let command = `New-EventLog -LogName "${logName}" -Source "${source}"`;
10+
if (!!computerName) command += ` -ComputerName "${computerName}"`;
11+
12+
return PsCommandExecutor.executeCommand(command, false);
13+
}
14+
15+
public static clearEventLog(eventLog: EventLog): Promise<string> {
916
let command = `Clear-EventLog -LogName "${eventLog.log}"`;
1017
if (eventLog.computerName) command += ` -ComputerName "${eventLog.computerName}"`;
1118

1219
return PsCommandExecutor.executeCommand(command, false);
1320
}
1421

1522

16-
static removeEventLog(eventLog: EventLog): Promise<string> {
23+
public static removeEventLog(eventLog: EventLog): Promise<string> {
1724
let command = `Remove-EventLog -LogName "${eventLog.log}"`;
1825
if (eventLog.computerName) command += ` -ComputerName "${eventLog.computerName}"`;
1926

0 commit comments

Comments
 (0)