Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated basic filtering to use dynamic inputs and improved sub filtering #127

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/EventLogExpert.Library/EventArgs/ValueChangedEventArgs.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/EventLogExpert.Library/Helpers/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ namespace EventLogExpert.Library.Helpers;

public enum SeverityLevel
{
All = -1,
Error = 2,
Warning = 3,
Information = 4
}

public enum FilterType
{
EventId,
[EnumMember(Value = "Event ID")] EventId,
Level,
Source,
Task,
Expand Down
42 changes: 12 additions & 30 deletions src/EventLogExpert.Library/Models/FilterModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Library.EventArgs;
using EventLogExpert.Library.Helpers;

namespace EventLogExpert.Library.Models;

public class FilterModel
public record FilterModel(Guid Id)
{
public FilterModel(Guid id)
{
Id = id;
FilterType = FilterType.EventId;
}

public Guid Id { get; init; }
private FilterType _filterType;

public List<Func<DisplayEventModel, bool>> Comparison { get; set; } = new();

Expand All @@ -24,30 +17,19 @@ public FilterModel(Guid id)

public bool IsEnabled { get; set; } = true;

public FilterType FilterType { get => _filterType; set => UpdateFilterType(value); }
public FilterType FilterType
{
get => _filterType;
set
{
_filterType = value;
FilterValue = string.Empty;
}
}

public FilterComparison FilterComparison { get; set; }

public dynamic? FilterValue { get; private set; }
public string FilterValue { get; set; } = string.Empty;

public List<SubFilterModel> SubFilters { get; set; } = new();

private FilterType _filterType;

private void UpdateFilterType(FilterType filterType)
{
FilterValue = filterType switch
{
FilterType.EventId => default(int),
FilterType.Level => SeverityLevel.All,
FilterType.Source => string.Empty,
FilterType.Task => string.Empty,
FilterType.Description => string.Empty,
_ => throw new Exception("Invalid Filter Type")
};

_filterType = filterType;
}

public void UpdateFilterValue(ValueChangedEventArgs args) => FilterValue = args.Value;
}
28 changes: 12 additions & 16 deletions src/EventLogExpert.Library/Models/SubFilterModel.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Library.EventArgs;
using EventLogExpert.Library.Helpers;

namespace EventLogExpert.Library.Models;

public class SubFilterModel
public record SubFilterModel
{
public SubFilterModel(FilterType filterType)
private FilterType _filterType;

public Guid Id { get; set; } = Guid.NewGuid();

public FilterType FilterType
{
FilterValue = filterType switch
get => _filterType;
set
{
FilterType.EventId => default(int),
FilterType.Level => SeverityLevel.All,
FilterType.Source => string.Empty,
FilterType.Task => string.Empty,
FilterType.Description => string.Empty,
_ => throw new Exception("Invalid Filter Type")
};
_filterType = value;
FilterValue = string.Empty;
}
}

public Guid Id { get; set; } = Guid.NewGuid();

public FilterComparison FilterComparison { get; set; }

public dynamic? FilterValue { get; private set; }

public void UpdateFilterValue(ValueChangedEventArgs args) => FilterValue = args.Value;
public string FilterValue { get; set; } = string.Empty;
}
22 changes: 10 additions & 12 deletions src/EventLogExpert/Components/FilterPane.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@inject IState<SettingsState> SettingsState

<div class="filter-pane">

<div class="filter-row">
<div class="filter-header">
<div>
<button class="button-primary" @onclick="AddFilter">
<i class="bi bi-plus-circle"></i> Add Filter
Expand All @@ -27,7 +26,7 @@
</button>
}
</div>

@if (FilterPaneState.Value.CurrentFilters.Any() || _isDateFilterVisible || _isAdvancedFilterVisible)
{
<div class="header-center">
Expand All @@ -43,17 +42,17 @@
}
</div>

<div class="filter-content" data-toggle="@MenuState">
<div class="filter-group" data-toggle="@MenuState">
@if (_isDateFilterVisible)
{
<EditForm id="filter-form" Model="_model">
<span>
After: <InputDate class="input-filter-datetime" Type="InputDateType.DateTimeLocal"
@bind-Value="_model.After" disabled="@(!_canEditDate)" />
After: <InputDate class="input-filter-datetime" Type="InputDateType.DateTimeLocal"
@bind-Value="_model.After" disabled="@(!_canEditDate)" />
</span>
<span>
Before: <InputDate class="input-filter-datetime" Type="InputDateType.DateTimeLocal"
@bind-Value="_model.Before" disabled="@(!_canEditDate)" />
Before: <InputDate class="input-filter-datetime" Type="InputDateType.DateTimeLocal"
@bind-Value="_model.Before" disabled="@(!_canEditDate)" />
</span>

@if (_canEditDate)
Expand Down Expand Up @@ -98,8 +97,8 @@
<div>
<span>
Expression: <input class="input-advanced-filter" type="text"
placeholder="(Id == 1000 || Id == 1001) && Description.Contains('Fault')"
@oninput="AdvancedFilterChanged" disabled="@(!_canEditAdvancedFilter)" />
placeholder="(Id == 1000 || Id == 1001) && Description.Contains('Fault')"
@oninput="AdvancedFilterChanged" disabled="@(!_canEditAdvancedFilter)" />
</span>
@if (_canEditAdvancedFilter)
{
Expand Down Expand Up @@ -133,7 +132,7 @@
</button>
}
}

