Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDPT-1939: Splash page #800

Merged
merged 9 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions public/app/themes/clarity/agency-switcher.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
<?php

use MOJ\Intranet\Agency;

/*
* Agency switcher
*/
get_header();
?>

<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main">
<h1 class="o-title o-title--page">Choose your agency or body</h1>
<p>Other agencies and bodies have their own specific intranet content available to view by visiting the links below. HMPPS and YJB links are external intranet websites not managed by this central MoJ intranet.</p>
<?php get_template_part('src/components/c-intranet-switcher/view'); ?>
</main>
$oAgency = new Agency();
$simpleHeader = !$oAgency->hasAgencyCookie();

$heading = 'Choose the version of the intranet you want to see';
$body = null;
// If we're using the simple header, assume a new user and change the intro text to reflect this
if ($simpleHeader) {
$heading = 'Welcome to the Ministry of Justice intranet';
$body = '<p>Choose the version you want to see.</p><p>You can change this at any time using the "Switch to other
intranet" link at the top of any page.</p>';
}
?>
<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main">
<h1 class="o-title o-title--page">
<?= $heading ?>
</h1>
<?= $body ? "<p>$body</p>" : '' ?>
<?php get_template_part('src/components/c-intranet-switcher/view'); ?>
</main>
<?php
get_footer();
52 changes: 43 additions & 9 deletions public/app/themes/clarity/inc/agency.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function getList()
* - label (string) - Text label for the link
* - classes (string) (optional) - Classes for the HTML element
* - is_external (boolean) - Is this a link to an external site?
* - main (boolean) - Should this link be used for the agency switcher?
* - has_archive (boolean) (optional) - is the intranet archive available for this agency?
*/

Expand Down Expand Up @@ -72,8 +73,9 @@ public function getList()
'is_integrated' => false,
'links' => [
[
'url' => 'https://intranet.noms.gsi.gov.uk/',
'url' => 'https://justiceuk.sharepoint.com/sites/HMPPSIntranet',
'label' => 'HM Prison & Probation Service intranet',
'main' => true,
'is_external' => true
]
]
Expand All @@ -90,14 +92,8 @@ public function getList()
'shortcode' => 'law-commission',
'label' => 'Law Commission',
'abbreviation' => 'LawCom',
'is_integrated' => false,
'links' => [
[
'url' => 'http://lawcommission.intranet.service.justice.gov.uk/',
'label' => 'Law Commission intranet',
'is_external' => true
]
]
'is_integrated' => true,
'links' => []
],
'laa' => [
'shortcode' => 'laa',
Expand Down Expand Up @@ -155,6 +151,36 @@ public function getList()
'is_integrated' => true,
'contact_email_address' => '[email protected]',
'links' => []
],
'ima' => [
'shortcode' => 'ima',
'label' => 'Independent Monitoring Authority',
'abbreviation' => 'IMA',
'is_integrated' => false,
'contact_email_address' => '',
'links' => [
[
'url' => 'https://myima.ima-citizensrights.org.uk',
'label' => 'Independent Monitoring Authority intranet',
'main' => true,
'is_external' => true
]
]
],
'yjbrh' => [
'shortcode' => 'yjbrh',
'label' => 'Youth Justice Board Resource Hub',
'abbreviation' => 'YJBRH',
'is_integrated' => false,
'contact_email_address' => '',
'links' => [
[
'url' => 'https://yjresourcehub.uk/',
'label' => 'Youth Justice Board Resource Hub intranet',
'main' => true,
'is_external' => true
]
]
]
];

Expand All @@ -169,6 +195,14 @@ public function getList()
return $agencies_array;
}

/*
* Check if the agency cookie is set
*/
public function hasAgencyCookie(): bool
{
return !empty($_COOKIE['dw_agency']);
}
EmilyHazlehurst marked this conversation as resolved.
Show resolved Hide resolved

