diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ca038..61dd3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ CHANGELOG =================== +## v2.3.0 - (2024-06-07) +### Added +- `ui_banner.html.twig` macro to prompt a tailwind banner for usefull info (current environment, ...) +- `AbstractApiCallAdmin::getOriginChoices` for api call origin filter +- `empty_layout.html.twig` add `ui_banner` on the **sonata_wrapper** block to show current server environment +- `standard_layout.html.twig` add `ui_banner` on the **sonata_header_noscript_warning** block to show current server environment + - to unlock it add the following to your `twig.globals` config : `smart_server_environment: '%env(default::ENVIRONMENT)%'` +- `admin.en.xlf` add missing english translations + ## v2.2.0 - (2024-06-04) ### Changed - `AbstractAdmin::__construct` params are now all optionnal as we must configure it through tags from what's ask on the next v5 of Sonata Admin diff --git a/assets/styles/_skin.scss b/assets/styles/_skin.scss index e2d9f2a..6e094df 100644 --- a/assets/styles/_skin.scss +++ b/assets/styles/_skin.scss @@ -1,4 +1,14 @@ .skin-smartbooster { + .main-sidebar-under-banner { + .main-sidebar { + padding-top: 79px; + } + } + .main-sidebar { + hr { + margin-bottom: 0; + } + } //Navbar .main-header { .navbar { diff --git a/src/Admin/Monitoring/AbstractApiCallAdmin.php b/src/Admin/Monitoring/AbstractApiCallAdmin.php index c263603..0c7d52b 100644 --- a/src/Admin/Monitoring/AbstractApiCallAdmin.php +++ b/src/Admin/Monitoring/AbstractApiCallAdmin.php @@ -37,9 +37,13 @@ protected function configureDefaultSortValues(array &$sortValues): void protected function configureDatagridFilters(DatagridMapper $filter): void { $filter - ->add('origin', null, [ + ->add('origin', ChoiceFilter::class, [ 'label' => 'label.origin', 'show_filter' => true, + 'field_type' => ChoiceType::class, + 'field_options' => [ + 'choices' => $this->getOriginChoices(), + ], ]) ->add('status', ChoiceFilter::class, [ 'label' => 'label.result', @@ -82,7 +86,10 @@ protected function configureListFields(ListMapper $list): void $list ->add('id', null, ['label' => 'field.label_id']) ->add('startedAt', null, ['label' => 'label.started_at']) - ->add('origin', null, ['label' => 'label.origin']) + ->add('origin', FieldDescriptionInterface::TYPE_CHOICE, [ + 'label' => 'label.origin', + 'choices' => array_flip($this->getOriginChoices()), + ]) ->add('statusCode', null, [ 'label' => 'label.result', 'template' => '@SmartSonata/admin/base_field/list_api_call_status_code.html.twig', @@ -107,7 +114,6 @@ protected function configureShowFields(ShowMapper $show): void ->add('type', FieldDescriptionInterface::TYPE_CHOICE, [ 'label' => 'label.route', 'choices' => array_flip($this->getRouteChoices()), - 'choice_translation_domain' => 'admin', ]) ->add('startedAt', null, ['label' => 'label.started_at']) ->add('endedAt', null, ['label' => 'label.ended_at']) @@ -119,7 +125,10 @@ protected function configureShowFields(ShowMapper $show): void ->add('summary', null, ['label' => 'label.summary']) ->end() ->with('api_params', ['label' => 'label.api_params', 'class' => 'col-md-8']) - ->add('origin', null, ['label' => 'label.origin']) + ->add('origin', FieldDescriptionInterface::TYPE_CHOICE, [ + 'label' => 'label.origin', + 'choices' => array_flip($this->getOriginChoices()), + ]) ->add('statusCode', null, [ 'label' => 'label.result', 'template' => '@SmartSonata/admin/base_field/show_api_call_status_code.html.twig', @@ -158,4 +167,6 @@ private function getStatusChoices(): array } abstract protected function getRouteChoices(): array; + + abstract protected function getOriginChoices(): array; } diff --git a/templates/empty_layout.html.twig b/templates/empty_layout.html.twig index ca6bb9f..a5aa021 100644 --- a/templates/empty_layout.html.twig +++ b/templates/empty_layout.html.twig @@ -1,4 +1,5 @@ {% extends "@SonataAdmin/empty_layout.html.twig" %} +{% import '@SmartSonata/macros/ui_banner.html.twig' as ui_banner %} {% block html_attributes %}class="login"{% endblock %} @@ -16,3 +17,8 @@ {% block javascripts %} {# disable javascript on empty_layout to prevent loading jquery #} {% endblock %} + +{% block sonata_wrapper %} + {{ ui_banner.env_banner(true) }} + {{ parent() }} +{% endblock %} diff --git a/templates/macros/ui_banner.html.twig b/templates/macros/ui_banner.html.twig new file mode 100644 index 0000000..2661a5b --- /dev/null +++ b/templates/macros/ui_banner.html.twig @@ -0,0 +1,36 @@ +{% trans_default_domain 'messages' %} + +{% macro env_banner(absolute = false) %} + {% if smart_server_environment is defined and smart_server_environment is not null and smart_server_environment != 'production' %} + {% set display_smart_env_banner = true %} + {% else %} + {% set display_smart_env_banner = false %} + {% endif %} + + {% if display_smart_env_banner %} + {% if smart_server_environment == 'developpement' + or smart_server_environment == 'development' + or smart_server_environment == 'dev' + or smart_server_environment == 'integration' + %} + {% set env_banner_class = 'bg-blue-600 text-white' %} + {% elseif smart_server_environment == 'recette' %} + {% set env_banner_class = 'bg-yellow-400 text-neutral-darker' %} + {% else %} + {% set env_banner_class = 'bg-danger text-white' %} + {% set env_banner_message_not_found = '' ~ smart_server_environment ~ '' ~ ('env_banner_message.unknown')|trans %} + {% endif %} +