Skip to content

Commit

Permalink
Merge pull request #63 from smartbooster/api_call_origin_filter_and_e…
Browse files Browse the repository at this point in the history
…nv_ui_banner

Api call origin filter and env UI banner
  • Loading branch information
mathieu-ducrot authored Jun 7, 2024
2 parents 6985668 + 5eee4d1 commit 7097be4
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions assets/styles/_skin.scss
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
19 changes: 15 additions & 4 deletions src/Admin/Monitoring/AbstractApiCallAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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'])
Expand All @@ -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',
Expand Down Expand Up @@ -158,4 +167,6 @@ private function getStatusChoices(): array
}

abstract protected function getRouteChoices(): array;

abstract protected function getOriginChoices(): array;
}
6 changes: 6 additions & 0 deletions templates/empty_layout.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}

Expand All @@ -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 %}
36 changes: 36 additions & 0 deletions templates/macros/ui_banner.html.twig
Original file line number Diff line number Diff line change
@@ -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 = '<b>' ~ smart_server_environment ~ '</b>' ~ ('env_banner_message.unknown')|trans %}
{% endif %}
<div class="sb-tailwind">
<div {% if absolute %}class="absolute w-full"{% endif %}>
<div class="text-center text-xs leading-6 p-0.5 {{ env_banner_class }}">
{% if env_banner_message_not_found is defined %}
{{ env_banner_message_not_found|raw }}
{% else %}
{{ ('env_banner_message.' ~ smart_server_environment)|trans|raw }}
{% endif %}
</div>
<div class="h-px bg-slate-700"></div>
</div>
</div>
{% endif %}
{% endmacro %}
17 changes: 17 additions & 0 deletions templates/standard_layout.html.twig
Original file line number Diff line number Diff line change
@@ -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 #}
<div class="main-sidebar-under-banner">
{{ parent() }}
</div>
{% else %}
{{ parent() }}
{% endif %}
{% endblock %}

{% block side_bar_before_nav %}
{% if app.user and is_granted('ROLE_SONATA_ADMIN') %}
<div class="user-panel">
Expand Down
83 changes: 83 additions & 0 deletions translations/admin.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="by">
<source>by</source>
<target> by </target>
</trans-unit>

<!-- Lists Action -->
<trans-unit id="list.label__actions">
<source>list.label__actions</source>
Expand All @@ -19,6 +24,10 @@
<source>list.action_view</source>
<target>Show</target>
</trans-unit>
<trans-unit id="list.label_id">
<source>list.label_id</source>
<target>#</target>
</trans-unit>

<!-- Dashboard & navigation -->
<trans-unit id="dashboard.label_documentations">
Expand All @@ -37,6 +46,10 @@
<source>dashboard.label_parameter</source>
<target>Parameters</target>
</trans-unit>
<trans-unit id="dashboard.label_batch_log">
<source>dashboard.label_batch_log</source>
<target>Batch log</target>
</trans-unit>
<trans-unit id="breadcrumb.link_parameter_list">
<source>breadcrumb.link_parameter_list</source>
<target>Parameter list</target>
Expand All @@ -45,6 +58,10 @@
<source>breadcrumb.link_parameter_create</source>
<target>Creating a parameter</target>
</trans-unit>
<trans-unit id="breadcrumb.link_batch_log_list">
<source>breadcrumb.link_batch_log_list</source>
<target>Logs list</target>
</trans-unit>

<trans-unit id="fieldset.label_general">
<source>fieldset.label_general</source>
Expand Down Expand Up @@ -119,6 +136,72 @@
<source>form.label_password_confirmation</source>
<target>Password Confirmation</target>
</trans-unit>
<trans-unit id="field.label_name">
<source>field.label_name</source>
<target>Name</target>
</trans-unit>
<trans-unit id="field.label_context">
<source>field.label_context</source>
<target>Context</target>
</trans-unit>
<trans-unit id="field.label_date">
<source>field.label_date</source>
<target>Date</target>
</trans-unit>
<trans-unit id="field.label_success">
<source>field.label_success</source>
<target>Success</target>
</trans-unit>
<trans-unit id="field.label_summary">
<source>field.label_summary</source>
<target>Summary</target>
</trans-unit>
<trans-unit id="field.label_comment">
<source>field.label_comment</source>
<target>Comment</target>
</trans-unit>
<trans-unit id="field.label_data">
<source>field.label_data</source>
<target>Data</target>
</trans-unit>

