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

866 alert banner #868

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ coverage
.byebug_history
.envrc
.yarnrc

config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ gem 'ed25519', '~> 1.2.4'
gem 'bcrypt_pbkdf', '~> 1.0.0'
# Error tracking
gem 'bugsnag', '~> 6.26'
# Configure environment settings
gem 'config', '~> 5.5.2'


group :development, :test do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
Expand Down Expand Up @@ -123,4 +126,4 @@ group :test do
gem 'rspec-retry', '~> 0.6.0'
# Stub http requests
gem 'webmock', '~> 3.14.0'
end
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ GEM
cocoon (1.2.15)
colorize (0.8.1)
concurrent-ruby (1.3.3)
config (5.5.2)
deep_merge (~> 1.2, >= 1.2.1)
ostruct
connection_pool (2.4.1)
countries (5.3.1)
unaccent (~> 0.3)
Expand All @@ -124,6 +127,7 @@ GEM
crass (1.0.6)
database_cleaner (1.8.5)
date (3.3.4)
deep_merge (1.2.2)
devise (4.9.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -252,6 +256,7 @@ GEM
version_gem (~> 1.1)
okcomputer (1.18.4)
orm_adapter (0.5.0)
ostruct (0.6.1)
parallel (1.25.1)
parser (3.3.3.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -480,6 +485,7 @@ DEPENDENCIES
carrierwave (~> 2.2.5)
clamby
cocoon (~> 1.2.0)
config (~> 5.5.2)
country_select!
database_cleaner (~> 1.8.0)
devise (>= 4.7.1)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ Any PRs merged to main will automatically be deployed to QA.

To initiate a production deploy, create a new release. Then, merge the automatically created PR in the config repo: https://github.com/psu-libraries/etda-config

### Config
The [config](https://rubygems.org/gems/config) gem provides a means for adding ad-hoc config as needed.
The file `config/settings.local.yml` is not tracked in git.
Currently this is used to add announcements quickly. By adding values such as:
```rb
# Strings
show_annoucements: true
announcement:
message: "Place your important message here"
```

## LionPath Integration

### Imports
Expand Down
7 changes: 7 additions & 0 deletions app/views/shared/_announcements.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="announcement container-fluid <%= Settings.announcement&.html_class || "yoo doggie" %>">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the OR operator needed here? It can just be nil if html_class is not defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha ha, absolutely not necessary. Glad you caught this.

Yes, my plan was to inject the yml from config like in catalog. Planning to try this out in the QA environment.

<div class="row align-items-center">
<div class="col align-content-center alert-warning">
<p class="text-center mt-2 mb-2 pb-1"><%= sanitize Settings.announcement&.message %></p>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<header class="<%= page_classes %>">
<%= render partial: 'shared/announcements' if Settings.show_announcements %>
<div class="container-fluid">
<div id="shield-and-logo" class="row">
<div class="col-sm-1">
Expand All @@ -15,4 +16,5 @@
</div>
<%= render partial: '/matomo_analytics' if ENV.fetch('HOSTNAME', 'dev').match(/^etda-wf-/).present? %>
<%= render partial: 'shared/nav_bar' %>

</header>
56 changes: 56 additions & 0 deletions config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = 'Settings'

# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil

# Overwrite an existing value when merging a `nil` value.
# When set to `false`, the existing value is retained after merge.
#
# config.merge_nil_values = true

# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true

# Load environment variables from the `ENV` object and override any settings defined in files.
#
config.use_env = true

# Define ENV variable prefix deciding which variables to load into config.
#
# Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
# prefixed in the same way.
#
# When not set it defaults to `config.const_name`.
#
config.env_prefix = 'SETTINGS'

# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
config.env_separator = '__'

# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase

# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true

# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
#
# config.schema do
# required(:name).filled
# required(:age).maybe(:int?)
# required(:email).filled(format?: EMAIL_REGEX)
# end
end
59 changes: 59 additions & 0 deletions spec/integration/announcement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Announcement', :js do
context 'when show_announcements is false' do
before do
Settings.add_source!(
{
show_announcements: false,
announcement: nil
}
)
Settings.reload!
end

it 'does not display an announcement on top' do
visit root_path
expect(page).to have_no_css '.announcement'
end
end

context 'when show_announcement is nil' do
before do
Settings.add_source!(
{
show_announcements: nil,
announcement: nil
}
)
Settings.reload!
end

it 'does not display an announcement on top' do
visit root_path
expect(page).to have_no_css '.announcement'
end
end

context 'when show_announcement is true' do
before do
Settings.add_source!(
{
show_announcements: true,
announcement: {
message: 'ETDA is for cool kids'
}
}
)
Settings.reload!
end

it 'displays the given announcement' do
visit root_path
expect(page).to have_css '.announcement'
expect(page).to have_content 'ETDA is for cool kids'
end
end
end