-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make rules (conditions) editable
- Loading branch information
Showing
7 changed files
with
223 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
@page "/rule/{Index:int}" | ||
@using CsvProc9000.Model.Configuration | ||
@using CsvProc9000.UI.States | ||
|
||
@inject IConfigurationState State | ||
@inject NavigationManager NavigationManager | ||
|
||
<h1>Edit Rule: @_rule?.GetName()</h1> | ||
|
||
@if (_rule == null) | ||
{ | ||
<p>There was an error loading the Rule...</p> | ||
return; | ||
} | ||
|
||
<div> | ||
<div class="row"> | ||
Name: | ||
<InputText type="text" @bind-Value="@_rule.Name"></InputText> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<h3>Conditions</h3> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">If the Field ...</th> | ||
<th scope="col">... has the Value ...</th> | ||
<th scope="col"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
@foreach (var condition in _rule.Conditions) | ||
{ | ||
<tr> | ||
<td> | ||
<InputText @bind-Value="@condition.Field"></InputText> | ||
</td> | ||
<td> | ||
<InputText @bind-Value="@condition.Value"></InputText> | ||
</td> | ||
<td> | ||
<button class="btn btn-danger oi oi-minus" @onclick="() => RemoveCondition(condition)"></button> | ||
</td> | ||
</tr> | ||
} | ||
|
||
</tbody> | ||
</table> | ||
|
||
<div class="mt-2"> | ||
<button class="btn btn-success float-end oi oi-plus" @onclick="AddCondition"></button> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-5"> | ||
<button class="btn btn-primary float-start" @onclick="Ok">OK</button> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public int Index { get; set; } | ||
|
||
private Rule _rule; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
_rule = State.GetRuleAt(Index); | ||
_rule.Conditions ??= new List<Condition>(); | ||
_rule.Changes ??= new List<Change>(); | ||
} | ||
|
||
private void RemoveCondition(Condition condition) | ||
{ | ||
_rule.Conditions.Remove(condition); | ||
} | ||
|
||
private void AddCondition() | ||
{ | ||
_rule.Conditions.Add(new Condition()); | ||
} | ||
|
||
private void Ok() | ||
{ | ||
NavigationManager.NavigateTo("/config"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using CsvProc9000.Model.Configuration; | ||
using CsvProc9000.UI.Settings; | ||
|
||
namespace CsvProc9000.UI.States; | ||
|
||
internal sealed class ConfigurationState : IConfigurationState | ||
{ | ||
private readonly ISettingsLoader _settingsLoader; | ||
|
||
/// <inheritdoc /> | ||
public CsvProcessorOptions Settings { get; private set; } | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public ConfigurationState(ISettingsLoader settingsLoader) | ||
{ | ||
_settingsLoader = settingsLoader ?? throw new ArgumentNullException(nameof(settingsLoader)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void ReadSettings(string pathToSettings) | ||
{ | ||
var settings = _settingsLoader.Load(pathToSettings); | ||
settings.Rules ??= new List<Rule>(); | ||
Settings = settings; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Rule GetRuleAt(int index) | ||
{ | ||
return Settings.Rules[index]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CsvProc9000.Model.Configuration; | ||
|
||
namespace CsvProc9000.UI.States; | ||
|
||
/// <summary> | ||
/// State for configuring the settings | ||
/// </summary> | ||
internal interface IConfigurationState | ||
{ | ||
/// <summary> | ||
/// Reads in the settings from the given path | ||
/// </summary> | ||
/// <param name="pathToSettings">The path to read in the settings from</param> | ||
void ReadSettings(string pathToSettings); | ||
|
||
/// <summary> | ||
/// Gets the rule from the given index | ||
/// </summary> | ||
/// <param name="index">The index to get the rule from</param> | ||
/// <returns>The rule that was gotten from the index</returns> | ||
Rule GetRuleAt(int index); | ||
|
||
/// <summary> | ||
/// The read in settings | ||
/// </summary> | ||
CsvProcessorOptions Settings { get; } | ||
} |