<!-- History -->
<trans-unit id="history.none">
<source>history.none</source>
<target>No history available.</target>
</trans-unit>
<trans-unit id="history.email.sent">
<source>history.email.sent</source>
<target>Email sent : </target>
</trans-unit>
<trans-unit id="history.entity.created">
<source>history.entity.created</source>
<target>Entity created</target>
</trans-unit>
<trans-unit id="history.entity.updated">
<source>history.entity.updated</source>
<target>Entity updated</target>
</trans-unit>
<trans-unit id="history.entity.archived">
<source>history.entity.archived</source>
<target>Entity archived</target>
</trans-unit>
<trans-unit id="history.error">
<source>history.error</source>
<target>Error : </target>
</trans-unit>
<trans-unit id="history.external">
<source>history.external</source>
<target>External event : </target>
</trans-unit>
<trans-unit id="history.interne">
<source>history.interne</source>
<target>Internal process : </target>
</trans-unit>
<trans-unit id="history.timeline_context">
<source>history.timeline_context</source>
<target> [context %context%]</target>
</trans-unit>

<!-- Action -->
<trans-unit id="action.impersonate">
Expand Down
2 changes: 1 addition & 1 deletion translations/admin.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
</trans-unit>
<trans-unit id="field.label_summary">
<source>field.label_summary</source>
<target>Résumer</target>
<target>Résumé</target>
</trans-unit>
<trans-unit id="field.label_comment">
<source>field.label_comment</source>
Expand Down
26 changes: 26 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@
<source>enum.process_status.error</source>
<target>Error</target>
</trans-unit>

<!-- Env Banner -->
<trans-unit id="env_banner_message.developpement">
<source>env_banner_message.developpement</source>
<target><![CDATA[<b>Development</b> - Developer localhost]]></target>
</trans-unit>
<trans-unit id="env_banner_message.development">
<source>env_banner_message.development</source>
<target><![CDATA[<b>Development</b> - Developer localhost]]></target>
</trans-unit>
<trans-unit id="env_banner_message.dev">
<source>env_banner_message.dev</source>
<target><![CDATA[<b>Development</b> - Developer localhost]]></target>
</trans-unit>
<trans-unit id="env_banner_message.integration">
<source>env_banner_message.integration</source>
<target><![CDATA[<b>Integration</b> - Internal validation environment]]></target>
</trans-unit>
<trans-unit id="env_banner_message.recette">
<source>env_banner_message.recette</source>
<target><![CDATA[<b>Pre Prod</b> - Customer validation environment]]></target>
</trans-unit>
<trans-unit id="env_banner_message.unknown">
<source>env_banner_message.unknown</source>
<target> - Unknown environment</target>
</trans-unit>
</body>
</file>
</xliff>
26 changes: 26 additions & 0 deletions translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@
<source>enum.process_status.error</source>
<target>Erreur</target>
</trans-unit>

<!-- Env Banner -->
<trans-unit id="env_banner_message.developpement">
<source>env_banner_message.developpement</source>
<target><![CDATA[<b>Développement</b> - Poste du développeur]]></target>
</trans-unit>
<trans-unit id="env_banner_message.development">
<source>env_banner_message.development</source>
<target><![CDATA[<b>Développement</b> - Poste du développeur]]></target>
</trans-unit>
<trans-unit id="env_banner_message.dev">
<source>env_banner_message.dev</source>
<target><![CDATA[<b>Développement</b> - Poste du développeur]]></target>
</trans-unit>
<trans-unit id="env_banner_message.integration">
<source>env_banner_message.integration</source>
<target><![CDATA[<b>Intégration</b> - Environnement de validation interne]]></target>
</trans-unit>
<trans-unit id="env_banner_message.recette">
<source>env_banner_message.recette</source>
<target><![CDATA[<b>Recette</b> - Environnement de validation client]]></target>
</trans-unit>
<trans-unit id="env_banner_message.unknown">
<source>env_banner_message.unknown</source>
<target> - Environnement inconnu</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 7097be4

Please sign in to comment.