Skip to content
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
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 2
updates:
# Enable version updates for NuGet
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
labels:
- "dependencies"
- "dotnet"

# Enable version updates for npm (Blazor WebAssembly)
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
labels:
- "dependencies"
- "javascript"

# Enable version updates for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
labels:
- "dependencies"
- "github-actions"
46 changes: 46 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "CodeQL"

on:
push:
branches: [ "main", "feature/*" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '0 0 * * 1' # Run weekly on Mondays

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp', 'javascript' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
105 changes: 50 additions & 55 deletions Client/Modules/FileHub/Category.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<h3>Categories</h3>

<RadzenTheme Theme="material" />
<RadzenContextMenu />
<RadzenDialog />
<RadzenComponents />

@if (IsLoading)
{
Expand All @@ -17,58 +16,54 @@ else if (!string.IsNullOrEmpty(ErrorMessage))
}
else
{
<div style="width: 100%; height: 500px; position: relative; margin-bottom: 20px;">
<RadzenTree Data="@(new List<ListCategoryDto> { _rootNode })"
Style="width: 100%; height: 100%;"
Expand="@OnNodeExpand"
Collapse="@OnNodeCollapse">
<RadzenTreeLevel TextProperty="@(nameof(ListCategoryDto.Name))"
ChildrenProperty="@(nameof(ListCategoryDto.Children))"
HasChildren=@(e => ((ListCategoryDto)e).Children?.Any() == true)
Expanded="@(e => ((ListCategoryDto)e).IsExpanded)">
<Template>
@{
var category = (context.Value as ListCategoryDto);
var isEditing = IsInlineEditing && EditingNode != null && EditingNode.Id == category?.Id;
var isRootNode = category?.Id == 0;
}
<RadzenTree Data="@(new List<ListCategoryDto> { _rootNode })"
Style="width: 100%; height: 100%;"
Expand="@OnNodeExpand"
Collapse="@OnNodeCollapse">
<RadzenTreeLevel TextProperty="@(nameof(ListCategoryDto.Name))"
ChildrenProperty="@(nameof(ListCategoryDto.Children))"
HasChildren=@(e => ((ListCategoryDto)e).Children?.Any() == true)
Expanded="@(e => ((ListCategoryDto)e).IsExpanded)">
<Template>
@{
var category = (context.Value as ListCategoryDto);
var isEditing = IsInlineEditing && EditingNode != null && EditingNode.Id == category?.Id;
var isRootNode = category?.Id == 0;
}

@if (isEditing)
{
<div style="display: inline-flex; align-items: center; gap: 4px;">
<RadzenTextBox @bind-Value="@EditingNodeName"
@onkeydown="HandleKeyPress"
Style="width: 200px; height: 24px; font-size: 14px;"
AutoComplete="false" />
<RadzenButton Icon="check"
ButtonStyle="ButtonStyle.Success"
Size="ButtonSize.ExtraSmall"
Click="@SaveInlineEdit"
title="Save (Enter)" />
<RadzenButton Icon="close"
ButtonStyle="ButtonStyle.Light"
Size="ButtonSize.ExtraSmall"
Click="@CancelInlineEdit"
title="Cancel (Esc)" />
</div>
}
else
{
<span @oncontextmenu="@(args => ShowContextMenu(args, category))"
@oncontextmenu:preventDefault="true"
@ondblclick="@(() => OnNodeDoubleClick(category))"
style="cursor: pointer; font-weight: @(isRootNode ? "bold" : "normal");">
@if (isRootNode)
{
<i class="oi oi-folder" style="margin-right: 4px;"></i>
}
@category?.Name
</span>
}
</Template>
</RadzenTreeLevel>
</RadzenTree>
</div>

@if (isEditing)
{
<div style="display: inline-flex; align-items: center; gap: 4px;">
<RadzenTextBox @bind-Value="@EditingNodeName"
@onkeydown="HandleKeyPress"
Style="width: 200px; height: 24px; font-size: 14px;"
AutoCompleteType="AutoCompleteType.Off" />
<RadzenButton Icon="check"
ButtonStyle="ButtonStyle.Success"
Size="ButtonSize.ExtraSmall"
Click="@SaveInlineEdit"
title="Save (Enter)" />
<RadzenButton Icon="close"
ButtonStyle="ButtonStyle.Light"
Size="ButtonSize.ExtraSmall"
Click="@CancelInlineEdit"
title="Cancel (Esc)" />
</div>
}
else
{
<span @oncontextmenu="@(args => ShowContextMenu(args, category))"
@oncontextmenu:preventDefault="true"
@ondblclick="@(() => OnNodeDoubleClick(category))"
style="cursor: pointer; font-weight: @(isRootNode ? "bold" : "normal");">
@if (isRootNode)
{
<i class="oi oi-folder" style="margin-right: 4px;"></i>
}
@category?.Name
</span>
}
</Template>
</RadzenTreeLevel>
</RadzenTree>
}

62 changes: 34 additions & 28 deletions Client/Modules/FileHub/Category.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
[Inject]
private Radzen.DialogService DialogService { get; set; } = default!;

[Parameter]
public int ModuleId { get; set; }

private const string SuccessNotificationMessage = "Success";
private const string ErrorNotificationMessage = "Error";
private List<ListCategoryDto> _treeData = [];
Expand All @@ -41,7 +44,7 @@
ErrorMessage = null;
try
{
Categories = await CategoryService.ListAsync(ModuleState.ModuleId, pageNumber: 1, pageSize: int.MaxValue);
Categories = await CategoryService.ListAsync(ModuleId, pageNumber: 1, pageSize: int.MaxValue);
CreateTreeStructure();
}
catch (Exception ex)
Expand All @@ -54,9 +57,12 @@
}
}

