From 1a542fa5db4fbac9b91d0fd7b2ce062cb1a3f0a3 Mon Sep 17 00:00:00 2001 From: Derek Keller Date: Fri, 6 Jan 2023 15:03:33 -0600 Subject: [PATCH] Early 2023 patches (#165) * fixed origins language group dropdown * fixed about_sources flatpage Co-authored-by: John Connor (Mulligan) --- voyages/apps/voyage/search_views.py | 5 +- .../scripts/vue/past/includes/helpers.js | 92 +++++++++++++++---- 2 files changed, 75 insertions(+), 22 deletions(-) diff --git a/voyages/apps/voyage/search_views.py b/voyages/apps/voyage/search_views.py index f91bf6de9..cb57e03e1 100644 --- a/voyages/apps/voyage/search_views.py +++ b/voyages/apps/voyage/search_views.py @@ -822,10 +822,11 @@ def get_filtered_places(request): filtered['filtered_var_name'] = var_name if var_name != blank else 'None' return JsonResponse(filtered) - +@csrf_exempt +@require_POST def get_all_sources(request): return JsonResponse({ - 'data': list(VoyageSources.objects.values('pk', 'short_ref', 'full_ref', type=F('source_type__group_name'))) + 'data': list(VoyageSources.objects.values('pk', 'short_ref', 'full_ref', group_name=F('source_type__group_name'))) }) @csrf_exempt diff --git a/voyages/sitemedia/scripts/vue/past/includes/helpers.js b/voyages/sitemedia/scripts/vue/past/includes/helpers.js index 52e3b620b..08c235c8d 100644 --- a/voyages/sitemedia/scripts/vue/past/includes/helpers.js +++ b/voyages/sitemedia/scripts/vue/past/includes/helpers.js @@ -718,7 +718,7 @@ function loadTreeselectOptions(vm, vTreeselect, filter, callback) { var options = parseVesselFate(response); break; } - + vm.filterData.treeselectOptions[varName] = options; vTreeselect.treeselectOptions = vm.filterData.treeselectOptions[varName]; @@ -849,24 +849,68 @@ var parseLanguageGroups = function(response) { ]; // fill countries - var countries = []; + var unique_countries = new Object; + var multi_country_language_groups = new Object; $.each(response.data, function(id, languageGroup) { + var thislanguagegroup={'id':languageGroup.id,'name':languageGroup.name,'count':0} $.each(languageGroup.countries, (id, country) => { - countries.push(country); + unique_countries[country.modern_country_id]=country.country_name + thislanguagegroup['count']+=1 }); + + if (thislanguagegroup['count']>1) { + multi_country_language_groups[languageGroup.id]=thislanguagegroup + } + }); - countries = [...new Set(countries)].sort() - - $.each(countries, function(key, country) { + + $.each(unique_countries, function(key, country) { options[0].children.push({ - id: country, + id: key, label: country, children: [], languageGroupIds: [] }); }); - // fill languageGroups + //fill multi-country languageGroups + + + + options[0].children.sort(function (a,b){ + if ( a.label < b.label ){ + return -1; + } + if ( a.label > b.label ){ + return 1; + } + return 0; + }); + + if (Object.keys(multi_country_language_groups).length>0) { + var multicountry={ + id: 1234567, + label: 'Multi-Country', + children: [], + languageGroupIds: [] + }; + + Object.keys(multi_country_language_groups).forEach(k=>{ + + var lg=multi_country_language_groups[k] + + multicountry.children.push({ + 'id':lg.id, + 'label':lg.name, + 'isDisabled':false, + 'languageGroupIds':[lg.id] + }); + multicountry.languageGroupIds.push(lg.id) + }) + options[0].children.splice(0,0,multicountry) + } + + // fill single-country languageGroups $.each(response.data, function(id, languageGroup) { var label = languageGroup.name; var languageGroupId = languageGroup.id; @@ -887,16 +931,29 @@ var parseLanguageGroups = function(response) { } $.each(options[0].children, function(key, country) { $.each(languageGroup.countries, (index, languageGroupCountry) => { - if (languageGroupCountry == country.label) { - if (options[0].children[key].languageGroupIds.indexOf(languageGroupId) === -1) { + if (languageGroupCountry.country_name == country.label && !multi_country_language_groups[languageGroupId]) { +// if (options[0].children[key].languageGroupIds.indexOf(languageGroupId) === -1) { options[0].children[key].languageGroupIds.push(languageGroupId); - } - options[0].children[key].children.push({'id': key+'-'+languageGroupId, 'label' : label, 'isDisabled': false, languageGroupIds: [languageGroupId]}); - } +// } + options[0].children[key].children.push({'id': languageGroupId, 'label' : label, 'isDisabled': false, languageGroupIds: [languageGroupId]}); + } }); + }); }); + + //clear out empty entries + var childrenplaceholder=new Array; $.each(options[0].children, function(key, country) { + if (options[0].children[key].children.length>0) { + childrenplaceholder.push(options[0].children[key]) + } + }) + options[0].children=[] + childrenplaceholder.forEach(c=>{options[0].children.push(c)}) + + + $.each(options[0].children, function(key, country) { country.children.sort(function (a, b) { if ( a.label < b.label ){ return -1; @@ -908,6 +965,7 @@ var parseLanguageGroups = function(response) { }) }); + return options; } @@ -1466,13 +1524,7 @@ function refreshUi(filter, filterData, currentTab, tabData, options) { weight: 1, opacity: 1, fillOpacity: 0.6 - }) -// -// if (Object.keys(distributedlanguagegroups[networkname]).includes(point_id.toString())) { -// console.log(feature) -// } -// -// + }) marker.on('mouseover', function (a) { activepopups.forEach(p=>p.remove());