From 9228aba17fbbe549b7762ff095a0fde900a6cac0 Mon Sep 17 00:00:00 2001 From: stevan Date: Thu, 11 Sep 2025 15:46:24 +0200 Subject: [PATCH] Update profile cities support active ambassadors with order by name --- app/Providers/AppServiceProvider.php | 55 ++++++++++++++++++--- public/js/ext/functions.js | 71 ++++++++++++++++++---------- resources/views/community.blade.php | 33 ------------- 3 files changed, 95 insertions(+), 64 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6aacdd9d1..1621b5b23 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -37,7 +37,7 @@ public function boot(): void Carbon::setLocale('app.locale'); \View::composer( - ['event.add', 'event.search', 'profile', 'event.edit'], + ['event.add', 'event.search', 'event.edit'], function ($view) { $audiences = \App\Audience::all()->map(function ($audience) { $audience->name = __('event.audience.' . $audience->name); @@ -57,17 +57,60 @@ function ($view) { $view->with('languages', Arr::sort(Lang::get('base.languages'))); $view->with('active_countries', $activeCountries); $view->with('themes', $themes); + } + ); - $cities = \App\City::query() - ->whereIn('country_iso', $activeCountries->pluck('iso')) + \View::composer(['community', 'profile'], function ($view) { + $supportedCountries = [ + 'GR', + 'CY', + 'MT', + 'IT', + 'BG', + 'TR', + 'UA', + 'PL', + 'IE', + 'FR', + 'LU', + 'NL', + 'BE', + 'SK', + 'CZ', + 'NO', + 'IS', + 'FI', + 'SE', + 'PT', + 'ES', + 'LV', + 'LT', + 'HR', + 'SI', + 'DE', + 'AT', + 'CH', + 'RO', + 'MD', + 'DK', + ]; + + $activeCountries = \App\Country::query() + ->whereIn('iso', $supportedCountries) + ->orderBy('name') + ->get(); + + $cities = \App\City::query() + ->whereIn('country_iso', $supportedCountries) ->select(['id', 'city', 'country_iso']) ->orderBy('country_iso') ->orderBy('city') ->get(); - $view->with('cities', $cities); - } - ); + $view->with('cities', $cities); + $view->with('active_countries', $activeCountries); + $view->with('supportedCountries', $supportedCountries); + }); \View::composer(['stats'], function ($view) { $view->with('active_countries', \App\Country::withEvents()); diff --git a/public/js/ext/functions.js b/public/js/ext/functions.js index 544110fd6..e6dff889e 100755 --- a/public/js/ext/functions.js +++ b/public/js/ext/functions.js @@ -2135,38 +2135,59 @@ var SEMICOLON = SEMICOLON || {}; var $country = $('#id_country'); var $city = $('#id_city'); if (!$country.length || !$city.length) return; + + if (!$city.data('originalHtml')) { + $city.data('originalHtml', $city.html()); + } - // cache once per current DOM - if (!$city.data('originalOptions')) { - $city.data('originalOptions', $city.find('option').clone()); - $city.data('emptyOption', $city.find('option').first().clone()); + function getAllOptions() { + var html = $city.data('originalHtml') || ''; + var $tmp = $(''); + return $tmp.find('option'); } function applyCityFilter() { - var iso = $country.val() || ''; - var prev = $city.val(); - var $original = $city.data('originalOptions'); - var $empty = $city.data('emptyOption').clone(); - - var $next = [$empty.get(0)]; - if (iso) { - $original.each(function (i, opt) { - if (i === 0) return; // keep first for empty - var $opt = $(opt); - if ($opt.attr('data-country') === iso) $next.push(opt); + var iso = ($country.val() || '').toUpperCase(); + var prev = $city.val(); + var $all = getAllOptions(); + + if (!iso) { + $city.html($all.clone()); + if ($city.find('option[value="'+ prev +'"]').length) $city.val(prev); + return; + } + + var $empty = $all.first().clone(); + var $filtered = $all.filter(function (i, opt) { + if (i === 0) return false; + var dc = (opt.getAttribute('data-country') || '').toUpperCase(); + return dc === iso; }); - } - $city.empty().append($next); - - // restore previous if still valid - if ($next.some(function(o){ return o.value === prev; })) { - $city.val(prev); - } else { - $city.val(''); - } + + $city.empty().append($empty).append($filtered.clone()); + + if ($city.find('option[value="'+ prev +'"]').length) { + $city.val(prev); + } else { + $city.val(''); // reset + } } + + (function autoSelectCountryFromCity() { + if ($country.val()) return; + var $sel = getAllOptions().filter(function(i, opt){ + return opt.value && opt.selected; + }).first(); + if ($sel.length) { + var dc = ($sel.attr('data-country') || '').toUpperCase(); + if (dc) { + var $opt = $country.find('option[value="'+ dc +'"]'); + if ($opt.length) $country.val(dc); + } + } + })(); - // bind once per render + // bind & run $country.off('change.cityfilter').on('change.cityfilter', applyCityFilter); applyCityFilter(); }, diff --git a/resources/views/community.blade.php b/resources/views/community.blade.php index f5983dc69..3419ebbaa 100755 --- a/resources/views/community.blade.php +++ b/resources/views/community.blade.php @@ -444,39 +444,6 @@ class="absolute left-0 z-50 hidden md:block"> {{-- Display this section only if a country is selected and has specific content --}} @php $country = app('request')->input('country_iso'); - $supportedCountries = [ - 'GR', - 'CY', - 'MT', - 'IT', - 'BG', - 'TR', - 'UA', - 'PL', - 'IE', - 'FR', - 'LU', - 'NL', - 'BE', - 'SK', - 'CZ', - 'NO', - 'IS', - 'FI', - 'SE', - 'PT', - 'ES', - 'LV', - 'LT', - 'HR', - 'SI', - 'DE', - 'AT', - 'CH', - 'RO', - 'MD', - 'DK', - ]; @endphp @if (in_array($country, $supportedCountries))