Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort knowledge entries by order & show indicator in overview #212

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ containerize SERVICE="" *ARGS="":
docker compose build {{ARGS}} {{SERVICE}}
if [[ $(docker compose ps --services --status running | wc -w) -gt 0 ]]; then
echo "Detected running stack! Refreshing service {{SERVICE}} …"
docker compose create --force-recreate {{SERVICE}} && docker compose start {{SERVICE}}
just recreate {{SERVICE}}
fi

recreate SERVICE="":
docker compose create --force-recreate {{SERVICE}} && docker compose start {{SERVICE}}

# Build sdk container for backend without executing second stage
containerize-dev:
docker build --target build -t ghcr.io/eurofurence/ef-app_backend-dotnet-core:dev-sdk -f Dockerfile .
Expand Down
1 change: 1 addition & 0 deletions src/Eurofurence.App.Backoffice/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{
Primary = "#69a3a2",
Secondary = "#a2c5c4",
Tertiary = "#dedede",
AppbarBackground = "#005953",
}
};
Expand Down
83 changes: 52 additions & 31 deletions src/Eurofurence.App.Backoffice/Pages/KnowledgeBase.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@page "/knowledgebase"
@page "/knowledgebase"
@attribute [Authorize(Policy = "RequireKnowledgeBaseEditor")]
@using Eurofurence.App.Backoffice.Services
@using Eurofurence.App.Domain.Model.Knowledge
@using Microsoft.AspNetCore.Authorization
@using Eurofurence.App.Backoffice.Components
@using Eurofurence.App.Domain.Model.Fragments
@using Eurofurence.App.Domain.Model.Images
@using Markdig
@inject IConfiguration Configuration
@inject ISnackbar Snackbar
@inject IKnowledgeService KnowledgeService
@inject IImageService ImageService
Expand All @@ -19,6 +19,8 @@
<MudToolBar>
<MudText Typo="Typo.h6">Groups</MudText>
<MudSpacer />
<MudIconButton Icon="@Icons.Material.Filled.OpenInNew" Href="@GetWebPreviewUrl(["KnowledgeGroups"])">
</MudIconButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
@onclick="AddKnowledgeGroup">New Group</MudButton>
</MudToolBar>
Expand All @@ -43,20 +45,24 @@
{
<MudListItem @onclick="() => _selectedGroup = knowledgeGroup">
<MudCard Style="background-color: transparent">
<MudCardHeader>
<CardHeaderAvatar>
<MudIcon Icon="@("fas fa-" + knowledgeGroup.FontAwesomeIconName)"></MudIcon>
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="Typo.h6">@knowledgeGroup.Name</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Edit"
@onclick="() => UpdateKnowledgeGroup(knowledgeGroup)"></MudIconButton>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
@onclick="() => DeleteKnowledgeGroup(knowledgeGroup.Id)"></MudIconButton>
</CardHeaderActions>
</MudCardHeader>
<MudBadge Content="@("#" + knowledgeGroup.Order)" Origin="Origin.TopLeft" Overlap="true">
<MudCardHeader>
<CardHeaderAvatar>
<MudIcon Icon="@("fas fa-" + knowledgeGroup.FontAwesomeIconName)"></MudIcon>
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="Typo.h6">@knowledgeGroup.Name</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Edit"
@onclick="() => UpdateKnowledgeGroup(knowledgeGroup)">
</MudIconButton>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
@onclick="() => DeleteKnowledgeGroup(knowledgeGroup.Id)">
</MudIconButton>
</CardHeaderActions>
</MudCardHeader>
</MudBadge>
<MudCardContent>
<MudText>@knowledgeGroup.Description</MudText>
</MudCardContent>
Expand Down Expand Up @@ -92,18 +98,24 @@
@foreach (var knowledgeEntry in GetKnowledgeEntities())
{
<MudCard Class="mt-4">
<MudCardHeader>
<CardHeaderContent>
<MudText Typo="Typo.caption" HtmlTag="h5">@knowledgeEntry.KnowledgeGroup.Name</MudText>
<MudText Typo="Typo.h6">@knowledgeEntry.Title</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Edit"
@onclick="() => UpdateKnowledgeEntry(knowledgeEntry)" />
<MudIconButton Icon="@Icons.Material.Filled.Delete"
@onclick="() => DeleteKnowledgeEntry(knowledgeEntry.Id)" />
</CardHeaderActions>
</MudCardHeader>
<MudBadge Content="@("#" + knowledgeEntry.Order)" Origin="Origin.TopLeft" Overlap="true">
<MudCardHeader>
<CardHeaderContent>
<MudText Typo="Typo.caption" HtmlTag="h5">@knowledgeEntry.KnowledgeGroup.Name</MudText>
<MudText Typo="Typo.h6">@knowledgeEntry.Title</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.OpenInNew"
Href="@GetWebPreviewUrl(["KnowledgeEntries", knowledgeEntry.Id.ToString()])"
Target="_blank">
</MudIconButton>
<MudIconButton Icon="@Icons.Material.Filled.Edit"
@onclick="() => UpdateKnowledgeEntry(knowledgeEntry)"/>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
@onclick="() => DeleteKnowledgeEntry(knowledgeEntry.Id)"/>
</CardHeaderActions>
</MudCardHeader>
</MudBadge>
<MudCardContent>
<MarkdownRenderer Text="@knowledgeEntry.Text"></MarkdownRenderer>

Expand Down Expand Up @@ -136,8 +148,8 @@
public bool Loading = true;
private string? _knowledgeEntrySearch;
private KnowledgeGroupRecord? _selectedGroup;
private Dictionary<Guid, KnowledgeGroupRecord> _knowledgeGroups = new Dictionary<Guid, KnowledgeGroupRecord>();
private List<KnowledgeEntryRecord> _knowledgeEntries = new List<KnowledgeEntryRecord>();
private Dictionary<Guid, KnowledgeGroupRecord> _knowledgeGroups = new();
private List<KnowledgeEntryRecord> _knowledgeEntries = [];

protected override async Task OnInitializedAsync()
{
Expand All @@ -150,7 +162,8 @@
Loading = true;
_knowledgeEntries = [];

var responses = (await KnowledgeService.GetKnowledgeEntriesAsync()).OrderBy(ke => ke.Order);
var responses = (await KnowledgeService.GetKnowledgeEntriesAsync()).OrderBy(ke => _knowledgeGroups.FirstOrDefault(kg => kg.Key == ke.KnowledgeGroupId).Value.Order).ThenBy(ke => ke.Order);

foreach (var response in responses)
{
var record = new KnowledgeEntryRecord()
Expand Down Expand Up @@ -271,6 +284,12 @@
}
}

private string GetWebPreviewUrl(IEnumerable<string> paths)
{
var webPreviewUrl = $"{Configuration.GetValue<string>("BackendBaseUrl")?.TrimEnd('/') ?? string.Empty}/Web";
return paths.Aggregate(webPreviewUrl, (current, path) => $"{current}/{path.TrimStart('/')}");
}

private async Task AddKnowledgeGroup()
{
var parameters = new DialogParameters<KnowledgeGroupDialog> { { x => x.Record, null } };
Expand All @@ -283,6 +302,7 @@
{
Loading = true;
await LoadKnowledgeGroups();
await LoadKnowledgeEntries();
}
}

Expand All @@ -298,6 +318,7 @@
{
Loading = true;
await LoadKnowledgeGroups();
await LoadKnowledgeEntries();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Backoffice/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
builder.Services.AddScoped<TokenAuthorizationMessageHandler>();
builder.Services.AddHttpClient("api", options =>
{
options.BaseAddress = new Uri(builder.Configuration.GetValue<string>("ApiUrl") ?? string.Empty);
options.BaseAddress = new Uri($"{builder.Configuration.GetValue<string>("BackendBaseUrl")?.TrimEnd('/') ?? string.Empty}/Api/");
}).AddHttpMessageHandler<TokenAuthorizationMessageHandler>();

builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("api"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ApiUrl": "http://localhost:7371/api/",
"BackendBaseUrl": "http://localhost:7371/",
"Oidc": {
"Authority": "https://identity.eurofurence.org/",
"ClientId": "<client-id>"
Expand Down