Skip to content

Commit 77049d5

Browse files
committed
Add Severity and Event Type filters to Bulk Install
1 parent f61fe39 commit 77049d5

7 files changed

Lines changed: 70 additions & 81 deletions

File tree

DNN Platform/Modules/BulkInstall/App_LocalResources/BulkInstall.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,7 @@
303303
<data name="PlatformVersion" xml:space="preserve">
304304
<value>Platform Version</value>
305305
</data>
306+
<data name="All" xml:space="preserve">
307+
<value>All</value>
308+
</data>
306309
</root>

DNN Platform/Modules/BulkInstall/BulkInstall.Web/src/clients/event-log-client.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export class EventLogClient {
1111
this.requestUrl = this.sf.getServiceRoot('BulkInstall') + 'EventLog/';
1212
}
1313

14-
public async browse(pageIndex = 0): Promise<BrowseResponse> {
15-
const response = await fetch(`${this.requestUrl}Browse?pageIndex=${pageIndex}`, {
14+
public async browse(pageIndex = 0, severity?: EventLogSeverityInfo, eventType?: string): Promise<BrowseResponse> {
15+
const severityParam = severity ? `&severity=${severity.eventLogSeverityKey}` : '';
16+
const eventTypeParam = eventType ? `&eventType=${eventType}` : '';
17+
const response = await fetch(`${this.requestUrl}Browse?pageIndex=${pageIndex}${severityParam}${eventTypeParam}`, {
1618
headers: this.sf.getModuleHeaders(),
1719
});
1820
const responseBody = (await response.json()) as ResponseBody;
@@ -22,6 +24,11 @@ export class EventLogClient {
2224
};
2325
}
2426

27+
public async getEventTypes(): Promise<string[]> {
28+
const response = await fetch(`${this.requestUrl}EventTypes`, { headers: this.sf.getModuleHeaders() });
29+
return (await response.json()) as string[];
30+
}
31+
2532
private static toSeverity(severity: EventLogSeverityResponse): EventLogSeverityInfo {
2633
switch (severity) {
2734
case EventLogSeverityResponse.Info:
@@ -50,11 +57,6 @@ export class EventLogClient {
5057
return {
5158
currentPage: pagination.CurrentPage,
5259
pages: pagination.Pages,
53-
records: pagination.Records,
54-
navigation: {
55-
next: pagination.Navigation.Next,
56-
previous: pagination.Navigation.Previous,
57-
},
5860
};
5961
}
6062
}
@@ -65,13 +67,8 @@ export interface BrowseResponse {
6567
}
6668

6769
export interface Pagination {
68-
records: number;
6970
pages: number;
7071
currentPage: number;
71-
navigation: {
72-
previous?: string;
73-
next?: string;
74-
};
7572
}
7673

7774
interface ResponseBody {
@@ -80,13 +77,8 @@ interface ResponseBody {
8077
}
8178

8279
interface PaginationResponse {
83-
Records: number;
8480
Pages: number;
8581
CurrentPage: number;
86-
Navigation: {
87-
Previous?: string;
88-
Next?: string;
89-
};
9082
}
9183

9284
interface EventLogResponse {

DNN Platform/Modules/BulkInstall/BulkInstall.Web/src/clients/localization-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class LocalizationClient {
2828
export interface BulkInstallLocalization {
2929
Action: string;
3030
Add: string;
31+
All: string;
3132
ApiError: string;
3233
ApiAuthDisabled: string;
3334
ApiKey: string;

DNN Platform/Modules/BulkInstall/BulkInstall.Web/src/components/tabs/dnn-bi-logs/dnn-bi-logs.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
width: fit-content;
5858
}
5959

60+
.filters {
61+
display: flex;
62+
justify-content: end;
63+
gap: 1em;
64+
}
65+
6066
/* Table styling */
6167
.table {
6268
width: 100%;

DNN Platform/Modules/BulkInstall/BulkInstall.Web/src/components/tabs/dnn-bi-logs/dnn-bi-logs.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, Host, h, State } from '@stencil/core';
22
import store from '../../../stores/store';
33
import { EventLogClient, Pagination } from '../../../clients/event-log-client';
44
import { Event } from './dnn-bi-logs.model';
5+
import { eventLogSeverity, EventLogSeverityInfo } from '../../../enums/EventLogSeverity';
56

67
@Component({
78
tag: 'dnn-bi-logs',
@@ -10,7 +11,10 @@ import { Event } from './dnn-bi-logs.model';
1011
})
1112
export class DnnBiLogs {
1213
@State() private events: Event[] = [];
14+
@State() private eventTypes: string[] = [];
1315
@State() private pagination: Pagination;
16+
@State() private severityFilter: EventLogSeverityInfo;
17+
@State() private eventTypeFilter: string;
1418

1519
private eventLogClient: EventLogClient;
1620

@@ -23,13 +27,24 @@ export class DnnBiLogs {
2327
const { data, pagination } = await this.eventLogClient.browse();
2428
this.events = data;
2529
this.pagination = pagination;
30+
this.eventTypes = await this.eventLogClient.getEventTypes();
2631
} catch (error) {
2732
console.error(error);
2833
}
2934
}
3035

36+
private async setSeverityFilter(key: string) {
37+
this.severityFilter = eventLogSeverity.fromKey(key);
38+
await this.loadPage(0);
39+
}
40+
41+
private async setEventTypeFilter(eventType: string) {
42+
this.eventTypeFilter = eventType;
43+
await this.loadPage(0);
44+
}
45+
3146
private async loadPage(pageIndex: number) {
32-
const { data, pagination } = await this.eventLogClient.browse(pageIndex);
47+
const { data, pagination } = await this.eventLogClient.browse(pageIndex, this.severityFilter, this.eventTypeFilter);
3348
this.events = data;
3449
this.pagination = pagination;
3550
}
@@ -49,6 +64,21 @@ export class DnnBiLogs {
4964
<h3 class="panel-title">{store.resx.Events}</h3>
5065
</div>
5166
<div class="panel-body">
67+
<div class="filters">
68+
<dnn-select label={store.resx.Severity} onValueChange={e => this.setSeverityFilter(e.detail).catch(console.error)}>
69+
<option value="">{store.resx.All}</option>
70+
<option value={eventLogSeverity.info.eventLogSeverityKey}>{eventLogSeverity.info.localizedName}</option>
71+
<option value={eventLogSeverity.warning.eventLogSeverityKey}>{eventLogSeverity.warning.localizedName}</option>
72+
<option value={eventLogSeverity.alert.eventLogSeverityKey}>{eventLogSeverity.alert.localizedName}</option>
73+
<option value={eventLogSeverity.critical.eventLogSeverityKey}>{eventLogSeverity.critical.localizedName}</option>
74+
</dnn-select>
75+
<dnn-select label={store.resx.Type} onValueChange={e => this.setEventTypeFilter(e.detail).catch(console.error)}>
76+
<option value="">{store.resx.All}</option>
77+
{this.eventTypes.map(eventType => (
78+
<option>{eventType}</option>
79+
))}
80+
</dnn-select>
81+
</div>
5282
<table class="table">
5383
<thead>
5484
<tr>

DNN Platform/Modules/BulkInstall/BulkInstall.Web/src/enums/EventLogSeverity.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ export class EventLogSeverity {
1212
this.alert = new EventLogSeverityInfo('Alert');
1313
this.critical = new EventLogSeverityInfo('Critical');
1414
}
15+
16+
public fromKey(eventLogSeverityKey: string) {
17+
switch (eventLogSeverityKey) {
18+
case this.info.eventLogSeverityKey:
19+
return this.info;
20+
case this.warning.eventLogSeverityKey:
21+
return this.warning;
22+
case this.alert.eventLogSeverityKey:
23+
return this.alert;
24+
case this.critical.eventLogSeverityKey:
25+
return this.critical;
26+
default:
27+
throw new Error(`Invalid EventLogSeverity key: ${eventLogSeverityKey}`);
28+
}
29+
}
1530
}
1631

1732
export class EventLogSeverityInfo {

DNN Platform/Modules/BulkInstall/Components/WebAPI/EventLogController.cs

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,77 +29,19 @@ public class EventLogController(EventLogManager eventLogManager) : DnnApiControl
2929
/// <param name="pageIndex">The 0-based page index.</param>
3030
/// <param name="pageSize">The page size.</param>
3131
/// <param name="eventType">An event type to filter by, or <see langword="null"/>.</param>
32-
/// <param name="severity">A <see cref="EventLogSeverity"/> to filter by, or <c>-1</c>.</param>
32+
/// <param name="severity">A <see cref="EventLogSeverity"/> to filter by, or <see langword="null"/>.</param>
3333
/// <returns>A response with a list of <see cref="EventLog"/> and pagination data.</returns>
3434
[HttpGet]
35-
public HttpResponseMessage Browse(int pageIndex = 0, int pageSize = 30, string eventType = null, int severity = -1)
35+
public HttpResponseMessage Browse(int pageIndex = 0, int pageSize = 30, string eventType = null, EventLogSeverity? severity = null)
3636
{
37-
EventLogSeverity? actualSeverity = null;
38-
39-
// Is there a severity set?
40-
if (severity >= 0)
41-
{
42-
actualSeverity = (EventLogSeverity)severity;
43-
}
44-
4537
// Get event logs.
46-
IEnumerable<EventLog> eventLogs = this.eventLogManager.Browse(pageIndex, pageSize, eventType, actualSeverity);
38+
IEnumerable<EventLog> eventLogs = this.eventLogManager.Browse(pageIndex, pageSize, eventType, severity);
4739

4840
// Work out pagination details.
49-
int rowCount = this.eventLogManager.BrowseCount(pageIndex, pageSize, eventType, actualSeverity);
41+
int rowCount = this.eventLogManager.BrowseCount(pageIndex, pageSize, eventType, severity);
5042
int pageCount = (int)Math.Ceiling(rowCount / (double)pageSize);
5143

52-
// Build navigation.
53-
Dictionary<string, string> navigation = new Dictionary<string, string>();
54-
55-
// Parameters passed in not changed by pagination.
56-
string fixedParams = string.Empty;
57-
58-
// Page size.
59-
if (pageSize != 30)
60-
{
61-
fixedParams += $"pageSize={pageSize}";
62-
}
63-
64-
// Event type.
65-
if (eventType != null)
66-
{
67-
fixedParams += $"eventType={eventType}";
68-
}
69-
70-
// Severity.
71-
if (severity != -1)
72-
{
73-
fixedParams += $"eventType={severity}";
74-
}
75-
76-
// Is there a next page?
77-
if (pageIndex < pageCount)
78-
{
79-
string nextLink = $"Browse?pageIndex={pageIndex + 1}";
80-
81-
if (!string.IsNullOrEmpty(fixedParams))
82-
{
83-
nextLink = $"{nextLink}&{fixedParams}";
84-
}
85-
86-
navigation.Add("Next", nextLink);
87-
}
88-
89-
// Is there a previous page?
90-
if (pageIndex > 0)
91-
{
92-
string prevLink = $"Browse?pageIndex={pageIndex - 1}";
93-
94-
if (!string.IsNullOrEmpty(fixedParams))
95-
{
96-
prevLink = $"{prevLink}&{fixedParams}";
97-
}
98-
99-
navigation.Add("Previous", prevLink);
100-
}
101-
102-
var pagination = new { Records = rowCount, Pages = pageCount, CurrentPage = pageIndex, Navigation = navigation, };
44+
var pagination = new { Pages = pageCount, CurrentPage = pageIndex, };
10345
return this.Request.CreateResponse(HttpStatusCode.OK, new { Data = eventLogs, Pagination = pagination, });
10446
}
10547

0 commit comments

Comments
 (0)