feat(Permission) Added start of the Storage feature. Detailed/Plain default toggle
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<div class="formContainer">
|
||||
<div class="formTextContainer">
|
||||
<div class="formLabel">
|
||||
@Label:
|
||||
</div>
|
||||
<label class="switch">
|
||||
<input readonly="@ReadOnly"
|
||||
type="checkbox"
|
||||
id="@labelId"
|
||||
checked="@Value"
|
||||
@oninput="OnChange"/>
|
||||
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
@if (Info != "")
|
||||
{
|
||||
<div class="formInfo">
|
||||
@Info
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<style>
|
||||
.formContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.formTextContainer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.formLabel {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.formInfo {
|
||||
font-size: 0.8rem;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
width: 60px;
|
||||
height: 34px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
top: 4px;
|
||||
}
|
||||
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: var(--paper-border);
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: #7838df;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(26px);
|
||||
-ms-transform: translateX(26px);
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string Label { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string Info { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ChangeEventArgs> OnChange { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool ReadOnly { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool Value { get; set; }
|
||||
|
||||
private string labelId = "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
labelId = Label.ToLower().Replace(" ", "_");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
@inject ISearchService searchService
|
||||
@inject NavigationManager navigationManager
|
||||
@inject IJSRuntime jsRuntime
|
||||
@inject ISearchService SearchService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<button class="searchButtonContainer" @onclick="ButtonClicked">
|
||||
<div class="searchText">
|
||||
@@ -48,12 +48,12 @@
|
||||
|
||||
private void ButtonClicked(EventArgs eventArgs)
|
||||
{
|
||||
searchService.Show();
|
||||
SearchService.Show();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
userAgent = await jsRuntime.InvokeAsync<string>("getUserAgent");
|
||||
userAgent = await JsRuntime.InvokeAsync<string>("getUserAgent");
|
||||
}
|
||||
|
||||
}
|
||||
+5
-1
@@ -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();
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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
@@ -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>
|
||||
@@ -22,23 +24,34 @@
|
||||
</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
|
||||
|
||||
@@ -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/>
|
||||
@@ -42,3 +53,43 @@
|
||||
</InfoBodyComponent>
|
||||
</PaperComponent>
|
||||
</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!);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
@page "/storage"
|
||||
|
||||
@inject IStorageService StorageService
|
||||
|
||||
@using Services.Website
|
||||
@implements IDisposable
|
||||
@layout PageLayout
|
||||
|
||||
<LayoutMediumContentComponent>
|
||||
<AlertComponent>
|
||||
<Title>Not Implemented</Title>
|
||||
<Message></Message>
|
||||
</AlertComponent>
|
||||
|
||||
@if (!_enabledPermissions)
|
||||
{
|
||||
<AlertComponent Type="@SeverityType.Error">
|
||||
<Title>Storage Disabled</Title>
|
||||
<Message>Enable Storage on the Permissions Page.</Message>
|
||||
</AlertComponent>
|
||||
}
|
||||
else
|
||||
{
|
||||
<PaperComponent>
|
||||
TODO
|
||||
<FormLayoutComponent>
|
||||
<FormToggleComponent
|
||||
Label="Is Plain View"
|
||||
Value="@_isEntityPlainView"
|
||||
OnChange="EntityViewChanged"/>
|
||||
</FormLayoutComponent>
|
||||
</PaperComponent>
|
||||
}
|
||||
|
||||
<ContentDividerComponent/>
|
||||
|
||||
@@ -18,3 +33,36 @@
|
||||
|
||||
</PaperComponent>
|
||||
</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
@@ -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 @@
|
||||
[{"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"}]
|
||||
@@ -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>
|
||||
|
||||
+27
-1
@@ -1,4 +1,5 @@
|
||||
using Model.BuildOrders;
|
||||
using Microsoft.AspNetCore.Components.ProtectedBrowserStorage;
|
||||
using Model.BuildOrders;
|
||||
using Model.Doc;
|
||||
using Model.Economy;
|
||||
using Model.Entity;
|
||||
@@ -10,6 +11,7 @@ using Model.Website;
|
||||
using Model.Website.Enums;
|
||||
using Model.Work.Tasks;
|
||||
using Services.Immortal;
|
||||
using Services.Website;
|
||||
|
||||
namespace Services;
|
||||
|
||||
@@ -25,6 +27,30 @@ public interface IToastService
|
||||
void ClearAllToasts();
|
||||
}
|
||||
|
||||
public interface IStorageService
|
||||
{
|
||||
public void Subscribe(Action action);
|
||||
public void Unsubscribe(Action action);
|
||||
T GetValue<T>(string forKey);
|
||||
void SetValue<T>(string key, T value);
|
||||
|
||||
Task Load();
|
||||
}
|
||||
|
||||
public interface IPermissionService
|
||||
{
|
||||
public void Subscribe(Action action);
|
||||
public void Unsubscribe(Action action);
|
||||
|
||||
public bool GetIsStorageEnabled();
|
||||
public bool GetIsDataCollectionEnabled();
|
||||
|
||||
public void SetIsStorageEnabled(bool isEnabled);
|
||||
public void SetIsDataCollectionEnabled(bool isEnabled);
|
||||
|
||||
Task Load();
|
||||
}
|
||||
|
||||
public interface ISearchService
|
||||
{
|
||||
public List<SearchPointModel> SearchPoints { get; set; }
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
namespace Services.Immortal;
|
||||
using Services.Website;
|
||||
|
||||
namespace Services.Immortal;
|
||||
|
||||
public class EntityViewType
|
||||
{
|
||||
public static string Detailed = "Detailed";
|
||||
public static string Plain = "Plain";
|
||||
|
||||
}
|
||||
public class EntityDisplayService : IEntityDisplayService
|
||||
{
|
||||
private string displayType = "Detailed";
|
||||
private string _displayType;
|
||||
|
||||
public EntityDisplayService(IStorageService storageService)
|
||||
{
|
||||
_displayType = storageService.GetValue<bool>(StorageKeys.IsPlainView)
|
||||
? EntityViewType.Plain : EntityViewType.Detailed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<string> DefaultChoices()
|
||||
{
|
||||
return new List<string> { "Detailed", "Plain" };
|
||||
return new List<string> { EntityViewType.Detailed, EntityViewType.Plain };
|
||||
}
|
||||
|
||||
public void Subscribe(Action action)
|
||||
@@ -21,12 +37,12 @@ public class EntityDisplayService : IEntityDisplayService
|
||||
|
||||
public string GetDisplayType()
|
||||
{
|
||||
return displayType;
|
||||
return _displayType;
|
||||
}
|
||||
|
||||
public void SetDisplayType(string displayType)
|
||||
{
|
||||
this.displayType = displayType;
|
||||
this._displayType = displayType;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0-preview.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" Version="5.0.0-rc.1.20451.17" />
|
||||
<PackageReference Include="Microsoft.JSInterop" Version="7.0.0-preview.2.22153.2" />
|
||||
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class PermissionService : IPermissionService
|
||||
{
|
||||
private bool isLoaded;
|
||||
|
||||
|
||||
private IJSRuntime _jsRuntime;
|
||||
private bool isStorageEnabled = false;
|
||||
private IToastService _toastService;
|
||||
private IStorageService _storageService;
|
||||
|
||||
public PermissionService(IJSRuntime jsRuntime, IToastService toastService, IStorageService storageService)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
_toastService = toastService;
|
||||
_storageService = storageService;
|
||||
}
|
||||
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public bool GetIsStorageEnabled()
|
||||
{
|
||||
return _storageService.GetValue<bool>(StorageKeys.EnabledStorage);
|
||||
}
|
||||
|
||||
public bool GetIsDataCollectionEnabled()
|
||||
{
|
||||
return _storageService.GetValue<bool>(StorageKeys.EnabledDataCollection);
|
||||
}
|
||||
|
||||
public void SetIsStorageEnabled(bool isEnabled)
|
||||
{
|
||||
_storageService.SetValue(StorageKeys.EnabledStorage, isEnabled);
|
||||
}
|
||||
|
||||
public void SetIsDataCollectionEnabled(bool isEnabled)
|
||||
{
|
||||
_storageService.SetValue(StorageKeys.EnabledDataCollection, isEnabled);
|
||||
}
|
||||
|
||||
public Task Load()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
{
|
||||
OnChange();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Microsoft.JSInterop;
|
||||
using Model.Feedback;
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class StorageKeys
|
||||
{
|
||||
public static string EnabledStorage = "StorageEnabled";
|
||||
public static string EnabledDataCollection = "StorageDataCollection";
|
||||
public static string IsPlainView { get; set; } = "IsPlainView";
|
||||
}
|
||||
|
||||
public class StorageService : IStorageService
|
||||
{
|
||||
private readonly ISyncLocalStorageService _localStorageService;
|
||||
private IJSRuntime _jsRuntime;
|
||||
private readonly IToastService _toastService;
|
||||
private bool isLoaded;
|
||||
private bool isStorageEnabled;
|
||||
|
||||
|
||||
public StorageService(IJSRuntime jsRuntime, IToastService toastService,
|
||||
ISyncLocalStorageService localStorageService)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
_toastService = toastService;
|
||||
_localStorageService = localStorageService;
|
||||
}
|
||||
|
||||
private string enabledKey => StorageKeys.EnabledStorage;
|
||||
|
||||
public void Subscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action)
|
||||
{
|
||||
OnChange += action;
|
||||
}
|
||||
|
||||
public T GetValue<T>(string forKey)
|
||||
{
|
||||
return _localStorageService.GetItem<T>(forKey);
|
||||
}
|
||||
|
||||
public void SetValue<T>(string key, T value)
|
||||
{
|
||||
if (key.Equals(StorageKeys.EnabledStorage) && value.Equals(true))
|
||||
{
|
||||
_localStorageService.SetItem(key, value);
|
||||
NotifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.Equals(StorageKeys.EnabledStorage))
|
||||
{
|
||||
_localStorageService.Clear();
|
||||
NotifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var isEnabled = GetValue<bool>(StorageKeys.EnabledStorage);
|
||||
if (!isEnabled)
|
||||
{
|
||||
_toastService.AddToast(new ToastModel
|
||||
{
|
||||
Title = "Permission Error",
|
||||
SeverityType = SeverityType.Error,
|
||||
Message = "Storage must be enabled before Storage can be used."
|
||||
});
|
||||
NotifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
_localStorageService.SetItem(key, value);
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
isStorageEnabled = GetValue<bool>(enabledKey);
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
private event Action OnChange = null!;
|
||||
|
||||
private void NotifyDataChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
OnChange();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user