Skip to content

Commit bb91d17

Browse files
authored
Merge pull request #1224 from Crown-Commercial-Service/feature/nrmi-165-add-archived-to-agreements-filter
NRMI-165
2 parents ea28a69 + e8b5e1b commit bb91d17

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

app/controllers/admin/frameworks_controller.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Admin::FrameworksController < AdminController
99
def index
1010
@frameworks = Framework.order(:short_name).all
1111

12-
filter_framework_status params[:framework_status] if params[:framework_status]
12+
@frameworks = filter_framework_status(@frameworks)
1313
end
1414

1515
def new
@@ -109,11 +109,14 @@ def download_template
109109

110110
private
111111

112-
def filter_framework_status(status_param)
113-
return if status_param.size == 2
112+
def filter_framework_status(scope)
113+
if params[:filters_applied].present?
114+
return scope unless params.key?(:framework_status)
114115

115-
@frameworks = @frameworks.new_state if status_param.include? 'New'
116-
@frameworks = @frameworks.published if status_param.include? 'Published'
116+
scope.where(aasm_state: params[:framework_status].map(&:downcase))
117+
else
118+
scope.where(aasm_state: %w[new published])
119+
end
117120
end
118121

119122
def find_framework

app/views/admin/frameworks/index.html.haml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
.govuk-grid-row
1414
- if @frameworks.present?
1515
= form_tag(admin_frameworks_path, method: :get, enforce_utf8: false, remote: :true, id: 'framework_status_filter') do
16+
= hidden_field_tag :filters_applied, '1'
1617
.govuk-grid-column-one-quarter
1718
#accordion-with-summary-sections.ccs-accordion.ccs-accordion--clean{"data-module" => "govuk-accordion", :class => 'govuk-!-margin-top-7'}
1819
.govuk-accordion__section.ccs-accordion__section--clean.govuk-form-group.govuk-form-group--enclosure.ccs-form-group--enclosure--tight
@@ -25,17 +26,30 @@
2526
.govuk-form-group
2627
%fieldset.govuk-fieldset
2728
%legend.govuk-fieldset__legend.govuk-fieldset__legend--m
29+
- if params[:filters_applied].present?
30+
- selected_statuses = Array(params[:framework_status])
31+
- else
32+
- selected_statuses = %w[published new]
33+
2834
.govuk-checkboxes{id: 'framework_status_checkboxes'}
2935
.govuk-checkboxes__item.govuk-checkboxes__item--small
30-
= check_box_tag('framework_status[]', 'New', false,
36+
= check_box_tag('framework_status[]', 'New',
37+
selected_statuses.include?('new'),
3138
id: 'framework_status_new',
3239
class: 'govuk-checkboxes__input govuk-checkboxes__input--small')
3340
= label_tag "framework_status_new", "New", class: 'govuk-checkboxes__label'
3441
.govuk-checkboxes__item.govuk-checkboxes__item--small
35-
= check_box_tag('framework_status[]', 'Published', false,
42+
= check_box_tag('framework_status[]', 'Published',
43+
selected_statuses.include?('published'),
3644
id: 'framework_status_published',
3745
class: 'govuk-checkboxes__input govuk-checkboxes__input--small')
3846
= label_tag "framework_status_published", "Published", class: 'govuk-checkboxes__label'
47+
.govuk-checkboxes__item.govuk-checkboxes__item--small
48+
= check_box_tag('framework_status[]', 'Archived',
49+
selected_statuses.include?('archived'),
50+
id: 'framework_status_archived',
51+
class: 'govuk-checkboxes__input govuk-checkboxes__input--small')
52+
= label_tag "framework_status_archived", "Archived", class: 'govuk-checkboxes__label'
3953
%noscript
4054
= surround "&nbsp&nbsp".html_safe do
4155
= submit_tag "Submit", id: 'framework-status-filter-submit', data: { 'prevent-double-click': true }, class: 'govuk-button'

spec/features/admin_can_list_frameworks_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
# And there are some published frameworks
99
FactoryBot.create(:framework, name: 'Laundry Framework 1', short_name: 'RM1234')
1010
FactoryBot.create(:framework, name: 'Vehicle Purchase Framework 1', short_name: 'RM5678')
11-
# And there are some unpublished frameworks
11+
# And there is a new/unpublished frameworks
1212
FactoryBot.create(:framework, aasm_state: 'new', name: 'Vehicle Purchase Framework 2', short_name: 'RM5679')
13+
# And there is an archived frameworks
14+
FactoryBot.create(:framework, aasm_state: 'archived', name: 'Archived framework', short_name: 'RM5789')
1315
end
1416

15-
scenario 'There are some published and unpublished agreements' do
17+
scenario 'There are some new and published but not archived agreements' do
1618
# When I click the "Agreements" link from the main admin page
1719
visit admin_root_path
1820
click_link 'Agreements'
@@ -35,26 +37,27 @@
3537
expect(page).to have_text('Vehicle Purchase Framework 2')
3638
expect(page).to have_text('new')
3739
end
40+
41+
expect(page).not_to have_text('RM5789')
42+
expect(page).not_to have_text('Vehicle Purchase Framework 3')
3843
end
3944

4045
scenario 'agreements can be filtered by status' do
4146
visit admin_root_path
4247
click_link 'Agreements'
4348

44-
page.check('framework_status_new')
49+
page.uncheck('framework_status_published')
4550
find('#framework-status-filter-submit').click
4651

4752
expect(page).to have_text('RM5679')
4853
expect(page).to have_text('Vehicle Purchase Framework 2')
4954
expect(page).not_to have_text('RM5678')
5055
expect(page).not_to have_text('Vehicle Purchase Framework 1')
5156

52-
page.check('framework_status_published')
57+
page.check('framework_status_archived')
5358
find('#framework-status-filter-submit').click
5459

55-
expect(page).to have_text('RM1234')
56-
expect(page).to have_text('Laundry Framework 1')
57-
expect(page).not_to have_text('RM5679')
58-
expect(page).not_to have_text('Vehicle Purchase Framework 2')
60+
expect(page).to have_text('RM5789')
61+
expect(page).to have_text('Archived framework')
5962
end
6063
end

0 commit comments

Comments
 (0)