From cde47062dcf51e6df6a1c33af0edb7c0439c781d Mon Sep 17 00:00:00 2001 From: Marko Ivancic <marko.ivancic@srce.hr> Date: Mon, 28 Aug 2023 10:20:38 +0000 Subject: [PATCH] Enable action buttons config --- config-templates/module_accounting.php | 13 ++++++ public/assets/css/src/default.css | 49 ++++++++++++++++++++ src/Http/Controllers/User/Profile.php | 4 +- src/ModuleConfiguration.php | 6 +++ templates/user/includes/_action-buttons.twig | 8 ++++ templates/user/personal-data.twig | 3 ++ tests/config-templates/module_accounting.php | 2 + tests/src/ModuleConfigurationTest.php | 14 ++++++ 8 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 templates/user/includes/_action-buttons.twig diff --git a/config-templates/module_accounting.php b/config-templates/module_accounting.php index 69a9027..8cd7b93 100755 --- a/config-templates/module_accounting.php +++ b/config-templates/module_accounting.php @@ -249,4 +249,17 @@ $config = [ */ ModuleConfiguration::OPTION_CRON_TAG_FOR_TRACKER_DATA_RETENTION_POLICY => 'accounting_tracker_data_retention_policy', + + /** + * Enable or disable 'action buttons'. Action buttons are displayed on 'Personal data' page, and can be used to + * provide links to relevant endpoints, for example to change a password, send email to support, etc. + * + * Note that you can easily override the action buttons Twig template using standard SimpleSAMLphp + * custom theming features: https://simplesamlphp.org/docs/stable/simplesamlphp-theming + * + * The path to the action buttons template file is: + * modules/accounting/templates/user/includes/_action-buttons.twig, so when creating a custom theme file, + * place it in: modules/mymodule/themes/fancytheme/accounting/user/includes/_action-buttons.twig + */ + ModuleConfiguration::OPTION_ACTION_BUTTONS_ENABLED => true, ]; diff --git a/public/assets/css/src/default.css b/public/assets/css/src/default.css index 22f17b9..49795d2 100755 --- a/public/assets/css/src/default.css +++ b/public/assets/css/src/default.css @@ -485,3 +485,52 @@ .close-btn:hover { color: black; } + +/* ================== */ +/* Dropdown */ +/* ================== */ + +.dropbtn { + background-color: #3C4A94; + color: var(--main-bg-c); + font-family: var(--main-font-family); + padding: 0.4em; + font-size: 100%; + border: none; + cursor: pointer; + width: 10em; + text-decoration: none; +} + +.dropdown { + position: relative; + display: inline-block; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #3C4A94; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; +} + +.dropdown-content a { + color: var(--main-bg-c); + padding: 12px 16px; + text-decoration: none; + display: block; + font-size: 80%; + font-family: var(--main-font-family); +} + +.dropdown-content a:hover {background-color: #4f5c9b} + +.dropdown:hover .dropdown-content { + display: block; +} + +.dropdown:hover .dropbtn { + background-color: #4f5c9b; +} diff --git a/src/Http/Controllers/User/Profile.php b/src/Http/Controllers/User/Profile.php index c4b029e..45bda14 100755 --- a/src/Http/Controllers/User/Profile.php +++ b/src/Http/Controllers/User/Profile.php @@ -127,8 +127,10 @@ class Profile $normalizedAttributes[$name] = implode('; ', $value); } + $actionButtonsEnabled = $this->moduleConfiguration->getActionButtonsEnabled(); + $template = $this->resolveTemplate('accounting:user/personal-data.twig'); - $template->data += compact('normalizedAttributes'); + $template->data += compact('normalizedAttributes', 'actionButtonsEnabled'); return $template; } diff --git a/src/ModuleConfiguration.php b/src/ModuleConfiguration.php index 3d911d9..3c3edfb 100755 --- a/src/ModuleConfiguration.php +++ b/src/ModuleConfiguration.php @@ -39,6 +39,7 @@ class ModuleConfiguration public const OPTION_CRON_TAG_FOR_TRACKER_DATA_RETENTION_POLICY = 'cron_tag_for_tracker_data_retention_policy'; public const OPTION_PROVIDER_FOR_CONNECTED_SERVICES = 'provider_for_connected_services'; public const OPTION_PROVIDER_FOR_ACTIVITY = 'provider_for_activity'; + public const OPTION_ACTION_BUTTONS_ENABLED = 'action_buttons_enabled'; /** * Contains configuration from module configuration file. @@ -483,4 +484,9 @@ class ModuleConfiguration { return $this->getConfiguration()->getString(self::OPTION_CRON_TAG_FOR_TRACKER_DATA_RETENTION_POLICY); } + + public function getActionButtonsEnabled(): bool + { + return $this->getConfiguration()->getBoolean(self::OPTION_ACTION_BUTTONS_ENABLED); + } } diff --git a/templates/user/includes/_action-buttons.twig b/templates/user/includes/_action-buttons.twig new file mode 100644 index 0000000..66d5be5 --- /dev/null +++ b/templates/user/includes/_action-buttons.twig @@ -0,0 +1,8 @@ + +<div class="dropdown"> + <button class="dropbtn">{% trans %}TODO Actions{% endtrans %} ▾</button> + <div class="dropdown-content"> + <a href="#">{% trans %}Download data{% endtrans %}</a> + <a href="#">{% trans %}Custom action{% endtrans %}</a> + </div> +</div> diff --git a/templates/user/personal-data.twig b/templates/user/personal-data.twig index 5113e37..43ec4bb 100755 --- a/templates/user/personal-data.twig +++ b/templates/user/personal-data.twig @@ -14,6 +14,9 @@ {% endblock %} {% block content %} + {% if actionButtonsEnabled %} + {% include "@accounting/user/includes/_action-buttons.twig" %} + {% endif %} <table> <!-- fixed table header --> <tr> diff --git a/tests/config-templates/module_accounting.php b/tests/config-templates/module_accounting.php index 014f2e5..a61244b 100755 --- a/tests/config-templates/module_accounting.php +++ b/tests/config-templates/module_accounting.php @@ -67,4 +67,6 @@ $config = [ 'accounting_tracker_data_retention_policy', ModuleConfiguration::OPTION_CRON_TAG_FOR_JOB_RUNNER => 'accounting_job_runner', + + ModuleConfiguration::OPTION_ACTION_BUTTONS_ENABLED => true, ]; diff --git a/tests/src/ModuleConfigurationTest.php b/tests/src/ModuleConfigurationTest.php index 77a9114..ab0c7d4 100755 --- a/tests/src/ModuleConfigurationTest.php +++ b/tests/src/ModuleConfigurationTest.php @@ -403,4 +403,18 @@ class ModuleConfigurationTest extends TestCase ] ); } + + public function testCanGetActionButtonsEnabled(): void + { + $moduleConfiguration = new ModuleConfiguration(); + + $this->assertTrue($moduleConfiguration->getActionButtonsEnabled()); + + $moduleConfiguration = new ModuleConfiguration( + null, + [ModuleConfiguration::OPTION_ACTION_BUTTONS_ENABLED => false] + ); + + $this->assertFalse($moduleConfiguration->getActionButtonsEnabled()); + } } -- GitLab