Skip to content

Commit

Permalink
feat: Document structure editor basics #3
Browse files Browse the repository at this point in the history
feat: Document structure editor basics
  • Loading branch information
Andras-Csanyi authored May 11, 2024
2 parents a187227 + bf3d8dd commit 1a89124
Show file tree
Hide file tree
Showing 20 changed files with 502 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using EncyclopediaGalactica.BusinessLogic.Contracts
<FluentGrid>
<FluentGridItem xs="12" sm="12" md="12" lg="12" xl="12" xxl="12">
<FluentCombobox TOption="DocumentResult"
OptionValue="@(r => r.Id.ToString())"
OptionText="@(r => r.Name)"
Items="_documentResults"
Label="Documents"
SelectedOptionChanged="SelectDocumentAsync!">
</FluentCombobox>
</FluentGridItem>
<FluentGridItem xs="12" sm="12" md="12" lg="12" xl="12" xxl="12">
@if (_selectedDocument == null)
{
<h4>No document is selected</h4>
}
else
{
<h4>Document (@(_selectedDocument.Id)): @(_selectedDocument.Name)</h4>
<hr/>
<p>Root Document Structure id: </p>
<FluentTreeView>
<EGDocumentStructureTree
StructureNode="_selectedDocument.DocumentStructure.StructureNode"/>
</FluentTreeView>
}
</FluentGridItem>
</FluentGrid>
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using UIWasm.Services;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructureEditor;

public partial class EGDocumentStructureEditor
{
private ICollection<DocumentResult> _documentResults = new List<DocumentResult>();
private DocumentResult? _selectedDocument;
private StructureNode? _structureNode;

[Inject]
private IDocumentService DocumentService { get; set; }

[Inject]
private IDocumentStructureService DocumentStructureService { get; set; }

[Inject]
private ILogger<EGDocumentStructureEditor> Logger { get; set; }

protected override async Task OnInitializedAsync()
{
_documentResults = await DocumentService.GetAllAsync().ConfigureAwait(false);
Logger.LogInformation("documents size: {Size}", _documentResults.Count);
}

private async Task SelectDocumentAsync(DocumentResult selectedDocument)
{
_selectedDocument = await DocumentService.GetById(selectedDocument.Id).ConfigureAwait(false);
// List<StructureNode> flatNodes = MapStructureNodeResultToStructureNode(_selectedDocument.StructureNodes);
_structureNode = new StructureNode
{
Id = 1,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 2,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 21,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 211,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 212,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 213,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
}
},
new StructureNode
{
Id = 3,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 31,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 311,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 312,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 313,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
}
},
new StructureNode
{
Id = 4,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 41,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
new StructureNode
{
Id = 411,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 412,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
new StructureNode
{
Id = 413,
DocumentId = 1,
StructureNodes = new List<StructureNode>
{
}
},
}
},
}
},
}
}
}
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@using EncyclopediaGalactica.BusinessLogic.Contracts
@if (StructureNode is not null)
{
<FluentTreeItem Text="@StructureNode.Id.ToString()">

<FluentIcon Value="@(new Icons.Regular.Size16.ListBarTree())" Color="Color.Neutral" Slot="start"/>
<FluentButton Appearance="Appearance.Neutral"
OnClick="@(async e => await HandleAddStructureNodeAsync(e, StructureNode.Id).ConfigureAwait(false))">
+1
</FluentButton>
<FluentButton Appearance="Appearance.Accent"
OnClick="@(async e => await HandleDeleteStructureNodeAsync(e, StructureNode.Id).ConfigureAwait(false))">
Delete
</FluentButton>

@if (StructureNode.HasChildren && StructureNodes.Any())
{
foreach (DocumentStructureNodeResult child in StructureNodes)
{
<EGDocumentStructureTree StructureNode="child"/>
}
}
</FluentTreeItem>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using UIWasm.Services;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructureEditor;

public partial class EGDocumentStructureTree
{
private ICollection<DocumentStructureNodeResult> StructureNodes = new List<DocumentStructureNodeResult>();

[Inject]
private ILogger<EGDocumentStructureEditor> Logger { get; set; }

[Parameter]
public DocumentStructureNodeResult? StructureNode { get; set; }

[Inject]
private IDocumentStructureNodeService DocumentStructureNodeService { get; set; }

protected override void OnInitialized()
{
Logger.LogInformation("structure node id: {Id}", StructureNode.Id);
Logger.LogInformation("has children: {Id}", StructureNode.HasChildren);
if (StructureNode is not null && StructureNode.HasChildren)
{
StructureNodes = DocumentStructureNodeService.GetChildrenOfANode(StructureNode.Id);
}

Logger.LogInformation("structurenodes amount: {amount}", StructureNodes.Count);
}

private async Task HandleAddStructureNodeAsync(MouseEventArgs mouseEventArgs, long structureNodeId)
{
Logger.LogInformation("HandleAddStructureNodeAsync");
}

private async Task HandleDeleteStructureNodeAsync(MouseEventArgs mouseEventArgs, long structureNodeId)
{
Logger.LogInformation("HandleDeleteStructureNodeAsync");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace UIWasm.Components.Modules.Documents.DocumentStructureEditor;

public class StructureNode
{
public long Id { get; set; }
public long DocumentId { get; set; }
public long ParentId { get; set; }
public List<StructureNode> StructureNodes { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructuresGrid;

public partial class EGAddDocumentStructureDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructuresGrid;

public partial class EGDeleteDocumentStructureDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.FluentUI.AspNetCore.Components;
using UIWasm.Services;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructuresGrid;

public partial class EGDocumentStructuresGrid
Expand All @@ -24,7 +28,8 @@ protected override async Task OnInitializedAsync()
{
GridItemsProvider = async request =>
{
ICollection<DocumentStructureResult> r = await DocumentStructureService.GetAllAsync().ConfigureAwait(false);
ICollection<DocumentStructureResult> r = await DocumentStructureService.GetAllAsync()
.ConfigureAwait(false);
return GridItemsProviderResult.From<DocumentStructureResult>(
r,
r.Count);
Expand Down Expand Up @@ -59,7 +64,7 @@ private async Task HandleAddDocumentStructureResultSave(DialogResult dialogResul
private async Task HandleOnClickPreviewAsync()
{
await DialogService.ShowDialogAsync<EGShowDocumentStructurePreviewDialog>(
new DocumentStructureResult(),
new DocumentStructureNodeResult(),
new DialogParameters
{
Height = "400px",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructuresGrid;

public partial class EGEditDocumentStructureDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#region

using EncyclopediaGalactica.BusinessLogic.Contracts;
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;

#endregion

namespace UIWasm.Components.Modules.Documents.DocumentStructuresGrid;

public partial class EGShowDocumentStructurePreviewDialog
{
[Parameter]
public DocumentStructureResult Content { get; set; }

[CascadingParameter]
public FluentDialog? DialogService { get; set; }

[Parameter]
public DocumentStructureResult Content { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ else
case "applications":
<EGApplicationGrid/>
break;

case "document_structure_tree_editor":
<EGDocumentStructureEditor/>
break;
}
}
}
Loading

0 comments on commit 1a89124

Please sign in to comment.