-
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: implement the first configuration stuff
- Loading branch information
Showing
11 changed files
with
367 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@using CsvProc9000.UI.Dialogues | ||
@inject IFolderPicker FolderPicker | ||
|
||
<div class="input-with-button"> | ||
<InputText type="text" @bind-Value="@SelectedPath"></InputText> | ||
<button class="btn btn-primary" @onclick="SelectFolderPath">Select</button> | ||
</div> | ||
|
||
@code { | ||
private string _selectedPath = string.Empty; | ||
|
||
[Parameter] | ||
public string DialogueTitle { get; set; } | ||
|
||
[Parameter] | ||
public string SelectedPath | ||
{ | ||
get => _selectedPath; | ||
set | ||
{ | ||
if (value == _selectedPath) return; | ||
_selectedPath = value; | ||
SelectedPathChanged.InvokeAsync(value); | ||
} | ||
} | ||
|
||
[Parameter] | ||
public EventCallback<string> SelectedPathChanged { get; set; } | ||
|
||
private void SelectFolderPath() | ||
{ | ||
var selectedPath = FolderPicker.Show(DialogueTitle); | ||
SelectedPath = selectedPath; | ||
} | ||
} |
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,14 @@ | ||
namespace CsvProc9000.UI.Dialogues; | ||
|
||
/// <summary> | ||
/// A dialogue to let the user pick a folder | ||
/// </summary> | ||
internal interface IFolderPicker | ||
{ | ||
/// <summary> | ||
/// Shows the dialogue and lets the user pick a folder | ||
/// </summary> | ||
/// <param name="title">A title for the dialogue</param> | ||
/// <returns>The path to the folder that the user picked</returns> | ||
string Show(string title); | ||
} |
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,131 @@ | ||
@page "/config" | ||
@using CsvProc9000.Model.Configuration | ||
@using CsvProc9000.UI.Settings | ||
@using CsvProc9000.UI.Components | ||
@inject ISettingsLoader SettingsLoader | ||
|
||
<!-- TODO: GO BACK TO HOME link! --> | ||
|
||
<h1>Configure</h1> | ||
|
||
<p> | ||
Here you can configure your <b>CsvProc9000</b> service to your needs. | ||
</p> | ||
|
||
<div class="load"> | ||
<div> | ||
<div> | ||
Where is the currently installed service located? | ||
</div> | ||
<div> | ||
<FolderSelect DialogueTitle="Select the service installation location" @bind-SelectedPath="@_serviceInstallationPath"></FolderSelect> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-1"> | ||
<button class="btn btn-primary" disabled="@IsLoadButtonDisabled" @onclick="LoadSettings">Load settings</button> | ||
</div> | ||
</div> | ||
|
||
@{ | ||
if (_settings != null) | ||
{ | ||
<div class="settings mt-4"> | ||
<h2>Settings</h2> | ||
<p> | ||
Change the settings of your current service installation here: | ||
</p> | ||
|
||
<div class="mt-2"> | ||
<h3>Inbox</h3> | ||
|
||
<div class="row"> | ||
<div> | ||
Inbox directory: | ||
</div> | ||
<div> | ||
<FolderSelect DialogueTitle="Select the Inbox" @bind-SelectedPath="@_settings.Inbox"></FolderSelect> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div> | ||
Inbox delimiter: | ||
</div> | ||
<div> | ||
<InputText type="text" @bind-Value="@_settings.InboxDelimiter"></InputText> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div> | ||
Should the file in the Inbox be deleted? | ||
</div> | ||
<div> | ||
<InputCheckbox @bind-Value="@_settings.DeleteInboxFile"></InputCheckbox> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<h3>Outbox</h3> | ||
|
||
<div class="row"> | ||
<div> | ||
Outbox directory: | ||
</div> | ||
<div> | ||
<FolderSelect DialogueTitle="Select the Outbox" @bind-SelectedPath="@_settings.Outbox"></FolderSelect> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div> | ||
Outbox delimiter: | ||
</div> | ||
<div> | ||
<InputText type="text" @bind-Value="@_settings.OutboxDelimiter"></InputText> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div> | ||
Outbox charset: | ||
</div> | ||
<div> | ||
<InputText type="text" @bind-Value="@_settings.OutboxFileCharset"></InputText> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div> | ||
Should the values in the Outbox-file be in quotes? | ||
</div> | ||
<div> | ||
<InputCheckbox @bind-Value="@_settings.OutboxValuesInQuotes"></InputCheckbox> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<h3>Rules</h3> | ||
|
||
<p>TODO...</p> | ||
</div> | ||
</div> | ||
} | ||
} | ||
|
||
@code { | ||
|
||
private string _serviceInstallationPath = string.Empty; | ||
private bool IsLoadButtonDisabled => string.IsNullOrWhiteSpace(_serviceInstallationPath); | ||
private CsvProcessorOptions _settings; | ||
|
||
private void LoadSettings() | ||
{ | ||
var settings = SettingsLoader.Load(_serviceInstallationPath); | ||
_settings = settings; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,51 @@ | ||
@page "/" | ||
@inject NavigationManager NavigationManager | ||
|
||
<h1>Hello, world!</h1> | ||
<h1>CsvProc900</h1> | ||
|
||
Welcome to your new app. | ||
<p> | ||
Welcome to the UI application for the <b>CsvProc900!</b> | ||
</p> | ||
<p> | ||
Here are some options you can use: | ||
</p> | ||
<div class="navigation"> | ||
<div class="row"> | ||
<div class="col-sm"> | ||
<button type="button" class="btn btn-primary btn-square" @onclick="NavigateToConfigPage"> | ||
<div class="oi oi-cog"> | ||
</div> | ||
<div> | ||
Config | ||
</div> | ||
</button> | ||
</div> | ||
|
||
<div class="col-sm"> | ||
<button type="button" class="btn btn-primary btn-square" disabled> | ||
<div class="oi oi-clock"> | ||
</div> | ||
<div> | ||
Coming Soon™ | ||
</div> | ||
</button> | ||
</div> | ||
|
||
<div class="col-sm"> | ||
<button type="button" class="btn btn-primary btn-square" disabled> | ||
<div class="oi oi-clock"> | ||
</div> | ||
<div> | ||
Coming Soon™ | ||
</div> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
private void NavigateToConfigPage() | ||
{ | ||
NavigationManager.NavigateTo("config"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/CsvProc9000.UI/Platforms/Windows/WindowsFolderPicker.cs
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,26 @@ | ||
using CsvProc9000.UI.Dialogues; | ||
using Microsoft.WindowsAPICodePack.Dialogs; | ||
|
||
namespace CsvProc9000.UI.Platforms.Windows; | ||
|
||
/// <summary> | ||
/// A windows specific <see cref="IFolderPicker"/> | ||
/// </summary> | ||
internal sealed class WindowsFolderPicker : IFolderPicker | ||
{ | ||
/// <inheritdoc /> | ||
public string Show(string title) | ||
{ | ||
var dialog = new CommonOpenFileDialog(title); | ||
|
||
dialog.IsFolderPicker = true; | ||
dialog.Multiselect = false; | ||
dialog.Title = title; | ||
|
||
var result = dialog.ShowDialog(); | ||
|
||
return result == CommonFileDialogResult.Ok | ||
? dialog.FileName | ||
: string.Empty; | ||
} | ||
} |
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,16 @@ | ||
using CsvProc9000.Model.Configuration; | ||
|
||
namespace CsvProc9000.UI.Settings; | ||
|
||
/// <summary> | ||
/// Loads the settings of the service from a given directory | ||
/// </summary> | ||
internal interface ISettingsLoader | ||
{ | ||
/// <summary> | ||
/// Loads the settings of the service from the given directory | ||
/// </summary> | ||
/// <param name="pathToDirectory">The directory to load the settings from</param> | ||
/// <returns>The loaded settings</returns> | ||
CsvProcessorOptions Load(string pathToDirectory); | ||
} |
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,39 @@ | ||
using CsvProc9000.Model.Configuration; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace CsvProc9000.UI.Settings; | ||
|
||
/// <inheritdoc /> | ||
internal sealed class SettingsLoader : ISettingsLoader | ||
{ | ||
/// <inheritdoc /> | ||
public CsvProcessorOptions Load(string pathToDirectory) | ||
{ | ||
if (!Directory.Exists(pathToDirectory)) | ||
{ | ||
throw new DirectoryNotFoundException($"Unable to find directory '{pathToDirectory}'"); | ||
} | ||
|
||
var pathToSettings = Path.Combine(pathToDirectory, "appsettings.json"); | ||
if (!File.Exists(pathToSettings)) | ||
{ | ||
throw new FileNotFoundException($"Expected a file at '{pathToSettings}' but couldn't find a file"); | ||
} | ||
|
||
var settings = LoadSettingsFromFile(pathToSettings); | ||
return settings; | ||
} | ||
|
||
private static CsvProcessorOptions LoadSettingsFromFile(string pathToSettingsFile) | ||
{ | ||
var configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddJsonFile(pathToSettingsFile); | ||
|
||
var configuration = configurationBuilder.Build(); | ||
|
||
var section = configuration.GetSection("CsvProcessor"); | ||
var settings = section.Get<CsvProcessorOptions>(); | ||
|
||
return settings; | ||
} | ||
} |
Oops, something went wrong.