diff --git a/config-templates/module_accounting.php b/config-templates/module_accounting.php index 69a9027adaf88b869070fa49ba29857a581ade07..8cd7b9339ad94554eaf895fffec11af546828c96 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 22f17b95949fc2e243781baa76507faecaca8e30..49795d2a93a6d43e18cf19522d2a3add0faebb1f 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 c4b029ec9001838695b03699af090080f35e6648..45bda1418216cf9d09d749ce2fe198b247301c6f 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 3d911d921eb11ceb341deb752315b988635b6564..3c3edfbf585c49109401cd9e12cca6f09d365b4d 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 0000000000000000000000000000000000000000..66d5be54c11675d875dd4f966e2df6098b3b84e6 --- /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 5113e37d0e0ba7a36cd3df6877d0203df3ffd95c..43ec4bb7109792efef5b4b9885b8ae5968b399c4 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 014f2e51d17f002891a5f9312833b4fb0e3198fa..a61244b97598e0a677e45cd876290c9cbe8bea6c 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 77a9114d9cd948b7fcc6fecf29ef15e54423b57e..ab0c7d4cf228f58609e5bf792e10232bfa5f268c 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()); + } }