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 8 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
15 changes: 15 additions & 0 deletions phalanx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3FBE741E-1
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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Warhub.ArmoryModel.DataProviders", "src\Warhub.ArmoryModel.DataProviders\Warhub.ArmoryModel.DataProviders.csproj", "{471CC761-6982-48D4-88F7-969C31999A78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
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
95 changes: 95 additions & 0 deletions src/Phalanx.App/Pages/Configuration/SystemSelect.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
@using Microsoft.Extensions.Options
@using WarHub.ArmoryModel.DataProviders
@inject GalleryHttpClient client
@inject GalleryBrowserState state

@if (CatpkgGallery is { InfoCache: { } galleryInfo } && _repositories is not null)
{
<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; }

string _selectedRepoName = "";

bool _showArchived;

bool ShowArchived
{
get => _showArchived;
set
{
_showArchived = value;
Console.WriteLine("Set_showArchive");
UpdateRepositories();
}
}

List<CatpkgRepositoryInfo>? _repositories;

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

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

CatpkgRepositoryInfo? repositoryInfo;

async Task SelectCatpkg(string catName)
{
_selectedRepoName = catName;
repositoryInfo = CatpkgGallery?.InfoCache?.Repositories.Find(x => x.Name == catName);
repositoryInfo = await state.Cache.GetHydratedCatpkgAsync(client, new RepositoryReference(_selectedRepoName, CatpkgGallery.Reference));
}

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();
}

}
62 changes: 61 additions & 1 deletion src/Phalanx.App/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
@page "/"
@using Microsoft.Extensions.Options
@using WarHub.ArmoryModel.DataProviders
@inject GalleryHttpClient httpClient
@inject IOptions<GalleryBrowserOptions> options
@inject GalleryBrowserState state

<FluentSelect @bind-Value="selectedGalleryName">
<FluentOption>Use Playground</FluentOption>

@foreach (var galleryRef in state.Cache.GalleryReferences)
{
<FluentOption Value="galleryRef.Name">@galleryRef.Name</FluentOption>
}

</FluentSelect>
<Phalanx.App.Pages.Configuration.SystemSelect @bind-CatpkgGallery=SelectedGalleryCache></Phalanx.App.Pages.Configuration.SystemSelect>
nstephenh marked this conversation as resolved.
Show resolved Hide resolved

<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>

@code {

private string selectedGalleryName = "";

private CatpkgGalleryCache? SelectedGalleryCache
{
get => 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());
}
}

}
10 changes: 9 additions & 1 deletion src/Phalanx.App/Phalanx.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<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" />
Expand All @@ -17,13 +18,20 @@

<ItemGroup>
<ProjectReference Include="..\Phalanx.SampleDataset\Phalanx.SampleDataset.csproj" />
<ProjectReference Include="..\Warhub.ArmoryModel.DataProviders\Warhub.ArmoryModel.DataProviders.csproj" />
<ProjectReference Include="..\WarHub.ArmouryModel.Concrete.Extensions\WarHub.ArmouryModel.Concrete.Extensions.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.

<None Include="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</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.ArmoryModel.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