From b7d4de933cde151fbc011948ba65a44d09fca588 Mon Sep 17 00:00:00 2001 From: Magnus Revheim Martinsen Date: Thu, 6 Jul 2023 10:58:07 +0200 Subject: [PATCH] Feat/add instance selection options to appmetadata (#271) * Add instance selection option to appmetadata * update test to use new OnEntry class * Fix obsolete method in IAppResources * newlines cleanup --------- Co-authored-by: Vemund Gaukstad --- .../Implementation/AppResourcesSI.cs | 8 ++++++- .../Models/ApplicationMetadata.cs | 6 +++++ .../Models/InstanceSelection.cs | 22 +++++++++++++++++++ src/Altinn.App.Core/Models/OnEntry.cs | 17 ++++++++++++++ .../Implementation/AppResourcesSITests.cs | 5 +++-- .../Implementation/DefaultTaskEventsTests.cs | 2 +- .../Internal/App/AppMedataTest.cs | 6 ++--- 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/Altinn.App.Core/Models/InstanceSelection.cs create mode 100644 src/Altinn.App.Core/Models/OnEntry.cs diff --git a/src/Altinn.App.Core/Implementation/AppResourcesSI.cs b/src/Altinn.App.Core/Implementation/AppResourcesSI.cs index 57e0c8bc0..a7d0b1f36 100644 --- a/src/Altinn.App.Core/Implementation/AppResourcesSI.cs +++ b/src/Altinn.App.Core/Implementation/AppResourcesSI.cs @@ -111,7 +111,13 @@ public Application GetApplication() { try { - return _appMetadata.GetApplicationMetadata().Result; + ApplicationMetadata applicationMetadata = _appMetadata.GetApplicationMetadata().Result; + Application application = applicationMetadata; + application.OnEntry = new OnEntryConfig() + { + Show = applicationMetadata.OnEntry.Show + }; + return application; } catch (AggregateException ex) { diff --git a/src/Altinn.App.Core/Models/ApplicationMetadata.cs b/src/Altinn.App.Core/Models/ApplicationMetadata.cs index f3d5fa79a..c7a9cd009 100644 --- a/src/Altinn.App.Core/Models/ApplicationMetadata.cs +++ b/src/Altinn.App.Core/Models/ApplicationMetadata.cs @@ -39,6 +39,12 @@ public ApplicationMetadata(string id) [JsonProperty(PropertyName = "features")] public Dictionary? Features { get; set; } + /// + /// Configure options for handling what happens when entering the application + /// + [JsonProperty(PropertyName = "onEntry")] + public new OnEntry OnEntry { get; set; } + /// /// Get AppIdentifier based on ApplicationMetadata.Id /// Updated by setting ApplicationMetadata.Id diff --git a/src/Altinn.App.Core/Models/InstanceSelection.cs b/src/Altinn.App.Core/Models/InstanceSelection.cs new file mode 100644 index 000000000..331f44074 --- /dev/null +++ b/src/Altinn.App.Core/Models/InstanceSelection.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Altinn.App.Core.Models +{ + /// + /// Contains options for displaying the instance selection component + /// + public class InstanceSelection + { + /// + /// A list of selectable options for amount of rows per page to show for pagination + /// + [JsonProperty(PropertyName = "rowsPerPageOptions")] + public List? RowsPerPageOptions { get; set; } + + /// + /// The direction of sorting the list of instances, asc or desc + /// + [JsonProperty(PropertyName = "sortDirection")] + public string? SortDirection { get; set; } + } +} diff --git a/src/Altinn.App.Core/Models/OnEntry.cs b/src/Altinn.App.Core/Models/OnEntry.cs new file mode 100644 index 000000000..e22186ee5 --- /dev/null +++ b/src/Altinn.App.Core/Models/OnEntry.cs @@ -0,0 +1,17 @@ +using Altinn.Platform.Storage.Interface.Models; +using Newtonsoft.Json; + +namespace Altinn.App.Core.Models { + + /// + /// The on entry configuration + /// + public class OnEntry : OnEntryConfig { + + /// + /// Options for displaying the instance selection component + /// + [JsonProperty(PropertyName = "instanceSelection")] + public InstanceSelection? InstanceSelection { get; set; } + } +} diff --git a/test/Altinn.App.Core.Tests/Implementation/AppResourcesSITests.cs b/test/Altinn.App.Core.Tests/Implementation/AppResourcesSITests.cs index c15478f32..be0ac9205 100644 --- a/test/Altinn.App.Core.Tests/Implementation/AppResourcesSITests.cs +++ b/test/Altinn.App.Core.Tests/Implementation/AppResourcesSITests.cs @@ -2,6 +2,7 @@ using Altinn.App.Core.Implementation; using Altinn.App.Core.Interface; using Altinn.App.Core.Internal.App; +using Altinn.App.Core.Models; using Altinn.Platform.Storage.Interface.Models; using FluentAssertions; using Microsoft.Extensions.Logging.Abstractions; @@ -57,7 +58,7 @@ public void GetApplication_desrializes_file_from_disk() Person = true, SubUnit = true }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" } @@ -110,7 +111,7 @@ public void GetApplication_second_read_from_cache() Person = true, SubUnit = true }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" }, diff --git a/test/Altinn.App.Core.Tests/Implementation/DefaultTaskEventsTests.cs b/test/Altinn.App.Core.Tests/Implementation/DefaultTaskEventsTests.cs index db5e0d72f..d0ff08e61 100644 --- a/test/Altinn.App.Core.Tests/Implementation/DefaultTaskEventsTests.cs +++ b/test/Altinn.App.Core.Tests/Implementation/DefaultTaskEventsTests.cs @@ -570,7 +570,7 @@ private ApplicationMetadata GetApplicationMetadataForShadowFields(bool useSaveTo Person = true, SubUnit = true }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" } diff --git a/test/Altinn.App.Core.Tests/Internal/App/AppMedataTest.cs b/test/Altinn.App.Core.Tests/Internal/App/AppMedataTest.cs index 3b8a45211..5fb58fab1 100644 --- a/test/Altinn.App.Core.Tests/Internal/App/AppMedataTest.cs +++ b/test/Altinn.App.Core.Tests/Internal/App/AppMedataTest.cs @@ -57,7 +57,7 @@ public async Task GetApplicationMetadata_desrializes_file_from_disk() Person = true, SubUnit = true }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" }, @@ -127,7 +127,7 @@ public async Task GetApplicationMetadata_eformidling_desrializes_file_from_disk( "372c7af5-71e1-4e99-8e05-4716711a8b53", } }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" }, @@ -179,7 +179,7 @@ public async void GetApplicationMetadata_second_read_from_cache() Person = true, SubUnit = true }, - OnEntry = new OnEntryConfig() + OnEntry = new OnEntry() { Show = "select-instance" },