From 51152e2a59c6c5e8a106eefc1b445f4e036c1512 Mon Sep 17 00:00:00 2001 From: Marvin Hochstetter <96189400+MarvinHo64@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:54:51 +0200 Subject: [PATCH] Fixed bug #538 * Introduced new order for learning elements in LearningWorldTreeView.razor * Changed order of ElementSlotPositions of Floorplans D40X3715LViewModel.cs and T40X * Removed element position in LearningWorldTreeViewItem.razor * Removed ordering elements after reading atf in ReadAtf.cs * Removed FloorPlanElementSorter.cs as it is no longer needed --- Changelog.md | 2 + Generator/ATF/ReadAtf.cs | 17 ++-- GeneratorTest/ATF/ReadAtfUt.cs | 2 +- .../FloorPlans/D40X3715LViewModel.cs | 12 +-- .../FloorPlans/T40X3213LViewModel.cs | 8 +- .../LearningWorld/LearningWorldTreeView.razor | 15 ++-- .../LearningWorldTreeViewItem.razor | 13 ++- Shared/FloorPlanElementSorter.cs | 50 ------------ SharedTest/FloorPlanElementSorterUt.cs | 81 ------------------- 9 files changed, 32 insertions(+), 168 deletions(-) delete mode 100644 Shared/FloorPlanElementSorter.cs delete mode 100644 SharedTest/FloorPlanElementSorterUt.cs diff --git a/Changelog.md b/Changelog.md index e01d2a539..e7b1bd220 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ ### Changed - Improved the filter search field in unplaced learning elements to be case-insensitive. +- Changed the order of learning elements in 13- and 15-slot floor plan ### Deprecated @@ -19,6 +20,7 @@ - Fixed a bug where the program crashed after deleting two learning elements in a row using the right click menu. - Fixed a bug where the list of unplaced elements was not updated after changing the floor plan. - Fixed a bug where a story slot was not made active after undoing the creation of a story element. +- Fixed the order of learning elements in learning world tree view - Fixed a bug in adaptivity element question preview, where long comments exceeded the viewport. ### Security diff --git a/Generator/ATF/ReadAtf.cs b/Generator/ATF/ReadAtf.cs index 67a8432d5..db916db49 100644 --- a/Generator/ATF/ReadAtf.cs +++ b/Generator/ATF/ReadAtf.cs @@ -43,7 +43,7 @@ public void ReadLearningWorld(string atfPath, DocumentRootJson? rootJsonForTest else { var jsonString = _fileSystem.File.ReadAllText(atfPath); - var options = new JsonSerializerOptions {WriteIndented = true, PropertyNameCaseInsensitive = true}; + var options = new JsonSerializerOptions { WriteIndented = true, PropertyNameCaseInsensitive = true }; _rootJson = JsonSerializer.Deserialize(jsonString, options) ?? throw new InvalidOperationException("Could not deserialize ATF_Document"); } @@ -150,7 +150,7 @@ private void GetH5PElements(IDocumentRootJson documentRootJson) { if (element.ElementFileType is "h5p" or "primitiveH5P") { - _listH5PElements.Add((ILearningElementJson) element); + _listH5PElements.Add((ILearningElementJson)element); } } @@ -168,7 +168,7 @@ private void GetResourceElements(IDocumentRootJson documentRootJson) or "c" or "h" or "cpp" or "cc" or "c++" or "py" or "cs" or "js" or "php" or "html" or "css") { - _listResourceElements.Add((ILearningElementJson) resource); + _listResourceElements.Add((ILearningElementJson)resource); } } @@ -204,11 +204,6 @@ private void GetWorldAttributes(IDocumentRootJson documentRootJson) private void GetSpaces(IDocumentRootJson rootJson) { _listSpaces = rootJson.World.Spaces; - foreach (var space in _listSpaces) - { - space.SpaceSlotContents = FloorPlanElementSorter.GetListInOrder(space.SpaceSlotContents, - Enum.Parse(space.SpaceTemplate)); - } } /// @@ -220,7 +215,7 @@ private void GetUrlElements(IDocumentRootJson documentRootJson) { if (url.ElementFileType is "url") { - _listUrlElements.Add((ILearningElementJson) url); + _listUrlElements.Add((ILearningElementJson)url); } } @@ -235,7 +230,7 @@ private void GetAdaptivityElements(IDocumentRootJson documentRootJson) foreach (var element in documentRootJson.World.Elements.Where( element => element.ElementFileType is "adaptivity")) { - _listAdaptivityElements.Add((IAdaptivityElementJson) element); + _listAdaptivityElements.Add((IAdaptivityElementJson)element); } } @@ -251,7 +246,7 @@ private void GetElementsOrdered(IDocumentRootJson? documentRootJson) foreach (var elementInSpace in space.SpaceSlotContents) { if (elementInSpace != null) - _listAllElementsOrdered.Add(documentRootJson.World.Elements[(int) elementInSpace - 1]); + _listAllElementsOrdered.Add(documentRootJson.World.Elements[(int)elementInSpace - 1]); } } diff --git a/GeneratorTest/ATF/ReadAtfUt.cs b/GeneratorTest/ATF/ReadAtfUt.cs index ea062c409..bc3b0b52f 100644 --- a/GeneratorTest/ATF/ReadAtfUt.cs +++ b/GeneratorTest/ATF/ReadAtfUt.cs @@ -120,7 +120,7 @@ public void ReadATF_ReadLearningWorld_ATFDocumentRead() Assert.That(listSpace.Count, Is.EqualTo(2)); Assert.That(listSpace[0].SpaceSlotContents, - Is.EqualTo(new List { 1, 2, null, 3, null, 4 })); // R_20X20_6L sort order is 0, 1, 2, 3, 5, 4 + Is.EqualTo(new List { 1, 2, null, 3, 4, null })); Assert.That(listSpace[1].SpaceSlotContents, Is.EqualTo(new List { 5, null, null, null, null, null })); Assert.That(getUrlList, Has.Count.EqualTo(1)); diff --git a/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/D40X3715LViewModel.cs b/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/D40X3715LViewModel.cs index c9a96c6e3..b05921c26 100644 --- a/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/D40X3715LViewModel.cs +++ b/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/D40X3715LViewModel.cs @@ -35,6 +35,11 @@ public class D40X3715LViewModel : IFloorPlanViewModel public IList ElementSlotPositions { get; } = new List { + new() { X = 4, Y = 33 }, + new() { X = 4, Y = 29 }, + new() { X = 4, Y = 22 }, + new() { X = 4, Y = 17 }, + new() { X = 4, Y = 10 }, new() { X = 4, Y = 5 }, new() { X = 10, Y = 5 }, new() { X = 16, Y = 5 }, @@ -44,12 +49,7 @@ public class D40X3715LViewModel : IFloorPlanViewModel new() { X = 31, Y = 24 }, new() { X = 27, Y = 30 }, new() { X = 20, Y = 33 }, - new() { X = 15, Y = 33 }, - new() { X = 4, Y = 33 }, - new() { X = 4, Y = 29 }, - new() { X = 4, Y = 22 }, - new() { X = 4, Y = 17 }, - new() { X = 4, Y = 10 } + new() { X = 15, Y = 33 } }; public IList StoryElementSlotPositions { get; } = new List diff --git a/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/T40X3213LViewModel.cs b/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/T40X3213LViewModel.cs index 0764550ab..b5dc9587c 100644 --- a/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/T40X3213LViewModel.cs +++ b/Presentation/PresentationLogic/LearningSpace/SpaceLayout/FloorPlans/T40X3213LViewModel.cs @@ -41,16 +41,16 @@ public class T40X3213LViewModel : IFloorPlanViewModel new() { X = 5, Y = 5 }, new() { X = 11, Y = 5 }, new() { X = 17, Y = 5 }, - new() { X = 5, Y = 16 }, - new() { X = 11, Y = 16 }, new() { X = 30, Y = 12 }, - new() { X = 17, Y = 19 }, new() { X = 30, Y = 26 }, new() { X = 17, Y = 33 }, new() { X = 11, Y = 33 }, new() { X = 5, Y = 33 }, new() { X = 5, Y = 22 }, - new() { X = 11, Y = 22 } + new() { X = 11, Y = 22 }, + new() { X = 17, Y = 19 }, + new() { X = 11, Y = 16 }, + new() { X = 5, Y = 16 } }; public IList StoryElementSlotPositions { get; } = new List diff --git a/Presentation/View/LearningWorld/LearningWorldTreeView.razor b/Presentation/View/LearningWorld/LearningWorldTreeView.razor index 15105bbfe..fb411f588 100644 --- a/Presentation/View/LearningWorld/LearningWorldTreeView.razor +++ b/Presentation/View/LearningWorld/LearningWorldTreeView.razor @@ -1,15 +1,15 @@ -@using Presentation.PresentationLogic.LearningWorld -@using Presentation.PresentationLogic.Mediator -@using Presentation.PresentationLogic.SelectedViewModels +@using System.ComponentModel +@using System.Diagnostics.CodeAnalysis @using Microsoft.Extensions.Localization +@using MudBlazor.Utilities @using Presentation.Components @using Presentation.Components.Forms @using Presentation.PresentationLogic @using Presentation.PresentationLogic.LearningElement @using Presentation.PresentationLogic.LearningSpace -@using System.ComponentModel -@using System.Diagnostics.CodeAnalysis -@using MudBlazor.Utilities +@using Presentation.PresentationLogic.LearningWorld +@using Presentation.PresentationLogic.Mediator +@using Presentation.PresentationLogic.SelectedViewModels @using Shared.Command @using Shared.Extensions @implements IDisposable @@ -54,8 +54,9 @@ IsSelected="@IsLearningElementSelected(entranceElement)" OnSelect="@(ele => OnLearningElementClicked(ele))"/> } - @foreach (var learningElement in learningSpace.ContainedLearningElements) + @foreach (var key in learningSpace.LearningSpaceLayout.LearningElements.Keys.OrderBy(key => key)) { + var learningElement = learningSpace.LearningSpaceLayout.LearningElements[key]; diff --git a/Presentation/View/LearningWorld/LearningWorldTreeViewItem.razor b/Presentation/View/LearningWorld/LearningWorldTreeViewItem.razor index 215edf73d..d72c3de43 100644 --- a/Presentation/View/LearningWorld/LearningWorldTreeViewItem.razor +++ b/Presentation/View/LearningWorld/LearningWorldTreeViewItem.razor @@ -1,11 +1,11 @@ -@using Presentation.PresentationLogic.LearningElement +@using System.Diagnostics.CodeAnalysis @using MudBlazor.Utilities @using Presentation.Components @using Presentation.PresentationLogic.LearningContent.AdaptivityContent @using Presentation.PresentationLogic.LearningContent.FileContent @using Presentation.PresentationLogic.LearningContent.LinkContent -@using System.Diagnostics.CodeAnalysis @using Presentation.PresentationLogic.LearningContent.Story +@using Presentation.PresentationLogic.LearningElement
@@ -15,12 +15,9 @@
@code { - [Parameter, EditorRequired, AllowNull] - public ILearningElementViewModel LearningElement { get; set; } - [Parameter, EditorRequired] - public EventCallback OnSelect { get; set; } - [Parameter, EditorRequired] - public bool IsSelected { get; set; } + [Parameter, EditorRequired, AllowNull] public ILearningElementViewModel LearningElement { get; set; } + [Parameter, EditorRequired] public EventCallback OnSelect { get; set; } + [Parameter, EditorRequired] public bool IsSelected { get; set; } private string GetElementDivCss() { diff --git a/Shared/FloorPlanElementSorter.cs b/Shared/FloorPlanElementSorter.cs deleted file mode 100644 index d8e3570f1..000000000 --- a/Shared/FloorPlanElementSorter.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace Shared; - -public static class FloorPlanElementSorter -{ - public static IEnumerable GetElementsInOrder( - IDictionary learningElements, - FloorPlanEnum floorPlanName) - { - return floorPlanName switch - { - FloorPlanEnum.L_32X31_10L => ConfigureOrderFor_L_32X31_10L.Where(learningElements.ContainsKey) - .Select(key => learningElements[key]), - FloorPlanEnum.R_20X20_6L => ConfigureOrderFor_R_20X20_6L.Where(learningElements.ContainsKey) - .Select(key => learningElements[key]), - FloorPlanEnum.R_20X30_8L => ConfigureOrderFor_R_20X30_8L.Where(learningElements.ContainsKey) - .Select(key => learningElements[key]), - FloorPlanEnum.T_40X32_13L => ConfigureOrderFor_T_40X32_13L.Where(learningElements.ContainsKey) - .Select(key => learningElements[key]), - FloorPlanEnum.D_40X37_15L => ConfigureOrderFor_D_40X37_15L.Where(learningElements.ContainsKey) - .Select(key => learningElements[key]), - _ => throw new ArgumentOutOfRangeException(nameof(floorPlanName), floorPlanName, null) - }; - } - - public static List GetListInOrder(List spaceSpaceSlotContents, FloorPlanEnum floorPlanName) - { - return floorPlanName switch - { - FloorPlanEnum.L_32X31_10L => ConfigureOrderFor_L_32X31_10L.Select(x => spaceSpaceSlotContents[x]).ToList(), - FloorPlanEnum.R_20X20_6L => ConfigureOrderFor_R_20X20_6L.Select(x => spaceSpaceSlotContents[x]).ToList(), - FloorPlanEnum.R_20X30_8L => ConfigureOrderFor_R_20X30_8L.Select(x => spaceSpaceSlotContents[x]).ToList(), - FloorPlanEnum.T_40X32_13L => ConfigureOrderFor_T_40X32_13L.Select(x => spaceSpaceSlotContents[x]).ToList(), - FloorPlanEnum.D_40X37_15L => ConfigureOrderFor_D_40X37_15L.Select(x => spaceSpaceSlotContents[x]).ToList(), - _ => throw new ArgumentOutOfRangeException(nameof(floorPlanName), floorPlanName, null) - }; - } - - // ReSharper disable InconsistentNaming - private static readonly List ConfigureOrderFor_L_32X31_10L = new() { 0, 1, 2, 3, 9, 8, 7, 4, 6, 5 }; - private static readonly List ConfigureOrderFor_R_20X20_6L = new() { 0, 1, 2, 3, 5, 4 }; - private static readonly List ConfigureOrderFor_R_20X30_8L = new() { 0, 1, 2, 3, 7, 6, 5, 4 }; - - private static readonly List - ConfigureOrderFor_T_40X32_13L = new() { 0, 1, 2, 5, 3, 4, 6, 11, 12, 7, 10, 9, 8 }; - - private static readonly List - ConfigureOrderFor_D_40X37_15L = new() { 0, 1, 2, 3, 14, 4, 5, 13, 12, 6, 11, 7, 10, 9, 8 }; - - // ReSharper restore InconsistentNaming -} \ No newline at end of file diff --git a/SharedTest/FloorPlanElementSorterUt.cs b/SharedTest/FloorPlanElementSorterUt.cs deleted file mode 100644 index 3d48fdbb9..000000000 --- a/SharedTest/FloorPlanElementSorterUt.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System.Reflection; -using System.Text.RegularExpressions; -using NUnit.Framework; -using Shared; - -namespace SharedTest; - -[TestFixture] -public class FloorPlanElementSorterUt -{ - [Test] - public void GetElementsInOrder_InvalidFloorPlanEnum_ThrowsException() - { - var invalidFloorPlan = (FloorPlanEnum) 999999; - Assert.Throws(() => - FloorPlanElementSorter.GetElementsInOrder(new Dictionary(), invalidFloorPlan)); - } - - [Test] - public void GetElementsInOrder_ForEachFloorPlanEnum_ContainsEachElementOnce([Values] FloorPlanEnum floorPlan) - { - var expectedCount = ExtractCountFromFloorPlanName(floorPlan); - // FloorPlanElementSorter takes Dictionary with any type, so it is tested only with string type here. - var elements = Enumerable.Range(0, expectedCount).ToDictionary(i => i, i => i.ToString()); - Assert.That(elements.Values, Is.Unique); - - var orderedElements = FloorPlanElementSorter.GetElementsInOrder(elements, floorPlan).ToList(); - - TestListContent(elements.Values.ToList(), orderedElements, floorPlan); - } - - - [Test] - public void GetListInOrder_InvalidFloorPlanEnum_ThrowsException() - { - var invalidFloorPlan = (FloorPlanEnum) 999999; - Assert.Throws(() => - FloorPlanElementSorter.GetListInOrder(new List(), invalidFloorPlan)); - } - - [Test] - public void GetListInOrder_ForEachFloorPlanEnum_ContainsEachElementOnce([Values] FloorPlanEnum floorPlan) - { - var expectedCount = ExtractCountFromFloorPlanName(floorPlan); - var elements = Enumerable.Range(0, expectedCount).Select(i => (int?) i).ToList(); - Assert.That(elements, Is.Unique); - - var orderedElements = FloorPlanElementSorter.GetListInOrder(elements, floorPlan).ToList(); - - TestListContent(elements, orderedElements, floorPlan); - } - - private static void TestListContent(List unorderedElements, List orderedElements, FloorPlanEnum floorPlan) - { - var expectedCount = ExtractCountFromFloorPlanName(floorPlan); - Assert.That(orderedElements, Has.Count.EqualTo(expectedCount)); - Assert.That(orderedElements, Is.Unique); - foreach (var element in unorderedElements) - { - Assert.That(orderedElements, Contains.Item(element)); - } - - var configureField = typeof(FloorPlanElementSorter).GetField($"ConfigureOrderFor_{floorPlan}", - BindingFlags.NonPublic | BindingFlags.Static); - Assert.That(configureField, Is.Not.Null); - var configureOrderFor = configureField!.GetValue(typeof(FloorPlanElementSorter)) as List; - for (var i = 0; i < expectedCount; i++) - { - Assert.That(orderedElements[i]?.ToString(), Is.EqualTo(configureOrderFor?[i].ToString())); - } - } - - private static int ExtractCountFromFloorPlanName(FloorPlanEnum floorPlan) - { - var floorPlanName = floorPlan.ToString(); - const string pattern = "_([0-9]+)L"; - var match = Regex.Match(floorPlanName, pattern); - var countString = match.Groups[1].Value; - return int.Parse(countString); - } -} \ No newline at end of file