Skip to content

Commit

Permalink
Merge pull request #3911 from sanger/sh51/add-environment-indicators
Browse files Browse the repository at this point in the history
Add more environment indicators to title and navbar
  • Loading branch information
stevieing authored Oct 30, 2023
2 parents 7683919 + 48d15c6 commit 48e18b6
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/frontend/stylesheets/all/colours.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* Colours defined per environment */
$production: $primary !default;
$training: $green !default;
$staging: $red !default;
$development: $gray-600 !default;

@mixin colour-badge($base_colour, $text_colour) {
background-color: $base_colour;
color: $text_colour;
Expand Down
14 changes: 14 additions & 0 deletions app/frontend/stylesheets/all/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
* Please ensure you keep it commented
*/

/* Background colours for different environments */
.bg-production {
background-color: $production;
}
.bg-training {
background-color: $training;
}
.bg-staging {
background-color: $staging;
}
.bg-development {
background-color: $development;
}

/* A Summary table presents simple key-value pairs */
.table-summary th {
text-align: right;
Expand Down
15 changes: 13 additions & 2 deletions app/frontend/stylesheets/all/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.main-nav {
@extend .navbar;
@extend .navbar-dark;
@extend .bg-danger;
@extend .bg-development; // development and unknown environments
@extend .navbar-expand-lg;

#logo_container {
Expand All @@ -17,9 +17,20 @@
}
}

// Set the background color of the navbar based on the environment
body.production {
.main-nav {
@extend .bg-primary;
@extend .bg-production;
}
}
body.training {
.main-nav {
@extend .bg-training;
}
}
body.staging {
.main-nav {
@extend .bg-staging;
}
}

Expand Down
29 changes: 29 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ def required_marker
icon('fas', 'asterisk', class: 'text-warning', title: 'required')
end

# Returns the appropriate icon suffix for the current environment
# Returns empty string for production
# Returns "-#{environment}" for training, staging
# Returns "-development" for any other environment
# @return [String] The suffix to append to the icon name
def icon_suffix
environment = Rails.env
case environment
when 'production'
''
when 'training', 'staging'
"-#{environment}"
else
'-development'
end
end

# Return the appropriate favicon for the current environment
# @return [String] The path to the favicon
def favicon
"favicon#{icon_suffix}.ico"
end

# Return the appropriate apple icon for the current environment
# @return [String] The path to the apple icon
def apple_icon
"apple-icon#{icon_suffix}.png"
end

def render_flashes
flash.each do |key, message|
concat(alert(key, id: "message_#{key}") { Array(message).each { |m| concat tag.div(m) } })
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<% end %>
<% end %>
<%= csrf_meta_tags %>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="/apple-icon.png" type="image/png" />
<link rel="shortcut icon" href="/<%= favicon %>" type="image/x-icon" />
<link rel="icon" href="/<%= favicon %>" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="/<%= apple_icon %>" type="image/png" />
</head>

<body class="<%= Rails.env %> <%= DeploymentEnvironment.role %>">
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/sessions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= vite_stylesheet_tag "application.scss", media: "all" %>
<title>Sequencescape : <%= I18n.t('global_links.login') %></title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="/apple-icon.png" type="image/png" />
<link rel="shortcut icon" href="/<%= favicon %>" type="image/x-icon" />
<link rel="icon" href="/<%= favicon %>" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="/<%= apple_icon %>" type="image/png" />
<% if Rails.application.config.disable_animations %>
<%= vite_stylesheet_tag 'disable_animations' %>

Expand Down
Binary file added public/apple-icon-development.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-staging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-training.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-development.ico
Binary file not shown.
Binary file added public/favicon-staging.ico
Binary file not shown.
Binary file added public/favicon-training.ico
Binary file not shown.
58 changes: 58 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,64 @@
require './app/helpers/application_helper'

describe ApplicationHelper do
describe '#favicon' do
subject(:favicon) { helper.favicon }

it 'returns the favicon path for the production environment' do
allow(Rails).to receive(:env).and_return('production')
expect(favicon).to eq('favicon.ico')
end

it 'returns the favicon path for the training environment' do
allow(Rails).to receive(:env).and_return('training')
expect(favicon).to eq('favicon-training.ico')
end

it 'returns the favicon path for the staging environment' do
allow(Rails).to receive(:env).and_return('staging')
expect(favicon).to eq('favicon-staging.ico')
end

it 'returns the favicon path for the development environment' do
allow(Rails).to receive(:env).and_return('development')
expect(favicon).to eq('favicon-development.ico')
end

it 'returns the favicon path for an unknown environment' do
allow(Rails).to receive(:env).and_return('unknown')
expect(favicon).to eq('favicon-development.ico')
end
end

describe '#apple_icon' do
subject(:apple_icon) { helper.apple_icon }

it 'returns the apple icon path for the production environment' do
allow(Rails).to receive(:env).and_return('production')
expect(apple_icon).to eq('apple-icon.png')
end

it 'returns the apple icon path for the training environment' do
allow(Rails).to receive(:env).and_return('training')
expect(apple_icon).to eq('apple-icon-training.png')
end

it 'returns the apple icon path for the staging environment' do
allow(Rails).to receive(:env).and_return('staging')
expect(apple_icon).to eq('apple-icon-staging.png')
end

it 'returns the apple icon path for the development environment' do
allow(Rails).to receive(:env).and_return('development')
expect(apple_icon).to eq('apple-icon-development.png')
end

it 'returns the apple icon path for an unknown environment' do
allow(Rails).to receive(:env).and_return('unknown')
expect(apple_icon).to eq('apple-icon-development.png')
end
end

describe '#render_parsed_json' do
subject(:returned_html) { render_parsed_json(json) }

Expand Down

0 comments on commit 48e18b6

Please sign in to comment.