Browse Source

Removing pointless WebsiteService.cs

main
Jonathan 11 months ago
parent
commit
9e9b25ae6f
  1. 5
      IGP/PageLayout.razor
  2. 1
      IGP/Program.cs
  3. 14
      Services/IServices.cs
  4. 10
      Services/Website/SearchService.cs
  5. 76
      Services/Website/WebsiteService.cs

5
IGP/PageLayout.razor

@ -1,6 +1,5 @@
@inherits LayoutComponentBase
@inject ISearchService SearchService
@inject IWebsiteService WebService
@inject IDataCollectionService DataCollectionService
@inject NavigationManager NavigationManager
@using Model.Website.Data
@ -79,7 +78,6 @@
protected override void OnInitialized()
{
base.OnInitialized();
WebService.Subscribe(HasChanged);
CollectFirstPageLoaded();
}
@ -110,8 +108,6 @@
protected override async Task OnInitializedAsync()
{
await WebService.Load();
await Focus();
}
@ -127,7 +123,6 @@
void IDisposable.Dispose()
{
WebService.Unsubscribe(HasChanged);
}
void HasChanged()

1
IGP/Program.cs

@ -57,7 +57,6 @@ builder.Services.AddScoped<IEntityFilterService, EntityFilterService>();
builder.Services.AddScoped<IEntityDisplayService, EntityDisplayService>();
builder.Services.AddScoped<IEntityDialogService, EntityDialogService>();
builder.Services.AddScoped<IToastService, ToastService>();
builder.Services.AddScoped<IWebsiteService, WebsiteService>();
builder.Services.AddScoped<INoteService, NoteService>();
builder.Services.AddScoped<ISearchService, SearchService>();
builder.Services.AddScoped<IVariableService, VariableService>();

14
Services/IServices.cs

@ -121,20 +121,6 @@ public interface IEntityDialogService
public bool HasHistory();
}
public interface IWebsiteService
{
public List<WebPageModel> WebPageModels { get; set; }
public List<WebSectionModel> WebSectionModels { get; set; }
public void Subscribe(Action action);
public void Unsubscribe(Action action);
public void Update();
public Task Load();
public bool IsLoaded();
}
public interface INoteService
{

10
Services/Website/SearchService.cs

@ -1,5 +1,6 @@
using Model.Entity.Data;
using Model.Website;
using Model.Website.Data;
namespace Services.Website;
@ -7,14 +8,10 @@ public class SearchService : ISearchService
{
private readonly INoteService noteService;
private readonly IWebsiteService websiteService;
private bool isLoaded;
public SearchService(IWebsiteService websiteService, INoteService noteService)
public SearchService(INoteService noteService)
{
this.websiteService = websiteService;
this.noteService = noteService;
}
@ -40,7 +37,6 @@ public class SearchService : ISearchService
public async Task Load()
{
await websiteService.Load();
await noteService.Load();
@ -48,7 +44,7 @@ public class SearchService : ISearchService
Searches.Add("Notes", new List<SearchPointModel>());
Searches.Add("Entities", new List<SearchPointModel>());
foreach (var webPage in websiteService.WebPageModels)
foreach (var webPage in WebsiteData.GetPages())
{
SearchPoints.Add(new SearchPointModel
{

76
Services/Website/WebsiteService.cs

@ -1,76 +0,0 @@
using System.Net.Http.Json;
using Model.Website;
namespace Services.Development;
public class WebsiteService : IWebsiteService
{
private readonly HttpClient httpClient;
private bool isLoaded;
public WebsiteService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public List<WebSectionModel> WebSectionModels { get; set; } = default!;
public List<WebPageModel> WebPageModels { get; set; } = default!;
public void Subscribe(Action action)
{
OnChange += action;
}
public void Unsubscribe(Action action)
{
OnChange -= action;
}
public bool IsLoaded()
{
return isLoaded;
}
public async Task Load()
{
if (isLoaded) return;
WebPageModels = (await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"))!.ToList();
WebSectionModels = (await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"))!
.ToList();
isLoaded = true;
SortSql();
NotifyDataChanged();
}
public void Update()
{
NotifyDataChanged();
}
private event Action OnChange = default!;
private void SortSql()
{
foreach (var page in WebPageModels)
if (page.WebSectionModelId != null)
{
var webSection =
WebSectionModels.Find(webSection => webSection.Id == page.WebSectionModelId);
webSection.WebPageModels.Add(page);
}
}
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
Loading…
Cancel
Save