Skip to content

Commit

Permalink
[FINNA-2865] Add site status bar (#3090)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksip authored Dec 4, 2024
1 parent 2632617 commit 133031d
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 0 deletions.
6 changes: 6 additions & 0 deletions local/config/finna/config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
67 changes: 67 additions & 0 deletions module/Finna/src/Finna/Site/SiteStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* Site status enum.
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Site
* @author Aleksi Peebles <aleksi.peebles@helsinki.fi>
* @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 <aleksi.peebles@helsinki.fi>
* @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;
}
}
64 changes: 64 additions & 0 deletions module/Finna/src/Finna/View/Helper/Root/SiteStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Site status helper class.
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package View_Helpers
* @author Aleksi Peebles <aleksi.peebles@helsinki.fi>
* @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 <aleksi.peebles@helsinki.fi>
* @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;
}
}
75 changes: 75 additions & 0 deletions module/Finna/src/Finna/View/Helper/Root/SiteStatusFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Site status helper factory.
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package View_Helpers
* @author Aleksi Peebles <aleksi.peebles@helsinki.fi>
* @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 <aleksi.peebles@helsinki.fi>
* @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);
}
}
23 changes: 23 additions & 0 deletions themes/finna2/scss/finna/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions themes/finna2/templates/layout/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
?>
<a class="skip-link" href="#<?=$contentElementId?>"><?=$this->transEsc('Skip to content') // skip to content ?></a>
<header class="hidden-print">
<?php if (($siteStatus = $this->siteStatus()) !== \Finna\Site\SiteStatus::PRODUCTION): ?>
<div class="container-fluid site-status-bar <?= $siteStatus->getCssClass() ?>">
<?= $this->transEsc($siteStatus->getTranslationKey()) ?>
</div>
<?php endif; ?>
<?php if ($this->bazaarSession()->isActive()): ?>
<?=$this->partial('Helpers/bazaar-browse-bar.phtml');?>
<?php endif; ?>
Expand Down
2 changes: 2 additions & 0 deletions themes/finna2/theme.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 133031d

Please sign in to comment.