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
57 changes: 39 additions & 18 deletions AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
namespace LearningHub.Nhs.AdminUI.Controllers
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Linq;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Io;
using LearningHub.Nhs.AdminUI.Configuration;
using LearningHub.Nhs.AdminUI.Extensions;
using LearningHub.Nhs.AdminUI.Interfaces;
using LearningHub.Nhs.AdminUI.Models;
using LearningHub.Nhs.Models.Catalogue;
using LearningHub.Nhs.Models.Common;
using LearningHub.Nhs.Models.Common.Enums;
using LearningHub.Nhs.Models.Entities.Hierarchy;
using LearningHub.Nhs.Models.Moodle;
using LearningHub.Nhs.Models.MyLearning;
using LearningHub.Nhs.Models.Paging;
using LearningHub.Nhs.Models.Resource;
using LearningHub.Nhs.Models.User;
using LearningHub.Nhs.Models.Validation;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

/// <summary>
/// Defines the <see cref="CatalogueController" />.
Expand Down Expand Up @@ -731,10 +723,10 @@ public async Task<IActionResult> AddUserGroupsToCatalogue(int catalogueNodeId, i
[Route("AddCategoryToCatalogue")]
public async Task<IActionResult> AddCategoryToCatalogue(CatalogueViewModel catalogueViewModel)
{
////if (catalogueViewModel.SelectedCategoryId == 0)
////{
//// this.ModelState.AddModelError("SelectedCategoryId", "Please select a category.");
////}
if (catalogueViewModel.SelectedCategoryId == 0)
{
this.ModelState.AddModelError("SelectedCategoryId", "Please select a category.");
}
var vm = await this.catalogueService.GetCatalogueAsync(catalogueViewModel.CatalogueNodeVersionId);
vm.SelectedCategoryId = catalogueViewModel.SelectedCategoryId;
var vr = await this.catalogueService.AddCategoryToCatalogue(vm);
Expand All @@ -754,6 +746,35 @@ public async Task<IActionResult> AddCategoryToCatalogue(CatalogueViewModel catal
}
}

/// <summary>
/// The RemoveCategoryFromCatalogue.
/// </summary>
/// <param name="categoryId">The categoryId/>.</param>
/// <param name="catalogueNodeVersionId">The CatalogueNodeVersionId.</param>
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
[HttpGet]
[Route("RemoveCategoryFromCatalogue/{categoryId}/{catalogueNodeVersionId}")]
public async Task<IActionResult> RemoveCategoryFromCatalogue(int categoryId, int catalogueNodeVersionId)
{
var vm = await this.catalogueService.GetCatalogueAsync(catalogueNodeVersionId);
vm.SelectedCategoryId = categoryId;
var vr = await this.catalogueService.RemoveCategoryFromCatalogue(vm);
if (vr.Success)
{
var categories = await this.moodleApiService.GetAllMoodleCategoriesAsync();
vm.MoodleCategories = categories;
vm.SelectedCategoryId = 0;
// Build hierarchical select list
var selectList = BuildList(categories, parentId: null, depth: 0);
vm.MoodleCategorySelectList = new SelectList(selectList, "Value", "Text");
return this.View("MoodleCategory", vm);
}
else
{
this.ViewBag.ErrorMessage = $"Category update failed.";
return this.View("MoodleCategory", vm);
}
}
/// <summary>
/// The CreateCatalogue.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ public interface ICatalogueService
/// <param name="catalogue">The catalogue.</param>
/// <returns></returns>
Task<ApiResponse> AddCategoryToCatalogue(CatalogueViewModel catalogue);

/// <summary>
/// RemoveCategoryFromCatalogue
/// </summary>
/// <param name="catalogue">The catalogue.</param>
/// <returns></returns>
Task<ApiResponse> RemoveCategoryFromCatalogue(CatalogueViewModel catalogue);
}
}
10 changes: 10 additions & 0 deletions AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,15 @@ public async Task<ApiResponse> AddCategoryToCatalogue(CatalogueViewModel catalog
{
return await this.facade.PostAsync<ApiResponse, CatalogueViewModel>("Catalogue/AddCategoryToCatalogue", catalogue);
}

/// <summary>
/// The RemoveCategoryFromCatalogue.
/// </summary>
/// <param name="catalogue">The CatalogueViewModel.</param>
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
public async Task<ApiResponse> RemoveCategoryFromCatalogue(CatalogueViewModel catalogue)
{
return await this.facade.PostAsync<ApiResponse, CatalogueViewModel>("Catalogue/RemoveCategoryFromCatalogue", catalogue);
}
}
}
6 changes: 5 additions & 1 deletion AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
.menu-font {
font-size: 19px !important;
}

