diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index e36052bc3..a9674f2e8 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -26,12 +26,8 @@ public RedlistController(ArtskartApiService artskartApiService) public IActionResult RodlisteForArter() => View("Species/Rodlisteforarter"); private static readonly Dictionary _resourceCache = new(); - private static readonly Dictionary _allAreas = Constants.AllAreas; - private static readonly Dictionary _allCriterias = Constants.AllCriterias; - private static readonly Dictionary _allEuropeanPopulationPercentages = Constants.AllEuropeanPopulationPercentages; private readonly ArtskartApiService _artskartApiService; - [Route("2021")] public async Task Index2021([FromQueryAttribute] RL2021ViewModel viewModel, int? page, bool export) { @@ -73,8 +69,6 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel var query = await DataRepository.GetSpeciesAssessments(); - ViewBag.AllTaxonRanks = Helpers.GetAllTaxonRanks(); - // Søk if (!string.IsNullOrEmpty(viewModel.Name)) { @@ -99,8 +93,6 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel // Filter // Areas - ViewBag.AllAreas = _allAreas; - if (viewModel.Area?.Any() == true) query = query.Where(x => viewModel.Area.Contains(x.AssessmentArea)); @@ -111,14 +103,18 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel query = query.Where(x => !string.IsNullOrEmpty(x.Category) && viewModel.Category.Any(y => x.Category.Contains(y))); // Criterias - ViewBag.AllCriterias = _allCriterias; - if (viewModel.Criterias?.Any() == true) query = query.Where(x => !string.IsNullOrEmpty(x.CriteriaSummarized) && viewModel.Criterias.Any(y => x.CriteriaSummarized.Contains(y))); // Habitat if (viewModel.Habitats?.Any() == true) - query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y))); + { + // The model names are not compatible with enum naming rules. We need to consider this. + if (viewModel.Habitats.Contains("Fastmark")) + query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y) || x.MainHabitat.Contains("Semi-naturlig fastmark"))); + else + query = query.Where(x => viewModel.Habitats.Any(y => x.MainHabitat.Contains(y))); + } // Regions ViewBag.AllRegions = Helpers.GetRegionsDict(); @@ -144,7 +140,6 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel query = query.Where(x => viewModel.TaxonRank.Contains(x.TaxonRank)); // European population percentages - ViewBag.AllEuroPop = _allEuropeanPopulationPercentages; string[] chosenEuropeanPopulation = Helpers.FindEuropeanPopProcentages(viewModel.EuroPop); if (chosenEuropeanPopulation?.Any() == true) @@ -454,4 +449,4 @@ private static async Task GetResource(string resourcePath) return jObject; } } -} +} \ No newline at end of file diff --git a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterHelpers.cs b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesFilterHelpers.cs similarity index 96% rename from Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterHelpers.cs rename to Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesFilterHelpers.cs index ebe2139c5..4554c7025 100644 --- a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesFilterHelpers.cs @@ -1,10 +1,12 @@ using Assessments.Frontend.Web.Models; using System; using System.Linq; +using Assessments.Frontend.Web.Infrastructure; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies { - public class FilterHelpers : IFilter + public class AlienSpeciesFilterHelpers : IFilter { public string IGetActiveFilters(string filterType, AlienSpeciesListParameters parameters) { @@ -26,7 +28,7 @@ public string[] IGetActiveSelectionElement(AlienSpeciesListParameters parameters return GetActiveSelectionElement(parameters); } - public string IGetChipText(string filter, Filter.FilterItem[] filterItems) + public string IGetChipText(string filter, FilterItem[] filterItems) { return GetChipText(filter, filterItems); } @@ -230,11 +232,11 @@ public static string[] GetActiveSelectionElement(AlienSpeciesListParameters para return selectionlist; } - public static string GetChipText(string filter, Filter.FilterItem[] filterItems) + public static string GetChipText(string filter, FilterItem[] filterItems) { for (int i = 0; i < filterItems.Length; i++) { - Filter.FilterItem item = filterItems[i]; + FilterItem item = filterItems[i]; if (item.NameShort == filter) { return item.Name; diff --git a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesHelpers.cs b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesHelpers.cs index 333b52bf6..e10f3b63d 100644 --- a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/AlienSpeciesHelpers.cs @@ -4,12 +4,13 @@ using System; using System.Collections.Generic; using System.Linq; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies { public class AlienSpeciesHelpers { - public static Filter.FilterItem GetSpeciesGroup(Filter.FilterItem[] speciesGroups, string speciesGroupName) + public static FilterItem GetSpeciesGroup(FilterItem[] speciesGroups, string speciesGroupName) { foreach (var speciesGroup in speciesGroups) { @@ -38,7 +39,7 @@ public static string GetSpeciesGroupByShortName(string shortName) foreach (var species in speciesGroups) { - Filter.FilterItem speciesGroup = species; + FilterItem speciesGroup = species; if (speciesGroup.NameShort == shortName) { return speciesGroup.Name; diff --git a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs index c3cb110a6..e73d0c1a8 100644 --- a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs @@ -6,19 +6,22 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using Assessments.Frontend.Web.Infrastructure; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies { public class Areas { - private readonly Filter.FilterItem[] AlienSpecies2023AreasFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + private readonly FilterItem[] AlienSpecies2023AreasFilters = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() }).ToArray(); - public Filter.FilterAndMetaData AlienSpecies2023Areas() => + + public FilterAndMetaData AlienSpecies2023Areas() => new() { Filters = AlienSpecies2023AreasFilters, @@ -30,14 +33,14 @@ public Filter.FilterAndMetaData AlienSpecies2023Areas() => public class Categories { - private readonly Filter.FilterItem[] AlienSpecies2023InvasionPotentialFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + private readonly FilterItem[] AlienSpecies2023InvasionPotentialFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.Description(), Name = x.DisplayName() }).Skip(1).ToArray(); - public Filter.FilterAndMetaData AlienSpecies2023InvasionPotential() => + public FilterAndMetaData AlienSpecies2023InvasionPotential() => new() { Filters = AlienSpecies2023InvasionPotentialFilters, @@ -46,14 +49,14 @@ public Filter.FilterAndMetaData AlienSpecies2023InvasionPotential() => FilterButtonText = "Invasjonspotensial (risikomatrisens x-akse)" }; - private readonly Filter.FilterItem[] AlienSpecies2023EcologicalEffectFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + private readonly FilterItem[] AlienSpecies2023EcologicalEffectFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.Description(), Name = x.DisplayName() }).Skip(1).ToArray(); - public Filter.FilterAndMetaData AlienSpecies2023EcologicalEffect() => + public FilterAndMetaData AlienSpecies2023EcologicalEffect() => new() { Filters = AlienSpecies2023EcologicalEffectFilters, @@ -62,16 +65,15 @@ public Filter.FilterAndMetaData AlienSpecies2023EcologicalEffect() => FilterButtonText = "Økologisk effekt (risikomatrisens y-akse)" }; - private readonly Filter.FilterItem[] _alienSpecies2023CategoriesFilters = Enum.GetValues() + private readonly FilterItem[] _alienSpecies2023CategoriesFilters = Enum.GetValues() .Where(x => x != AlienSpeciesAssessment2023Category.NR) - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - - public Filter.FilterAndMetaData AlienSpecies2023Categories() => + public FilterAndMetaData AlienSpecies2023Categories() => new() { Filters = _alienSpecies2023CategoriesFilters, @@ -111,7 +113,7 @@ public enum CategoryChangeEnum public class CategoryChange { - private static readonly Filter.FilterItem[] DifferFrom2018 = + private static readonly FilterItem[] DifferFrom2018 = { new() { @@ -140,7 +142,7 @@ public class CategoryChange } }; - public static readonly Filter.FilterItem[] AlienSpecies2023CategoryChangedFilters = + public static readonly FilterItem[] AlienSpecies2023CategoryChangedFilters = { new() { @@ -164,7 +166,7 @@ public class CategoryChange } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023CategoryChanged = new() + public static readonly FilterAndMetaData AlienSpecies2023CategoryChanged = new() { Filters = AlienSpecies2023CategoryChangedFilters, FilterDescription = "", @@ -196,12 +198,12 @@ public enum DecisiveCriteriaEcologicalEffect I = AlienSpeciesAssessment2023CriteriaLetter.I }; - public static Filter.FilterAndMetaData MedianLifeTimeAndExpansionSpeed() => + public static FilterAndMetaData MedianLifeTimeAndExpansionSpeed() => new() { Filters = Enum.GetValues().Where(x => x is DecisiveCriteriaInvasion.A or DecisiveCriteriaInvasion.B) - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { Name = x.ToString() + " - " + ((AlienSpeciesAssessment2023CriteriaLetter)x).DisplayName(), NameShort = x.ToString() @@ -210,11 +212,11 @@ public static Filter.FilterAndMetaData MedianLifeTimeAndExpansionSpeed() => FilterDescription = "" }; - private static Filter.FilterAndMetaData InvationPotential() => + private static FilterAndMetaData InvationPotential() => new() { Filters = Enum.GetValues().Where(x => x != DecisiveCriteriaInvasion.A & x != DecisiveCriteriaInvasion.B) - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { Name = x != DecisiveCriteriaInvasion.C ? x.DisplayName() : x.ToString() + " - " + ((AlienSpeciesAssessment2023CriteriaLetter)x).DisplayName(), @@ -226,11 +228,11 @@ private static Filter.FilterAndMetaData InvationPotential() => FilterDescription = "" }; - public static Filter.FilterAndMetaData EcologicalEffect() => + public static FilterAndMetaData EcologicalEffect() => new() { Filters = Enum.GetValues() - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { Name = x.ToString() + " - " + ((AlienSpeciesAssessment2023CriteriaLetter) x).DisplayName(), NameShort = x.ToString() @@ -238,7 +240,7 @@ public static Filter.FilterAndMetaData EcologicalEffect() => FilterDescription = "" }; - public readonly Filter.FilterItem[] AlienSpecies2023DeciciveCriteriaFilters = + public readonly FilterItem[] AlienSpecies2023DeciciveCriteriaFilters = { new() { @@ -255,7 +257,7 @@ public static Filter.FilterAndMetaData EcologicalEffect() => } }; - public Filter.FilterAndMetaData AlienSpecies2023DeciciveCriteria() => + public FilterAndMetaData AlienSpecies2023DeciciveCriteria() => new() { Filters = AlienSpecies2023DeciciveCriteriaFilters, @@ -271,7 +273,7 @@ public class Environments public const string Limnic = "Eli"; public const string Terrestrial = "Ete"; - public static readonly Filter.FilterItem[] AlienSpecies2023EnvironmentFilters = + public static readonly FilterItem[] AlienSpecies2023EnvironmentFilters = { new() { @@ -290,7 +292,7 @@ public class Environments } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023Environment = new() + public static readonly FilterAndMetaData AlienSpecies2023Environment = new() { Filters = AlienSpecies2023EnvironmentFilters, FilterDescription = "", @@ -310,7 +312,7 @@ public enum GeographicVariationEnum Gvn, }; - public static readonly Filter.FilterItem[] AlienSpecies2023GeographicVariationFilters = + public static readonly FilterItem[] AlienSpecies2023GeographicVariationFilters = { new () { @@ -324,7 +326,7 @@ public enum GeographicVariationEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023GeographicVariation = new() + public static readonly FilterAndMetaData AlienSpecies2023GeographicVariation = new() { Filters = AlienSpecies2023GeographicVariationFilters, FilterDescription = "", @@ -356,7 +358,7 @@ public enum ClimateEffectsEnum Cei, }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFiltersAffected = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFiltersAffected = { new () { @@ -370,7 +372,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFiltersNotAffected = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFiltersNotAffected = { new () { @@ -384,7 +386,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFilters = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFilters = { new () { @@ -408,7 +410,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023ClimateEffects = new() + public static readonly FilterAndMetaData AlienSpecies2023ClimateEffects = new() { Filters = AlienSpecies2023ClimateEffectsFilters, FilterDescription = "", @@ -433,11 +435,11 @@ public enum ImpactedNaturetypesThreatened WetlandsThreatned = AlienSpeciesAssessment2023MajorTypeGroup.WetlandsThreatned } - public static Filter.FilterAndMetaData AlienSpecies2023AlteredEcosystems() => + public static FilterAndMetaData AlienSpecies2023AlteredEcosystems() => new() { Filters = Enum.GetValues() - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() @@ -445,11 +447,11 @@ public static Filter.FilterAndMetaData AlienSpecies2023AlteredEcosystems() => FilterDescription = "" }; - public static Filter.FilterAndMetaData AlienSpecies2023AlteredMajorTypeGroupTypes() => + public static FilterAndMetaData AlienSpecies2023AlteredMajorTypeGroupTypes() => new() { Filters = Enum.GetValues() - .Select(x => new Filter.FilterItem + .Select(x => new FilterItem { Name = ((AlienSpeciesAssessment2023MajorTypeGroup)x).DisplayName(), NameShort = x.ToString() @@ -457,7 +459,7 @@ public static Filter.FilterAndMetaData AlienSpecies2023AlteredMajorTypeGroupType FilterDescription = "" }; - private readonly Filter.FilterItem[] AlienSpecies2023NatureTypesFilters = + private readonly FilterItem[] AlienSpecies2023NatureTypesFilters = { new () @@ -474,7 +476,7 @@ public static Filter.FilterAndMetaData AlienSpecies2023AlteredMajorTypeGroupType } }; - public Filter.FilterAndMetaData AlienSpecies2023NatureTypes() => + public FilterAndMetaData AlienSpecies2023NatureTypes() => new() { Filters = AlienSpecies2023NatureTypesFilters, @@ -540,7 +542,7 @@ public enum SpreadWaysEnum Swspr, }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersImportPathways = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersImportPathways = { new () { @@ -559,7 +561,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersIntroduction = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersIntroduction = { new () { @@ -593,7 +595,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersSpread = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersSpread = { new () { @@ -622,7 +624,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFilters = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFilters = { new () { @@ -656,7 +658,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpreadWays = new() + public static readonly FilterAndMetaData AlienSpecies2023SpreadWays = new() { Filters = AlienSpecies2023SpreadWaysFilters, FilterDescription = "", @@ -728,7 +730,7 @@ public enum RegionallyAlienEnum } - public static readonly Filter.FilterItem[] RegionalSpread = + public static readonly FilterItem[] RegionalSpread = { new() { @@ -813,7 +815,7 @@ public enum RegionallyAlienEnum }; - public static readonly Filter.FilterItem[] AlienSpecies2023RegionallyAlienFilters = + public static readonly FilterItem[] AlienSpecies2023RegionallyAlienFilters = { new() { @@ -837,7 +839,7 @@ public enum RegionallyAlienEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023RegionallyAlien = new() + public static readonly FilterAndMetaData AlienSpecies2023RegionallyAlien = new() { Filters = AlienSpecies2023RegionallyAlienFilters, FilterDescription = "", @@ -868,7 +870,7 @@ public enum TaxonRankEnum tvi } - public static readonly Filter.FilterItem[] TaxonRanks2023 = + public static readonly FilterItem[] TaxonRanks2023 = { new() { @@ -897,7 +899,7 @@ public enum TaxonRankEnum }, }; - public static readonly Filter.FilterItem[] AlienSpecies2023TaxonRanksFilters = + public static readonly FilterItem[] AlienSpecies2023TaxonRanksFilters = { new() { @@ -921,7 +923,7 @@ public enum TaxonRankEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023TaxonRanks = new() + public static readonly FilterAndMetaData AlienSpecies2023TaxonRanks = new() { Filters = AlienSpecies2023TaxonRanksFilters, FilterDescription = "", @@ -933,7 +935,7 @@ public enum TaxonRankEnum public class SpeciesGroups { // All NameShort for speciesGroup starts with 's' to not confuse them with other short names. - private static readonly Filter.FilterItem[] AlienSpecies2023Algae = + private static readonly FilterItem[] AlienSpecies2023Algae = { new() { @@ -961,7 +963,7 @@ public class SpeciesGroups } }; - private static readonly Filter.FilterItem[] AlienSpecies2023Insects = + private static readonly FilterItem[] AlienSpecies2023Insects = { new() { @@ -1037,7 +1039,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterItem[] AlienSpecies2023Crustacean = + public static readonly FilterItem[] AlienSpecies2023Crustacean = { new() { @@ -1073,7 +1075,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpeciesGroupsFilters = + public static readonly FilterItem[] AlienSpecies2023SpeciesGroupsFilters = { new() { @@ -1308,7 +1310,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpeciesGroups = new() + public static readonly FilterAndMetaData AlienSpecies2023SpeciesGroups = new() { Filters = AlienSpecies2023SpeciesGroupsFilters, FilterDescription = "", @@ -1319,14 +1321,14 @@ public class SpeciesGroups public class Regions { - public static readonly Filter.FilterItem[] AlienSpecies2023RegionsFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023RegionsFilters = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() }).ToArray(); - public static readonly Filter.FilterAndMetaData AlienSpecies2023Regions = new() + public static readonly FilterAndMetaData AlienSpecies2023Regions = new() { Filters = AlienSpecies2023RegionsFilters, FilterDescription = "Regioner med kjent, antatt eller forventet forekomst", @@ -1337,7 +1339,7 @@ public class Regions public class Habitat { - public static readonly Filter.FilterItem[] AlienSpecies2023HabitatsFilters = + public static readonly FilterItem[] AlienSpecies2023HabitatsFilters = { new() { @@ -1373,7 +1375,7 @@ public class Habitat } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023Habitats = new() + public static readonly FilterAndMetaData AlienSpecies2023Habitats = new() { Filters = AlienSpecies2023HabitatsFilters, FilterDescription = "", @@ -1384,21 +1386,21 @@ public class Habitat public class ProductionSpecies { - public static readonly Filter.FilterItem[] AlienSpecies2023ProductionSpeciesFilters = + public static readonly FilterItem[] AlienSpecies2023ProductionSpeciesFilters = { - new Filter.FilterItem() + new FilterItem() { Name = "Tidligere eller nåværende bruksart", NameShort = true.ToString() }, - new Filter.FilterItem() + new FilterItem() { Name = "Ikke bruksart", NameShort = false.ToString() } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023ProductionSpecies = new() + public static readonly FilterAndMetaData AlienSpecies2023ProductionSpecies = new() { Filters = AlienSpecies2023ProductionSpeciesFilters, FilterDescription = "", @@ -1409,7 +1411,7 @@ public class ProductionSpecies public class SpeciesStatus { - public static readonly Filter.FilterItem[] AlienSpecies2023Doorknockers = + public static readonly FilterItem[] AlienSpecies2023Doorknockers = { new() { @@ -1438,7 +1440,7 @@ public class SpeciesStatus } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpeciesStatusFilters = + public static readonly FilterItem[] AlienSpecies2023SpeciesStatusFilters = { new() { @@ -1462,7 +1464,7 @@ public class SpeciesStatus } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpeciesStatus = new() + public static readonly FilterAndMetaData AlienSpecies2023SpeciesStatus = new() { Filters = AlienSpecies2023SpeciesStatusFilters, FilterDescription = "", @@ -1483,10 +1485,10 @@ public enum NotAssessedAlienSpeciesCategory MisIdentified = AlienSpeciecAssessment2023AlienSpeciesCategory.MisIdentified } - public static Filter.FilterAndMetaData AlienSpecies2023NotAssessed() => + public static FilterAndMetaData AlienSpecies2023NotAssessed() => new() { - Filters = Enum.GetValues().Select(x => new Filter.FilterItem { Name = ((AlienSpeciecAssessment2023AlienSpeciesCategory) x).DisplayName(), NameShort = x.ToString() }).ToArray(), + Filters = Enum.GetValues().Select(x => new FilterItem { Name = ((AlienSpeciecAssessment2023AlienSpeciesCategory) x).DisplayName(), NameShort = x.ToString() }).ToArray(), FilterDescription = "", FilterButtonName = "'ikke vurdert'-filtre", FilterButtonText = "Ikke-risikovurderte arter" diff --git a/Assessments.Frontend.Web/Infrastructure/Constants.cs b/Assessments.Frontend.Web/Infrastructure/Constants.cs index e65cc139e..5a81fced1 100644 --- a/Assessments.Frontend.Web/Infrastructure/Constants.cs +++ b/Assessments.Frontend.Web/Infrastructure/Constants.cs @@ -8,20 +8,6 @@ public static class Constants public const string AssessmentsMappingAssembly = "Assessments.Mapping"; - public static readonly Dictionary AllAreas = new() - { - {"Norge", "N"}, - {"Svalbard", "S"} - }; - - public static readonly Dictionary AllCriterias = new() - { - {"A", "populasjonsreduksjon"}, - {"B", "lite areal"}, - {"C", "liten populasjon"}, - {"D", "svært liten populasjon eller forekomst"} - }; - public class HeadingsNo { public static class SubHeadings diff --git a/Assessments.Frontend.Web/Infrastructure/Criteria.cs b/Assessments.Frontend.Web/Infrastructure/CriteriaHelpers.cs similarity index 86% rename from Assessments.Frontend.Web/Infrastructure/Criteria.cs rename to Assessments.Frontend.Web/Infrastructure/CriteriaHelpers.cs index 3c404504f..e78f55227 100644 --- a/Assessments.Frontend.Web/Infrastructure/Criteria.cs +++ b/Assessments.Frontend.Web/Infrastructure/CriteriaHelpers.cs @@ -3,7 +3,7 @@ namespace Assessments.Frontend.Web.Infrastructure { - public static class Criteria + public static class CriteriaHelpers { public static string handleCCriteria(string current_element, string key) { @@ -65,8 +65,8 @@ public static string[] obtainSubCriteriaList(string[] splitlist, string k) } } current_element = current_element.Replace(k, ""); // remove main criteria, leaving nested subcriteria - current_element = Criteria.removeOuterParenthesis(current_element); - current_element = Criteria.handleCCriteria(current_element, k); + current_element = CriteriaHelpers.removeOuterParenthesis(current_element); + current_element = CriteriaHelpers.handleCCriteria(current_element, k); return current_element.Split(";"); } @@ -79,7 +79,7 @@ public static string sortBCriteria(string b) { string b_subcriteria = ""; - b = Criteria.subCriteria("B", b); + b = CriteriaHelpers.subCriteria("B", b); if (b.Contains("B1")) { b_subcriteria += "B1;"; @@ -143,10 +143,10 @@ void placeCriteria(string criteria) } // Sort criteria contents - a = Criteria.subCriteria("A", a); // A CRITERIA - OPTIONS AND SUBCRITERIA ARE NOT SEPARATE ENTITIES - c = Criteria.subCriteria("C", c); // C CRITERIA - All options are only relevant for C2 - handle in code. - d = Criteria.subCriteria("D", d); // D CRITERIA: - ONLY subcriteria. - b = Criteria.sortBCriteria(b); // B CRITERIA - OPTIONS AND SUBCRITERIA ARE SEPARATE ENTITIES, options may contain sub-options + a = CriteriaHelpers.subCriteria("A", a); // A CRITERIA - OPTIONS AND SUBCRITERIA ARE NOT SEPARATE ENTITIES + c = CriteriaHelpers.subCriteria("C", c); // C CRITERIA - All options are only relevant for C2 - handle in code. + d = CriteriaHelpers.subCriteria("D", d); // D CRITERIA: - ONLY subcriteria. + b = CriteriaHelpers.sortBCriteria(b); // B CRITERIA - OPTIONS AND SUBCRITERIA ARE SEPARATE ENTITIES, options may contain sub-options // The dictionaries used in the view <- two dicts made sense back when A was thought to have options as well. Now not as much diff --git a/Assessments.Frontend.Web/Infrastructure/Filter.cs b/Assessments.Frontend.Web/Infrastructure/Filter.cs deleted file mode 100644 index 18712068d..000000000 --- a/Assessments.Frontend.Web/Infrastructure/Filter.cs +++ /dev/null @@ -1,155 +0,0 @@ -using Assessments.Frontend.Web.Models; -using System; -using System.Linq; -using static Assessments.Frontend.Web.Infrastructure.Constants; - -namespace Assessments.Frontend.Web.Infrastructure -{ - public static class Filter - { - public class FilterAndMetaData - { - /// - /// The filters themselfes - /// - public FilterItem[] Filters { get; set; } - - /// - /// Describing the filter. This will show as info text when you open a filter. - /// - public string FilterDescription { get; set; } - - /// - /// A norwegian name for the button to open filters. Sub groups do not need this. - /// - public string FilterButtonName { get; set; } - - /// - /// The text displayed on the button. Also known as the name of the filter. - /// - public string FilterButtonText { get; set; } - } - - public class FilterItem - { - public string Description { get; set; } - - public string FilterHelpText { get; set; } - - public string InfoUrl { get; set; } - - public string ImageUrl { get; set; } - - public string Mapping { get; set; } - - public string Name { get; set; } - - public string NameShort { get; set; } - - public FilterAndMetaData SubGroup { get; set; } - } - - public static string GetActiveFilters(string filterType, RL2021ViewModel Model) - { - switch (filterType) - { - case "Area": - if (Model.Area?.Any() == true) - return $"{Model.Area.Length}"; - return String.Empty; - case "Category": - if (Model.Category?.Any() == true) - return $"{Model.Category.Length}"; - return String.Empty; - case "TaxonRank": - if (Model.TaxonRank?.Any() == true) - return $"{Model.TaxonRank.Length}"; - return String.Empty; - case "SpeciesGroups": - if (Model.SpeciesGroups?.Any() == true) - { - if (Model.SpeciesGroups.Contains("Insekter")) - return $"{Model.SpeciesGroups.Length - 1}"; - return $"{Model.SpeciesGroups.Length}"; - } - return String.Empty; - case "Habitats": - if (Model.Habitats?.Any() == true) - return $"{Model.Habitats.Length}"; - return String.Empty; - case "Regions": - if (Model.Regions?.Any() == true) - return $"{Model.Regions.Length}"; - return String.Empty; - case "EuroPop": - if (Model.EuroPop?.Any() == true) - return $"{Model.EuroPop.Length}"; - return String.Empty; - case "Criterias": - if (Model.Criterias?.Any() == true) - return $"{Model.Criterias.Length}"; - return String.Empty; - case "PresumedExtinct": - if (Model.PresumedExtinct == true) - return $"1"; - return String.Empty; - case "Insects": - if (AllInsects.Any(insect => Model.SpeciesGroups.Contains(insect))) - { - int count = 0; - foreach (var insect in AllInsects) - if (Model.SpeciesGroups.Contains(insect)) - count++; - return $"{count}"; - } - return String.Empty; - default: - return String.Empty; - } - } - - public static string GetActiveSelection(RL2021ViewModel Model) - { - if (!string.IsNullOrEmpty(Model.Name)) - { - return $"{Model.Name}"; - } - return String.Empty; - } - - public static int GetActiveSelectionCount(RL2021ViewModel Model) - { - int count = 0; - count += Model.Area.Length; - count += Model.Category.Length; - count += Model.SpeciesGroups.Length; - count += Model.TaxonRank.Length; - count += Model.Habitats.Length; - count += Model.Regions.Length; - count += Model.EuroPop.Length; - count += Model.Criterias.Length; - if (Model.PresumedExtinct) - count++; - - return count; - } - - public static string[] GetActiveSelectionElement(RL2021ViewModel Model) - { - var selectionlist = Model.Area; - selectionlist = selectionlist.Concat(Model.Category).ToArray(); - selectionlist = selectionlist.Concat(Model.SpeciesGroups).ToArray(); - selectionlist = selectionlist.Concat(Model.TaxonRank).ToArray(); - selectionlist = selectionlist.Concat(Model.Habitats).ToArray(); - selectionlist = selectionlist.Concat(Model.Regions).ToArray(); - selectionlist = selectionlist.Concat(Model.EuroPop).ToArray(); - selectionlist = selectionlist.Concat(Model.Criterias).ToArray(); - if (Model.PresumedExtinct) - { - string[] PresumedExtinct = new string[] { "Antatt utd�dd" }; - selectionlist = selectionlist.Concat(PresumedExtinct).ToArray(); - } - return selectionlist; - } - } -} \ No newline at end of file diff --git a/Assessments.Frontend.Web/Infrastructure/FilterHelpers.cs b/Assessments.Frontend.Web/Infrastructure/FilterHelpers.cs new file mode 100644 index 000000000..0d21c2b93 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/FilterHelpers.cs @@ -0,0 +1,47 @@ +namespace Assessments.Frontend.Web.Infrastructure +{ + public class FilterHelpers + { + public class FilterAndMetaData + { + /// + /// The filters themselfes + /// + public FilterItem[] Filters { get; set; } + + /// + /// Describing the filter. This will show as info text when you open a filter. + /// + public string FilterDescription { get; set; } + + /// + /// A norwegian name for the button to open filters. Sub groups do not need this. + /// + public string FilterButtonName { get; set; } + + /// + /// The text displayed on the button. Also known as the name of the filter. + /// + public string FilterButtonText { get; set; } + } + + public class FilterItem + { + public string Description { get; set; } + + public string FilterHelpText { get; set; } + + public string InfoUrl { get; set; } + + public string ImageUrl { get; set; } + + public string Mapping { get; set; } + + public string Name { get; set; } + + public string NameShort { get; set; } + + public FilterAndMetaData SubGroup { get; set; } + } + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/Helpers.cs b/Assessments.Frontend.Web/Infrastructure/Helpers.cs index 7cbf6da45..99b1a1f23 100644 --- a/Assessments.Frontend.Web/Infrastructure/Helpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/Helpers.cs @@ -11,13 +11,6 @@ namespace Assessments.Frontend.Web.Infrastructure { public static class Helpers { - private static readonly Dictionary _ranks = new() - { - { "Species", "Art" }, - { "SubSpecies", "Underart" }, - { "Variety", "Varietet" } - }; - public static string FormatNumeric(string value) { if (int.TryParse(value, out int result)) @@ -182,7 +175,9 @@ public static string[] FindSelectedRegions(string[] selectedRegions, Dictionary< List regions = new(); foreach (var region in selectedRegions) { - regions.Add(allRegions[region]); + // Mark all button har "Regions", and is not a region + if (region != "Regions") + regions.Add(allRegions[region]); } return regions.ToArray(); } @@ -255,11 +250,6 @@ public static string removeLineBreaksForMobile(string text) return text.Replace("
", "").Replace("", ""); } - public static Dictionary GetAllTaxonRanks() - { - return _ranks; - } - public static bool IsNotEmpty(string key) { if (key != null && key != " " && key != "-" && key != "" && key != "Helt ukjent") diff --git a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/Interfaces.cs b/Assessments.Frontend.Web/Infrastructure/Interfaces.cs similarity index 56% rename from Assessments.Frontend.Web/Infrastructure/AlienSpecies/Interfaces.cs rename to Assessments.Frontend.Web/Infrastructure/Interfaces.cs index 47b4220d9..5ab9d1fff 100644 --- a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/Interfaces.cs +++ b/Assessments.Frontend.Web/Infrastructure/Interfaces.cs @@ -1,4 +1,6 @@ -namespace Assessments.Frontend.Web.Infrastructure.AlienSpecies +using Assessments.Frontend.Web.Infrastructure.RedlistSpecies; + +namespace Assessments.Frontend.Web.Infrastructure { public interface IFilter { @@ -10,6 +12,6 @@ public interface IFilter string[] IGetActiveSelectionElement(T obj); - string IGetChipText(string s, Filter.FilterItem[] f); + string IGetChipText(string s, FilterHelpers.FilterItem[] f); } } diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Category.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Category.cs new file mode 100644 index 000000000..8751ae8ee --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Category.cs @@ -0,0 +1,41 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021Category + { + // ReSharper disable InconsistentNaming + [Display(Name = "regionalt utdødd")] + RE, + + [Display(Name = "kritisk truet")] + CR, + + [Display(Name = "sterkt truet")] + EN, + + [Display(Name = "sårbar")] + VU, + + [Display(Name = "nær truet")] + NT, + + [Display(Name = "datamangel")] + DD, + + [Display(Name = "livskraftig")] + LC, + + [Display(Name = "ikke egnet")] + NA, + + [Display(Name = "ikke vurdert")] + NE, + + [Display(Name = "Merk alle rødlistearter")] + RED, + + [Display(Name = "Marker alle truede arter")] + END, + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Criteria.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Criteria.cs new file mode 100644 index 000000000..08f35cf69 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Criteria.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021Criteria + { + [Display(Name = "populasjonsreduksjon")] + A, + + [Display(Name = "lite areal")] + B, + + [Display(Name = "liten populasjon")] + C, + + [Display(Name = "svært liten populasjon eller forekomst")] + D, + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EuropeanPopulation.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EuropeanPopulation.cs new file mode 100644 index 000000000..4d055dbba --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EuropeanPopulation.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021EuropeanPopulation + { + [Display(Name = "< 5 %")] + Lt5, + + [Display(Name = "5 - 25 %")] + Fr5To25, + + [Display(Name = "25 - 50 %")] + Fr25To50, + + [Display(Name = "> 50 %")] + Gt50, + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EvaluationContext.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EvaluationContext.cs new file mode 100644 index 000000000..141c8dfe6 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EvaluationContext.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021EvaluationContext + { + [Display(Name = "Norge")] + N, + + [Display(Name = "Svalbard")] + S + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs new file mode 100644 index 000000000..934cb91d6 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs @@ -0,0 +1,46 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021Habitats + { + [Display(Name = "Arktisk")] + Arktisk, + + [Display(Name = "Fjell")] + ArktiskAlpineJorddektFastmark, + + [Display(Name = "Berg og ur")] + BergUrAndreGrunnjordsystemer, + + [Display(Name = "Skog")] + Fastmarksskogsmark, + + [Display(Name = "Ferskvann")] + Ferskvannssystemer, + + [Display(Name = "Fjæresone")] + Fjæresone, + + [Display(Name = "Flomsone")] + Flomsone, + + [Display(Name = "Snø og is")] + IsSnø, + + [Display(Name = "Kyst")] + KysttilknyttedeFastmarkssystemer, + + [Display(Name = "Saltvann")] + Saltvannssystemer, + + [Display(Name = "Semi-naturlig mark")] + Fastmark, + + [Display(Name = "Sterkt endret mark")] + SterktEndretFastmark, + + [Display(Name = "Våtmark")] + Våtmarkssystemer, + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Regions.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Regions.cs new file mode 100644 index 000000000..8a8fa527b --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Regions.cs @@ -0,0 +1,79 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021Regions + { + [Display(Name = "Østfold")] + Ost, + + [Display(Name = "Oslo og Akershus")] + Ooa, + + [Display(Name = "Hedmark")] + Hed, + + [Display(Name = "Oppland")] + Opp, + + [Display(Name = "Buskerud")] + Bus, + + [Display(Name = "Vestfold")] + Ves, + + [Display(Name = "Telemark")] + Tel, + + [Display(Name = "Aust-Agder")] + Aus, + + [Display(Name = "Vest-Agder")] + VeA, + + [Display(Name = "Rogaland")] + Rog, + + [Display(Name = "Hordaland")] + Hor, + + [Display(Name = "Sogn og Fjordane")] + SoF, + + [Display(Name = "Møre og Romsdal")] + MoR, + + [Display(Name = "Trøndelag")] + Tron, + + [Display(Name = "Nordland")] + Nor, + + [Display(Name = "Troms")] + Tro, + + [Display(Name = "Finnmark")] + Fin, + + [Display(Name = "Svalbard")] + Sva, + + [Display(Name = "Jan Mayen")] + JaM, + + [Display(Name = "Nordsjøen")] + NoSj, + + [Display(Name = "Norskehavet")] + NoHa, + + [Display(Name = "Barentshavet sør")] + BaSo, + + [Display(Name = "Barentshavet nord og Polhavet")] + BaNoP, + + [Display(Name = "Grønlandshavet")] + Gro, + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021TaxonRank.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021TaxonRank.cs new file mode 100644 index 000000000..bb437385c --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021TaxonRank.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums +{ + public enum RedlistSpeciesAssessment2021TaxonRank + { + [Display(Name = "Art")] + Species , + + [Display(Name = "Underart")] + SubSpecies , + + [Display(Name = "Varietet")] + Variety + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs new file mode 100644 index 000000000..9323b8a21 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -0,0 +1,385 @@ +using Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums; +using Assessments.Mapping.AlienSpecies.Model.Enums; +using Assessments.Shared.Helpers; +using System; +using System.Linq; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies +{ + public class RedlistAreas + { + public static readonly FilterItem[] RedlistSpecies2021AreasFilters = Enum.GetValues() + .Select(x => new FilterItem + { + Name = x.DisplayName(), + NameShort = x.ToString() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Areas = new() + { + Filters = RedlistSpecies2021AreasFilters, + FilterDescription = "", + FilterButtonName = "områdefiltre", + FilterButtonText = "Vurderingsområde" + }; + } + + public class RedlistCategories + { + public static readonly FilterItem[] RedlistSpecies2021CategoriesFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Categories = new() + { + Filters = RedlistSpecies2021CategoriesFilters, + FilterDescription = "", + FilterButtonName = "kategorifiltre", + FilterButtonText = "Kategori" + }; + } + + public class RedlistCriteria + { + public static readonly FilterItem[] RedlistSpecies2021CriteriaFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Criteria = new() + { + Filters = RedlistSpecies2021CriteriaFilters, + FilterDescription = "", + FilterButtonName = "kriteriefiltre", + FilterButtonText = "Kriterier" + }; + } + + public class RedlistEuropeanPopulation + { + public static readonly FilterItem[] RedlistSpecies2021EuropeanPopulationFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021EuropeanPopulation = new() + { + Filters = RedlistSpecies2021EuropeanPopulationFilters, + FilterDescription = "", + FilterButtonName = "europeiskandelpopulasjonsfiltre", + FilterButtonText = "Andel av europeisk populasjon" + }; + } + + public class RedlistRegions + { + public static readonly FilterItem[] RedlistSpecies2021RegionsFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = ((int) x).ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Regions = new() + { + Filters = RedlistSpecies2021RegionsFilters, + FilterDescription = "", + FilterButtonName = "regionsfiltre", + FilterButtonText = "Regioner og havområder" + }; + } + + public class RedlistHabitats + { + public static readonly FilterItem[] RedlistSpecies2021HabitatFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Habitats = new() + { + Filters = RedlistSpecies2021HabitatFilters, + FilterDescription = "", + FilterButtonName = "habitatfiltre", + FilterButtonText = "Hovedhabitat" + }; + } + + public class RedlistTaxonRank + { + public static readonly FilterItem[] RedlistSpecies2021TaxonRankFilters = Enum.GetValues() + .Select(x => new FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly FilterAndMetaData RedlistSpecies2021Habitats = new() + { + Filters = RedlistSpecies2021TaxonRankFilters, + FilterDescription = "", + FilterButtonName = "taksonomisknivåfiltre", + FilterButtonText = "Taksonomisk nivå" + }; + } + + public class RedlistSpeciesGroups + { + private static readonly FilterItem[] RedlistSpecies2021Insects = + { + new() + { + Name = "Biller", + NameShort = "Biller", + }, + new() + { + Name = "Døgnfluer", + NameShort = "Døgnfluer", + }, + new() + { + Name = "Kakerlakker", + NameShort = "Kakerlakker", + }, + new() + { + Name = "Kamelhalsfluer", + NameShort = "Kamelhalsfluer", + }, + new() + { + Name = "Mudderfluer", + NameShort = "Mudderfluer", + }, + new() + { + Name = "Nebbfluer", + NameShort = "Nebbfluer", + }, + new() + { + Name = "Nebbmunner", + NameShort = "Nebbmunner", + }, + new() + { + Name = "Nettvinger", + NameShort = "Nettvinger", + }, + new() + { + Name = "Rettvinger", + NameShort = "Rettvinger", + }, + new() + { + Name = "Saksedyr", + NameShort = "Saksedyr", + }, + new() + { + Name = "Sommerfugler", + NameShort = "Sommerfugler", + }, + new() + { + Name = "Steinfluer", + NameShort = "Steinfluer", + }, + new() + { + Name = "Tovinger", + NameShort = "Tovinger", + }, + new() + { + Name = "Vepser", + NameShort = "Vepser", + }, + new() + { + Name = "Vårfluer", + NameShort = "Vårfluer", + }, + new() + { + Name = "Øyenstikkere", + NameShort = "Øyenstikkere", + } + }; + + public static readonly FilterItem[] RedlistSpecies2021SpeciesGroupsFilters = + { + new() + { + Name = "Alger", + NameShort = "Alger", + }, + new() + { + Name = "Amfibier og reptiler", + NameShort = "Amfibier og reptiler", + }, + new() + { + Name = "Armfotinger", + NameShort = "Armfotinger", + }, + new() + { + Name = "Bløtdyr", + NameShort = "Bløtdyr", + }, + new() + { + Name = "Edderkoppdyr", + NameShort = "Edderkoppdyr", + }, + new() + { + Name = "Fisker", + NameShort = "Fisker", + }, + new() + { + Name = "Fugler", + NameShort = "Fugler", + }, + new() + { + Name = "Hydrozoer", + NameShort = "Hydrozoer", + }, + new() + { + Name = "Insekter", + NameShort = "Insekter", + SubGroup = new() + { + Filters = RedlistSpecies2021Insects, + FilterDescription = "" + } + }, + new() + { + Name = "Karplanter", + NameShort = "Karplanter", + }, + new() + { + Name = "Koralldyr", + NameShort = "Koralldyr", + }, + new() + { + Name = "Krepsdyr", + NameShort = "Krepsdyr", + }, + new() + { + Name = "Larver", + NameShort = "Larver", + }, + new() + { + Name = "Leddormer", + NameShort = "Leddormer", + }, + new() + { + Name = "Mangefotinger", + NameShort = "Mangefotinger", + }, + new() + { + Name = "Mosdyr", + NameShort = "Mosdyr", + }, + new() + { + Name = "Moser", + NameShort = "Moser", + }, + new() + { + Name = "Pattedyr", + NameShort = "Pattedyr", + }, + new() + { + Name = "Pigghuder", + NameShort = "Pigghuder", + }, + new() + { + Name = "Sekkdyr", + NameShort = "Sekkdyr", + }, + new() + { + Name = "Sopper", + NameShort = "Sopper", + }, + new() + { + Name = "Spretthaler", + NameShort = "Spretthaler", + }, + new() + { + Name = "Stormaneter", + NameShort = "Stormaneter", + }, + new() + { + Name = "Svamper", + NameShort = "Svamper", + }, + }; + + public static readonly FilterAndMetaData RedlistSpecies2021SpeciesGroups = new() + { + Filters = RedlistSpecies2021SpeciesGroupsFilters, + FilterDescription = "", + FilterButtonName = "artsgruppefiltre", + FilterButtonText = "Artsgruppe" + }; + } + + public class PresumedExtinct + { + public static readonly FilterItem[] RedlistSpecies2021PresumedExtinctFilters = + { + new() + { + Name = "Trolig utdødd", + NameShort = "True", + }, + }; + + public static readonly FilterAndMetaData RedlistSpecies2021PresumedExtinct = new() + { + Filters = RedlistSpecies2021PresumedExtinctFilters, + FilterDescription = "", + FilterButtonName = "utdøddfiltre", + FilterButtonText = "Trolig utdødd" + }; + } +} diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs new file mode 100644 index 000000000..cff069997 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs @@ -0,0 +1,187 @@ +using Assessments.Frontend.Web.Models; +using DocumentFormat.OpenXml.Spreadsheet; +using System; +using System.Linq; +using static Assessments.Frontend.Web.Infrastructure.Constants; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies +{ + public static class RedlistSpeciesFilterHelpers + { + public static string GetActiveFilters(string filterType, RL2021ViewModel Model) + { + switch (filterType) + { + case "Area": + if (Model.Area?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.Area.Contains(nameof(Model.Area))) + return $"{Model.Area.Length - 1}"; + return $"{Model.Area.Length}"; + } + return string.Empty; + case "Category": + if (Model.Category?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.Category.Contains(nameof(Model.Category))) + return $"{Model.Category.Length - 1}"; + return $"{Model.Category.Length}"; + } + return string.Empty; + case "TaxonRank": + if (Model.TaxonRank?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.TaxonRank.Contains(nameof(Model.TaxonRank))) + return $"{Model.TaxonRank.Length - 1}"; + return $"{Model.TaxonRank.Length}"; + } + return string.Empty; + case "SpeciesGroups": + if (Model.SpeciesGroups?.Any() == true) + { + var count = Model.SpeciesGroups.Length; + if (Model.SpeciesGroups.Contains("Insekter")) + count--; + if (Model.SpeciesGroups.Contains(nameof(Model.SpeciesGroups))) + count--; + return $"{count}"; + } + return string.Empty; + case "Habitats": + if (Model.Habitats?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.Habitats.Contains(nameof(Model.Habitats))) + return $"{Model.Habitats.Length - 1}"; + return $"{Model.Habitats.Length}"; + } + return string.Empty; + case "Regions": + if (Model.Regions?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.Regions.Contains(nameof(Model.Regions))) + return $"{Model.Regions.Length - 1}"; + return $"{Model.Regions.Length}"; + } + return string.Empty; + case "EuroPop": + if (Model.EuroPop?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.EuroPop.Contains(nameof(Model.EuroPop))) + return $"{Model.EuroPop.Length - 1}"; + return $"{Model.EuroPop.Length}"; + } + return string.Empty; + case "Criterias": + if (Model.Criterias?.Any() == true) + { + // Removes the value added by "mark all" + if (Model.Criterias.Contains(nameof(Model.Criterias))) + return $"{Model.Criterias.Length - 1}"; + return $"{Model.Criterias.Length}"; + } + return string.Empty; + case "PresumedExtinct": + if (Model.PresumedExtinct == true) + return $"1"; + return string.Empty; + default: + return string.Empty; + } + } + + public static string GetChipText(string filter, FilterItem[] filterItems) + { + for (int i = 0; i < filterItems.Length; i++) + { + FilterItem item = filterItems[i]; + if (item.NameShort == filter) + { + return item.Name; + } + else if (item.SubGroup != null) + { + string buttonText = GetChipText(filter, item.SubGroup.Filters); + if (!string.IsNullOrEmpty(buttonText)) + return buttonText; + } + } + return String.Empty; + } + + public static string GetActiveSelection(RL2021ViewModel Model) + { + if (!string.IsNullOrEmpty(Model.Name)) + { + return $"{Model.Name}"; + } + return string.Empty; + } + + public static int GetActiveSelectionCount(RL2021ViewModel Model) + { + int count = 0; + count += Model.Area.Length; + count += Model.Category.Length; + count += Model.SpeciesGroups.Length; + count += Model.TaxonRank.Length; + count += Model.Habitats.Length; + count += Model.Regions.Length; + count += Model.EuroPop.Length; + count += Model.Criterias.Length; + if (Model.PresumedExtinct) + count++; + + return count; + } + + public static string[] GetActiveSelectionElement(RL2021ViewModel Model) + { + var selectionlist = Model.Area; + selectionlist = selectionlist.Concat(Model.Category).ToArray(); + selectionlist = selectionlist.Concat(Model.SpeciesGroups).ToArray(); + selectionlist = selectionlist.Concat(Model.TaxonRank).ToArray(); + selectionlist = selectionlist.Concat(Model.Habitats).ToArray(); + selectionlist = selectionlist.Concat(Model.Regions).ToArray(); + selectionlist = selectionlist.Concat(Model.EuroPop).ToArray(); + selectionlist = selectionlist.Concat(Model.Criterias).ToArray(); + if (Model.PresumedExtinct) + { + string[] PresumedExtinct = new string[] { "Antatt utd�dd" }; + selectionlist = selectionlist.Concat(PresumedExtinct).ToArray(); + } + return selectionlist; + } + + public static string[] GetActiveSelectionElement(AlienSpeciesListParameters parameters) + { + var selectionlist = parameters.Area; + selectionlist = selectionlist.Concat(parameters.Category).ToArray(); + selectionlist = selectionlist.Concat(parameters.EcologicalEffect).ToArray(); + selectionlist = selectionlist.Concat(parameters.Environment).ToArray(); + selectionlist = selectionlist.Concat(parameters.NatureTypes).ToArray(); + selectionlist = selectionlist.Concat(parameters.InvasionPotential).ToArray(); + selectionlist = selectionlist.Concat(parameters.CategoryChanged).ToArray(); + selectionlist = selectionlist.Concat(parameters.DecisiveCriterias).ToArray(); + selectionlist = selectionlist.Concat(parameters.SpeciesStatus).ToArray(); + selectionlist = selectionlist.Concat(parameters.NotAssessed).ToArray(); + selectionlist = selectionlist.Concat(parameters.ProductionSpecies).ToArray(); + selectionlist = selectionlist.Concat(parameters.SpeciesGroups).ToArray(); + selectionlist = selectionlist.Concat(parameters.SpreadWays).ToArray(); + selectionlist = selectionlist.Concat(parameters.TaxonRank).ToArray(); + selectionlist = selectionlist.Concat(parameters.Habitats).ToArray(); + selectionlist = selectionlist.Concat(parameters.RegionallyAlien).ToArray(); + selectionlist = selectionlist.Concat(parameters.Regions).ToArray(); + selectionlist = selectionlist.Concat(parameters.Criterias).ToArray(); + selectionlist = selectionlist.Concat(parameters.GeographicVariations).ToArray(); + selectionlist = selectionlist.Concat(parameters.ClimateEffects).ToArray(); + return selectionlist; + } + } +} diff --git a/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml b/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml index 05618fb81..8e529df6a 100644 --- a/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml +++ b/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml @@ -3,6 +3,8 @@ @using System.Linq; @using Assessments.Shared.Options @using Microsoft.Extensions.Options +@using Assessments.Frontend.Web.Infrastructure +@using static Assessments.Frontend.Web.Infrastructure.FilterHelpers @inject IOptions Options @@ -84,7 +86,7 @@ } - void MakeFilterGroup(string filterName, string modelName, bool isSubGroup, string[] filterModel, Filter.FilterAndMetaData filterItems, string buttonText, string buttonName, string outerClassName) + void MakeFilterGroup(string filterName, string modelName, bool isSubGroup, string[] filterModel, FilterAndMetaData filterItems, string buttonText, string buttonName, string outerClassName) { string className = isSubGroup ? $"filter_subgroup filter_{filterName.ToLower()}" : $"filter_{filterName.ToLower()}"; @@ -128,7 +130,7 @@ } - void MakeFilterGroup(string filterName, string[] filterModel, Filter.FilterAndMetaData filterItems) + void MakeFilterGroup(string filterName, string[] filterModel, FilterAndMetaData filterItems) { MakeFilterGroup(filterName, filterName, false, filterModel, filterItems, filterItems.FilterButtonText, filterItems.FilterButtonName, string.Empty); } @@ -141,19 +143,16 @@ close - - } - void MakeFilterChips(string[] filterModel, Filter.FilterItem[] filterItems) + void MakeFilterChips(string[] filterModel, FilterItem[] filterItems) { foreach (var filter in filterModel) { - string buttonText = GetChipText(filter, filterItems); + string buttonText = AlienSpeciesFilterHelpers.GetChipText(filter, filterItems); if (!string.IsNullOrEmpty(buttonText)) RenderChip(buttonText, filter); } - } } diff --git a/Assessments.Frontend.Web/Views/AlienSpecies/_ViewImports.cshtml b/Assessments.Frontend.Web/Views/AlienSpecies/_ViewImports.cshtml index 4c513ccc6..c18915d85 100644 --- a/Assessments.Frontend.Web/Views/AlienSpecies/_ViewImports.cshtml +++ b/Assessments.Frontend.Web/Views/AlienSpecies/_ViewImports.cshtml @@ -1,7 +1,8 @@ @using Assessments.Mapping.AlienSpecies.Model @using Assessments.Frontend.Web.Infrastructure.AlienSpecies; @using static Assessments.Frontend.Web.Infrastructure.Helpers; -@using static Assessments.Frontend.Web.Infrastructure.AlienSpecies.FilterHelpers; +@using static Assessments.Frontend.Web.Infrastructure.RedlistSpecies.RedlistSpeciesFilterHelpers; +@using static Assessments.Frontend.Web.Infrastructure.AlienSpecies.AlienSpeciesFilterHelpers; @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Assessments.Frontend.Web \ No newline at end of file diff --git a/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Criteria.cshtml b/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Criteria.cshtml index b65485a34..5f627d16a 100644 --- a/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Criteria.cshtml +++ b/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Criteria.cshtml @@ -100,7 +100,7 @@ Dictionary> criteria = ViewBag.kriterier.ToObject>>(); // CRITERIA SUMMARIZED SORTED BY SUBCRITERIA - var subcriteria = Criteria.sortCriteria(Model.CriteriaSummarized); + var subcriteria = CriteriaHelpers.sortCriteria(Model.CriteriaSummarized); string options = ""; if (subcriteria["B"].Contains("+")) { @@ -479,14 +479,14 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) @foreach (var (key, value) in criteria) { - string isactive = @Criteria.inString(key, @Model.CriteriaSummarized); + string isactive = CriteriaHelpers.inString(key, @Model.CriteriaSummarized); string valtitle = @Helpers.FixSpeciesLevel(value["title"].ToString(), Model.TaxonRank);
  • @{ expandOrBullet(true);} @key - @valtitle - @{ iconChooser(Criteria.inString(key, Model.CriteriaSummarized)); } + @{ iconChooser(CriteriaHelpers.inString(key, Model.CriteriaSummarized)); } @{ hasKey("description", @value);} @@ -502,7 +502,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) { string vtitle = @Helpers.FixSpeciesLevel(v["title"].ToString(), Model.TaxonRank); - var subcriteria_isactive = @Criteria.inString(k, subcriteria[key]); + var subcriteria_isactive = CriteriaHelpers.inString(k, subcriteria[key]);
  • @@ -522,7 +522,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) @if (v.ContainsKey("subsub")) { - string[] currentlist = Criteria.obtainSubCriteriaList(subcriteria[key].Split(";"), k); + string[] currentlist = CriteriaHelpers.obtainSubCriteriaList(subcriteria[key].Split(";"), k); var subdict = parseDictNested(@v["subsub"].ToString()); @if (currentlist.Length > 0) { @@ -537,13 +537,13 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) string subvaltitle = @Helpers.FixSpeciesLevel(subval["title"].ToString(), Model.TaxonRank); string modelkey = k + subkey; -
  • +
  • @{expandOrBullet(false);} - @subkey - @subvaltitle @{ iconChooser(Criteria.inList(subkey, currentlist)); } + @subkey - @subvaltitle @{ iconChooser(CriteriaHelpers.inList(subkey, currentlist)); } @{ getQuantile(subval, modelkey, modelkey);} @@ -567,7 +567,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) if (key == "C") {
      - @{var activeC = @Criteria.inString("C", @Model.CriteriaSummarized); } + @{var activeC = CriteriaHelpers.inString("C", @Model.CriteriaSummarized); }
    • @@ -621,7 +621,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) @if (@value.ContainsKey("options")) {
        -
      • +
      • @@ -639,7 +639,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) @foreach (var (k, v) in thesubcriteria) { string vtitle = @v["title"].ToString(); - var subcriteria_isactive = @Criteria.inString(k, subcriteria[key]); + var subcriteria_isactive = CriteriaHelpers.inString(k, subcriteria[key]);
      • @@ -667,7 +667,7 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) } } current_element = current_element.Replace(k, ""); - current_element = Criteria.removeOuterParenthesis(current_element); + current_element = CriteriaHelpers.removeOuterParenthesis(current_element); var clean_list = current_element.Split(","); var subdict = parseDictNested(@v["sub"].ToString()); } @@ -681,14 +681,14 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT"))) { clickable = "clickable"; } -
      • +
      • @{expandOrBullet(clickable == "clickable");} @subkey - @Helpers.FixSpeciesLevel(vsubtitle, Model.TaxonRank) - @{ iconChooser(Criteria.inList(subkey, clean_list)); } + @{ iconChooser(CriteriaHelpers.inList(subkey, clean_list)); } @@ -708,8 +708,8 @@ Model.Category.Contains("VU") || Model.Category.Contains("NT")))
        - @{var activeB = @Criteria.inString("B", @Model.CriteriaSummarized); } -
      • + @{var activeB = CriteriaHelpers.inString("B", @Model.CriteriaSummarized); } +
      • diff --git a/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Ingress.cshtml b/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Ingress.cshtml index 252593637..d7f98c799 100644 --- a/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Ingress.cshtml +++ b/Assessments.Frontend.Web/Views/Redlist/Species/2021/Assessment/partials/_Ingress.cshtml @@ -1,7 +1,7 @@ @model SpeciesAssessment2021 @{ // Obtain which criteria are used and their titles. - var subcriteria = Criteria.sortCriteria(Model.CriteriaSummarized); + var subcriteria = CriteriaHelpers.sortCriteria(Model.CriteriaSummarized); string sentence = String.Empty; string[] cri = { "A", "B", "C", "D" }; diff --git a/Assessments.Frontend.Web/Views/Redlist/Species/2021/List/partials/_Filters.cshtml b/Assessments.Frontend.Web/Views/Redlist/Species/2021/List/partials/_Filters.cshtml index 8fb9f490c..3d14e4181 100644 --- a/Assessments.Frontend.Web/Views/Redlist/Species/2021/List/partials/_Filters.cshtml +++ b/Assessments.Frontend.Web/Views/Redlist/Species/2021/List/partials/_Filters.cshtml @@ -1,18 +1,20 @@ @model RL2021ViewModel; @using static Assessments.Frontend.Web.Infrastructure.Constants; @using static Assessments.Frontend.Web.Infrastructure.Helpers; +@using Assessments.Frontend.Web.Infrastructure.RedlistSpecies; +@using Assessments.Frontend.Web.Infrastructure; @using System.Linq; @{ - var AllAreas = ViewBag.AllAreas; - Dictionary> AllCategories = ViewBag.categories.ToObject>>(); - var AllCriterias = ViewBag.AllCriterias; - var AllEuroPop = ViewBag.AllEuroPop; - var AllRegions = ViewBag.AllRegions; - Dictionary> AllHabitats = ViewBag.habitat.ToObject>>(); - var AllTaxonRanks = ViewBag.AllTaxonRanks; - string[] AllSpeciesGroups = ViewBag.AllSpeciesGroups; - string[] AllInsects = ViewBag.AllInsects; + var AllAreas = RedlistAreas.RedlistSpecies2021Areas; + var AllCategories = RedlistCategories.RedlistSpecies2021Categories; + var AllCriterias = RedlistCriteria.RedlistSpecies2021Criteria; + var AllEuroPop = RedlistEuropeanPopulation.RedlistSpecies2021EuropeanPopulation; + var AllRegions = RedlistRegions.RedlistSpecies2021Regions; + var AllHabitats = RedlistHabitats.RedlistSpecies2021Habitats; + var AllTaxonRanks = RedlistTaxonRank.RedlistSpecies2021Habitats; + var AllSpeciesGroups = RedlistSpeciesGroups.RedlistSpecies2021SpeciesGroups; + var AllPresumedExtinct = PresumedExtinct.RedlistSpecies2021PresumedExtinct; var startHit = Model.Redlist2021Results.PageNumber * 25 - 24; var endHit = startHit + @Model.Redlist2021Results.Count - 1; @@ -26,7 +28,7 @@ } @functions{ - void InputTag(string id, string _class, string name, string[] elements, string value) + void InputTag(string id, string className, string name, string[] elements, string value) { if (id == "remember_scroll") { @@ -35,133 +37,106 @@ value = item.Replace("scroll_", ""); } id = id.Replace(" ", "_"); - + } + void InputTag(string name, string[] elements, string value) { InputTag(value, "submitOnclick", name, elements, value); } - void getInsectsList(string[] insects) + + void MakeCheckBoxLi(string value, string label, string name, string[] model, string labelClassName, string inputClassName) { -
        -
          - @foreach (var insect in insects) - { -
        • - -
        • - } -
        -
        - } - void makeCheckBoxLi(string key, string value, string name, string[] model) - { - string id= key.Replace(" ", "_"); + string id = value.Replace(" ", "_");
      • -
      • } - void makeFilterElement(string buttontext, string filtername, string action, string id, string buttonname, string numbername) + + void MakeFilterElement(string buttonText, string filterName, string buttonname) { - InputTag(action, "collapse_checkbox", "IsCheck", Model.IsCheck, filtername); + string action = $"show_{filterName.ToLower()}"; + string id = $"list_header_{filterName.ToLower()}"; + + InputTag(action, "collapse_checkbox", "IsCheck", Model.IsCheck, filterName); } - void makeFilterGroup(bool swap, string groupclassname, string name, dynamic modelname, dynamic looplist, string buttontext, string filtername, string action, string id, string buttonname, string numbername) + + void MakeFilterGroup(string filterName, string modelName, bool isSubGroup, string[] filterModel, FilterHelpers.FilterAndMetaData filterItems, string buttonText, string buttonName, string outerClassName) { + string className = isSubGroup ? $"filter_subgroup filter_{filterName.ToLower()}" : $"filter_{filterName.ToLower()}"; +
      • - @{makeFilterElement(buttontext, filtername, action, id, buttonname, numbername);} -
        -
          - @foreach (var el in looplist) + @{ + MakeFilterElement(buttonText, filterName, buttonName); + } +
          + @{ + if (!string.IsNullOrEmpty(filterItems.FilterDescription)) { - var value = el.Value; - var key = el.Key; - if (swap) // Seriously. Why. - { - value = el.Key; - key = el.Value; - } - if (name == "Criterias") - { - key = el.Key + " - " + el.Value; - } - else if (name == "Habitats") +
          @filterItems.FilterDescription
          + } + } +
            + @{ + string label; + string value; + string markAllClassName = "mark_all"; + + if (filterItems.Filters.Length > 4) + MakeCheckBoxLi(filterName, "Merk alle", modelName, filterModel, markAllClassName, outerClassName); + + foreach (var el in filterItems.Filters) { - key = key["shortname"]; + value = el.NameShort; + label = (filterName == nameof(Model.Category) && value != "RED" && value != "END") ? $"{el.NameShort} - {el.Description}" : el.Name; + string extraOuterClassName = $"{outerClassName} {filterName}_input"; + if (el.SubGroup != null) + { + MakeFilterGroup(el.NameShort, modelName, true, filterModel, el.SubGroup, el.Name, $"{el.Name}filtre", extraOuterClassName); + } + else + { + MakeCheckBoxLi(value, label, modelName, filterModel, string.Empty, extraOuterClassName); + } } - makeCheckBoxLi(value, key, name, modelname); }
          } - void makeSuperChips(bool swap, string name, dynamic modelname, dynamic looplist) - { - @foreach (var el in looplist) - { - dynamic value = el; - dynamic key = el; - if (name != "SpeciesGroups" && name != "PresumedExtinct") - { - if (swap) - { - value = el.Key; - key = el.Value; - } - else - { - value = el.Value; - key = el.Key; - } - } - string labelname = value; - if(name == "PresumedExtinct") - { - labelname = "PresumedExtinct"; - } - if (name == "Criterias") - { - key = el.Key + " - " + el.Value; - } - else if (name == "Habitats") - { - key = key["shortname"]; - } - else if (name == "Category") - { - key = key["presentationstring"]; - labelname = "input_" + value; - } + void MakeFilterGroup(string filterName, string[] filterModel, FilterHelpers.FilterAndMetaData filterItems) + { + MakeFilterGroup(filterName, filterName, false, filterModel, filterItems, filterItems.FilterButtonText, filterItems.FilterButtonName, string.Empty); + } - @foreach (string element in modelname) - { - if (element == value) - { - makeChips(key, "generic", labelname); - } - } - } + void RenderChip(string buttontext, string filterValue) + { +
        • + @buttontext + +
        • } - void makeChips(string buttontext, string className,string value) + + void MakeFilterChips(string[] filterModel, FilterHelpers.FilterItem[] filterItems) { -
        • - @buttontext - -
        • + foreach (var filter in filterModel) + { + string buttonText = RedlistSpeciesFilterHelpers.GetChipText(filter, filterItems); + if (!string.IsNullOrEmpty(buttonText)) + RenderChip(buttonText, filter); + } } } @@ -169,54 +144,48 @@

          - @if (Filter.GetActiveSelectionCount(Model) != 0 -|| !string.IsNullOrEmpty(Filter.GetActiveSelection(Model))) + @if (RedlistSpeciesFilterHelpers.GetActiveSelectionCount(Model) != 0 +|| !string.IsNullOrEmpty(RedlistSpeciesFilterHelpers.GetActiveSelection(Model))) { - @if (!string.IsNullOrEmpty(Filter.GetActiveSelection(Model))) + @if (!string.IsNullOrEmpty(RedlistSpeciesFilterHelpers.GetActiveSelection(Model))) { - string searchstring = "Viser treff for " + '"' + @Filter.GetActiveSelection(Model) + '"'; + string searchstring = "Viser treff for " + '"' + RedlistSpeciesFilterHelpers.GetActiveSelection(Model) + '"'; @searchstring } - -

            - @if (Filter.GetActiveSelectionCount(Model) > 0) - { - var allFilterElements = Filter.GetActiveSelectionElement(Model); - makeSuperChips(false, "Area", allFilterElements, AllAreas); - makeSuperChips(true, "Category", Model.Category, AllCategories); - makeSuperChips(false, "SpeciesGroups", Model.SpeciesGroups, AllSpeciesGroups); - makeSuperChips(false, "SpeciesGroups", Model.SpeciesGroups, AllInsects); - makeSuperChips(true, "TaxonRank", Model.TaxonRank, AllTaxonRanks); - makeSuperChips(true, "Habitats", Model.Habitats, AllHabitats); - makeSuperChips(true, "Regions", Model.Regions, AllRegions); - makeSuperChips(true, "EuroPop", Model.EuroPop, AllEuroPop); - makeSuperChips(true, "Criterias", Model.Criterias, AllCriterias); - - if (Model.PresumedExtinct) +
            +
              + @if (RedlistSpeciesFilterHelpers.GetActiveSelectionCount(Model) > 0) { - string[] PresumedExtinct = new string[] { "Antatt utdødd" }; - makeSuperChips(true, "PresumedExtinct", PresumedExtinct, PresumedExtinct); - } - } + MakeFilterChips(Model.Area, AllAreas.Filters); + MakeFilterChips(Model.Category, AllCategories.Filters); + MakeFilterChips(Model.SpeciesGroups, AllSpeciesGroups.Filters); + MakeFilterChips(Model.TaxonRank, AllTaxonRanks.Filters); + MakeFilterChips(Model.Habitats, AllHabitats.Filters); + MakeFilterChips(Model.Regions, AllRegions.Filters); + MakeFilterChips(Model.EuroPop, AllEuroPop.Filters); + MakeFilterChips(Model.Criterias, AllCriterias.Filters); + MakeFilterChips(new string[]{ Model.PresumedExtinct.ToString()}, AllPresumedExtinct.Filters); + }
            - @{string buttontext = @Filter.GetActiveSelectionCount(Model) + " filter"; } - @if(Filter.GetActiveSelectionCount(Model) > 1) + @{ + string buttontext = RedlistSpeciesFilterHelpers.GetActiveSelectionCount(Model) + " filter"; + } + @if (RedlistSpeciesFilterHelpers.GetActiveSelectionCount(Model) > 1) { buttontext.Replace("filter", "filtre"); } - +
            }

            -
          @@ -225,9 +194,9 @@ Sorter etter:
          @@ -259,101 +228,20 @@
            - @{makeFilterGroup(false, "filter_area", "Area", Model.Area, AllAreas, @SearchAndFilter.SearchChooseArea, "Area", "show_area", "list_header_area", "områdefiltre", "Area");} - -
          • - @{makeFilterElement(@SearchAndFilter.SearchChooseCategory, "Category", "show_category", "list_header_category", "kategorifiltre", "Category");} -
            -
              - @foreach (var category in AllCategories) - { -
            • - -
            • - } - -
            • - -
            • -
            • - -
            • -
            -
            -
          • - @{makeFilterGroup(true, "filter_taxon_rank", "TaxonRank", Model.TaxonRank, AllTaxonRanks, @SearchAndFilter.SearchFilterTaxonRank, "TaxonRank", "show_taxon_rank", "list_header_taxon_rank", "'taksonomisk nivå'-filtre", "TaxonRank");} - -
          • - @{makeFilterElement("Artsgruppe", "SpeciesGroups", "show_species_groups", "list_header_species_groups", "artsgruppefiltre", "SpeciesGroups");} -
            -
              - @foreach (var species in AllSpeciesGroups) - { - @if (species == "Insekter") - { -
            • - @{ InputTag("show_insects", "collapse_checkbox", "IsCheck", Model.IsCheck, "Insects"); } - - @{ getInsectsList(AllInsects); } -
            • - } - else - { - makeCheckBoxLi(@species, @species, "SpeciesGroups", Model.SpeciesGroups); - } - } -
            -
            -
          • @{ - makeFilterGroup(true, "filter_habitat", "Habitats", Model.Habitats, AllHabitats, "Hovedhabitat", "Habitat", "show_habitat", "list_header_habitat", "hovedhabitatfiltre", "Habitats"); - makeFilterGroup(true, "filter_region", "Regions", Model.Regions, AllRegions, "Regioner og havområder", "Region", "show_region", "list_header_region", "regionfiltre", "Regions"); - makeFilterGroup(true, "filter_european_population", "EuroPop", Model.EuroPop, AllEuroPop, "Andel av europeisk populasjon", "EuroPop", "show_european_population", "list_header_european_population", "'andel av europeisk populasjon'-filtre", "EuroPop"); - makeFilterGroup(true, "filter_criteria", "Criterias", Model.Criterias, AllCriterias, @SearchAndFilter.SearchChooseCriteria, "Criteria", "show_criteria", "list_header_criteria", "kriteriefiltre", "Criterias"); + MakeFilterGroup(nameof(Model.Area), Model.Area, AllAreas); + MakeFilterGroup(nameof(Model.Category), Model.Category, AllCategories); + MakeFilterGroup(nameof(Model.TaxonRank), Model.TaxonRank, AllTaxonRanks); + MakeFilterGroup(nameof(Model.SpeciesGroups), Model.SpeciesGroups, AllSpeciesGroups); + MakeFilterGroup(nameof(Model.Habitats), Model.Habitats, AllHabitats); + MakeFilterGroup(nameof(Model.Regions), Model.Regions, AllRegions); + MakeFilterGroup(nameof(Model.EuroPop), Model.EuroPop, AllEuroPop); + MakeFilterGroup(nameof(Model.Criterias), Model.Criterias, AllCriterias); + MakeFilterGroup(nameof(Model.PresumedExtinct), new string[] { Model.PresumedExtinct.ToString() }, AllPresumedExtinct); } - -
          • - @{ InputTag("show_extinct", "collapse_checkbox", "IsCheck", Model.IsCheck, "Extinct");} - -
            -
              -
            • - -
            • -
            -
            -
          - +
        diff --git a/Assessments.Frontend.Web/Views/Shared/_ListView.cshtml b/Assessments.Frontend.Web/Views/Shared/_ListView.cshtml index 8635fa502..4f7fd4a01 100644 --- a/Assessments.Frontend.Web/Views/Shared/_ListView.cshtml +++ b/Assessments.Frontend.Web/Views/Shared/_ListView.cshtml @@ -13,7 +13,7 @@ Kategori
      • - @if (Model.Results.Count > 0) + @if (Model.Results?.Count > 0) { @foreach (var item in Model.Results) { diff --git a/Assessments.Frontend.Web/Views/_ViewImports.cshtml b/Assessments.Frontend.Web/Views/_ViewImports.cshtml index 49e7c4b33..b33b8b961 100644 --- a/Assessments.Frontend.Web/Views/_ViewImports.cshtml +++ b/Assessments.Frontend.Web/Views/_ViewImports.cshtml @@ -1,6 +1,7 @@ @using Assessments.Frontend.Web @using Assessments.Frontend.Web.Models @using Assessments.Frontend.Web.Infrastructure +@using Assessments.Frontend.Web.Infrastructure.RedlistSpecies; @using Assessments.Mapping.RedlistSpecies @using Assessments.Mapping.AlienSpecies @using Assessments.Shared.Helpers diff --git a/Assessments.Frontend.Web/wwwroot/css/filter.css b/Assessments.Frontend.Web/wwwroot/css/filter.css index b211526dd..7068dd9ba 100644 --- a/Assessments.Frontend.Web/wwwroot/css/filter.css +++ b/Assessments.Frontend.Web/wwwroot/css/filter.css @@ -275,23 +275,19 @@ li.checkbox label { } .filter_groups ul.Alger_filters, -.filter_groups ul.insect_filters, .filter_groups ul.Insekter_filters, .filter_groups ul.Krepsdyr_filters { padding-right: 0; } -div.filter_insects, div.filter_subgroup { margin-left: 15px; } -.list_header, -.list_header_insects { +.list_header { background-color: transparent; } -.filter_insects, .filter_subgroup, .mark_all { border-bottom: 1px solid lightgray; @@ -303,10 +299,6 @@ label.switch_list_element { margin: 5px 0; } -#list_header_insects { - padding-right: 3px; -} - .list_header_text { display: flex; flex-direction: row; @@ -337,10 +329,6 @@ button.list_header { padding-right: 5px; } -#show_all_insects { - display: none; -} - @media only screen and (max-width: 750px) { .show_filters { @@ -396,15 +384,9 @@ button.list_header { text-align: center; } - .filter_insects, .filter_subgroup { margin-bottom: 10px; } - - #show_all_insects { - display: inline-block; - white-space: nowrap; - } } .collapse_checkbox, @@ -598,9 +580,9 @@ button.list_header { .only_js .filter_regionallyalien, .only_js .filter_regions, .only_js .filter_waterregions, -.only_js .filter_european_population, -.only_js .filter_criteria, -.only_js .filter_extinct, +.only_js .filter_europop, +.only_js .filter_criterias, +.only_js .filter_presumedextinct, .only_js .filter_habitat, .only_js .filter_habitats, .only_js .filter_species_groups, @@ -622,7 +604,7 @@ button.list_header { .only_js input[type=checkbox]:not(:checked)#show_dcok ~ .filter_subgroup, .only_js input[type=checkbox]:not(:checked)#show_dcipah ~ .filter_subgroup, .only_js input[type=checkbox]:not(:checked)#show_eds ~ .filter_subgroup, -.only_js input[type=checkbox]:not(:checked)#show_insects ~ .filter_insects, +.only_js input[type=checkbox]:not(:checked)#show_insekter ~ .filter_subgroup, .only_js input[type=checkbox]:not(:checked)#show_sal ~ .filter_subgroup, .only_js input[type=checkbox]:not(:checked)#show_sin ~ .filter_subgroup, .only_js input[type=checkbox]:not(:checked)#show_skr ~ .filter_subgroup, @@ -648,12 +630,12 @@ button.list_header { .only_js input[type=checkbox]:not(:checked)#show_regionallyalien ~ .filter_regionallyalien, .only_js input[type=checkbox]:not(:checked)#show_regions ~ .filter_regions, .only_js input[type=checkbox]:not(:checked)#show_waterregions ~ .filter_waterregions, -.only_js input[type=checkbox]:not(:checked)#show_european_population ~ .filter_european_population, -.only_js input[type=checkbox]:not(:checked)#show_criteria ~ .filter_criteria, +.only_js input[type=checkbox]:not(:checked)#show_europop ~ .filter_europop, +.only_js input[type=checkbox]:not(:checked)#show_criterias ~ .filter_criterias, .only_js input[type=checkbox]:not(:checked)#show_speciesstatus ~ .filter_speciesstatus, .only_js input[type=checkbox]:not(:checked)#show_habitat ~ .filter_habitat, .only_js input[type=checkbox]:not(:checked)#show_habitats ~ .filter_habitats, -.only_js input[type=checkbox]:not(:checked)#show_extinct ~ .filter_extinct, +.only_js input[type=checkbox]:not(:checked)#show_presumedextinct ~ .filter_presumedextinct, .only_js input[type=checkbox]:not(:checked)#show_species_groups ~ .filter_species_groups, .only_js input[type=checkbox]:not(:checked)#show_speciesgroups ~ .filter_speciesgroups, .only_js input[type=checkbox]:not(:checked)#show_productionspecies ~ .filter_productionspecies, diff --git a/Assessments.Frontend.Web/wwwroot/js/filter.js b/Assessments.Frontend.Web/wwwroot/js/filter.js index 6721a417f..fc040424b 100644 --- a/Assessments.Frontend.Web/wwwroot/js/filter.js +++ b/Assessments.Frontend.Web/wwwroot/js/filter.js @@ -6,10 +6,8 @@ const filters = document.getElementById("filters"); if (filters) { const isCheckInputs = document.getElementsByClassName("collapse_checkbox"); - const insectFilters = document.getElementsByClassName("insect_input"); - const insectInput = document.getElementById("Insekter"); - const redlistCheckbox = document.getElementById("redlisted_check"); - const endangeredCheckbox = document.getElementById("endangered_check"); + const redlistCheckbox = document.getElementById("RED"); + const endangeredCheckbox = document.getElementById("END"); const init = document.getElementById("initial_check"); const scrollTo = document.getElementById("remember_scroll"); @@ -26,7 +24,7 @@ if (filters) { "show_eds", "show_sal", "show_ccke", - "show_insects", + "show_insekter", "show_skr", "show_sin", "show_ttn", @@ -35,7 +33,6 @@ if (filters) { "show_swimp", "show_swnat", "show_swspr", - "show_taxonrank", "show_nta", "show_ntn", ]; @@ -190,7 +187,7 @@ if (filters) { function shouldToggleMarkRedOrEnd(list) { return Array.prototype.every.call(list, (item) => { - return document.getElementById("input_" + item)?.checked === true; + return document.getElementById(item)?.checked === true; }) } @@ -203,9 +200,6 @@ if (filters) { }); } // redlist species 2021 - if (shouldToggleMarkAll("insect_input")) { - insectInput.checked = true; - } if (shouldToggleMarkRedOrEnd(redlisted)) { redlistCheckbox.checked = true; } @@ -219,22 +213,23 @@ if (filters) { const primaryToggleElement = document.getElementById(primaryToggleElementId).checked; what.forEach(el => { if (primaryToggleElement) { - document.getElementById("input_" + el).checked = true; + document.getElementById(el).checked = true; } else { if (secondaryToggleElement) { document.getElementById(secondaryToggleElementId).checked = false; } - document.getElementById("input_" + el).checked = false; + document.getElementById(el).checked = false; } }) + allChildrenMarkedTriggerMarkAll(); } function toggleRedlistedCategories() { - toggleAllOfType(redlisted, "redlisted_check", "endangered_check"); + toggleAllOfType(redlisted, "RED", "END"); } function toggleEndangeredCategories() { - toggleAllOfType(endangered, "endangered_check", "redlisted_check"); + toggleAllOfType(endangered, "END", "RED"); } function toggleSubGroup(filters, input) { @@ -263,32 +258,29 @@ if (filters) { } const classNames = Array.prototype.filter.call(el.classList, name => name.indexOf('_input') != -1); - if (classNames.length && !classNames.includes('insect_input')) { + if (classNames.length) { classNames.forEach(name => { const idIndex = name.indexOf('_input'); const filterId = name.substring(0, idIndex); toggleSingleFilter(el, filterId); }) } + // redlist species 2021 - else if (el.classList[0] === "insect_input") { - toggleSingleFilter(el, "Insekter"); - } else if (endangered.some(category => el.id.indexOf(category) != -1)) { - toggleSingleFilter(el, "endangered_check"); - toggleSingleFilter(el, "redlisted_check"); + if (endangered.some(category => el.id.indexOf(category) != -1)) { + toggleSingleFilter(el, "END"); + toggleSingleFilter(el, "RED"); } else if (redlisted.some(category => el.id.indexOf(category) != -1)) { - toggleSingleFilter(el, "redlisted_check"); + toggleSingleFilter(el, "RED"); } } // Clickevents for the toggles function onClickAction(el, addOrRemove) { - if (el.id === "redlisted_check") { + if (el.id === "RED") { toggleRedlistedCategories(); - } else if (el.id === "endangered_check") { + } else if (el.id === "END") { toggleEndangeredCategories(); - } else if (el.id === "Insekter") { - toggleSubGroup(insectFilters, insectInput); } else { if (addOrRemove == "add") { updateToggleAll(el);