/***
* Get the agency from cookie, and make sure it's in
* the list, otherwise default to HQ
Expand Down
46 changes: 29 additions & 17 deletions public/app/themes/clarity/inc/cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/
add_action('wp', function () {
$agency_default = 'hq';
$agency = $_GET['agency'] ?? false;
$agency_param = $_GET['agency'] ?? false;
$agencies = new Agency();

$options = [
'expires' => time() + (3650 * DAY_IN_SECONDS),
Expand All @@ -20,29 +21,40 @@
if (!empty($_SERVER["HTTPS"])) {
$options['secure'] = true;
}
// If the agency param is set, set the dw_agency cookie and return
if ($agency_param) {
$agency = trim($agency_param);

$agencies = new Agency();
if ($agency) {
// tidy up
$agency = trim($agency);

// If the agency is not valid, set it to the default agency ('hq')
if (!$agencies->agencyExists($agency)) {
$agency = $agency_default;
}

// set a cookie with an agency defined by the user
setcookie('dw_agency', $agency, $options);
$_COOKIE['dw_agency'] = $agency;

// else fires if agency is false and
// a dw_agency cookie does not exist
} else {
$agency = $_COOKIE['dw_agency'] ?? '';

if (!$agencies->agencyExists($agency)) {
setcookie('dw_agency', $agency_default, $options);
$_COOKIE['dw_agency'] = $agency_default;
}
// Return
return;
}
// Otherwise, check if the agency cookie is already set
$agency = $_COOKIE['dw_agency'] ?? '';
$slug = get_post_field('post_name');
if (
// If the agency cookie isn't set or is set to an invalid agency
EmilyHazlehurst marked this conversation as resolved.
Show resolved Hide resolved
!$agencies->agencyExists($agency) &&
// And the current page isn't the agency switcher, privacy notice, or accessibility page
!in_array($slug, ['agency-switcher', 'privacy-notice', 'accessibility'], true) &&
// And the user isn't logged in
!is_user_logged_in() &&
// And we're not in the admin area
(!is_admin() && !wp_doing_ajax() && !wp_doing_cron())
)
{
$url = '/agency-switcher';
// Set the send_back param so that we can send the user back to the current page after selecting an agency
$url = add_query_arg(['send_back' => urlencode(get_permalink())], $url);
// Redirect to the agency switcher page
wp_safe_redirect($url);
exit;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@

.c-header-container {
margin-bottom: $spacing;

&--underlined {
border-bottom: 10px solid $defaultAgencyColour;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<header class="c-header-container" role="banner">
<?php

use MOJ\Intranet\Agency;

$oAgency = new Agency();

// Show a simplified header if the user has not yet chosen an agency
$simpleHeader = !$oAgency->hasAgencyCookie();

?>
<header class="c-header-container<?= $simpleHeader ? " c-header-container--underlined" : ""?>" role="banner">

<?php
// Hide the search bar and main nav bar if hideHeader is set, e.g. on first login before the user has chosen an agency
get_template_part('src/components/c-logo-bar/view');
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
?>

if (!$simpleHeader) {
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
}
?>
<!--[if lte IE 9]>
<div class="u-message u-message--warning">
You are using an old browser that may impact your web browsing experience. It is recommended you switch to use Firefox or a modern version of Internet Explorer if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
clearfix();
&__switch {
margin-bottom: $spacing;
+above(m) {
column(1, $cycle: 1)
}

a {
display: block;
//background-color: $boxBg;
padding: $spacing*.5;
padding-left: 0;
color: $text-colour;
//border: 2px solid $boxBg;
font-size: $outerCore;
Expand All @@ -28,10 +26,16 @@
//border: 2px solid $boxBg;
}
}


}



&__list-element {
margin-bottom: $spacing*2;
&:last-child {
margin-bottom: 0;
}
}
&__heading {
font-size: $outerCore;
margin-bottom: 0 !important;
}
}
116 changes: 60 additions & 56 deletions public/app/themes/clarity/src/components/c-intranet-switcher/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,76 @@
$activeAgencies = $oAgency->getList();
$current_intranet = get_intranet_code();

$referrer = (isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER']) : parse_url(get_home_url()));
/**
* Remove the query parameter so it isn't sent
* twice/several times on repeated access to this page
*/
if (isset($referrer['query'])) {
parse_str($referrer['query'], $output);

if (isset($output['agency'])) {
unset($output['agency']);
}

$previous_parameters = [];
$url = get_home_url();

foreach ($output as $key => $value) {
$previous_parameters[] = $key . '=' . $value;
}
// Redirect back to the previous page after selecting an agency if this is their first visit
if (isset($_GET['send_back'])) {
// Validate the URL to prevent open redirects
$url = wp_validate_redirect($_GET['send_back'], get_home_url());
}

$referrer['query'] = implode('&', $previous_parameters);
// Temporarily filtering out JAC/PB until site is ready to go live
// 10th Jan 2024: Parole Board added to exclude list: https://dsdmoj.atlassian.net/jira/software/c/projects/CDPT/boards/1154?selectedIssue=CDPT-1170
$excluded = ['pb'];
$integrated = [];
$external = [];

$filteredAgencies = array_filter($activeAgencies, function($agency) use ($excluded) {
return !in_array($agency['shortcode'], $excluded);
});

array_map(function($key, array $agency) use (&$integrated, &$external) {
$shortcode = $agency['shortcode'];
if ($agency['is_integrated']) {
$integrated[$shortcode] = $agency;
} else {
$homepage = array_filter($agency['links'], function ($link) {
return $link['main'];
});

if (trim($referrer['query']) != '') {
$referrer['query'] = '&' . $referrer['query'];
$external[$shortcode] = $homepage ? [...$agency, 'homepage' => $homepage[0]['url']] : $agency;
}
} else {
$referrer['query'] = '';
}
}, array_keys($filteredAgencies), $filteredAgencies);

/**
* Displaying agencies by rows and adding agency
* specific classes to those agencies listed.
*/
?>

<div class="c-intranet-switcher">
<ul class="c-intranet-switcher">

<?php
// Temporarily filtering out JAC/PB until site is ready to go live
// 10th Jan 2024: Parole Board added to exclude list: https://dsdmoj.atlassian.net/jira/software/c/projects/CDPT/boards/1154?selectedIssue=CDPT-1170
// 17th July 2024: JAC removed
$modified_agency_array = array_filter($activeAgencies, function ($data) {
return $data["shortcode"] != 'pb';
});

foreach ($modified_agency_array as $agency_id => $agency) {
if ($current_intranet == $agency_id) {
$extra_class = ' u-active';
} else {
$extra_class = '';
<nav class="c-intranet-switcher__nav">
<ul class="c-intranet-switcher__list">
<li class="c-intranet-switcher__list-element">
<ul class="c-intranet-switcher__section">
<?php
foreach ($integrated as $agency_id => $agency) {
if ($current_intranet == $agency_id) {
$extra_class = ' u-active';
} else {
$extra_class = '';
}
echo '<li class="c-intranet-switcher__switch c-intranet-switcher__switch--' . $agency_id . $extra_class . ' "><a href="'. $url .'?agency=' . $agency_id . '">' . $agency['label'] . '</a></li>';
Dismissed Show dismissed Hide dismissed
}
?>
</ul>
</li>
<?php
if (!empty($external)) {
?>
<li class="c-intranet-switcher__list-element">
<h2 class="o-title o-title--subtitle c-intranet-switcher__heading">Other intranets</h2>
<p>These agencies have their own separate intranet sites.</p>
<ul class="c-intranet-switcher__section">
<?php
foreach ($external as $agency_id => $agency) {
echo '<li class="c-intranet-switcher__switch c-intranet-switcher__switch--' . $agency_id . ' "><a href="'. $agency['homepage']. '">' . $agency['label'] . '</a></li>';
}
?>
</ul>
</li>
<?php
}

if ($agency_id != 'noms') {
echo '<li class="c-intranet-switcher__switch c-intranet-switcher__switch--' . $agency_id . $extra_class . ' "><a href="/?agency=' . $agency_id . $referrer['query'] . '">' . $agency['label'] . '</a></li>';
} else {
echo '<li class="c-intranet-switcher__switch c-intranet-switcher__switch--' . $agency_id . $extra_class . ' "><a href="https://justiceuk.sharepoint.com/sites/HMPPSIntranet">' . $agency['label'] . '</a></li>';
}
}
?>

<li class="c-intranet-switcher__switch c-intranet-switcher__switch--ima">
<a href="https://myima.ima-citizensrights.org.uk">Independent Monitoring Authority</a>
</li>

<li class="c-intranet-switcher__switch c-intranet-switcher__switch--yjbrh">
<a href="https://yjresourcehub.uk/">Youth Justice Board</a>
</li>

</ul>
?>
</ul>
</nav>
</div>
Loading
Loading