Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chri-s committed Aug 25, 2022
0 parents commit 94c06dd
Show file tree
Hide file tree
Showing 44 changed files with 2,615 additions and 0 deletions.
402 changes: 402 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions OpenAS2WebUI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAS2UI.Server", "src\Server\OpenAS2UI.Server.csproj", "{A84A6AE3-94DD-4266-B632-4F8CE34ECDC5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAS2UI.Client", "src\Client\OpenAS2UI.Client.csproj", "{76721170-C5C1-454F-A72F-8BE3888A35DA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAS2UI.Shared", "src\Shared\OpenAS2UI.Shared.csproj", "{581052B9-EFFF-4AA2-8796-8A132BDA2653}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A84A6AE3-94DD-4266-B632-4F8CE34ECDC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A84A6AE3-94DD-4266-B632-4F8CE34ECDC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A84A6AE3-94DD-4266-B632-4F8CE34ECDC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A84A6AE3-94DD-4266-B632-4F8CE34ECDC5}.Release|Any CPU.Build.0 = Release|Any CPU
{76721170-C5C1-454F-A72F-8BE3888A35DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76721170-C5C1-454F-A72F-8BE3888A35DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76721170-C5C1-454F-A72F-8BE3888A35DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76721170-C5C1-454F-A72F-8BE3888A35DA}.Release|Any CPU.Build.0 = Release|Any CPU
{581052B9-EFFF-4AA2-8796-8A132BDA2653}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{581052B9-EFFF-4AA2-8796-8A132BDA2653}.Debug|Any CPU.Build.0 = Debug|Any CPU
{581052B9-EFFF-4AA2-8796-8A132BDA2653}.Release|Any CPU.ActiveCfg = Release|Any CPU
{581052B9-EFFF-4AA2-8796-8A132BDA2653}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C03633C0-66CC-40E9-BCA7-D6AFA1A659B8}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions src/Client/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@using OpenAS2UI.Client.Shared
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
@*<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>*@
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(Shared.EmptyLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
24 changes: 24 additions & 0 deletions src/Client/ClipboardService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Microsoft.JSInterop;
namespace OpenAS2UI.Client
{
public sealed class ClipboardService
{
private readonly IJSRuntime _jsRuntime;

public ClipboardService(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}

public ValueTask<string> ReadTextAsync()
{
return _jsRuntime.InvokeAsync<string>("navigator.clipboard.readText");
}

public ValueTask WriteTextAsync(string text)
{
return _jsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
}
}
}
30 changes: 30 additions & 0 deletions src/Client/OpenAS2UI.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Content Remove="Pages\PartnerAdd.razor" />
<Content Remove="Pages\PartnerDelete.razor" />
</ItemGroup>

<ItemGroup>
<None Include="Pages\PartnerAdd.razor" />
<None Include="Pages\PartnerDelete.razor" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BlazorStrap" Version="5.0.106" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\OpenAS2UI.Shared.csproj" />
</ItemGroup>

</Project>
148 changes: 148 additions & 0 deletions src/Client/Pages/CertificateList.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
@page "/certificates"
@inject HttpClient HttpClient
@inject NavigationManager navigationManager

<PageTitle>Certificates - OpenAS2</PageTitle>

<div class="
d-flex
justify-content-between
flex-wrap flex-md-nowrap
align-items-center
pt-3
pb-2
mb-3
border-bottom
">
<h1><i class="fa-solid fa-key"></i> Certificates</h1>

<BSButtonGroup Class="mr-2">
<BSButton DataId="btnRefresh" IsOutlined="true" Color="BSColor.Secondary" Size="Size.Small" OnClick="UpdateData" IsDisabled="isLoading"><i class="fa-solid fa-rotate"></i></BSButton>
<BSTooltip Target="btnRefresh" Placement="Placement.Bottom">Refresh</BSTooltip>

@*Add the tooltip before the button. Otherwise the button won't get round corders because it is not the last element in the div*@
<BSTooltip Target="btnNew" Placement="Placement.Bottom">Add new certificate</BSTooltip>
<BSButton DataId="btnNew" IsOutlined="true" Color="BSColor.Secondary" Size="Size.Small" OnClick="AddNewCertificate"><i class="fa-solid fa-plus"></i></BSButton>
</BSButtonGroup>
</div>

<div>
@if (isLoading)
{
<div class="d-flex align-items-center justify-content-center">
<div class="spinner-border" role="status" aria-hidden="true"></div>
<strong class="ms-3">Loading...</strong>
</div>
}
else
{
@if (errorMsg == null)
{
<BSDataTable IsResponsive="true" IsStriped="true" IsSmall="true" FetchItems="FetchItems" PaginationBottom="true" RowsPerPage="rowsPerPage" Context="item">
<Header>
<BSDataTableHead TValue="CertificateItem" Sortable="true" Column="@(nameof(CertificateItem.Name))" ColumnFilter="true" Class="form-control-sm">Name</BSDataTableHead>
<BSDataTableHead TValue="CertificateItem">Actions</BSDataTableHead>
</Header>
<Body>
<BSDataTableRow>
@{
string certificateEditUrl = $"/certificates/view/{Uri.EscapeDataString(item.Name)}";
string certificateDeleteUrl = $"/certificates/delete/{Uri.EscapeDataString(item.Name)}";
}
<BSTD>@item.Name</BSTD>
<BSTD>
<BSLink Url="@certificateEditUrl">View</BSLink>
<BSLink Url="@certificateDeleteUrl" Class="text-danger ms-3">Delete</BSLink>
</BSTD>
</BSDataTableRow>
</Body>
</BSDataTable>

}
else
{
<BSAlert Color="BSColor.Danger" HasIcon="true">
@errorMsg
</BSAlert>
}
}
</div>

@code {
private List<CertificateItem> certificates = new List<CertificateItem>();

private bool isLoading = true;

private const int rowsPerPage = 20;

private string? errorMsg;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

await this.UpdateData();
}

private async Task UpdateData()
{
isLoading = true;
try
{
HttpResponseMessage msg = await HttpClient.GetAsync("certificate/");

if (msg.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
errorMsg = "Could not connect to OpenAS2-server: " + await msg.Content.ReadAsStringAsync();
isLoading = false;
return;
}

msg.EnsureSuccessStatusCode();

certificates = (await msg.Content.ReadFromJsonAsync<string[]>())!.Select(p => new CertificateItem(p)).ToList();
}
catch (Exception ex)
{
errorMsg = "Error loading data: " + ex.Message;
isLoading = false;
return;
}

errorMsg = null;
isLoading = false;
}

private void AddNewCertificate()
{

}

private Task<(IEnumerable<CertificateItem>, int)> FetchItems(DataRequest dataRequest)
{
IEnumerable<CertificateItem> data = this.certificates;

if (dataRequest.FilterColumnProperty != null && dataRequest.Filter != null)
{
data = data.Where(c =>
(dataRequest.FilterColumn == nameof(CertificateItem.Name) && c.Name.Contains(dataRequest.Filter, StringComparison.InvariantCultureIgnoreCase))
);
}

data = data.ToList();
int count = data.Count();

if (dataRequest.SortColumnProperty != null)
{
if (dataRequest.Descending)
data = data.OrderByDescending(c => c.Name);
else
data = data.OrderBy(c => c.Name);
}

data = data.Skip(dataRequest.Page * rowsPerPage).Take(rowsPerPage).ToList();
return Task.FromResult((data, count));
}

private record CertificateItem(string Name);
}
Loading

0 comments on commit 94c06dd

Please sign in to comment.