Skip to content

Commit 8aa4495

Browse files
authored
Merge pull request #1123 from kennethrioja/searchbox
Option: search_box
2 parents 9b0d17a + 128a5a0 commit 8aa4495

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%# Big search box %>
2+
<div class="searchbox">
3+
<%= form_tag search_path, method: :get, role: 'search' do %>
4+
<div class="searchbox-wrapper">
5+
<input type="text" class="searchbox-field" name="q"
6+
placeholder= "<%= t('home.search_placeholder', site_name: TeSS::Config.site['title_short']) %>" ">
7+
<button type="submit" class="searchbox-btn">
8+
<i class="icon icon-h3 search-icon"></i>
9+
</button>
10+
</div>
11+
<% end %>
12+
</div>

app/views/static/home/_welcome.html.erb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
<p class="font-size-lg"><%== t 'home.subtitle' %></p>
66
</div>
77

8-
<%# Big search box %>
9-
<div class="searchbox">
10-
<%= form_tag search_path, method: :get, role: 'search' do %>
11-
<div class="searchbox-wrapper">
12-
<input type="text" class="searchbox-field" name="q"
13-
placeholder= "<%= t('home.search_placeholder', site_name: TeSS::Config.site['title_short']) %>" autofocus="autofocus">
14-
<button type="submit" class="searchbox-btn">
15-
<i class="icon icon-h3 search-icon"></i>
16-
</button>
17-
</div>
18-
<% end %>
19-
</div>
8+
<%= render partial: 'static/home/search_box' if TeSS::Config.site.dig('home_page', 'search_box') %>
9+
2010
</section>

config/tess.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ default: &default
113113
latest_materials: # Number of materials on home page. Leave blank to turn off
114114
featured_trainer: false
115115
counters: false # Whether or not to show number of database objects in separate blocks
116+
search_box: true # Whether or not to show the search box
116117
# The order in which the tabs appear (if feature enabled)
117118
tab_order: ['about', 'events', 'materials', 'elearning_materials', 'workflows', 'collections', 'trainers', 'content_providers', 'nodes']
118119
# The tabs that should be collapsed under the "Directory" tab. Can be left blank to hide it.

test/controllers/static_controller_test.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class StaticControllerTest < ActionController::TestCase
7272
'provider_carousel': false,
7373
'featured_providers': nil,
7474
'faq': [],
75-
'promo_blocks': false
75+
'promo_blocks': false,
76+
'search_box': false
7677
}
7778

7879
with_settings({ site: site_settings }) do
@@ -81,6 +82,8 @@ class StaticControllerTest < ActionController::TestCase
8182
assert_select 'section#providers', count: 0
8283
assert_select 'section#faq', count: 0
8384
assert_select 'ul#promo-blocks', count: 0
85+
assert_select 'ul#promo-blocks', count: 0
86+
assert_select 'div.searchbox', count: 0
8487
end
8588

8689
site_settings['home_page']['catalogue_blocks'] = true
@@ -90,6 +93,7 @@ class StaticControllerTest < ActionController::TestCase
9093
assert_select 'section#providers', count: 0
9194
assert_select 'section#faq', count: 0
9295
assert_select 'ul#promo-blocks', count: 0
96+
assert_select 'div.searchbox', count: 0
9397
end
9498

9599
site_settings['home_page']['provider_carousel'] = true
@@ -104,6 +108,7 @@ class StaticControllerTest < ActionController::TestCase
104108
assert_select 'section#providers .item a[href=?]', content_provider_path(provider2)
105109
assert_select 'section#faq', count: 0
106110
assert_select 'ul#promo-blocks', count: 0
111+
assert_select 'div.searchbox', count: 0
107112
end
108113

109114
site_settings['home_page']['faq'] = %w[who why]
@@ -114,6 +119,7 @@ class StaticControllerTest < ActionController::TestCase
114119
assert_select 'section#faq', count: 1
115120
assert_select 'section#faq .question', count: 2
116121
assert_select 'ul#promo-blocks', count: 0
122+
assert_select 'div.searchbox', count: 0
117123
end
118124

119125
site_settings['home_page']['promo_blocks'] = true
@@ -123,6 +129,17 @@ class StaticControllerTest < ActionController::TestCase
123129
assert_select 'section#providers', count: 1
124130
assert_select 'section#faq', count: 1
125131
assert_select 'ul#promo-blocks', count: 1
132+
assert_select 'div.searchbox', count: 0
133+
end
134+
135+
site_settings['home_page']['search_box'] = true
136+
with_settings({ site: site_settings }) do
137+
get :home
138+
assert_select 'section#catalogue', count: 1
139+
assert_select 'section#providers', count: 1
140+
assert_select 'section#faq', count: 1
141+
assert_select 'ul#promo-blocks', count: 1
142+
assert_select 'div.searchbox', count: 1
126143
end
127144
end
128145

0 commit comments

Comments
 (0)