private void ShowContextMenu(MouseEventArgs args, ListCategoryDto? category)

Check warning on line 60 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Analyze

Method is too long (63 lines; maximum allowed: 60) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)

Check warning on line 60 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Method is too long (63 lines; maximum allowed: 60) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)

Check warning on line 60 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Method is too long (63 lines; maximum allowed: 60) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)

Check warning on line 60 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Method is too long (63 lines; maximum allowed: 60) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)

Check warning on line 60 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Method is too long (63 lines; maximum allowed: 60) (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0051.md)
{
if (category == null) return;
if (category == null)
{
return;
}

SelectedCategory = category;

Expand All @@ -69,7 +75,7 @@
Text = "Add Category",
Value = "add",
Icon = "add",
}
},
};

ContextMenuService.Open(args, rootMenuItems, OnContextMenuClick);
Expand Down Expand Up @@ -117,8 +123,10 @@
ContextMenuService.Open(args, menuItems, OnContextMenuClick);
}

private void OnContextMenuClick(Radzen.MenuItemEventArgs args)
private async void OnContextMenuClick(Radzen.MenuItemEventArgs args)
{
ContextMenuService.Close();

var action = args.Value?.ToString();

switch (action)
Expand All @@ -130,17 +138,15 @@
EditCategoryInline();
break;
case "moveup":
_ = MoveUp();
await MoveUp();
break;
case "movedown":
_ = MoveDown();
await MoveDown();
break;
case "delete":
PromptDeleteCategory();
await PromptDeleteCategory();
break;
}

ContextMenuService.Close();
}

private bool CanMoveUp(ListCategoryDto category)
Expand Down Expand Up @@ -195,7 +201,7 @@

private void AddChildCategoryInline()
{
if (SelectedCategory == null) return;

Check warning on line 204 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 204 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 204 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 204 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

// Cancel any existing inline editing
CancelInlineEdit();
Expand Down Expand Up @@ -227,7 +233,7 @@

private void OnNodeDoubleClick(ListCategoryDto? category)
{
if (category == null || category.Id == 0) return; // Don't allow editing root node

Check warning on line 236 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 236 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 236 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 236 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

// Cancel any existing inline editing
CancelInlineEdit();
Expand All @@ -243,7 +249,7 @@

private void EditCategoryInline()
{
if (SelectedCategory == null || SelectedCategory.Id == 0) return; // Don't allow editing root node

Check warning on line 252 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 252 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 252 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

Check warning on line 252 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Add braces to 'if' statement. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011)

// Cancel any existing inline editing
CancelInlineEdit();
Expand Down Expand Up @@ -283,7 +289,7 @@
ParentId = EditingNode.ParentId,
};

var id = await CategoryService.CreateAsync(ModuleState.ModuleId, createDto);
var id = await CategoryService.CreateAsync(ModuleId, createDto);
await logger.LogInformation("Category Created {Id}", id);

// Update the temporary node in-place with the real ID and name
Expand All @@ -308,7 +314,7 @@
ParentId = EditingNode.ParentId,
};

await CategoryService.UpdateAsync(EditingNode.Id, ModuleState.ModuleId, updateDto);
await CategoryService.UpdateAsync(EditingNode.Id, ModuleId, updateDto);
await logger.LogInformation("Category Updated {Id}", EditingNode.Id);

// Update the node name in-place
Expand Down Expand Up @@ -405,7 +411,7 @@
var previous = siblings[currentIndex - 1];

// Update on server using dedicated move endpoint
await CategoryService.MoveUpAsync(current.Id, ModuleState.ModuleId);
await CategoryService.MoveUpAsync(current.Id, ModuleId);

