feat(Documents) Notes/Docs page improvements and warning cleanup

This commit is contained in:
2022-04-07 13:30:00 -04:00
parent b270453030
commit d82e60efdf
223 changed files with 4396 additions and 2861 deletions
+40 -15
View File
@@ -11,19 +11,17 @@ public class AgileService : IAgileService {
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action _onChange;
private event Action OnChange = default!;
public AgileService(HttpClient httpClient) {
this.httpClient = httpClient;
}
#if NO_SQL
public List<SprintModel> SprintModels { get; set; }
public List<TaskModel> TaskModels { get; set; }
public List<AgileSprintModel>? AgileSprintModels { get; set; }
public List<AgileTaskModel>? AgileTaskModels { get; set; }
#else
private DatabaseContext Database { get; set; }
@@ -32,12 +30,12 @@ public class AgileService : IAgileService {
#endif
public void Subscribe(Action action) {
_onChange += action;
public void Subscribe(Action? action) {
OnChange += action;
}
public void Unsubscribe(Action action) {
_onChange -= action;
public void Unsubscribe(Action? action) {
OnChange -= action;
}
public bool IsLoaded() {
@@ -50,13 +48,40 @@ public class AgileService : IAgileService {
return;
}
SprintModels = (await httpClient.GetFromJsonAsync<SprintModel[]>("generated/SprintModels.json")?? Array.Empty<SprintModel>() ).ToList();
TaskModels =(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/TaskModels.json") ?? Array.Empty<TaskModel>()).ToList();
AgileSprintModels = (await httpClient.GetFromJsonAsync<AgileSprintModel[]>("generated/AgileSprintModels.json")?? Array.Empty<AgileSprintModel>() ).ToList();
AgileTaskModels = (await httpClient.GetFromJsonAsync<AgileTaskModel[]>("generated/AgileTaskModels.json") ?? Array.Empty<AgileTaskModel>()).ToList();
foreach (var agileTask in AgileTaskModels)
{
if (agileTask.AgileSprintModelId != null)
{
SprintById(agileTask.AgileSprintModelId.Value)?.AgileTaskModels.Add(agileTask);
}
}
isLoaded = true;
NotifyDataChanged();
}
private AgileSprintModel? SprintById(int id)
{
foreach (var data in AgileSprintModels!)
if (data.Id == id)
return data;
return null;
}
private AgileTaskModel? TaskById(int id)
{
foreach (var data in AgileTaskModels!)
if (data.Id == id)
return data;
return null;
}
#else
public async Task Load(DatabaseContext database) {
Database = database;
@@ -65,8 +90,8 @@ public class AgileService : IAgileService {
return;
}
Database.SprintModels.AddRange(await httpClient.GetFromJsonAsync<SprintModel[]>("generated/SprintModels.json"));
Database.TaskModels.AddRange(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/TaskModels.json"));
Database.SprintModels.AddRange(await httpClient.GetFromJsonAsync<SprintModel[]>("generated/AgileSprintModels.json"));
Database.TaskModels.AddRange(await httpClient.GetFromJsonAsync<TaskModel[]>("generated/AgileTaskModels.json"));
Database.SaveChanges();
@@ -81,6 +106,6 @@ public class AgileService : IAgileService {
}
private void NotifyDataChanged() {
_onChange?.Invoke();
OnChange?.Invoke();
}
}
+131 -14
View File
@@ -1,5 +1,5 @@
using System.Net.Http.Json;
using Model.Documentation;
using Model.Doc;
#if NO_SQL
@@ -13,29 +13,31 @@ namespace Services.Development;
public class DocumentationService : IDocumentationService
{
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action _onChange;
public DocumentationService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public List<DocumentationModel> DocumentationModels { get; set; }
public List<DocContentModel> DocContentModels { get; set; } = new();
public List<DocContentModel> DocContentModelsByPageOrder { get; set; } = new();
public List<DocSectionModel> DocSectionModels { get; set; } = new();
public List<DocConnectionModel> DocConnectionModels { get; set; } = new();
public void Subscribe(Action action)
public void Subscribe(Action? action)
{
_onChange += action;
OnChange += action;
}
public void Unsubscribe(Action action)
public void Unsubscribe(Action? action)
{
_onChange -= action;
OnChange -= action;
}
public bool IsLoaded()
@@ -48,9 +50,25 @@ public class DocumentationService : IDocumentationService
{
if (isLoaded) return;
DocumentationModels =
(await httpClient.GetFromJsonAsync<DocumentationModel[]>("generated/DocumentationModels.json") ?? Array.Empty<DocumentationModel>()).ToList();
DocContentModels =
(await httpClient.GetFromJsonAsync<DocContentModel[]>("generated/DocContentModels.json") ??
Array.Empty<DocContentModel>()).ToList();
DocConnectionModels =
(await httpClient.GetFromJsonAsync<DocConnectionModel[]>("generated/DocConnectionModels.json") ??
Array.Empty<DocConnectionModel>()).ToList();
DocSectionModels =
(await httpClient.GetFromJsonAsync<DocSectionModel[]>("generated/DocSectionModels.json") ??
Array.Empty<DocSectionModel>()).ToList();
#if DEBUG
AddTestCode();
#endif
//TODO Until SQL work in production. Or, why even add SQL?
SortSQL();
isLoaded = true;
@@ -63,9 +81,108 @@ public class DocumentationService : IDocumentationService
NotifyDataChanged();
}
private event Action? OnChange;
private DocContentModel? ContentById(int id)
{
foreach (var doc in DocContentModels!)
if (doc.Id == id)
return doc;
return null;
}
private void SortSQL()
{
foreach (var connection in DocConnectionModels)
{
ContentById(connection.ParentId)!.DocumentationModels.Add(ContentById(connection.ChildId));
ContentById(connection.ChildId)!.Parent = ContentById(connection.ParentId);
}
foreach (var content in DocContentModels)
{
if (content.DocSectionModelId != null)
{
foreach (var section in DocSectionModels)
{
if (section.Id == content.DocSectionModelId)
{
section.DocumentationModels.Add(content);
}
}
}
}
ByPageOrder();
}
private void ByPageOrder()
{
DocContentModelsByPageOrder = new List<DocContentModel>();
int order = 1;
foreach (var documentation in DocContentModels)
{
if (documentation.Parent != null) continue;
documentation.PageOrder = order++;
DocContentModelsByPageOrder.Add(documentation);
void GetAllChildren(DocContentModel docs)
{
foreach (var doc in docs.DocumentationModels)
{
doc.PageOrder = order++;
DocContentModelsByPageOrder.Add(doc);
if (doc.DocumentationModels.Count > 0) GetAllChildren(doc);
}
}
GetAllChildren(documentation);
}
DocContentModelsByPageOrder = DocContentModelsByPageOrder.OrderBy(docContent => docContent.PageOrder).ToList();
}
private void AddTestCode()
{
DocContentModels.Add(new DocContentModel
{
Id = -110, Name = "Root Parent", Href = "root-parent", CreatedDate = DateTime.Now,
UpdatedDate = DateTime.Now, Content = "Example root parent"
});
DocContentModels.Add(new DocContentModel
{
Id = -109, Name = "Child Parent", Href = "child-parent", CreatedDate = DateTime.Now,
UpdatedDate = DateTime.Now, Content = "Example child parent"
});
DocContentModels.Add(new DocContentModel
{
Id = -108, Name = "Child Child 2", Href = "child-child", CreatedDate = DateTime.Now,
UpdatedDate = DateTime.Now, Content = "Example child child"
});
DocContentModels.Add(new DocContentModel
{
Id = -107, Name = "A", Href = "A", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, Content = "A"
});
DocContentModels.Add(new DocContentModel
{
Id = -106, Name = "B", Href = "B", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, Content = "B"
});
DocConnectionModels.Add(new DocConnectionModel { Id = -110, ParentId = -110, ChildId = -109 });
DocConnectionModels.Add(new DocConnectionModel { Id = -109, ParentId = -109, ChildId = -108 });
DocConnectionModels.Add(new DocConnectionModel { Id = -108, ParentId = -108, ChildId = -106 });
DocConnectionModels.Add(new DocConnectionModel { Id = -107, ParentId = -108, ChildId = -107 });
}
private void NotifyDataChanged()
{
_onChange?.Invoke();
OnChange?.Invoke();
}
}
+13 -12
View File
@@ -1,5 +1,5 @@
using System.Net.Http.Json;
using Model.Work.Git;
using Model.Development.Git;
#if NO_SQL
@@ -15,13 +15,16 @@ public class GitService : IGitService {
private bool isLoaded;
private event Action OnChange = default!;
public GitService(HttpClient httpClient) {
this.httpClient = httpClient;
}
#if NO_SQL
public List<ChangeModel> ChangeModels { get; set; }
public List<PatchModel> PatchModels { get; set; }
public List<GitChangeModel> GitChangeModels { get; set; } = default!;
public List<GitPatchModel> GitPatchModels { get; set; } = default!;
#else
public DbSet<ChangeModel> ChangeModels => Database.ChangeModels;
public DbSet<PatchModel> PatchModels => Database.PatchModels;
@@ -31,11 +34,11 @@ public class GitService : IGitService {
public void Subscribe(Action action) {
_onChange += action;
OnChange += action;
}
public void Unsubscribe(Action action) {
_onChange -= action;
OnChange -= action;
}
public bool IsLoaded() {
@@ -51,8 +54,8 @@ public class GitService : IGitService {
return;
}
ChangeModels = (await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/ChangeModels.json") ?? Array.Empty<ChangeModel>()).ToList();
PatchModels = (await httpClient.GetFromJsonAsync<PatchModel[]>("generated/PatchModels.json") ?? Array.Empty<PatchModel>()).ToList();
GitChangeModels = (await httpClient.GetFromJsonAsync<GitChangeModel[]>("generated/GitChangeModels.json") ?? Array.Empty<GitChangeModel>()).ToList();
GitPatchModels = (await httpClient.GetFromJsonAsync<GitPatchModel[]>("generated/GitPatchModels.json") ?? Array.Empty<GitPatchModel>()).ToList();
isLoaded = true;
@@ -69,8 +72,8 @@ public class GitService : IGitService {
return;
}
Database.ChangeModels.AddRange(await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/ChangeModels.json"));
Database.PatchModels.AddRange(await httpClient.GetFromJsonAsync<PatchModel[]>("generated/PatchModels.json"));
Database.ChangeModels.AddRange(await httpClient.GetFromJsonAsync<ChangeModel[]>("generated/GitChangeModels.json"));
Database.PatchModels.AddRange(await httpClient.GetFromJsonAsync<PatchModel[]>("generated/GitPatchModels.json"));
Database.SaveChanges();
@@ -86,9 +89,7 @@ public class GitService : IGitService {
NotifyDataChanged();
}
private event Action _onChange;
private void NotifyDataChanged() {
_onChange?.Invoke();
OnChange?.Invoke();
}
}
+77 -12
View File
@@ -1,5 +1,5 @@
using System.Net.Http.Json;
using Model.Immortal.Notes;
using Model.Notes;
#if NO_SQL
@@ -16,50 +16,115 @@ public class NoteService : INoteService {
private bool isLoaded;
private event Action _onChange;
private event Action OnChange = default!;
private void NotifyDataChanged() {
_onChange?.Invoke();
OnChange?.Invoke();
}
public NoteService(HttpClient httpClient) {
this.httpClient = httpClient;
}
public List<NoteModel> NoteModels { get; set; }
public List<NoteContentModel> NoteContentModels { get; set; } = default!;
public List<NoteConnectionModel> NoteConnectionModels { get; set; }
public List<NoteSectionModel> NoteSectionModels { get; set; }
public List<NoteContentModel> NoteContentModelsByPageOrder { get; set; } = new();
public void Subscribe(Action action) {
_onChange += action;
OnChange += action;
}
public void Unsubscribe(Action action) {
_onChange -= action;
OnChange -= action;
}
public bool IsLoaded() {
return isLoaded;
}
public async Task Load() {
if (isLoaded) {
return;
}
NoteModels = (await httpClient.GetFromJsonAsync<NoteModel[]>("generated/NoteModels.json") ?? Array.Empty<NoteModel>()).ToList();
NoteContentModels = (await httpClient.GetFromJsonAsync<NoteContentModel[]>("generated/NoteContentModels.json") ?? Array.Empty<NoteContentModel>()).ToList();
NoteConnectionModels = (await httpClient.GetFromJsonAsync<NoteConnectionModel[]>("generated/NoteConnectionModels.json") ?? Array.Empty<NoteConnectionModel>()).ToList();
NoteSectionModels = (await httpClient.GetFromJsonAsync<NoteSectionModel[]>("generated/NoteSectionModels.json") ?? Array.Empty<NoteSectionModel>()).ToList();
isLoaded = true;
SortSQL();
NotifyDataChanged();
}
private NoteContentModel? ContentById(int id)
{
foreach (var data in NoteContentModels!)
if (data.Id == id)
return data;
return null;
}
private void SortSQL()
{
foreach (var connection in NoteConnectionModels)
{
ContentById(connection.ParentId)!.NoteContentModels.Add(ContentById(connection.ChildId));
ContentById(connection.ChildId)!.Parent = ContentById(connection.ParentId);
}
foreach (var content in NoteContentModels)
{
if (content.NoteSectionModelId != null)
{
foreach (var section in NoteSectionModels)
{
if (section.Id == content.NoteSectionModelId)
{
section.NoteContentModels.Add(content);
}
}
}
}
ByPageOrder();
}
private void ByPageOrder()
{
NoteContentModelsByPageOrder = new List<NoteContentModel>();
int order = 1;
foreach (var note in NoteContentModels)
{
if (note.Parent != null) continue;
note.PageOrder = order++;
NoteContentModelsByPageOrder.Add(note);
void GetAllChildren(NoteContentModel docs)
{
foreach (var doc in docs.NoteContentModels)
{
doc.PageOrder = order++;
NoteContentModelsByPageOrder.Add(doc);
if (doc.NoteContentModels.Count > 0) GetAllChildren(doc);
}
}
GetAllChildren(note);
}
NoteContentModelsByPageOrder = NoteContentModelsByPageOrder.OrderBy(noteContent => noteContent.PageOrder).ToList();
}
public void Update() {
NotifyDataChanged();
}
}