@if (!_isAdvancedFilterValid)
{
<div hidden="@(string.IsNullOrWhiteSpace(_advancedFilterErrorMessage))">
Expand All @@ -143,5 +142,4 @@
</div>
}
</div>

</div>
18 changes: 8 additions & 10 deletions src/EventLogExpert/Components/FilterPane.razor.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
.filter-pane {
display: flex;
flex-direction: column;

margin: 5px;

max-height: 25%;
/* max-height: 25%; */
}

.filter-row {
.filter-header {
display: grid;
grid-template-columns: repeat(3, 1fr);
}

.filter-content {
display: flex;
flex-direction: column;

max-height: calc(100% - 20px);
overflow: auto;
.filter-group {
/* overflow: auto; */

border-bottom: solid var(--background-darkgray);

transition: all 1s;
}

.filter-content[data-toggle="false"] {
.filter-group[data-toggle="false"] {
display: none;

border: none;
Expand Down
7 changes: 3 additions & 4 deletions src/EventLogExpert/Shared/Components/FilterInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// // Licensed under the MIT License.

using Microsoft.AspNetCore.Components;
using ValueChangedEventArgs = EventLogExpert.Library.EventArgs.ValueChangedEventArgs;

namespace EventLogExpert.Shared.Components;

Expand All @@ -12,11 +11,11 @@ public partial class FilterInput
public string Value { get; set; } = string.Empty;

[Parameter]
public EventCallback<ValueChangedEventArgs> OnValueChangedEvent { get; set; }
public EventCallback<string> ValueChanged { get; set; }

private async Task UpdateValue(ChangeEventArgs args)
{
Value = (string)Convert.ChangeType(args.Value?.ToString(), typeof(string))!;
await OnValueChangedEvent.InvokeAsync(new ValueChangedEventArgs(Value));
Value = args.Value?.ToString() ?? string.Empty;
await ValueChanged.InvokeAsync(Value);
}
}
72 changes: 20 additions & 52 deletions src/EventLogExpert/Shared/Components/FilterRow.razor
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
@inject IState<EventLogState> EventLogState

<div class="filter-row">
<div class="filter-row">
@if (Value.IsEditing)
{
<div>

<div class="filter-content">
<span>Filter On: </span>
<select class="input-filter-select" @bind="@Value.FilterType" disabled="@(Value.SubFilters.Count > 0)">
@foreach (FilterType type in Enum.GetValues(typeof(FilterType)))
{
<option value="@type">@type.ToString()</option>
}
</select>
<FilterSelect @bind-Value="Value.FilterType" InputType="FilterType" />

<span>Comparison: </span>
<select class="input-filter-select" @bind="@Value.FilterComparison">
@foreach (FilterComparison type in Enum.GetValues(typeof(FilterComparison)))
{
<option value="@type">@type.ToFullString()</option>
}
</select>
<FilterSelect @bind-Value="Value.FilterComparison" InputType="FilterComparison" />

<span>Value: </span>
@switch (Value.FilterType)
{
case FilterType.EventId :
<FilterSelect CssClass="input-filter-id" TInput="int"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="EventLogState.Value.EventIds.OrderBy(id => id)" />
break;
case FilterType.Level :
<FilterSelect CssClass="input-filter-severity" TInput="SeverityLevel"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue" />
break;
case FilterType.Source :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="EventLogState.Value.EventProviderNames.OrderBy(n => n)" />
break;
case FilterType.Task :
<FilterSelect CssClass="input-filter-dropdown" TInput="string"
Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue"
Items="EventLogState.Value.TaskNames.OrderBy(n => n)" />
break;
case FilterType.Description :
default :
<FilterInput Value="@Value.FilterValue" OnValueChangedEvent="@Value.UpdateFilterValue" />
break;
}

<div>
@if (Value.FilterType is FilterType.Description)
{
<FilterInput @bind-Value="@Value.FilterValue" />
}
else
{
<FilterValueSelect @bind-Value="@Value.FilterValue" Type="Value.FilterType" />
}
</div>
</div>
}
else if (string.IsNullOrWhiteSpace(Value.ComparisonString))
Expand Down Expand Up @@ -94,17 +64,15 @@
</button>
}
}

</div>

</div>

<div class="sub-filter-row">
@if (Value.SubFilters.Any() && Value.IsEditing)
{
@if (Value.SubFilters.Any() && Value.IsEditing)
{
<div class="sub-filter-row">
@foreach (var item in Value.SubFilters)
{
<SubFilterRow ParentId="@Value.Id" FilterType="@Value.FilterType" Value="@item" />
<SubFilterRow ParentId="@Value.Id" FilterType="Value.FilterType" Value="@item" />
}
}
</div>
</div>
}
Loading