From 0c15b36f14662e86f7668e9ca0b897d80be5d6f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 15:29:39 +0100 Subject: [PATCH 01/18] move areas filter data to FilterItemHelper --- .../Controllers/RedlistController.cs | 1 - .../Infrastructure/Constants.cs | 6 ---- .../RedlistSpecies/FilterItemHelpers.cs | 32 +++++++++++++++++++ .../2021/List/partials/_Filters.cshtml | 2 +- .../Views/_ViewImports.cshtml | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index e36052bc3..8c02b1fd2 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -26,7 +26,6 @@ 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; diff --git a/Assessments.Frontend.Web/Infrastructure/Constants.cs b/Assessments.Frontend.Web/Infrastructure/Constants.cs index 9ede92871..919413dfb 100644 --- a/Assessments.Frontend.Web/Infrastructure/Constants.cs +++ b/Assessments.Frontend.Web/Infrastructure/Constants.cs @@ -8,12 +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"}, diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs new file mode 100644 index 000000000..4be97afe1 --- /dev/null +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -0,0 +1,32 @@ +using Assessments.Mapping.AlienSpecies.Model.Enums; +using Assessments.Shared.Helpers; +using System; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies +{ + public class Areas + { + public static readonly Filter.FilterItem[] RedlistSpecies2021AreasFilters = new Filter.FilterItem[] + { + new () + { + Name = "Norge", + NameShort = "N" + }, + new() { + Name = "Svalbard", + NameShort = "S" + } + }; + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Areas = new() + { + Filters = RedlistSpecies2021AreasFilters, + FilterDescription = "", + FilterButtonName = "områdefiltre", + FilterButtonText = "Område" + }; + } +} 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..5ddcb7190 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 @@ -4,7 +4,7 @@ @using System.Linq; @{ - var AllAreas = ViewBag.AllAreas; + var AllAreas = Areas.AlienSpecies2023Areas; Dictionary> AllCategories = ViewBag.categories.ToObject>>(); var AllCriterias = ViewBag.AllCriterias; var AllEuroPop = ViewBag.AllEuroPop; diff --git a/Assessments.Frontend.Web/Views/_ViewImports.cshtml b/Assessments.Frontend.Web/Views/_ViewImports.cshtml index 10639bd0e..034e56514 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.AlienSpecies; @using Assessments.Mapping.RedlistSpecies @using Assessments.Mapping.AlienSpecies @using Assessments.Shared.Helpers From 5474940c6c02cbf7dae8f9b3c0bbfea38f212f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 16:09:04 +0100 Subject: [PATCH 02/18] move categories filter data to FilterItemHelper --- .../Controllers/RedlistController.cs | 5 --- .../RedlistSpeciesAssessment2021Category.cs | 41 ++++++++++++++++++ ...tSpeciesAssessment2021EvaluationContext.cs | 13 ++++++ .../RedlistSpecies/FilterItemHelpers.cs | 42 ++++++++++++------- .../2021/List/partials/_Filters.cshtml | 2 +- 5 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Category.cs create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EvaluationContext.cs diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index 8c02b1fd2..f05b980e6 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -63,9 +63,6 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel ViewBag.habitat = await GetResource("wwwroot/json/habitat.json"); - ViewBag.categories = await GetResource("wwwroot/json/categories.json"); - - // Pagination const int pageSize = 25; var pageNumber = page ?? 1; @@ -98,8 +95,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)); 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/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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 4be97afe1..195e352ae 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -1,32 +1,46 @@ -using Assessments.Mapping.AlienSpecies.Model.Enums; +using Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums; +using Assessments.Mapping.AlienSpecies.Model.Enums; using Assessments.Shared.Helpers; using System; -using System.ComponentModel.DataAnnotations; using System.Linq; +using static Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums.Enums; namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies { public class Areas { - public static readonly Filter.FilterItem[] RedlistSpecies2021AreasFilters = new Filter.FilterItem[] - { - new () + public static readonly Filter.FilterItem[] RedlistSpecies2021AreasFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem { - Name = "Norge", - NameShort = "N" - }, - new() { - Name = "Svalbard", - NameShort = "S" - } - }; + Name = x.DisplayName(), + NameShort = x.ToString() + }).ToArray(); public static readonly Filter.FilterAndMetaData RedlistSpecies2021Areas = new() { Filters = RedlistSpecies2021AreasFilters, FilterDescription = "", FilterButtonName = "områdefiltre", - FilterButtonText = "Område" + FilterButtonText = "Vurderingsområde" + }; + } + + public class Categories + { + public static readonly Filter.FilterItem[] RedlistSpecies2021CategoriesFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Categories = new() + { + Filters = RedlistSpecies2021CategoriesFilters, + FilterDescription = "", + FilterButtonName = "kategorifiltre", + FilterButtonText = "Kategori" }; } } 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 5ddcb7190..e189da69d 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 @@ -5,7 +5,7 @@ @{ var AllAreas = Areas.AlienSpecies2023Areas; - Dictionary> AllCategories = ViewBag.categories.ToObject>>(); + var AllCategories = Categories.AlienSpecies2023Categories; var AllCriterias = ViewBag.AllCriterias; var AllEuroPop = ViewBag.AllEuroPop; var AllRegions = ViewBag.AllRegions; From a0db9b15e2f604809fa2c0d6ff7e8db6c6940fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 16:41:40 +0100 Subject: [PATCH 03/18] move criteria filter data to FilterItemHelper --- .../{Criteria.cs => CriteriaHelpers.cs} | 16 +++++----- .../RedlistSpeciesAssessment2021Criteria.cs | 19 ++++++++++++ .../RedlistSpecies/FilterItemHelpers.cs | 19 ++++++++++++ .../2021/Assessment/partials/_Criteria.cshtml | 30 +++++++++---------- .../2021/Assessment/partials/_Ingress.cshtml | 2 +- .../2021/List/partials/_Filters.cshtml | 6 ++-- .../Views/_ViewImports.cshtml | 2 +- 7 files changed, 66 insertions(+), 28 deletions(-) rename Assessments.Frontend.Web/Infrastructure/{Criteria.cs => CriteriaHelpers.cs} (86%) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Criteria.cs 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/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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 195e352ae..2110fd6e6 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -43,4 +43,23 @@ public class Categories FilterButtonText = "Kategori" }; } + + public class Criteria + { + public static readonly Filter.FilterItem[] RedlistSpecies2021CriteriaFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Criteria = new() + { + Filters = RedlistSpecies2021CriteriaFilters, + FilterDescription = "", + FilterButtonName = "kriteriefiltre", + FilterButtonText = "Kriterier" + }; + } } 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 e189da69d..706fdeb07 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 @@ -4,9 +4,9 @@ @using System.Linq; @{ - var AllAreas = Areas.AlienSpecies2023Areas; - var AllCategories = Categories.AlienSpecies2023Categories; - var AllCriterias = ViewBag.AllCriterias; + var AllAreas = Areas.RedlistSpecies2021Areas; + var AllCategories = Categories.RedlistSpecies2021Categories; + var AllCriterias = Criteria.RedlistSpecies2021Criteria; var AllEuroPop = ViewBag.AllEuroPop; var AllRegions = ViewBag.AllRegions; Dictionary> AllHabitats = ViewBag.habitat.ToObject>>(); diff --git a/Assessments.Frontend.Web/Views/_ViewImports.cshtml b/Assessments.Frontend.Web/Views/_ViewImports.cshtml index 034e56514..0934de71c 100644 --- a/Assessments.Frontend.Web/Views/_ViewImports.cshtml +++ b/Assessments.Frontend.Web/Views/_ViewImports.cshtml @@ -1,7 +1,7 @@ @using Assessments.Frontend.Web @using Assessments.Frontend.Web.Models @using Assessments.Frontend.Web.Infrastructure -@using Assessments.Frontend.Web.Infrastructure.AlienSpecies; +@using Assessments.Frontend.Web.Infrastructure.RedlistSpecies; @using Assessments.Mapping.RedlistSpecies @using Assessments.Mapping.AlienSpecies @using Assessments.Shared.Helpers From 0cd86e5a9d7ddb3096dc33beac943f66adf3a3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 16:44:13 +0100 Subject: [PATCH 04/18] remove criteria from constants --- Assessments.Frontend.Web/Controllers/RedlistController.cs | 3 --- Assessments.Frontend.Web/Infrastructure/Constants.cs | 8 -------- .../Infrastructure/RedlistSpecies/FilterItemHelpers.cs | 2 -- 3 files changed, 13 deletions(-) diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index f05b980e6..7426e92ee 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -26,7 +26,6 @@ public RedlistController(ArtskartApiService artskartApiService) public IActionResult RodlisteForArter() => View("Species/Rodlisteforarter"); private static readonly Dictionary _resourceCache = new(); - private static readonly Dictionary _allCriterias = Constants.AllCriterias; private static readonly Dictionary _allEuropeanPopulationPercentages = Constants.AllEuropeanPopulationPercentages; private readonly ArtskartApiService _artskartApiService; @@ -105,8 +104,6 @@ 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))); diff --git a/Assessments.Frontend.Web/Infrastructure/Constants.cs b/Assessments.Frontend.Web/Infrastructure/Constants.cs index 919413dfb..9c3567c20 100644 --- a/Assessments.Frontend.Web/Infrastructure/Constants.cs +++ b/Assessments.Frontend.Web/Infrastructure/Constants.cs @@ -8,14 +8,6 @@ public static class Constants public const string AssessmentsMappingAssembly = "Assessments.Mapping"; - 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/RedlistSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 2110fd6e6..d6c8db87c 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -1,9 +1,7 @@ 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.RedlistSpecies.Enums.Enums; namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies { From 11856bd8f9a57e294c8f3e6286ccd5ccd2caf8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 16:55:02 +0100 Subject: [PATCH 05/18] move european population filter data to FilterItemHelper --- .../Controllers/RedlistController.cs | 2 -- ...SpeciesAssessment2021EuropeanPopulation.cs | 19 +++++++++++++++++++ .../RedlistSpecies/FilterItemHelpers.cs | 19 +++++++++++++++++++ .../2021/List/partials/_Filters.cshtml | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021EuropeanPopulation.cs diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index 7426e92ee..0550dcc4d 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -26,7 +26,6 @@ public RedlistController(ArtskartApiService artskartApiService) public IActionResult RodlisteForArter() => View("Species/Rodlisteforarter"); private static readonly Dictionary _resourceCache = new(); - private static readonly Dictionary _allEuropeanPopulationPercentages = Constants.AllEuropeanPopulationPercentages; private readonly ArtskartApiService _artskartApiService; @@ -135,7 +134,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) 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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index d6c8db87c..5670377a3 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -60,4 +60,23 @@ public class Criteria FilterButtonText = "Kriterier" }; } + + public class EuropeanPopulation + { + public static readonly Filter.FilterItem[] RedlistSpecies2021EuropeanPopulationFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021EuropeanPopulation = new() + { + Filters = RedlistSpecies2021EuropeanPopulationFilters, + FilterDescription = "", + FilterButtonName = "europeiskandelpopulasjonsfiltre", + FilterButtonText = "Andel av europeisk populasjon" + }; + } } 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 706fdeb07..b52a62f81 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 @@ -7,7 +7,7 @@ var AllAreas = Areas.RedlistSpecies2021Areas; var AllCategories = Categories.RedlistSpecies2021Categories; var AllCriterias = Criteria.RedlistSpecies2021Criteria; - var AllEuroPop = ViewBag.AllEuroPop; + var AllEuroPop = EuropeanPopulation.RedlistSpecies2021EuropeanPopulation; var AllRegions = ViewBag.AllRegions; Dictionary> AllHabitats = ViewBag.habitat.ToObject>>(); var AllTaxonRanks = ViewBag.AllTaxonRanks; From 7c4f671c62ce4f7b8e7a488eaf02e0f7cbed2dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 17:17:07 +0100 Subject: [PATCH 06/18] move regions filter data to FilterItemHelper --- .../RedlistSpeciesAssessment2021Regions.cs | 79 +++++++++++++++++++ .../RedlistSpecies/FilterItemHelpers.cs | 19 +++++ .../2021/List/partials/_Filters.cshtml | 2 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Regions.cs 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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 5670377a3..393700040 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -79,4 +79,23 @@ public class EuropeanPopulation FilterButtonText = "Andel av europeisk populasjon" }; } + + public class Regions + { + public static readonly Filter.FilterItem[] RedlistSpecies2021RegionsFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = ((int) x).ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Regions = new() + { + Filters = RedlistSpecies2021RegionsFilters, + FilterDescription = "", + FilterButtonName = "regionsfiltre", + FilterButtonText = "Regioner og havområder" + }; + } } 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 b52a62f81..152fdd11a 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 @@ -8,7 +8,7 @@ var AllCategories = Categories.RedlistSpecies2021Categories; var AllCriterias = Criteria.RedlistSpecies2021Criteria; var AllEuroPop = EuropeanPopulation.RedlistSpecies2021EuropeanPopulation; - var AllRegions = ViewBag.AllRegions; + var AllRegions = Regions.RedlistSpecies2021Regions; Dictionary> AllHabitats = ViewBag.habitat.ToObject>>(); var AllTaxonRanks = ViewBag.AllTaxonRanks; string[] AllSpeciesGroups = ViewBag.AllSpeciesGroups; From 6bb37fb9c6e589648efe2f4d2fe0337b94b16703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 17:29:04 +0100 Subject: [PATCH 07/18] move habitat filters data to FilterItemHelper --- .../RedlistSpeciesAssessment2021Habitats.cs | 46 +++++++++++++++++++ .../RedlistSpecies/FilterItemHelpers.cs | 19 ++++++++ .../2021/List/partials/_Filters.cshtml | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs 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..2f1af04d5 --- /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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 393700040..db155635f 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -98,4 +98,23 @@ public class Regions FilterButtonText = "Regioner og havområder" }; } + + public class Habitats + { + public static readonly Filter.FilterItem[] RedlistSpecies2021HabitatFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Habitats = new() + { + Filters = RedlistSpecies2021HabitatFilters, + FilterDescription = "", + FilterButtonName = "habitatfiltre", + FilterButtonText = "Hovedhabitat" + }; + } } 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 152fdd11a..4eb88e3cc 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 @@ -9,7 +9,7 @@ var AllCriterias = Criteria.RedlistSpecies2021Criteria; var AllEuroPop = EuropeanPopulation.RedlistSpecies2021EuropeanPopulation; var AllRegions = Regions.RedlistSpecies2021Regions; - Dictionary> AllHabitats = ViewBag.habitat.ToObject>>(); + var AllHabitats = Habitats.RedlistSpecies2021Habitats; var AllTaxonRanks = ViewBag.AllTaxonRanks; string[] AllSpeciesGroups = ViewBag.AllSpeciesGroups; string[] AllInsects = ViewBag.AllInsects; From 39e46ca4cf9d5a8e0e57ae5779cde9e7b89570dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 17:39:03 +0100 Subject: [PATCH 08/18] move taxon rank filter data to FilterItemHelper --- .../Controllers/RedlistController.cs | 2 -- .../Infrastructure/Helpers.cs | 12 ------------ .../RedlistSpeciesAssessment2021TaxonRank.cs | 16 ++++++++++++++++ .../RedlistSpecies/FilterItemHelpers.cs | 19 +++++++++++++++++++ .../2021/List/partials/_Filters.cshtml | 2 +- 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021TaxonRank.cs diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index 0550dcc4d..768433ae9 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -67,8 +67,6 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel var query = await DataRepository.GetSpeciesAssessments(); - ViewBag.AllTaxonRanks = Helpers.GetAllTaxonRanks(); - // Søk if (!string.IsNullOrEmpty(viewModel.Name)) { diff --git a/Assessments.Frontend.Web/Infrastructure/Helpers.cs b/Assessments.Frontend.Web/Infrastructure/Helpers.cs index 7cbf6da45..e6095b397 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)) @@ -255,11 +248,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/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 index db155635f..169053458 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -117,4 +117,23 @@ public class Habitats FilterButtonText = "Hovedhabitat" }; } + + public class TaxonRank + { + public static readonly Filter.FilterItem[] RedlistSpecies2021TaxonRankFilters = Enum.GetValues() + .Select(x => new Filter.FilterItem + { + NameShort = x.ToString(), + Name = x.DisplayName(), + Description = x.DisplayName() + }).ToArray(); + + public static readonly Filter.FilterAndMetaData RedlistSpecies2021Habitats = new() + { + Filters = RedlistSpecies2021TaxonRankFilters, + FilterDescription = "", + FilterButtonName = "taksonomisknivåfiltre", + FilterButtonText = "Taksonomisk nivå" + }; + } } 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 4eb88e3cc..ced1f82e4 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 @@ -10,7 +10,7 @@ var AllEuroPop = EuropeanPopulation.RedlistSpecies2021EuropeanPopulation; var AllRegions = Regions.RedlistSpecies2021Regions; var AllHabitats = Habitats.RedlistSpecies2021Habitats; - var AllTaxonRanks = ViewBag.AllTaxonRanks; + var AllTaxonRanks = TaxonRank.RedlistSpecies2021Habitats; string[] AllSpeciesGroups = ViewBag.AllSpeciesGroups; string[] AllInsects = ViewBag.AllInsects; From 6ffd64e395863e2752bd07357ba01306d26c1b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 18:13:27 +0100 Subject: [PATCH 09/18] move species groups filter data to FilterItemHelper --- .../RedlistSpecies/FilterItemHelpers.cs | 225 ++++++++++++++++++ .../2021/List/partials/_Filters.cshtml | 3 +- 2 files changed, 226 insertions(+), 2 deletions(-) diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 169053458..631ba8156 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -1,4 +1,5 @@ using Assessments.Frontend.Web.Infrastructure.RedlistSpecies.Enums; +using Assessments.Mapping.AlienSpecies.Model.Enums; using Assessments.Shared.Helpers; using System; using System.Linq; @@ -136,4 +137,228 @@ public class TaxonRank FilterButtonText = "Taksonomisk nivå" }; } + + public class SpeciesGroups + { + private static readonly Filter.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 Filter.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 Filter.FilterAndMetaData RedlistSpecies2021SpeciesGroups = new() + { + Filters = RedlistSpecies2021SpeciesGroupsFilters, + FilterDescription = "", + FilterButtonName = "artsgruppefiltre", + FilterButtonText = "Artspgruppe" + }; + } } 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 ced1f82e4..27d3786e6 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 @@ -11,8 +11,7 @@ var AllRegions = Regions.RedlistSpecies2021Regions; var AllHabitats = Habitats.RedlistSpecies2021Habitats; var AllTaxonRanks = TaxonRank.RedlistSpecies2021Habitats; - string[] AllSpeciesGroups = ViewBag.AllSpeciesGroups; - string[] AllInsects = ViewBag.AllInsects; + var AllSpeciesGroups = SpeciesGroups.RedlistSpecies2021SpeciesGroups; var startHit = Model.Redlist2021Results.PageNumber * 25 - 24; var endHit = startHit + @Model.Redlist2021Results.Count - 1; From 77ffdc191f0db5052fe299a50493dac4bb16925f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Mon, 11 Dec 2023 19:56:43 +0100 Subject: [PATCH 10/18] redlist filters are displayed the same way as alien species filters --- ...elpers.cs => AlienSpeciesFilterHelpers.cs} | 10 +- .../AlienSpecies/AlienSpeciesHelpers.cs | 5 +- .../AlienSpecies/FilterItemHelpers.cs | 130 +++---- .../Infrastructure/FilterHelpers.cs | 47 +++ .../{AlienSpecies => }/Interfaces.cs | 6 +- .../RedlistSpecies/FilterItemHelpers.cs | 85 +++-- .../RedlistSpeciesFilterHelpers.cs} | 135 ++++--- .../2023/ListPartials/_Filters.cshtml | 13 +- .../Views/AlienSpecies/_ViewImports.cshtml | 3 +- .../2021/List/partials/_Filters.cshtml | 347 ++++++------------ 10 files changed, 370 insertions(+), 411 deletions(-) rename Assessments.Frontend.Web/Infrastructure/AlienSpecies/{FilterHelpers.cs => AlienSpeciesFilterHelpers.cs} (96%) create mode 100644 Assessments.Frontend.Web/Infrastructure/FilterHelpers.cs rename Assessments.Frontend.Web/Infrastructure/{AlienSpecies => }/Interfaces.cs (56%) rename Assessments.Frontend.Web/Infrastructure/{Filter.cs => RedlistSpecies/RedlistSpeciesFilterHelpers.cs} (50%) 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 b0065ff96..04d01acbf 100644 --- a/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/AlienSpecies/FilterItemHelpers.cs @@ -3,19 +3,21 @@ using System; 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 { - public static readonly Filter.FilterItem[] AlienSpecies2023AreasFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023AreasFilters = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() }).ToArray(); - public static readonly Filter.FilterAndMetaData AlienSpecies2023Areas = new() + public static readonly FilterAndMetaData AlienSpecies2023Areas = new() { Filters = AlienSpecies2023AreasFilters, FilterDescription = "", @@ -26,14 +28,14 @@ public class Areas public class Categories { - public static readonly Filter.FilterItem[] AlienSpecies2023InvasionPotentialFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023InvasionPotentialFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.Description(), Name = x.DisplayName() }).Skip(1).ToArray(); - public static readonly Filter.FilterAndMetaData AlienSpecies2023InvasionPotential = new() + public static readonly FilterAndMetaData AlienSpecies2023InvasionPotential = new() { Filters = AlienSpecies2023InvasionPotentialFilters, FilterDescription = "Artens levedyktighet og evne til å ekspandere", @@ -41,14 +43,14 @@ public class Categories FilterButtonText = "Invasjonspotensial (risikomatrisens x-akse)" }; - public static readonly Filter.FilterItem[] AlienSpecies2023EcologicalEffectFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023EcologicalEffectFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.Description(), Name = x.DisplayName() }).Skip(1).ToArray(); - public static readonly Filter.FilterAndMetaData AlienSpecies2023EcologicalEffect = new() + public static readonly FilterAndMetaData AlienSpecies2023EcologicalEffect = new() { Filters = AlienSpecies2023EcologicalEffectFilters, FilterDescription = "Påvirkning på arter og naturtyper i Norge", @@ -56,16 +58,16 @@ public class Categories FilterButtonText = "Økologisk effekt (risikomatrisens y-akse)" }; - public static readonly Filter.FilterItem[] AlienSpecies2023CategoriesFilters = Enum.GetValues() + public static 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 static readonly Filter.FilterAndMetaData AlienSpecies2023Categories = new() + public static readonly FilterAndMetaData AlienSpecies2023Categories = new() { Filters = AlienSpecies2023CategoriesFilters, FilterDescription = "", @@ -104,7 +106,7 @@ public enum CategoryChangeEnum public class CategoryChange { - private static readonly Filter.FilterItem[] DifferFrom2018 = + private static readonly FilterItem[] DifferFrom2018 = { new() { @@ -133,7 +135,7 @@ public class CategoryChange } }; - public static readonly Filter.FilterItem[] AlienSpecies2023CategoryChangedFilters = + public static readonly FilterItem[] AlienSpecies2023CategoryChangedFilters = { new() { @@ -157,7 +159,7 @@ public class CategoryChange } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023CategoryChanged = new() + public static readonly FilterAndMetaData AlienSpecies2023CategoryChanged = new() { Filters = AlienSpecies2023CategoryChangedFilters, FilterDescription = "", @@ -201,7 +203,7 @@ public enum DecisiveCriteriaEnum dcipi, }; - public static readonly Filter.FilterItem[] ExistanceTimeAndExpansionSpeed = + public static readonly FilterItem[] ExistanceTimeAndExpansionSpeed = { new() { @@ -215,7 +217,7 @@ public enum DecisiveCriteriaEnum } }; - public static readonly Filter.FilterItem[] InvationPotential = + public static readonly FilterItem[] InvationPotential = { new() { @@ -239,7 +241,7 @@ public enum DecisiveCriteriaEnum } }; - public static readonly Filter.FilterItem[] EcologicalEffect = + public static readonly FilterItem[] EcologicalEffect = { new() { @@ -273,7 +275,7 @@ public enum DecisiveCriteriaEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023DeciciveCriteriaFilters = + public static readonly FilterItem[] AlienSpecies2023DeciciveCriteriaFilters = { new() { @@ -297,7 +299,7 @@ public enum DecisiveCriteriaEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023DeciciveCriteria = new() + public static readonly FilterAndMetaData AlienSpecies2023DeciciveCriteria = new() { Filters = AlienSpecies2023DeciciveCriteriaFilters, FilterDescription = "", @@ -312,7 +314,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() { @@ -331,7 +333,7 @@ public class Environments } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023Environment = new() + public static readonly FilterAndMetaData AlienSpecies2023Environment = new() { Filters = AlienSpecies2023EnvironmentFilters, FilterDescription = "", @@ -351,7 +353,7 @@ public enum GeographicVariationEnum Gvn, }; - public static readonly Filter.FilterItem[] AlienSpecies2023GeographicVariationFilters = + public static readonly FilterItem[] AlienSpecies2023GeographicVariationFilters = { new () { @@ -365,7 +367,7 @@ public enum GeographicVariationEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023GeographicVariation = new() + public static readonly FilterAndMetaData AlienSpecies2023GeographicVariation = new() { Filters = AlienSpecies2023GeographicVariationFilters, FilterDescription = "", @@ -397,7 +399,7 @@ public enum ClimateEffectsEnum Cei, }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFiltersAffected = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFiltersAffected = { new () { @@ -411,7 +413,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFiltersNotAffected = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFiltersNotAffected = { new () { @@ -425,7 +427,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023ClimateEffectsFilters = + public static readonly FilterItem[] AlienSpecies2023ClimateEffectsFilters = { new () { @@ -449,7 +451,7 @@ public enum ClimateEffectsEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023ClimateEffects = new() + public static readonly FilterAndMetaData AlienSpecies2023ClimateEffects = new() { Filters = AlienSpecies2023ClimateEffectsFilters, FilterDescription = "", @@ -472,21 +474,21 @@ public class NatureTypes AlienSpeciesAssessment2023MajorTypeGroup.WetlandSystems.DisplayName(), }; - public static readonly Filter.FilterItem[] AlienSpecies2023AlteredEcosystems = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023AlteredEcosystems = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName().ToUpper()[0] + x.DisplayName()[1..], NameShort = x.ToString() }).ToArray(); - public static readonly Filter.FilterItem[] AlienSpecies2023AlteredMajorTypeGroupTypes = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] AlienSpecies2023AlteredMajorTypeGroupTypes = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() }).Skip(1).Where(x => !isNotThreatened.Contains(x.Name)).ToArray(); - public static readonly Filter.FilterItem[] AlienSpecies2023NatureTypesFilters = + public static readonly FilterItem[] AlienSpecies2023NatureTypesFilters = { new () @@ -511,7 +513,7 @@ public class NatureTypes } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023NatureTypes = new() + public static readonly FilterAndMetaData AlienSpecies2023NatureTypes = new() { Filters = AlienSpecies2023NatureTypesFilters, FilterDescription = "", @@ -576,7 +578,7 @@ public enum SpreadWaysEnum Swspr, }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersImportPathways = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersImportPathways = { new () { @@ -595,7 +597,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersIntroduction = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersIntroduction = { new () { @@ -629,7 +631,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFiltersSpread = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFiltersSpread = { new () { @@ -658,7 +660,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpreadWaysFilters = + public static readonly FilterItem[] AlienSpecies2023SpreadWaysFilters = { new () { @@ -692,7 +694,7 @@ public enum SpreadWaysEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpreadWays = new() + public static readonly FilterAndMetaData AlienSpecies2023SpreadWays = new() { Filters = AlienSpecies2023SpreadWaysFilters, FilterDescription = "", @@ -764,7 +766,7 @@ public enum RegionallyAlienEnum } - public static readonly Filter.FilterItem[] RegionalSpread = + public static readonly FilterItem[] RegionalSpread = { new() { @@ -849,7 +851,7 @@ public enum RegionallyAlienEnum }; - public static readonly Filter.FilterItem[] AlienSpecies2023RegionallyAlienFilters = + public static readonly FilterItem[] AlienSpecies2023RegionallyAlienFilters = { new() { @@ -873,7 +875,7 @@ public enum RegionallyAlienEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023RegionallyAlien = new() + public static readonly FilterAndMetaData AlienSpecies2023RegionallyAlien = new() { Filters = AlienSpecies2023RegionallyAlienFilters, FilterDescription = "", @@ -904,7 +906,7 @@ public enum TaxonRankEnum tvi } - public static readonly Filter.FilterItem[] TaxonRanks2023 = + public static readonly FilterItem[] TaxonRanks2023 = { new() { @@ -933,7 +935,7 @@ public enum TaxonRankEnum }, }; - public static readonly Filter.FilterItem[] AlienSpecies2023TaxonRanksFilters = + public static readonly FilterItem[] AlienSpecies2023TaxonRanksFilters = { new() { @@ -957,7 +959,7 @@ public enum TaxonRankEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023TaxonRanks = new() + public static readonly FilterAndMetaData AlienSpecies2023TaxonRanks = new() { Filters = AlienSpecies2023TaxonRanksFilters, FilterDescription = "", @@ -969,7 +971,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() { @@ -997,7 +999,7 @@ public class SpeciesGroups } }; - private static readonly Filter.FilterItem[] AlienSpecies2023Insects = + private static readonly FilterItem[] AlienSpecies2023Insects = { new() { @@ -1073,7 +1075,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterItem[] AlienSpecies2023Crustacean = + public static readonly FilterItem[] AlienSpecies2023Crustacean = { new() { @@ -1109,7 +1111,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpeciesGroupsFilters = + public static readonly FilterItem[] AlienSpecies2023SpeciesGroupsFilters = { new() { @@ -1344,7 +1346,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpeciesGroups = new() + public static readonly FilterAndMetaData AlienSpecies2023SpeciesGroups = new() { Filters = AlienSpecies2023SpeciesGroupsFilters, FilterDescription = "", @@ -1355,14 +1357,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", @@ -1373,7 +1375,7 @@ public class Regions public class Habitat { - public static readonly Filter.FilterItem[] AlienSpecies2023HabitatsFilters = + public static readonly FilterItem[] AlienSpecies2023HabitatsFilters = { new() { @@ -1409,7 +1411,7 @@ public class Habitat } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023Habitats = new() + public static readonly FilterAndMetaData AlienSpecies2023Habitats = new() { Filters = AlienSpecies2023HabitatsFilters, FilterDescription = "", @@ -1420,21 +1422,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 = "", @@ -1445,7 +1447,7 @@ public class ProductionSpecies public class SpeciesStatus { - public static readonly Filter.FilterItem[] AlienSpecies2023Doorknockers = + public static readonly FilterItem[] AlienSpecies2023Doorknockers = { new() { @@ -1474,7 +1476,7 @@ public class SpeciesStatus } }; - public static readonly Filter.FilterItem[] AlienSpecies2023SpeciesStatusFilters = + public static readonly FilterItem[] AlienSpecies2023SpeciesStatusFilters = { new() { @@ -1498,7 +1500,7 @@ public class SpeciesStatus } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023SpeciesStatus = new() + public static readonly FilterAndMetaData AlienSpecies2023SpeciesStatus = new() { Filters = AlienSpecies2023SpeciesStatusFilters, FilterDescription = "", @@ -1522,7 +1524,7 @@ public enum NotAssessedEnum Nam } - public static readonly Filter.FilterItem[] AlienSpecies2023NotAssessedFilters = + public static readonly FilterItem[] AlienSpecies2023NotAssessedFilters = { new() { @@ -1541,7 +1543,7 @@ public enum NotAssessedEnum } }; - public static readonly Filter.FilterAndMetaData AlienSpecies2023NotAssessed = new() + public static readonly FilterAndMetaData AlienSpecies2023NotAssessed = new() { Filters = AlienSpecies2023NotAssessedFilters, FilterDescription = "", 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/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/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 631ba8156..3724d77ed 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -3,19 +3,20 @@ using Assessments.Shared.Helpers; using System; using System.Linq; +using static Assessments.Frontend.Web.Infrastructure.FilterHelpers; namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies { - public class Areas + public class RedlistAreas { - public static readonly Filter.FilterItem[] RedlistSpecies2021AreasFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021AreasFilters = Enum.GetValues() + .Select(x => new FilterItem { Name = x.DisplayName(), NameShort = x.ToString() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021Areas = new() + public static readonly FilterAndMetaData RedlistSpecies2021Areas = new() { Filters = RedlistSpecies2021AreasFilters, FilterDescription = "", @@ -24,17 +25,17 @@ public class Areas }; } - public class Categories + public class RedlistCategories { - public static readonly Filter.FilterItem[] RedlistSpecies2021CategoriesFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021CategoriesFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021Categories = new() + public static readonly FilterAndMetaData RedlistSpecies2021Categories = new() { Filters = RedlistSpecies2021CategoriesFilters, FilterDescription = "", @@ -43,17 +44,17 @@ public class Categories }; } - public class Criteria + public class RedlistCriteria { - public static readonly Filter.FilterItem[] RedlistSpecies2021CriteriaFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021CriteriaFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021Criteria = new() + public static readonly FilterAndMetaData RedlistSpecies2021Criteria = new() { Filters = RedlistSpecies2021CriteriaFilters, FilterDescription = "", @@ -62,17 +63,17 @@ public class Criteria }; } - public class EuropeanPopulation + public class RedlistEuropeanPopulation { - public static readonly Filter.FilterItem[] RedlistSpecies2021EuropeanPopulationFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021EuropeanPopulationFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021EuropeanPopulation = new() + public static readonly FilterAndMetaData RedlistSpecies2021EuropeanPopulation = new() { Filters = RedlistSpecies2021EuropeanPopulationFilters, FilterDescription = "", @@ -81,17 +82,17 @@ public class EuropeanPopulation }; } - public class Regions + public class RedlistRegions { - public static readonly Filter.FilterItem[] RedlistSpecies2021RegionsFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + 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 Filter.FilterAndMetaData RedlistSpecies2021Regions = new() + public static readonly FilterAndMetaData RedlistSpecies2021Regions = new() { Filters = RedlistSpecies2021RegionsFilters, FilterDescription = "", @@ -100,17 +101,17 @@ public class Regions }; } - public class Habitats + public class RedlistHabitats { - public static readonly Filter.FilterItem[] RedlistSpecies2021HabitatFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021HabitatFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021Habitats = new() + public static readonly FilterAndMetaData RedlistSpecies2021Habitats = new() { Filters = RedlistSpecies2021HabitatFilters, FilterDescription = "", @@ -119,17 +120,17 @@ public class Habitats }; } - public class TaxonRank + public class RedlistTaxonRank { - public static readonly Filter.FilterItem[] RedlistSpecies2021TaxonRankFilters = Enum.GetValues() - .Select(x => new Filter.FilterItem + public static readonly FilterItem[] RedlistSpecies2021TaxonRankFilters = Enum.GetValues() + .Select(x => new FilterItem { NameShort = x.ToString(), Name = x.DisplayName(), Description = x.DisplayName() }).ToArray(); - public static readonly Filter.FilterAndMetaData RedlistSpecies2021Habitats = new() + public static readonly FilterAndMetaData RedlistSpecies2021Habitats = new() { Filters = RedlistSpecies2021TaxonRankFilters, FilterDescription = "", @@ -138,9 +139,9 @@ public class TaxonRank }; } - public class SpeciesGroups + public class RedlistSpeciesGroups { - private static readonly Filter.FilterItem[] RedlistSpecies2021Insects = + private static readonly FilterItem[] RedlistSpecies2021Insects = { new() { @@ -224,7 +225,7 @@ public class SpeciesGroups } }; - public static readonly Filter.FilterItem[] RedlistSpecies2021SpeciesGroupsFilters = + public static readonly FilterItem[] RedlistSpecies2021SpeciesGroupsFilters = { new() { @@ -353,7 +354,7 @@ public class SpeciesGroups }, }; - public static readonly Filter.FilterAndMetaData RedlistSpecies2021SpeciesGroups = new() + public static readonly FilterAndMetaData RedlistSpecies2021SpeciesGroups = new() { Filters = RedlistSpecies2021SpeciesGroupsFilters, FilterDescription = "", @@ -361,4 +362,24 @@ public class SpeciesGroups FilterButtonText = "Artspgruppe" }; } + + 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/Filter.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs similarity index 50% rename from Assessments.Frontend.Web/Infrastructure/Filter.cs rename to Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs index 18712068d..200869a1f 100644 --- a/Assessments.Frontend.Web/Infrastructure/Filter.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs @@ -1,54 +1,14 @@ 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 +namespace Assessments.Frontend.Web.Infrastructure.RedlistSpecies { - public static class Filter + public static class RedlistSpeciesFilterHelpers { - 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) @@ -56,65 +16,75 @@ public static string GetActiveFilters(string filterType, RL2021ViewModel Model) case "Area": if (Model.Area?.Any() == true) return $"{Model.Area.Length}"; - return String.Empty; + return string.Empty; case "Category": if (Model.Category?.Any() == true) return $"{Model.Category.Length}"; - return String.Empty; + return string.Empty; case "TaxonRank": if (Model.TaxonRank?.Any() == true) return $"{Model.TaxonRank.Length}"; - return String.Empty; + return string.Empty; case "SpeciesGroups": - if (Model.SpeciesGroups?.Any() == true) { - if (Model.SpeciesGroups.Contains("Insekter")) - return $"{Model.SpeciesGroups.Length - 1}"; - return $"{Model.SpeciesGroups.Length}"; + var count = Model.SpeciesGroups.Length; + if (Model.SpeciesGroups.Contains("Insects")) + count--; + if (Model.SpeciesGroups.Contains(nameof(Model.SpeciesGroups))) + count--; + return $"{count}"; } - return String.Empty; case "Habitats": if (Model.Habitats?.Any() == true) return $"{Model.Habitats.Length}"; - return String.Empty; + return string.Empty; case "Regions": if (Model.Regions?.Any() == true) return $"{Model.Regions.Length}"; - return String.Empty; + return string.Empty; case "EuroPop": if (Model.EuroPop?.Any() == true) return $"{Model.EuroPop.Length}"; - return String.Empty; + return string.Empty; case "Criterias": if (Model.Criterias?.Any() == true) return $"{Model.Criterias.Length}"; - return String.Empty; + 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; + return string.Empty; default: - return String.Empty; + 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; + return string.Empty; } public static int GetActiveSelectionCount(RL2021ViewModel Model) @@ -151,5 +121,30 @@ public static string[] GetActiveSelectionElement(RL2021ViewModel Model) } 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; + } } -} \ No newline at end of file +} diff --git a/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml b/Assessments.Frontend.Web/Views/AlienSpecies/2023/ListPartials/_Filters.cshtml index 47f0787f9..7d549bf5c 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/List/partials/_Filters.cshtml b/Assessments.Frontend.Web/Views/Redlist/Species/2021/List/partials/_Filters.cshtml index 27d3786e6..882e400ec 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,17 +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 = Areas.RedlistSpecies2021Areas; - var AllCategories = Categories.RedlistSpecies2021Categories; - var AllCriterias = Criteria.RedlistSpecies2021Criteria; - var AllEuroPop = EuropeanPopulation.RedlistSpecies2021EuropeanPopulation; - var AllRegions = Regions.RedlistSpecies2021Regions; - var AllHabitats = Habitats.RedlistSpecies2021Habitats; - var AllTaxonRanks = TaxonRank.RedlistSpecies2021Habitats; - var AllSpeciesGroups = SpeciesGroups.RedlistSpecies2021SpeciesGroups; + 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; @@ -25,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") { @@ -34,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) ? $"{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); + } } } @@ -168,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"); } - +
            }

            -
          @@ -224,9 +194,9 @@ Sorter etter:
          @@ -258,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");} - -
            -
              -
            • - -
            • -
            -
            -
          - +
        From a9ebde71e4871e45201129566d1e91c6f70b2c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 12 Dec 2023 10:59:05 +0100 Subject: [PATCH 11/18] add previously removed json resource file --- Assessments.Frontend.Web/Controllers/RedlistController.cs | 6 ++++-- Assessments.Frontend.Web/Views/Shared/_ListView.cshtml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index 768433ae9..c9d3f70eb 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -28,7 +28,6 @@ public RedlistController(ArtskartApiService artskartApiService) private static readonly Dictionary _resourceCache = new(); private readonly ArtskartApiService _artskartApiService; - [Route("2021")] public async Task Index2021([FromQueryAttribute] RL2021ViewModel viewModel, int? page, bool export) { @@ -61,6 +60,9 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel ViewBag.habitat = await GetResource("wwwroot/json/habitat.json"); + ViewBag.categories = await GetResource("wwwroot/json/categories.json"); + + // Pagination const int pageSize = 25; var pageNumber = page ?? 1; @@ -441,4 +443,4 @@ private static async Task GetResource(string resourcePath) return jObject; } } -} +} \ No newline at end of file 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) { From 20fcf0742e907c101b8c0b91642782ac3bfc011a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 12 Dec 2023 14:28:24 +0100 Subject: [PATCH 12/18] update js and css to accomodate new filter names to open/close them correct --- .../wwwroot/css/filter.css | 34 +++++-------------- Assessments.Frontend.Web/wwwroot/js/filter.js | 16 ++------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/Assessments.Frontend.Web/wwwroot/css/filter.css b/Assessments.Frontend.Web/wwwroot/css/filter.css index 7ff7a794b..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; - #fff9f0-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..9ef68c070 100644 --- a/Assessments.Frontend.Web/wwwroot/js/filter.js +++ b/Assessments.Frontend.Web/wwwroot/js/filter.js @@ -6,8 +6,6 @@ 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 init = document.getElementById("initial_check"); @@ -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", ]; @@ -203,9 +200,6 @@ if (filters) { }); } // redlist species 2021 - if (shouldToggleMarkAll("insect_input")) { - insectInput.checked = true; - } if (shouldToggleMarkRedOrEnd(redlisted)) { redlistCheckbox.checked = true; } @@ -263,7 +257,7 @@ 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); @@ -271,9 +265,7 @@ if (filters) { }) } // redlist species 2021 - else if (el.classList[0] === "insect_input") { - toggleSingleFilter(el, "Insekter"); - } else if (endangered.some(category => el.id.indexOf(category) != -1)) { + if (endangered.some(category => el.id.indexOf(category) != -1)) { toggleSingleFilter(el, "endangered_check"); toggleSingleFilter(el, "redlisted_check"); } else if (redlisted.some(category => el.id.indexOf(category) != -1)) { @@ -287,8 +279,6 @@ if (filters) { toggleRedlistedCategories(); } else if (el.id === "endangered_check") { toggleEndangeredCategories(); - } else if (el.id === "Insekter") { - toggleSubGroup(insectFilters, insectInput); } else { if (addOrRemove == "add") { updateToggleAll(el); From 7f15133fb8c4580d89e7292a660354c84f37b08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 12 Dec 2023 14:44:53 +0100 Subject: [PATCH 13/18] remove 0 filters active bug for species groups --- .../RedlistSpecies/RedlistSpeciesFilterHelpers.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs index 200869a1f..431f10815 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs @@ -26,6 +26,7 @@ public static string GetActiveFilters(string filterType, RL2021ViewModel Model) return $"{Model.TaxonRank.Length}"; return string.Empty; case "SpeciesGroups": + if (Model.SpeciesGroups?.Any() == true) { var count = Model.SpeciesGroups.Length; if (Model.SpeciesGroups.Contains("Insects")) @@ -34,6 +35,7 @@ public static string GetActiveFilters(string filterType, RL2021ViewModel Model) count--; return $"{count}"; } + return string.Empty; case "Habitats": if (Model.Habitats?.Any() == true) return $"{Model.Habitats.Length}"; From 88b4d724bb5089fdc0820e63b5f85e12d53b8209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 12 Dec 2023 14:50:25 +0100 Subject: [PATCH 14/18] regions filter 'mark all' works --- Assessments.Frontend.Web/Infrastructure/Helpers.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Assessments.Frontend.Web/Infrastructure/Helpers.cs b/Assessments.Frontend.Web/Infrastructure/Helpers.cs index e6095b397..99b1a1f23 100644 --- a/Assessments.Frontend.Web/Infrastructure/Helpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/Helpers.cs @@ -175,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(); } From 878daadb302e6cd2f34d18d8ec058075f29a633e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 16 Jan 2024 09:34:53 +0100 Subject: [PATCH 15/18] consider mainhabitat value containing spaces --- Assessments.Frontend.Web/Controllers/RedlistController.cs | 8 +++++++- .../Enums/RedlistSpeciesAssessment2021Habitats.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Assessments.Frontend.Web/Controllers/RedlistController.cs b/Assessments.Frontend.Web/Controllers/RedlistController.cs index c9d3f70eb..a9674f2e8 100644 --- a/Assessments.Frontend.Web/Controllers/RedlistController.cs +++ b/Assessments.Frontend.Web/Controllers/RedlistController.cs @@ -108,7 +108,13 @@ public async Task Index2021([FromQueryAttribute] RL2021ViewModel // 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(); diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs index 2f1af04d5..934cb91d6 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/Enums/RedlistSpeciesAssessment2021Habitats.cs @@ -35,7 +35,7 @@ public enum RedlistSpeciesAssessment2021Habitats Saltvannssystemer, [Display(Name = "Semi-naturlig mark")] - fastmark, + Fastmark, [Display(Name = "Sterkt endret mark")] SterktEndretFastmark, From 5e09a27f824627f3f611fdc8d10da87ee77d3fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 16 Jan 2024 09:40:57 +0100 Subject: [PATCH 16/18] remove typing mistake --- .../Infrastructure/RedlistSpecies/FilterItemHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs index 3724d77ed..9323b8a21 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/FilterItemHelpers.cs @@ -359,7 +359,7 @@ public class RedlistSpeciesGroups Filters = RedlistSpecies2021SpeciesGroupsFilters, FilterDescription = "", FilterButtonName = "artsgruppefiltre", - FilterButtonText = "Artspgruppe" + FilterButtonText = "Artsgruppe" }; } From dd8c189f0d9151777db0f2c75a0e6ca1e4461a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 16 Jan 2024 10:46:02 +0100 Subject: [PATCH 17/18] update filter.js to support new id for redlist categories logic for toggling redlisted and endangered --- .../2021/List/partials/_Filters.cshtml | 2 +- Assessments.Frontend.Web/wwwroot/js/filter.js | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) 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 882e400ec..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 @@ -97,7 +97,7 @@ foreach (var el in filterItems.Filters) { value = el.NameShort; - label = filterName == nameof(Model.Category) ? $"{el.NameShort} - {el.Description}" : el.Name; + label = (filterName == nameof(Model.Category) && value != "RED" && value != "END") ? $"{el.NameShort} - {el.Description}" : el.Name; string extraOuterClassName = $"{outerClassName} {filterName}_input"; if (el.SubGroup != null) { diff --git a/Assessments.Frontend.Web/wwwroot/js/filter.js b/Assessments.Frontend.Web/wwwroot/js/filter.js index 9ef68c070..fc040424b 100644 --- a/Assessments.Frontend.Web/wwwroot/js/filter.js +++ b/Assessments.Frontend.Web/wwwroot/js/filter.js @@ -6,8 +6,8 @@ const filters = document.getElementById("filters"); if (filters) { const isCheckInputs = document.getElementsByClassName("collapse_checkbox"); - 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"); @@ -187,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; }) } @@ -213,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) { @@ -264,20 +265,21 @@ if (filters) { toggleSingleFilter(el, filterId); }) } + // redlist species 2021 if (endangered.some(category => el.id.indexOf(category) != -1)) { - toggleSingleFilter(el, "endangered_check"); - toggleSingleFilter(el, "redlisted_check"); + 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 (addOrRemove == "add") { From ebeaed6cd203fe3a2b7cc6bb86bfc3707148703f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20S=C3=A6ter?= Date: Tue, 16 Jan 2024 11:33:24 +0100 Subject: [PATCH 18/18] remove filter count for "mark all" --- .../RedlistSpeciesFilterHelpers.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs index 431f10815..cff069997 100644 --- a/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs +++ b/Assessments.Frontend.Web/Infrastructure/RedlistSpecies/RedlistSpeciesFilterHelpers.cs @@ -15,21 +15,36 @@ public static string GetActiveFilters(string filterType, RL2021ViewModel Model) { 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("Insects")) + if (Model.SpeciesGroups.Contains("Insekter")) count--; if (Model.SpeciesGroups.Contains(nameof(Model.SpeciesGroups))) count--; @@ -38,19 +53,39 @@ public static string GetActiveFilters(string filterType, RL2021ViewModel Model) 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)