mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 05:58:00 +00:00
Added the EDI specification
This commit is contained in:
6 files changed
+605
No files matched your search
@@ -20,6 +20,18 @@
|
||||
<PreviewPrototype/>
|
||||
<div class="mb-6"></div>
|
||||
|
||||
<MudStack Row="@true" AlignItems="AlignItems.Center" Class="mb-3">
|
||||
<MudSelect T="EDIVersion" @bind-Value="@this.selectedEDIVersion" Label="EDI specification version" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateEDIVersion">
|
||||
@foreach (var version in Enum.GetValues<EDIVersion>())
|
||||
{
|
||||
<MudSelectItem Value="@version">@version</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Disabled="@(!this.selectedEDIVersion.WasSpecificationSelected())" Href="@this.selectedEDIVersion.SpecificationURL()" Target="_blank">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Link" Class="mr-2"/> Download specification
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row="@true" Class="mb-3">
|
||||
<MudSelect T="ProgrammingLanguages" @bind-Value="@this.selectedProgrammingLanguage" AdornmentIcon="@Icons.Material.Filled.Code" Adornment="Adornment.Start" Label="Programming language" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateProgrammingLanguage">
|
||||
@foreach (var language in Enum.GetValues<ProgrammingLanguages>())
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using AIStudio.Chat;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Assistants.EDI;
|
||||
|
||||
public partial class AssistantEDI : AssistantBaseCore
|
||||
{
|
||||
[Inject]
|
||||
private HttpClient HttpClient { get; set; } = null!;
|
||||
|
||||
public override Tools.Components Component => Tools.Components.EDI_ASSISTANT;
|
||||
|
||||
protected override string Title => "EDI Server";
|
||||
@@ -37,6 +42,7 @@ public partial class AssistantEDI : AssistantBaseCore
|
||||
{
|
||||
if (!this.MightPreselectValues())
|
||||
{
|
||||
this.selectedEDIVersion = EDIVersion.V1;
|
||||
this.selectedProgrammingLanguage = ProgrammingLanguages.NONE;
|
||||
this.otherProgrammingLanguage = string.Empty;
|
||||
this.selectedDataSource = DataSources.NONE;
|
||||
@@ -56,6 +62,7 @@ public partial class AssistantEDI : AssistantBaseCore
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.EDI.PreselectOptions)
|
||||
{
|
||||
this.selectedEDIVersion = this.SettingsManager.ConfigurationData.EDI.PreselectedEDIVersion;
|
||||
this.selectedProgrammingLanguage = this.SettingsManager.ConfigurationData.EDI.PreselectedProgrammingLanguage;
|
||||
this.otherProgrammingLanguage = this.SettingsManager.ConfigurationData.EDI.PreselectedOtherProgrammingLanguage;
|
||||
this.selectedDataSource = this.SettingsManager.ConfigurationData.EDI.PreselectedDataSource;
|
||||
@@ -77,6 +84,7 @@ public partial class AssistantEDI : AssistantBaseCore
|
||||
return false;
|
||||
}
|
||||
|
||||
private EDIVersion selectedEDIVersion = EDIVersion.V1;
|
||||
private ProgrammingLanguages selectedProgrammingLanguage = ProgrammingLanguages.NONE;
|
||||
private string otherProgrammingLanguage = string.Empty;
|
||||
private DataSources selectedDataSource = DataSources.NONE;
|
||||
@@ -90,6 +98,14 @@ public partial class AssistantEDI : AssistantBaseCore
|
||||
private string retrievalDescription = string.Empty;
|
||||
private string additionalLibraries = string.Empty;
|
||||
|
||||
private string? ValidateEDIVersion(EDIVersion version)
|
||||
{
|
||||
if (version == EDIVersion.NONE)
|
||||
return "Please select an EDI specification version for the EDI server.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateProgrammingLanguage(ProgrammingLanguages language)
|
||||
{
|
||||
if (language == ProgrammingLanguages.OTHER)
|
||||
@@ -307,5 +323,11 @@ public partial class AssistantEDI : AssistantBaseCore
|
||||
await this.form!.Validate();
|
||||
if (!this.inputIsValid)
|
||||
return;
|
||||
|
||||
var ediSpecification = await this.selectedEDIVersion.ReadSpecification(this.HttpClient);
|
||||
if (string.IsNullOrWhiteSpace(ediSpecification))
|
||||
{
|
||||
// TODO: Show an error message
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AIStudio.Assistants.EDI;
|
||||
|
||||
public enum EDIVersion
|
||||
{
|
||||
NONE,
|
||||
|
||||
V1,
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace AIStudio.Assistants.EDI;
|
||||
|
||||
public static class EDIVersionExtensions
|
||||
{
|
||||
public static async Task<string> ReadSpecification(this EDIVersion version, HttpClient httpClient)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = version.SpecificationURL();
|
||||
var response = await httpClient.GetAsync(url);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static string SpecificationURL(this EDIVersion version)
|
||||
{
|
||||
var nameLower = version.ToString().ToLowerInvariant();
|
||||
var filename = $"{nameLower}.json";
|
||||
return $"specs/edi/{filename}";
|
||||
}
|
||||
|
||||
public static bool WasSpecificationSelected(this EDIVersion version) => version != EDIVersion.NONE;
|
||||
}
|
||||
Reference in new issue
Block a user