Skip to content

Commit 44a8585

Browse files
committed
Initial start date and date filter.
1 parent aa195cd commit 44a8585

File tree

7 files changed

+55
-18
lines changed

7 files changed

+55
-18
lines changed

src/Serilog.Ui.Core/IDataProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34

45
namespace Serilog.Ui.Core
@@ -9,7 +10,9 @@ public interface IDataProvider
910
int page,
1011
int count,
1112
string level = null,
12-
string searchCriteria = null
13+
string searchCriteria = null,
14+
DateTime? startDate = null,
15+
DateTime? endDate = null
1316
);
1417
}
1518
}

src/Serilog.Ui.ElasticSearchProvider/ElasticSearchDbDataProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public ElasticSearchDbDataProvider(IElasticClient client, ElasticSearchDbOptions
2323
int page,
2424
int count,
2525
string level = null,
26-
string searchCriteria = null)
26+
string searchCriteria = null,
27+
DateTime? startDate = null,
28+
DateTime? endDate = null)
2729
{
2830
return GetLogsAsync(page - 1, count, level, searchCriteria);
2931
}

src/Serilog.Ui.MongoDbProvider/MongoDbDataProvider.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
using System;
1+
using MongoDB.Driver;
2+
using Serilog.Ui.Core;
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Threading.Tasks;
5-
using MongoDB.Driver;
6-
using Serilog.Ui.Core;
77

