feat(Permission) Added start of the Storage feature. Detailed/Plain default toggle

This commit is contained in:
2022-04-24 19:33:18 -04:00
parent 8a4d00054a
commit afaafbe713
20 changed files with 538 additions and 65 deletions
+5 -1
View File
@@ -1,4 +1,7 @@
@inject IVariableService VariableService
@using Microsoft.AspNetCore.Components.ProtectedBrowserStorage
@inject IVariableService VariableService
@inject IStorageService StorageService
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
@@ -76,6 +79,7 @@
protected override async Task OnInitializedAsync()
{
await VariableService.Load();
await StorageService.Load();
isLoaded = true;
StateHasChanged();
}
BIN
View File
Binary file not shown.
+1
View File
@@ -20,6 +20,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0-preview.1" />
<PackageReference Include="Markdig" Version="0.28.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0-preview.2.22153.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0-preview.2.22153.2" PrivateAssets="all" />
+1 -1
View File
@@ -3,7 +3,7 @@
@layout PageLayout
<DevOnlyComponent>
<BuildCalculatorPage></BuildCalculatorPage>
<PermissionsPage/>
</DevOnlyComponent>
<HomePage/>
@@ -1,15 +1,17 @@
@inject IJSRuntime jsRuntime;
@inject IKeyService keyService
@inject IImmortalSelectionService filterService
@inject IBuildOrderService buildOrderService
@inject IJSRuntime JsRuntime
@inject IKeyService KeyService
@inject IImmortalSelectionService FilterService
@inject IBuildOrderService BuildOrderService
@inject IStorageService StorageService
@using Services.Website
@implements IDisposable
@if (entity != null)
@if (_entity != null)
{
<div class="entityClickView">
<CascadingValue Value="entity">
<CascadingValue Value="@viewType">
<CascadingValue Value="_entity">
<CascadingValue Value="@_viewType">
<EntityViewComponent></EntityViewComponent>
</CascadingValue>
</CascadingValue>
@@ -17,28 +19,39 @@
}
<style>
.entityClickView {
overflow-y: scroll; width: 100%; overflow-x: hidden; height: 550px;
overflow-y: scroll; width: 100%; overflow-x: hidden; height: 550px;
}
</style>
@code {
private EntityModel? entity = default!;
private string viewType = "Detailed";
private EntityModel? _entity = default!;
private string _viewType = EntityViewType.Detailed;
protected override void OnInitialized()
{
keyService.Subscribe(HandleClick);
KeyService.Subscribe(HandleClick);
StorageService.Subscribe(RefreshDefaults);
RefreshDefaults();
}
void IDisposable.Dispose()
{
keyService.Unsubscribe(HandleClick);
KeyService.Unsubscribe(HandleClick);
StorageService.Unsubscribe(RefreshDefaults);
}
void RefreshDefaults()
{
_viewType = StorageService.GetValue<bool>(StorageKeys.IsPlainView) ? EntityViewType.Plain : EntityViewType.Detailed;
}
protected override bool ShouldRender()
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.time", "EntityClickViewComponent");
JsRuntime.InvokeVoidAsync("console.time", "EntityClickViewComponent");
#endif
return true;
}
@@ -46,23 +59,23 @@
protected override void OnAfterRender(bool firstRender)
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.timeEnd", "EntityClickViewComponent");
JsRuntime.InvokeVoidAsync("console.timeEnd", "EntityClickViewComponent");
#endif
}
private void HandleClick()
{
var hotkey = keyService.GetHotkey();
var hotkeyGroup = keyService.GetHotkeyGroup();
var isHoldSpace = keyService.IsHoldingSpace();
var faction = filterService.GetFactionType();
var immortal = filterService.GetImmortalType();
var hotkey = KeyService.GetHotkey();
var hotkeyGroup = KeyService.GetHotkeyGroup();
var isHoldSpace = KeyService.IsHoldingSpace();
var faction = FilterService.GetFactionType();
var immortal = FilterService.GetImmortalType();
var foundEntity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
if (foundEntity != null && entity != foundEntity)
if (foundEntity != null && _entity != foundEntity)
{
entity = foundEntity;
_entity = foundEntity;
StateHasChanged();
}
}
@@ -1,4 +1,4 @@
@page "/analytics"
@page "/data-collection"
@layout PageLayout
+58 -7
View File
@@ -1,16 +1,27 @@
@page "/permissions"
@inject IPermissionService PermissionService
@layout PageLayout
@using Services.Website
@inject Blazored.LocalStorage.ILocalStorageService LocalStorage
@implements IDisposable
<LayoutMediumContentComponent>
<AlertComponent>
<Title>Not Implemented</Title>
<Message></Message>
</AlertComponent>
<PaperComponent>
TODO
<FormLayoutComponent>
<FormToggleComponent
Label="Storage Enabled"
Info="Is storage enabled?"
Value="@_storageEnabled"
OnChange="StoragePermissionChanged"/>
<FormToggleComponent
Label="Data Collection Enabled"
Info="Is data collection enabled?"
Value="@_dataCollectionEnabled"
OnChange="DataCollectionPermissionChanged"/>
</FormLayoutComponent>
</PaperComponent>
<ContentDividerComponent/>
@@ -41,4 +52,44 @@
<InfoAnswerComponent>Enable data tracking if you want the website maintainer to know how your using the website.</InfoAnswerComponent>
</InfoBodyComponent>
</PaperComponent>
</LayoutMediumContentComponent>
</LayoutMediumContentComponent>
@code {
private bool _storageEnabled = false;
private bool _dataCollectionEnabled = false;
protected override void OnInitialized()
{
PermissionService.Subscribe(Update);
Update();
}
void Update()
{
_storageEnabled = PermissionService.GetIsStorageEnabled();
_dataCollectionEnabled = PermissionService.GetIsDataCollectionEnabled();
StateHasChanged();
}
public void Dispose()
{
PermissionService.Unsubscribe(Update);
}
private void StoragePermissionChanged(ChangeEventArgs obj)
{
PermissionService.SetIsStorageEnabled((bool)obj.Value!);
}
private void DataCollectionPermissionChanged(ChangeEventArgs obj)
{
PermissionService.SetIsDataCollectionEnabled((bool)obj.Value!);
}
}
+56 -8
View File
@@ -1,20 +1,68 @@
@page "/storage"
@inject IStorageService StorageService
@using Services.Website
@implements IDisposable
@layout PageLayout
<LayoutMediumContentComponent>
<AlertComponent>
<Title>Not Implemented</Title>
<Message></Message>
</AlertComponent>
<PaperComponent>
TODO
</PaperComponent>
@if (!_enabledPermissions)
{
<AlertComponent Type="@SeverityType.Error">
<Title>Storage Disabled</Title>
<Message>Enable Storage on the Permissions Page.</Message>
</AlertComponent>
}
else
{
<PaperComponent>
<FormLayoutComponent>
<FormToggleComponent
Label="Is Plain View"
Value="@_isEntityPlainView"
OnChange="EntityViewChanged"/>
</FormLayoutComponent>
</PaperComponent>
}
<ContentDividerComponent/>
<PaperComponent>
</PaperComponent>
</LayoutMediumContentComponent>
</LayoutMediumContentComponent>
@code {
bool _enabledPermissions;
protected override void OnInitialized()
{
_enabledPermissions = StorageService.GetValue<bool>(StorageKeys.EnabledStorage);
Update();
StorageService.Subscribe(Update);
}
public void Dispose()
{
StorageService.Unsubscribe(Update);
}
void Update()
{
_isEntityPlainView = StorageService.GetValue<bool>(StorageKeys.IsPlainView);
StateHasChanged();
}
private bool _isEntityPlainView;
private void EntityViewChanged(ChangeEventArgs obj)
{
StorageService.SetValue(StorageKeys.IsPlainView, obj.Value);
}
}
+21 -3
View File
@@ -1,8 +1,10 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using Blazored.LocalStorage;
using IGP;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Services;
using Model;
using Services;
using Services.Development;
using Services.Immortal;
@@ -17,11 +19,24 @@ builder.Logging.SetMinimumLevel(LogLevel.Warning);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<LazyAssemblyLoader>();
builder.Services.AddSingleton(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<LazyAssemblyLoader>();
builder.Services.AddProtectedBrowserStorage();
builder.Services.AddLocalization();
builder.Services.AddBlazoredLocalStorageAsSingleton(config =>
{
config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
config.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
config.JsonSerializerOptions.IgnoreReadOnlyProperties = true;
config.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
config.JsonSerializerOptions.WriteIndented = false;
});
builder.Services.AddSingleton<INavigationService, NavigationService>();
builder.Services.AddSingleton<IKeyService, KeyService>();
builder.Services.AddSingleton<IImmortalSelectionService, ImmortalSelectionService>();
@@ -42,6 +57,9 @@ builder.Services.AddSingleton<IDocumentationService, DocumentationService>();
builder.Services.AddSingleton<ISearchService, SearchService>();
builder.Services.AddSingleton<IVariableService, VariableService>();
builder.Services.AddSingleton<IStorageService, StorageService>();
builder.Services.AddSingleton<IPermissionService, PermissionService>();
builder.Services.AddSingleton<IEconomyComparisonService, EconomyComparisionService>();
builder.Services.AddSingleton(new HttpClient
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
[{"Id":1,"WebSectionModelId":2,"Name":"Database","Description":"Database of game information","Href":"database","IsPrivate":"False"},{"Id":2,"WebSectionModelId":1,"Name":"Build Calculator","Description":"Build order calculator for determining army timings","Href":"build-calculator","IsPrivate":"False"},{"Id":3,"WebSectionModelId":1,"Name":"Harass Calculator","Description":"Alloy harassment calculator","Href":"harass-calculator","IsPrivate":"False"},{"Id":4,"WebSectionModelId":1,"Name":"Memory Tester","Description":"Testing memory","Href":"memory-tester","IsPrivate":"False"},{"Id":5,"WebSectionModelId":1,"Name":"Comparion Charts","Description":"Ecnomy charts to compare build orders","Href":"comparison-charts","IsPrivate":"True"},{"Id":6,"WebSectionModelId":2,"Name":"Notes","Description":"General player notes","Href":"notes","IsPrivate":"False"},{"Id":7,"WebSectionModelId":2,"Name":"Key Mapping","Description":"General key mapping info","Href":"keymapping","IsPrivate":"True"},{"Id":8,"WebSectionModelId":4,"Name":"Road Map","Description":"Plans for this website","Href":"roadmap","IsPrivate":"False"},{"Id":9,"WebSectionModelId":4,"Name":"Change Log","Description":"Past updates to the website","Href":"changelog","IsPrivate":"False"},{"Id":10,"WebSectionModelId":4,"Name":"Agile","Description":"Showing agile view of this website","Href":"agile","IsPrivate":"False"},{"Id":11,"WebSectionModelId":4,"Name":"Making Of","Description":"Explaining development details of this website","Href":"makingof","IsPrivate":"False"},{"Id":12,"WebSectionModelId":2,"Name":"Documentation","Description":"Explaining how to use this website","Href":"documentation","IsPrivate":"True"},{"Id":13,"WebSectionModelId":3,"Name":"About","Description":"Answering general questions on the website","Href":"about","IsPrivate":"False"},{"Id":14,"WebSectionModelId":3,"Name":"Contact","Description":"My contact info","Href":"contact","IsPrivate":"False"},{"Id":15,"WebSectionModelId":3,"Name":"Streams","Description":"Stream info","Href":"streams","IsPrivate":"False"},{"Id":16,"WebSectionModelId":4,"Name":"Documentation","Description":"Development information","Href":"docs","IsPrivate":"False"},{"Id":17,"WebSectionModelId":5,"Name":"Permissions","Description":"Permission Settings","Href":"permissions","IsPrivate":"False"},{"Id":18,"WebSectionModelId":5,"Name":"Analytics","Description":"Analytics Settings","Href":"analytics","IsPrivate":"False"},{"Id":19,"WebSectionModelId":5,"Name":"Storage","Description":"Storage Settings","Href":"storage","IsPrivate":"False"},{"Id":20,"WebSectionModelId":1,"Name":"Economy Comparison","Description":"Compare economies","Href":"economy-comparison","IsPrivate":"False"}]
[{"Id":1,"WebSectionModelId":2,"Name":"Database","Description":"Database of game information","Href":"database","IsPrivate":"False"},{"Id":2,"WebSectionModelId":1,"Name":"Build Calculator","Description":"Build order calculator for determining army timings","Href":"build-calculator","IsPrivate":"False"},{"Id":3,"WebSectionModelId":1,"Name":"Harass Calculator","Description":"Alloy harassment calculator","Href":"harass-calculator","IsPrivate":"False"},{"Id":4,"WebSectionModelId":1,"Name":"Memory Tester","Description":"Testing memory","Href":"memory-tester","IsPrivate":"False"},{"Id":5,"WebSectionModelId":1,"Name":"Comparion Charts","Description":"Ecnomy charts to compare build orders","Href":"comparison-charts","IsPrivate":"True"},{"Id":6,"WebSectionModelId":2,"Name":"Notes","Description":"General player notes","Href":"notes","IsPrivate":"False"},{"Id":7,"WebSectionModelId":2,"Name":"Key Mapping","Description":"General key mapping info","Href":"keymapping","IsPrivate":"True"},{"Id":8,"WebSectionModelId":4,"Name":"Road Map","Description":"Plans for this website","Href":"roadmap","IsPrivate":"False"},{"Id":9,"WebSectionModelId":4,"Name":"Change Log","Description":"Past updates to the website","Href":"changelog","IsPrivate":"False"},{"Id":10,"WebSectionModelId":4,"Name":"Agile","Description":"Showing agile view of this website","Href":"agile","IsPrivate":"False"},{"Id":11,"WebSectionModelId":4,"Name":"Making Of","Description":"Explaining development details of this website","Href":"makingof","IsPrivate":"False"},{"Id":12,"WebSectionModelId":2,"Name":"Documentation","Description":"Explaining how to use this website","Href":"documentation","IsPrivate":"True"},{"Id":13,"WebSectionModelId":3,"Name":"About","Description":"Answering general questions on the website","Href":"about","IsPrivate":"False"},{"Id":14,"WebSectionModelId":3,"Name":"Contact","Description":"My contact info","Href":"contact","IsPrivate":"False"},{"Id":15,"WebSectionModelId":3,"Name":"Streams","Description":"Stream info","Href":"streams","IsPrivate":"False"},{"Id":16,"WebSectionModelId":4,"Name":"Documentation","Description":"Development information","Href":"docs","IsPrivate":"False"},{"Id":17,"WebSectionModelId":5,"Name":"Permissions","Description":"Permission Settings","Href":"permissions","IsPrivate":"False"},{"Id":18,"WebSectionModelId":5,"Name":"Data Collection","Description":"Data Collection Settings","Href":"data-collection","IsPrivate":"False"},{"Id":19,"WebSectionModelId":5,"Name":"Storage","Description":"Storage Settings","Href":"storage","IsPrivate":"False"},{"Id":20,"WebSectionModelId":1,"Name":"Economy Comparison","Description":"Compare economies","Href":"economy-comparison","IsPrivate":"False"}]
+1
View File
@@ -52,6 +52,7 @@
document.addEventListener("keydown", function (e) {
DotNetReference?.invokeMethodAsync('OnKeyPress', e.key, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey)
});
</script>
<script>navigator.serviceWorker.register('service-worker.js');</script>