.nhs-item-row {
display: flex;
justify-content: space-between;
align-items: center;
}


Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@
<div class="form-group">
@if (Model.SelectedCategoryId > 0)
{
<div id="selectedCategoryDisplay" class="nhsuk-u-padding-left-3">
<label>Selected Category:</label>
<span class="selected-category nhsuk-u-padding-right-8">@selectedCategoryName</span>
<a href="#" onclick="return DisplayCategory();">Change</a>
<div class="nhs-item-row">
<div id="selectedCategoryDisplay" class="nhsuk-u-padding-left-3">
<label>Selected Category:</label>
<span class="selected-category nhsuk-u-padding-right-8">@selectedCategoryName</span>

<a href="#" onclick="return DisplayCategory();">Change</a>
<a asp-controller="Catalogue" asp-action="RemoveCategoryFromCatalogue" asp-route-categoryId="@Model.SelectedCategoryId" asp-route-catalogueNodeVersionId="@Model.CatalogueNodeVersionId" class="nhsuk-u-padding-left-3">Remove</a>
</div>
</div>
}

Expand Down Expand Up @@ -88,13 +92,12 @@
@section Scripts {
<script>
function DisplayCategory() {
debugger
// Show the category selection div
document.getElementById('divcategory').style.display = 'block';
document.getElementById('example-error').style.display = 'none'
document.getElementById('errortext').style.display = 'none'
document.getElementById('diverror').classList.remove('nhsuk-form-group--error');

// Hide the selected category display div
var selectedCategoryDiv = document.getElementById('selectedCategoryDisplay');
if (selectedCategoryDiv) {
Expand Down
15 changes: 11 additions & 4 deletions LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@
@Html.Raw(Model.NodeDetails.Description)
</div>
}

@if (Model.MoodleCategories != null)
{
<div class="folder-description">
@Html.Raw(Model.MoodleCategories.Last().Description)
</div>
}
</div>

@* Tab header *@
Expand All @@ -180,10 +187,10 @@
</label>
</div>
<div class="navbar-collapse collapse" id="catalogue-details">
<ul class="navbar-nav">
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
<a tabindex="0" class="subnavwhite-link text-nowrap" asp-controller="Catalogue" asp-route-reference="@Model.Catalogue.Url" asp-route-tab="browse" asp-fragment="catalogue-details">Resources</a>
</li>
<ul class="navbar-nav">
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
<a tabindex="0" class="subnavwhite-link text-nowrap" asp-controller="Catalogue" asp-route-reference="@Model.Catalogue.Url" asp-route-tab="browse" asp-fragment="catalogue-details">Resources</a>
</li>
@if (Model.Catalogue.SelectedCategoryId > 0)
{
<li class="subnavwhite-item @(ViewBag.ActiveTab == "courses" ? "active" : string.Empty)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public interface ICatalogueNodeVersionRepository : IGenericRepository<CatalogueN
/// <returns></returns>
Task AddCategoryToCatalogueAsync(int userId, CatalogueViewModel vm);

/// <summary>
/// The RemoveCategoryFromCatalogueAsync.
/// </summary>
/// <param name="userId">The userId.</param>
/// <param name="vm">The viewmodel.</param>
/// <returns></returns>
Task RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel vm);

/// <summary>
/// The CreateCatalogueAsync.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ public async Task AddCategoryToCatalogueAsync(int userId, CatalogueViewModel vm)
}
}

/// <summary>
/// The RemoveCategoryFromCatalogueAsync.
/// </summary>
/// <param name="userId">The userId.</param>
/// <param name="vm">The viewmodel.</param>
/// <returns></returns>
public async Task RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel vm)
{
try
{
var param0 = new SqlParameter("@p0", SqlDbType.Int) { Value = userId };
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = vm.CatalogueNodeVersionId };
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = vm.SelectedCategoryId };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };

await DbContext.Database.ExecuteSqlRawAsync("hierarchy.RemoveCatalogueCategory @p0, @p1, @p2, @p3", param0, param1, param2, param3);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