// Swap ViewOrder values locally
(current.ViewOrder, previous.ViewOrder) = (previous.ViewOrder, current.ViewOrder);
Expand All @@ -430,7 +436,7 @@
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Moving Category Up {Id} {Error}", SelectedCategory.Id, ex.Message);

Check warning on line 439 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Analyze

Dereference of a possibly null reference.

Check warning on line 439 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Dereference of a possibly null reference.

Check warning on line 439 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Dereference of a possibly null reference.

Check warning on line 439 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 439 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
NotificationService.Notify(new Radzen.NotificationMessage
{
Severity = Radzen.NotificationSeverity.Error,
Expand Down Expand Up @@ -460,7 +466,7 @@
var next = siblings[currentIndex + 1];

// Update on server using dedicated move endpoint
await CategoryService.MoveDownAsync(current.Id, ModuleState.ModuleId);
await CategoryService.MoveDownAsync(current.Id, ModuleId);

// Swap ViewOrder values locally
(current.ViewOrder, next.ViewOrder) = (next.ViewOrder, current.ViewOrder);
Expand All @@ -485,7 +491,7 @@
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Moving Category Down {Id} {Error}", SelectedCategory.Id, ex.Message);

Check warning on line 494 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Analyze

Dereference of a possibly null reference.

Check warning on line 494 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Dereference of a possibly null reference.

Check warning on line 494 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Dereference of a possibly null reference.

Check warning on line 494 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 494 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
NotificationService.Notify(new Radzen.NotificationMessage
{
Severity = Radzen.NotificationSeverity.Error,
Expand Down Expand Up @@ -534,7 +540,7 @@
{
var categoryToDelete = SelectedCategory;

await CategoryService.DeleteAsync(categoryToDelete.Id, ModuleState.ModuleId);
await CategoryService.DeleteAsync(categoryToDelete.Id, ModuleId);
await logger.LogInformation("Category Deleted {Id}", categoryToDelete.Id);

if (categoryToDelete.ParentId is null)
Expand All @@ -545,10 +551,7 @@
else
{
var parent = FindCategoryById([_rootNode], categoryToDelete.ParentId.Value);
if (parent != null)
{
parent.Children.Remove(categoryToDelete);
}
parent?.Children.Remove(categoryToDelete);
}

NotificationService.Notify(new Radzen.NotificationMessage
Expand All @@ -564,7 +567,7 @@
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Category {Id} {Error}", SelectedCategory.Id, ex.Message);

Check warning on line 570 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Analyze

Dereference of a possibly null reference.

Check warning on line 570 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Client Component Tests (bUnit)

Dereference of a possibly null reference.

Check warning on line 570 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Server Unit Tests (TUnit)

Dereference of a possibly null reference.

Check warning on line 570 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 570 in Client/Modules/FileHub/Category.razor.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
NotificationService.Notify(new Radzen.NotificationMessage
{
Severity = Radzen.NotificationSeverity.Error,
Expand All @@ -577,7 +580,7 @@

private void CreateTreeStructure()
{
if (Categories.Items is null || !Categories.Items.Any())
if (Categories.Items?.Any() != true)
{
_treeData = [];

Expand All @@ -589,7 +592,7 @@
ParentId = -1,
ViewOrder = 0,
IsExpanded = true,
Children = []
Children = [],
};
return;
}
Expand Down Expand Up @@ -625,23 +628,26 @@
ParentId = null,
ViewOrder = 0,
IsExpanded = true,
Children = _treeData
Children = _treeData,
};
}

private static void SortChildren(List<ListCategoryDto> categories)
{
foreach (var category in categories)
{
if (category.Children.Any())
if (category.Children.Count == 0)
{
category.Children = category.Children
.OrderBy(c => c.ViewOrder)
.ThenBy(c => c.Name, StringComparer.Ordinal)
.ToList();

SortChildren(category.Children.ToList());
continue;
}

var sortedChildren = category.Children
.OrderBy(c => c.ViewOrder)
.ThenBy(c => c.Name, StringComparer.Ordinal)
.ToList();

category.Children = sortedChildren;
SortChildren(sortedChildren);
}
}

Expand Down
2 changes: 0 additions & 2 deletions Client/Modules/FileHub/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ else
{
<p>@Localizer["Message.DisplayNone"]</p>
}

<ICTAce.FileHub.Category />
}
1 change: 0 additions & 1 deletion Client/Modules/FileHub/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public partial class Index
[
new Stylesheet(ModulePath() + "Module.css"),
new Script(ModulePath() + "Module.js"),
new Script("_content/Radzen.Blazor/Radzen.Blazor.js"),
];

private List<ListSampleModuleDto>? _filehubs;
Expand Down
Loading
Loading