88
namespace Serilog.Ui.MongoDbProvider
99
{
1010
public class MongoDbDataProvider : IDataProvider
1111
{
12-
private readonly IMongoClient _client;
1312
private readonly IMongoCollection<MongoDbLogModel> _collection;
1413

1514
public MongoDbDataProvider(IMongoClient client, MongoDbOptions options)
1615
{
17-
_client = client;
16+
if (client is null) throw new ArgumentNullException(nameof(client));
17+
if (options is null) throw new ArgumentNullException(nameof(options));
18+
1819
_collection = client.GetDatabase(options.DatabaseName).GetCollection<MongoDbLogModel>(options.CollectionName);
1920
}
2021

2122
public async Task<(IEnumerable<LogModel>, int)> FetchDataAsync(
2223
int page,
2324
int count,
2425
string level = null,
25-
string searchCriteria = null)
26+
string searchCriteria = null,
27+
DateTime? startDate = null,
28+
DateTime? endDate = null)
2629
{
2730
var logsTask = GetLogsAsync(page - 1, count, level, searchCriteria);
2831
var logCountTask = CountLogsAsync(level, searchCriteria);

src/Serilog.Ui.MsSqlServerProvider/SqlServerDataProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Dapper;
22
using Microsoft.Data.SqlClient;
33
using Serilog.Ui.Core;
4+
using System;
45
using System.Collections.Generic;
56
using System.Data;
67
using System.Text;
@@ -14,14 +15,16 @@ public class SqlServerDataProvider : IDataProvider
1415

1516
public SqlServerDataProvider(RelationalDbOptions options)
1617
{
17-
_options = options;
18+
_options = options ?? throw new ArgumentNullException(nameof(options));
1819
}
1920

2021
public async Task<(IEnumerable<LogModel>, int)> FetchDataAsync(
2122
int page,
2223
int count,
2324
string logLevel = null,
24-
string searchCriteria = null
25+
string searchCriteria = null,
26+
DateTime? startDate = null,
27+
DateTime? endDate = null
2528
)
2629
{
2730
var logsTask = GetLogsAsync(page - 1, count, logLevel, searchCriteria);

src/Serilog.Ui.PostgreSqlProvider/PostgreDataProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Dapper;
22
using Npgsql;
33
using Serilog.Ui.Core;
4+
using System;
45
using System.Collections.Generic;
56
using System.Data;
67
using System.Text;
@@ -14,14 +15,16 @@ public class PostgresDataProvider : IDataProvider
1415

1516
public PostgresDataProvider(RelationalDbOptions options)
1617
{
17-
_options = options;
18+
_options = options ?? throw new ArgumentNullException(nameof(options));
1819
}
1920

2021
public async Task<(IEnumerable<LogModel>, int)> FetchDataAsync(
2122
int page,
2223
int count,
2324
string logLevel = null,
24-
string searchCriteria = null
25+
string searchCriteria = null,
26+
DateTime? startDate = null,
27+
DateTime? endDate = null
2528
)
2629
{
2730
var logsTask = GetLogsAsync(page - 1, count, logLevel, searchCriteria);

src/Serilog.Ui.Web/SerilogUiMiddleware.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,20 @@ private async Task<string> FetchLogsAsync(HttpContext httpContext)
142142
httpContext.Request.Query.TryGetValue("count", out var countStr);
143143
httpContext.Request.Query.TryGetValue("level", out var levelStr);
144144
httpContext.Request.Query.TryGetValue("search", out var searchStr);
145+
httpContext.Request.Query.TryGetValue("startDate", out var startDateStar);
146+
httpContext.Request.Query.TryGetValue("endDate", out var endDateStar);
145147

146148
int.TryParse(pageStr, out var currentPage);
147149
int.TryParse(countStr, out var count);
150+
DateTime.TryParse(startDateStar, out var startDate);
151+
DateTime.TryParse(endDateStar, out var endDate);
152+
148153
currentPage = currentPage == default ? 1 : currentPage;
149154
count = count == default ? 10 : count;
150155

151156
var provider = httpContext.RequestServices.GetService<IDataProvider>();
152-
var (logs, total) = await provider.FetchDataAsync(currentPage, count, levelStr, searchStr);
153-
157+
var (logs, total) = await provider.FetchDataAsync(currentPage, count, levelStr, searchStr,
158+
startDate == default ? (DateTime?)null : startDate, endDate == default ? (DateTime?)null : endDate);
154159
//var result = JsonSerializer.Serialize(logs, _jsonSerializerOptions);
155160
var result = JsonConvert.SerializeObject(new { logs, total, count, currentPage }, _jsonSerializerOptions);
156161
return result;

src/Serilog.Ui.Web/wwwroot/index.html

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h5 class="modal-title" id="loginModalLabel">JWT Authorizations</h5>
7373
</div>
7474

7575
<div class="row">
76-
<div class="col-sm-12 col-md-4">
76+
<div class="col col-auto">
7777
<div class="table-select" id="logCount">
7878
<label>
7979
Show
@@ -87,7 +87,7 @@ <h5 class="modal-title" id="loginModalLabel">JWT Authorizations</h5>
8787
</label>
8888
</div>
8989
</div>
90-
<div class="col-sm-12 col-md-4">
90+
<div class="col col-auto">
9191
<div class="table-select" id="logFilter">
9292
<label>
9393
Level
@@ -102,7 +102,25 @@ <h5 class="modal-title" id="loginModalLabel">JWT Authorizations</h5>
102102
</label>
103103
</div>
104104
</div>
105-
<div class="col-sm-12 col-md-4">
105+
<div class="col col-auto">
106+
<div class="table-filter">
107+
<label>
108+
Start date:
109+
<input type="date" name="startDate" id="startDate" class="form-control form-control-sm">
110+
<button onclick="javascript:startDate.value='';">X</button>
111+
</label>
112+
</div>
113+
</div>
114+
<div class="col col-auto">
115+
<div class="table-filter">
116+
<label>
117+
End date:
118+
<input type="date" name="endDate" id="endDate" class="form-control form-control-sm">
119+
<button onclick="javascript:endDate.value='';">X</button>
120+
</label>
121+
</div>
122+
</div>
123+
<div class="col col-auto">
106124
<div class="table-filter">
107125
<label>
108126
Search message:

0 commit comments

Comments
 (0)