From 74d79e1ee0a75022a1e2bb2cac04756c848a9d8e Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Tue, 4 Jun 2024 17:22:36 +0200 Subject: [PATCH 1/2] Add AbstractApiCallAdmin::getOriginChoices for api call origin filter --- src/Admin/Monitoring/AbstractApiCallAdmin.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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; } From 5eee4d1cc6e9c8b44aab06b4a07eb96fba4b19d0 Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Tue, 4 Jun 2024 18:54:32 +0200 Subject: [PATCH 2/2] Add twig macro ui_banner and set it on empty_layout and standard_layout.html.twig --- CHANGELOG.md | 9 +++ assets/styles/_skin.scss | 10 ++++ templates/empty_layout.html.twig | 6 ++ templates/macros/ui_banner.html.twig | 36 ++++++++++++ templates/standard_layout.html.twig | 17 ++++++ translations/admin.en.xlf | 83 ++++++++++++++++++++++++++++ translations/admin.fr.xlf | 2 +- translations/messages.en.xlf | 26 +++++++++ translations/messages.fr.xlf | 26 +++++++++ 9 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 templates/macros/ui_banner.html.twig 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/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 %} +
+
+
+ {% if env_banner_message_not_found is defined %} + {{ env_banner_message_not_found|raw }} + {% else %} + {{ ('env_banner_message.' ~ smart_server_environment)|trans|raw }} + {% endif %} +
+
+
+
+ {% endif %} +{% endmacro %} diff --git a/templates/standard_layout.html.twig b/templates/standard_layout.html.twig index 4bc3730..45e523c 100644 --- a/templates/standard_layout.html.twig +++ b/templates/standard_layout.html.twig @@ -1,9 +1,26 @@ {% extends "@SonataAdmin/standard_layout.html.twig" %} +{% import '@SmartSonata/macros/ui_banner.html.twig' as ui_banner %} {# Disable sonata link and search bar #} {% block side_bar_after_nav %}{% endblock %} {% block sonata_sidebar_search %}{% endblock %} +{% block sonata_header_noscript_warning %} + {{ ui_banner.env_banner }} + {{ parent() }} +{% endblock %} + +{% block sonata_left_side %} + {% if smart_server_environment is defined and smart_server_environment is not null and smart_server_environment != 'production' %} + {# MDT extra div class to increase the padding-top of the sidebar if we have a banner #} +
+ {{ parent() }} +
+ {% else %} + {{ parent() }} + {% endif %} +{% endblock %} + {% block side_bar_before_nav %} {% if app.user and is_granted('ROLE_SONATA_ADMIN') %}
diff --git a/translations/admin.en.xlf b/translations/admin.en.xlf index 03108d5..f589077 100644 --- a/translations/admin.en.xlf +++ b/translations/admin.en.xlf @@ -2,6 +2,11 @@ + + by + by + + list.label__actions @@ -19,6 +24,10 @@ list.action_view Show + + list.label_id + # + @@ -37,6 +46,10 @@ dashboard.label_parameter Parameters + + dashboard.label_batch_log + Batch log + breadcrumb.link_parameter_list Parameter list @@ -45,6 +58,10 @@ breadcrumb.link_parameter_create Creating a parameter + + breadcrumb.link_batch_log_list + Logs list + fieldset.label_general @@ -119,6 +136,72 @@ form.label_password_confirmation Password Confirmation + + field.label_name + Name + + + field.label_context + Context + + + field.label_date + Date + + + field.label_success + Success + + + field.label_summary + Summary + + + field.label_comment + Comment + + + field.label_data + Data + + + + + history.none + No history available. + + + history.email.sent + Email sent : + + + history.entity.created + Entity created + + + history.entity.updated + Entity updated + + + history.entity.archived + Entity archived + + + history.error + Error : + + + history.external + External event : + + + history.interne + Internal process : + + + history.timeline_context + [context %context%] + diff --git a/translations/admin.fr.xlf b/translations/admin.fr.xlf index 1d252bd..fa22791 100644 --- a/translations/admin.fr.xlf +++ b/translations/admin.fr.xlf @@ -154,7 +154,7 @@ field.label_summary - Résumer + Résumé field.label_comment diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index c675ab3..2a53409 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -55,6 +55,32 @@ enum.process_status.error Error + + + + env_banner_message.developpement + Development - Developer localhost]]> + + + env_banner_message.development + Development - Developer localhost]]> + + + env_banner_message.dev + Development - Developer localhost]]> + + + env_banner_message.integration + Integration - Internal validation environment]]> + + + env_banner_message.recette + Pre Prod - Customer validation environment]]> + + + env_banner_message.unknown + - Unknown environment + \ No newline at end of file diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index 8d2a198..4c889ae 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -55,6 +55,32 @@ enum.process_status.error Erreur + + + + env_banner_message.developpement + Développement - Poste du développeur]]> + + + env_banner_message.development + Développement - Poste du développeur]]> + + + env_banner_message.dev + Développement - Poste du développeur]]> + + + env_banner_message.integration + Intégration - Environnement de validation interne]]> + + + env_banner_message.recette + Recette - Environnement de validation client]]> + + + env_banner_message.unknown + - Environnement inconnu + \ No newline at end of file