/// <summary>
/// Get Catlogue by reference.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public interface ICatalogueService
/// <returns></returns>
Task<LearningHubValidationResult> AddCategoryToCatalogueAsync(int userId, CatalogueViewModel catalogue);

/// <summary>
/// The RemoveCategoryFromCatalogueAsync.
/// </summary>
/// <param name="userId">The userId.</param>
/// <param name="catalogue">The catalogue.</param>
/// <returns>The catalogue id.</returns>
Task<LearningHubValidationResult> RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel catalogue);

/// <summary>
/// The UpdateCatalogueAsync.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ public async Task<LearningHubValidationResult> AddCategoryToCatalogueAsync(int u
return new LearningHubValidationResult(true);
}

/// <summary>
/// The RemoveCategoryFromCatalogueAsync.
/// </summary>
/// <param name="userId">The userId.</param>
/// <param name="catalogue">The catalogue.</param>
/// <returns>The catalogue id.</returns>
public async Task<LearningHubValidationResult> RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel catalogue)
{
await this.catalogueNodeVersionRepository.RemoveCategoryFromCatalogueAsync(userId, catalogue);

return new LearningHubValidationResult(true);
}

/// <summary>
/// The IsUserLocalAdminAsync.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public MoodleApiService(IMoodleHttpClient moodleHttpClient, ILogger<MoodleApiSer
/// <returns>UserId from Moodle.</returns>
public async Task<int> GetMoodleUserIdByUsernameAsync(int currentUserId)
{
currentUserId = 56778;
var parameters = new Dictionary<string, string>
{
{ "criteria[0][key]", "username" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public async Task<IActionResult> CreateCatalogue([FromBody] CatalogueViewModel v
}

/// <summary>
/// The CreateCatalogue.
/// The AddCategoryToCatalogue.
/// </summary>
/// <param name="viewModel">The viewModel.</param>
/// <returns>The actionResult.</returns>
Expand All @@ -186,6 +186,26 @@ public async Task<IActionResult> AddCategoryToCatalogue([FromBody] CatalogueView
}
}

/// <summary>
/// The RemoveCategoryFromCatalogue.
/// </summary>
/// <param name="viewModel">The viewModel.</param>
/// <returns>The actionResult.</returns>
[HttpPost]
[Route("RemoveCategoryFromCatalogue")]
public async Task<IActionResult> RemoveCategoryFromCatalogue([FromBody] CatalogueViewModel viewModel)
{
try
{
var vr = await this.catalogueService.RemoveCategoryFromCatalogueAsync(this.CurrentUserId.GetValueOrDefault(), viewModel);
return this.Ok(new ApiResponse(true, vr));
}
catch (Exception ex)
{
return this.Ok(new ApiResponse(false, new LearningHubValidationResult(false, ex.Message)));
}
}

/// <summary>
/// Returns true if the catalogue is editable by the current user.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
<Build Include="Stored Procedures\Hub\GetActiveNotificationCount.sql" />
<Build Include="Tables\Hierarchy\CatalogueNodeVersionCategory.sql" />
<Build Include="Stored Procedures\Hierarchy\CatalogueNodeVersionCategoryCreate.sql" />
<Build Include="Stored Procedures\Hierarchy\RemoveCatalogueCategory.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-------------------------------------------------------------------------------
-- Author SA
-- Created 14-10-2025
-- Purpose Removes a Catalogue NodeVersion Category.
--
-- Modification History
--
-- 05-11-2025 SA Initial Revision.
-------------------------------------------------------------------------------
CREATE PROCEDURE [hierarchy].[RemoveCatalogueCategory]
(
@userId INT,
@CatalogueNodeVersionId INT,
@CategoryId INT,
@UserTimezoneOffset int = NULL
)

AS
BEGIN
DECLARE @AmendDate datetimeoffset(7) = ISNULL(TODATETIMEOFFSET(DATEADD(mi, @UserTimezoneOffset, GETUTCDATE()), @UserTimezoneOffset), SYSDATETIMEOFFSET())
IF EXISTS (SELECT 1
FROM [hierarchy].[CatalogueNodeVersionCategory]
WHERE CatalogueNodeVersionId = @CatalogueNodeVersionId AND deleted =0
)
BEGIN
UPDATE [hierarchy].[CatalogueNodeVersionCategory]
SET
Deleted = 1,
AmendDate = @AmendDate,
AmendUserId = @UserId
WHERE
CatalogueNodeVersionId = @CatalogueNodeVersionId
END
END
Loading