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

Implement data aquisition #60

Merged
merged 15 commits into from
Oct 4, 2022
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
17 changes: 16 additions & 1 deletion phalanx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Phalanx.App", "src\Phalanx.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3FBE741E-1ACA-4907-AEDA-610F32175AEF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarHub.ArmouryModel.Concrete.Extensions.Tests", "test\WarHub.ArmouryModel.Concrete.Extensions.Tests\WarHub.ArmouryModel.Concrete.Extensions.Tests.csproj", "{20B48EC9-3C85-4748-A6CF-6A5E20769BA5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WarHub.ArmouryModel.Concrete.Extensions.Tests", "test\WarHub.ArmouryModel.Concrete.Extensions.Tests\WarHub.ArmouryModel.Concrete.Extensions.Tests.csproj", "{20B48EC9-3C85-4748-A6CF-6A5E20769BA5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Warhub.ArmouryModel.DataProviders", "src\Warhub.ArmouryModel.DataProviders\Warhub.ArmouryModel.DataProviders.csproj", "{471CC761-6982-48D4-88F7-969C31999A78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -120,6 +122,18 @@ Global
{20B48EC9-3C85-4748-A6CF-6A5E20769BA5}.Release|x64.Build.0 = Release|Any CPU
{20B48EC9-3C85-4748-A6CF-6A5E20769BA5}.Release|x86.ActiveCfg = Release|Any CPU
{20B48EC9-3C85-4748-A6CF-6A5E20769BA5}.Release|x86.Build.0 = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|x64.ActiveCfg = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|x64.Build.0 = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|x86.ActiveCfg = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Debug|x86.Build.0 = Debug|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|Any CPU.Build.0 = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|x64.ActiveCfg = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|x64.Build.0 = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|x86.ActiveCfg = Release|Any CPU
{471CC761-6982-48D4-88F7-969C31999A78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -132,6 +146,7 @@ Global
{3B8D010C-44BB-4CB2-AF19-67D5255108A9} = {C3511AB4-867D-4076-B2A5-FC12CF75EADB}
{C6899AC8-32B8-4CD1-80F2-0B1F9D68846D} = {C3511AB4-867D-4076-B2A5-FC12CF75EADB}
{20B48EC9-3C85-4748-A6CF-6A5E20769BA5} = {3FBE741E-1ACA-4907-AEDA-610F32175AEF}
{471CC761-6982-48D4-88F7-969C31999A78} = {C3511AB4-867D-4076-B2A5-FC12CF75EADB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {588DA2B5-3BD3-4ECF-B037-C6FA3F57128C}
Expand Down
98 changes: 98 additions & 0 deletions src/Phalanx.App/Pages/Configuration/SystemSelect.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@using Microsoft.Extensions.Options
@using WarHub.ArmouryModel.DataProviders
@using WarHub.ArmouryModel.Workspaces.BattleScribe;

@inject GalleryHttpClient client
@inject GalleryBrowserState state

@if (CatpkgGallery is { InfoCache: { } galleryInfo })
{
<h2>System:</h2>
<FluentSelect TValue=string Value="_selectedRepoName" ValueChanged="(x => SelectCatpkg(x))">
@foreach (var repo in _repositories)
{
<FluentOption Value="repo.Name">@repo.Name</FluentOption>
}
</FluentSelect>
<FluentCheckbox @bind-Value="ShowArchived">
Show Archived Repositories
</FluentCheckbox>
}
else
{
<FluentProgressRing />
<p>Loading catpkg gallery...</p>
}

@code {
[Parameter]
public CatpkgGalleryCache? CatpkgGallery { get; set; }

[Parameter]
public EventCallback<CatpkgGalleryCache> CatpkgGalleryChanged { get; set; }

XmlWorkspace? workspace;

string _selectedRepoName = "";

bool _showArchived;

bool ShowArchived
{
get => _showArchived;
set
{
_showArchived = value;
UpdateRepositories();
}
}

readonly List<CatpkgRepositoryInfo> _repositories = new();

List<ColumnDefinition<CatpkgRepositoryInfo>> ColumnDefinitions { get; } = new()
{
#nullable disable
new("Name", x => x.Description),
new("Latest Release", x => x.Version),
#nullable restore
};

void UpdateRepositories()
{
_repositories.Clear();
if (CatpkgGallery?.InfoCache?.Repositories is { } repos)
{
_repositories.AddRange(repos.Where(x => x.Archived != true || ShowArchived).OrderBy(x => x.Description));
// Clear value if we switch away from archived
if (!ShowArchived && (repos.Where(x => x.Description == _selectedRepoName).FirstOrDefault()?.Archived ?? false))
{
_selectedRepoName = "";
}
}
}

CatpkgRepositoryInfo? repositoryInfo;

async Task SelectCatpkg(string catName)
{
if (CatpkgGallery is null)
return;
_selectedRepoName = catName;
repositoryInfo = CatpkgGallery.InfoCache?.Repositories.Find(x => x.Name == catName);
var repoRef = new RepositoryReference(_selectedRepoName, CatpkgGallery.Reference);
repositoryInfo = await state.Cache.GetHydratedCatpkgAsync(client, repoRef);
workspace = await state.Cache.GetXMLWorkspaceAsync(client, repoRef);
Console.WriteLine(workspace);
}

protected async override Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
if (CatpkgGallery is { Reference: { } galleryRef, InfoCache: null })
{
var result = await state.Cache.GetHydratedCatpkgGalleryCacheAsync(client, galleryRef);
await CatpkgGalleryChanged.InvokeAsync(result);
}
UpdateRepositories();
}
}
3 changes: 2 additions & 1 deletion src/Phalanx.App/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@page "/"


<Phalanx.App.Pages.Home.WelcomeView></Phalanx.App.Pages.Home.WelcomeView>

<div style="display: flex; justify-content: space-around;">
<FluentAnchor Appearance="Appearance.Accent" Href="/rosteredit">Edit sample roster</FluentAnchor>
<FluentAnchor Appearance="Appearance.Accent" Href="/print">Format roster</FluentAnchor>
</div>
</div>
77 changes: 77 additions & 0 deletions src/Phalanx.App/Pages/RosterCreateSelectSystem.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@page "/rostercreateselectsystem"

@using WarHub.ArmouryModel.Source
@using Microsoft.Extensions.Options
@using WarHub.ArmouryModel.DataProviders
@using WarHub.ArmouryModel.Workspaces.BattleScribe

@inject GalleryHttpClient httpClient
@inject IOptions<GalleryBrowserOptions> options
@inject GalleryBrowserState state

<h1>Select System for Roster</h1>

<FluentSelect TValue=string Value="_selectedGalleryName" ValueChanged="(x => onSelectedGalleryChanged(x))">
<FluentOption>Phalanx Playground</FluentOption>
@foreach (var galleryRef in state.Cache.GalleryReferences)
{
<FluentOption Value="galleryRef.Name">@galleryRef.Name</FluentOption>
}
</FluentSelect>

@if (_selectedGalleryName.Length > 0)
{
<Phalanx.App.Pages.Configuration.SystemSelect @bind-CatpkgGallery=SelectedGalleryCache>
</Phalanx.App.Pages.Configuration.SystemSelect>
}

@code {
private string _selectedGalleryName = "";

private CatpkgGalleryCache? SelectedGalleryCache
{
get
{
return _selectedGalleryName == ""
? new CatpkgGalleryCache(new GalleryReference("Phalanx Playground", new Uri("file://")))
: state.Cache[_selectedGalleryName];
}
set
{
if (value is not null)
{
state.Cache.Upsert(value);
}
}
}

protected override void OnInitialized()
{
base.OnInitialized();

// add if not already existing
foreach (var galleryRefDto in options.Value.DefaultGalleries)
{
var galleryRef = galleryRefDto.ToRecord();
if (state.Cache[galleryRef] is null)
{
state.Cache.Upsert(new(galleryRef));
}
}
_selectedGalleryName = options.Value.DefaultGalleries.FirstOrDefault()?.Name ?? "";
}

protected async override Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
foreach (var galleryRef in options.Value.DefaultGalleries)
{
var galleryInfo = await state.Cache.GetCatpkgGalleryInfoAsync(httpClient, galleryRef.ToRecord());
}
}
protected async Task onSelectedGalleryChanged(string galleryName)
{
await base.OnParametersSetAsync();
_selectedGalleryName = galleryName;
}
}
8 changes: 3 additions & 5 deletions src/Phalanx.App/Phalanx.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
<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.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Fast.Components.FluentUI" Version="1.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NuGet.Versioning" Version="6.3.0" />
<PackageReference Include="PublishSPAforGitHubPages.Build" Version="2.0.1" />
<PackageReference Include="WarHub.ArmouryModel.Workspaces.BattleScribe" Version="0.13.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Phalanx.SampleDataset\Phalanx.SampleDataset.csproj" />
<ProjectReference Include="..\WarHub.ArmouryModel.Concrete.Extensions\WarHub.ArmouryModel.Concrete.Extensions.csproj" />
<ProjectReference Include="..\Warhub.ArmouryModel.DataProviders\Warhub.ArmouryModel.DataProviders.csproj" />
<ProjectReference Include="..\WarHub.ArmouryModel.EditorServices\WarHub.ArmouryModel.EditorServices.csproj" />
<ProjectReference Include="..\WarHub.ArmouryModel.Extensions\WarHub.ArmouryModel.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<!-- <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" /> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these changes are necessary. wwwroot/appsettings.json will automatically be included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 29-35.

</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/Phalanx.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Phalanx.App;
using Phalanx.App.Pages.Printing;
using WarHub.ArmouryModel.DataProviders;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
Expand All @@ -10,4 +11,10 @@
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<RosterFormatsProvider>();


builder.Services.AddOptions<GalleryBrowserOptions>().BindConfiguration("GalleryBrowser");
builder.Services.AddSingleton<GalleryBrowserState>();
builder.Services.AddScoped<GalleryHttpClient>();


await builder.Build().RunAsync();
8 changes: 8 additions & 0 deletions src/Phalanx.App/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"GalleryBrowser:DefaultGalleries": [
{
"Name": "BSData/gallery",
"CatpkgUrl": "https://github.com/BSData/gallery/releases/download/index-v1/bsdata.catpkg-gallery.json"
}
]
}
Loading