From 133031df9dfa90acd8e4fb6f5404bfe403cf980b Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Wed, 4 Dec 2024 11:16:04 +0200 Subject: [PATCH] [FINNA-2865] Add site status bar (#3090) --- local/config/finna/config.ini.sample | 6 ++ local/languages/finna/en-gb.ini | 4 + local/languages/finna/fi.ini | 4 + local/languages/finna/sv.ini | 4 + module/Finna/src/Finna/Site/SiteStatus.php | 67 +++++++++++++++++ .../src/Finna/View/Helper/Root/SiteStatus.php | 64 ++++++++++++++++ .../View/Helper/Root/SiteStatusFactory.php | 75 +++++++++++++++++++ themes/finna2/scss/finna/common.scss | 23 ++++++ themes/finna2/templates/layout/layout.phtml | 5 ++ themes/finna2/theme.config.php | 2 + 10 files changed, 254 insertions(+) create mode 100644 module/Finna/src/Finna/Site/SiteStatus.php create mode 100644 module/Finna/src/Finna/View/Helper/Root/SiteStatus.php create mode 100644 module/Finna/src/Finna/View/Helper/Root/SiteStatusFactory.php diff --git a/local/config/finna/config.ini.sample b/local/config/finna/config.ini.sample index 3ac4ce24b8a..dc9d42edeb1 100644 --- a/local/config/finna/config.ini.sample +++ b/local/config/finna/config.ini.sample @@ -1895,3 +1895,9 @@ Summon = tabs_summon [ReservationList] ; Enable functionality in view by uncommenting the next line ;enabled = true + +[Finna] +; Site status. Displayed in a status bar unless value is 'production'. +; Possible values are: 'production', 'beta', 'test' and 'disabled'. +; Default value is 'production'. +site_status = production diff --git a/local/languages/finna/en-gb.ini b/local/languages/finna/en-gb.ini index 6ee91623ff4..e305cbf2ee9 100644 --- a/local/languages/finna/en-gb.ini +++ b/local/languages/finna/en-gb.ini @@ -1097,6 +1097,10 @@ SMS Number = "SMS Number" sms_number_format_hint = "Use format +3584... or +3585..." site_header_slogan = "site_header_slogan " site_header_slogan_small = "site_header_slogan_small " +site_status_beta = "Beta" +site_status_disabled = "Disabled" +site_status_production = "Production" +site_status_test = "Test" socialmedia_share_in_facebook = "Share on Facebook" socialmedia_share_in_pinterest = "Share on Pinterest" socialmedia_share_in_twitter = "Share on Twitter" diff --git a/local/languages/finna/fi.ini b/local/languages/finna/fi.ini index 49457eb14fe..2411f603e42 100644 --- a/local/languages/finna/fi.ini +++ b/local/languages/finna/fi.ini @@ -1090,6 +1090,10 @@ SMS Number = "Numero tekstiviesteille" sms_number_format_hint = "Anna muodossa +3584... tai +3585..." site_header_slogan = "site_header_slogan " site_header_slogan_small = "site_header_slogan_small " +site_status_beta = "Beta" +site_status_disabled = "Poistettu käytöstä" +site_status_production = "Tuotanto" +site_status_test = "Testi" socialmedia_share_in_facebook = "Jaa Facebookiin" socialmedia_share_in_pinterest = "Jaa Pinterestiin" socialmedia_share_in_twitter = "Jaa Twitteriin" diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index 7f404dd3d84..448e9c330d0 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -1088,6 +1088,10 @@ SMS Number = "SMS-nummer" sms_number_format_hint = "Använd format +3584... eller +3585..." site_header_slogan = "site_header_slogan " site_header_slogan_small = "site_header_slogan_small " +site_status_beta = "Beta" +site_status_disabled = "Inaktiverad" +site_status_production = "Produktion" +site_status_test = "Test" socialmedia_share_in_facebook = "Dela på Facebook" socialmedia_share_in_pinterest = "Dela på Pinterest" socialmedia_share_in_twitter = "Dela på Twitter" diff --git a/module/Finna/src/Finna/Site/SiteStatus.php b/module/Finna/src/Finna/Site/SiteStatus.php new file mode 100644 index 00000000000..8b96604e3d1 --- /dev/null +++ b/module/Finna/src/Finna/Site/SiteStatus.php @@ -0,0 +1,67 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ + +namespace Finna\Site; + +/** + * Site status enum. + * + * @category VuFind + * @package Site + * @author Aleksi Peebles + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +enum SiteStatus: string +{ + case BETA = 'beta'; + case DISABLED = 'disabled'; + case PRODUCTION = 'production'; + case TEST = 'test'; + + /** + * Return a translation key representing the status. + * + * @return string + */ + public function getTranslationKey(): string + { + return 'site_status_' . $this->value; + } + + /** + * Return a CSS class representing the status. + * + * @return string + */ + public function getCssClass(): string + { + return 'site-status-' . $this->value; + } +} diff --git a/module/Finna/src/Finna/View/Helper/Root/SiteStatus.php b/module/Finna/src/Finna/View/Helper/Root/SiteStatus.php new file mode 100644 index 00000000000..5ffab773dd3 --- /dev/null +++ b/module/Finna/src/Finna/View/Helper/Root/SiteStatus.php @@ -0,0 +1,64 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ + +namespace Finna\View\Helper\Root; + +use Finna\Site\SiteStatus as SiteStatusEnum; + +/** + * Site status helper class. + * + * @category VuFind + * @package View_Helpers + * @author Aleksi Peebles + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +class SiteStatus extends \Laminas\View\Helper\AbstractHelper +{ + /** + * Constructor. + * + * @param array $config Configuration + */ + public function __construct(protected array $config) + { + } + + /** + * Return site status. + * + * @return SiteStatusEnum + */ + public function __invoke(): SiteStatusEnum + { + return SiteStatusEnum::tryFrom($this->config['Finna']['site_status'] ?? '') + ?? SiteStatusEnum::PRODUCTION; + } +} diff --git a/module/Finna/src/Finna/View/Helper/Root/SiteStatusFactory.php b/module/Finna/src/Finna/View/Helper/Root/SiteStatusFactory.php new file mode 100644 index 00000000000..d10683fdc75 --- /dev/null +++ b/module/Finna/src/Finna/View/Helper/Root/SiteStatusFactory.php @@ -0,0 +1,75 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ + +namespace Finna\View\Helper\Root; + +use Laminas\ServiceManager\Exception\ServiceNotCreatedException; +use Laminas\ServiceManager\Exception\ServiceNotFoundException; +use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerExceptionInterface as ContainerException; +use Psr\Container\ContainerInterface; + +/** + * Site status helper factory. + * + * @category VuFind + * @package View_Helpers + * @author Aleksi Peebles + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +class SiteStatusFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke( + ContainerInterface $container, + $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + $config = $container->get(\VuFind\Config\PluginManager::class) + ->get('config')->toArray(); + return new $requestedName($config); + } +} diff --git a/themes/finna2/scss/finna/common.scss b/themes/finna2/scss/finna/common.scss index ed6dcdc8e40..f69486287ac 100644 --- a/themes/finna2/scss/finna/common.scss +++ b/themes/finna2/scss/finna/common.scss @@ -147,6 +147,29 @@ float: right; } +/* Site status bar */ +.site-status-bar { + color: #fff; + background-color: $brand-info; + padding-top: 0.6em; + padding-bottom: 0.6em; + text-align: center; + z-index: 1; + &.site-status-beta { + background-color: $brand-warning; + } + &.site-status-disabled { + background-color: $brand-danger; + } + &.site-status-production { + display: none; + } + @media (max-width: $grid-float-breakpoint) { + position: relative; + top: $navbar-height; + } +} + //== SYSTEM MESSAGES .system-messages { background-color: $state-warning-bg; diff --git a/themes/finna2/templates/layout/layout.phtml b/themes/finna2/templates/layout/layout.phtml index ec73902864c..fe51208e376 100644 --- a/themes/finna2/templates/layout/layout.phtml +++ b/themes/finna2/templates/layout/layout.phtml @@ -173,6 +173,11 @@ ?>
+ siteStatus()) !== \Finna\Site\SiteStatus::PRODUCTION): ?> +
+ transEsc($siteStatus->getTranslationKey()) ?> +
+ bazaarSession()->isActive()): ?> partial('Helpers/bazaar-browse-bar.phtml');?> diff --git a/themes/finna2/theme.config.php b/themes/finna2/theme.config.php index f10d79e2f33..4aec817c867 100644 --- a/themes/finna2/theme.config.php +++ b/themes/finna2/theme.config.php @@ -65,6 +65,7 @@ 'Finna\View\Helper\Root\SearchMemory' => 'VuFind\View\Helper\Root\SearchMemoryFactory', 'Finna\View\Helper\Root\SearchTabs' => 'Finna\View\Helper\Root\SearchTabsFactory', 'Finna\View\Helper\Root\SearchTabsRecommendations' => 'Finna\View\Helper\Root\SearchTabsRecommendationsFactory', + \Finna\View\Helper\Root\SiteStatus::class => \Finna\View\Helper\Root\SiteStatusFactory::class, 'Finna\View\Helper\Root\StreetSearch' => 'Laminas\ServiceManager\Factory\InvokableFactory', 'Finna\View\Helper\Root\StripTags' => 'Laminas\ServiceManager\Factory\InvokableFactory', 'Finna\View\Helper\Root\Summon' => 'Finna\View\Helper\Root\SummonFactory', @@ -133,6 +134,7 @@ 'searchbox' => 'Finna\View\Helper\Root\SearchBox', 'searchMemory' => 'Finna\View\Helper\Root\SearchMemory', 'searchTabsRecommendations' => 'Finna\View\Helper\Root\SearchTabsRecommendations', + 'siteStatus' => \Finna\View\Helper\Root\SiteStatus::class, 'streetSearch' => 'Finna\View\Helper\Root\StreetSearch', 'systemMessages' => 'Finna\View\Helper\Root\SystemMessages', 'tags' => 'Finna\View\Helper\Root\Tags',