Skip to content

Commit

Permalink
Views & policies for nomination statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubosky committed Aug 21, 2024
1 parent 67e6d81 commit 0573e18
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/assets/stylesheets/admin/tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,40 @@
[role="region"][aria-labelledby][tabindex]:focus {
outline: .1em solid rgba(0,0,0,.1);
}

.kavs-table {
border-top: 1px solid #b1b4b6;
border-bottom: 1px solid #b1b4b6;
width: max-content;

thead {
background-color: #f2f2f2;

.govuk-table__header:last-child,
.govuk-table__cell:last-child,
.govuk-table__footer:last-child {
padding-right: 10px;
}
}

tfoot {
&.govuk-table__footer {
background-color: #f2f2f2;
font-weight: 700;
text-align: left;
}
}
}

.kavs-table__header--dense,
.kavs-table__cell--dense,
.kavs-table__footer--dense {
font-size: 1rem;
padding: 10px
}

.kavs-table__header--border-right,
.kavs-table__cell--border-right,
.kavs-table__footer--border-right {
border-right: 1px solid #b1b4b6;
}
96 changes: 96 additions & 0 deletions app/controllers/admin/statistics/nominations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
class Admin::Statistics::NominationsController < Admin::BaseController
def index
authorize :statistics, :index?

@search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params)
end

def create
authorize :statistics, :send?

@search = NominationStatsSearch.new(FormAnswer.all).search(permitted_params)

redirect_to admin_statistics_nominations_path(search: permitted_params), success: "CSV with nomination statistics has been sent to #{current_admin.email}."
end

private

def permitted_params
params.fetch(:search, NominationStatsSearch.default_search).permit!
end

def generate_csv(data)
CSV.generate(encoding: "UTF-8", force_quotes: true) do |csv|
csv << csv_mapping.map { |m| m[:label] }
data.each do |row|
csv << csv_mapping.map do |m|
func = m[:method]
row[func]
end
end

csv << csv_mapping.map do |m|
func = m[:method]

if func == :ceremonial_county_name
"Total"
else
data.sum(&func)
end
end
end
end

def csv_mapping
[
{
label: "Lieutenancy",
method: :ceremonial_county_name
},
{
label: "Nominations submitted",
method: :submitted_count
},
{
label: "Eligiblity - Admin eligible",
method: :admin_eligible_count
},
{
label: "Eligiblity - Not eligible nominator",
method: :admin_not_eligible_nominator_count
},
{
label: "Eligiblity - Not eligible group",
method: :admin_not_eligible_group_count
},
{
label: "Eligiblity - Withdrawn",
method: :withdrawn_count
},
{
label: "Local Assessment - Not recommended",
method: :local_assessment_not_recommended_count
},
{
label: "Local Assessment - Recommended",
method: :local_assessment_recommended_count
},
{
label: "National Assessment - Not recommended",
method: :not_recommended_count
},
{
label: "National Assessment - Recommended",
method: :shortlisted_count
},
{
label: "Royal Approval - Awarded",
method: :awarded_count
},
{
label: "Total",
method: :total_count
}
]
end
end
9 changes: 9 additions & 0 deletions app/policies/statistics_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class StatisticsPolicy < ApplicationPolicy
def index?
admin?
end

def send?
admin?
end
end
106 changes: 106 additions & 0 deletions app/views/admin/statistics/nominations/_list.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
ruby:
results = object.results

div role="region" aria-labelledby="table-list-nomination-statistics-caption" tabindex="0"
table.govuk-table.kavs-table#table-list-nomination-statistics
caption.govuk-visually-hidden#table-list-nomination-statistics-caption
| nomination statistics report
colgroup
col style="width: 135px;"
col style="width: 110px;"
col style="width: 55px;"
col style="width: 90px;"
col style="width: 90px;"
col style="width: auto;"
col style="width: 110px;"
col style="width: auto;"
col style="width: 110px;"
col style="width: auto;"
col style="width: 75px;"
col style="width: auto;"
thead.govuk-table__head
tr.govuk-table__row
th.sortable.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" rowspan="2"
= sort_link f, 'Lieutenancy', object, :ceremonial_county_name
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" rowspan="2"
| Submitted nominations
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" colspan="4"
| Eligibility
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" colspan="2"
| Local Assessment
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" colspan="2"
| National Assessment
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col" rowspan="2"
| Royal Approval - Awarded
th.govuk-table__header.kavs-table__header--dense scope="col" rowspan="2"
| Total
tr.govuk-table__row
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Admin eligible
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Not eligible nominator
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Not eligible group
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Withdrawn
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Not recommended
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Recommended
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Not recommended
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="col"
| Recommended
tbody.govuk-table__body
- results.each do |row|
tr.govuk-table__row
th.govuk-table__header.kavs-table__header--dense.kavs-table__header--border-right scope="row"
= row[:ceremonial_county_name]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:submitted_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:admin_eligible_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:admin_not_eligible_nominator_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:admin_not_eligible_group_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:withdrawn_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:local_assessment_not_recommended_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:local_assessment_recommended_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:not_recommended_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:shortlisted_count]
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= row[:awarded_count]
td.govuk-table__cell.kavs-table__cell--dense
= row[:total_count]
tfoot.govuk-table__footer
tr.govuk-table__row
th.kavs-table__footer--dense.kavs-table__footer--border-right scope="row"
| Total
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:submitted_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:admin_eligible_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:admin_not_eligible_nominator_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:admin_not_eligible_group_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:withdrawn_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:local_assessment_not_recommended_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:local_assessment_recommended_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:not_recommended_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:shortlisted_count)
td.govuk-table__cell.kavs-table__cell--dense.kavs-table__cell--border-right
= results.sum(&:awarded_count)
td.govuk-table__cell.kavs-table__cell--dense
= results.sum(&:total_count)
44 changes: 44 additions & 0 deletions app/views/admin/statistics/nominations/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- title "Nomination statistics"

h1.govuk-heading-xl
| Nomination statistics

= simple_form_for @search, url: "#", method: :get, as: :search, html: { id: "nomination-statistics-form", class: "search-form" } do |f|
= f.simple_fields_for [:filters, @search.filters] do |g|
div[class="govuk-grid-row"]
div[class="govuk-grid-column-one-quarter"]
div[class="govuk-form-group" aria-label="Award year"]
label[class="govuk-label" for="award-year-select"]
' Award year
= g.select :year, award_years_collection, {}, { id: "award-year-select", class: "govuk-select custom-select", style: "height: 40px;", aria: { label: "award year select" } }

= render "shared/form_answers/filters/assigned_lieutenancy_filter", g: g, options: NominationStatsSearch.ceremonial_county_options

div[class="govuk-button-group"]
= f.submit "Apply filters",
class: "govuk-button",
id: "apply-nomination-filters"

= link_to "Remove filters",
admin_statistics_nominations_path,
class: "govuk-button govuk-button--secondary",
role: "button"

div[class="govuk-button-group"]
= link_to "Receive CSV with nomination statistics via email",
admin_statistics_nominations_path(params.to_unsafe_h),
class: "govuk-link",
method: :post

= render partial: "list", locals: { f: f, object: @search }

scss:
.autocomplete__input {
min-height: 2.5rem;
}

@media (max-width: 991px) {
.autocomplete__input {
min-height: 2rem;
}
}
4 changes: 4 additions & 0 deletions app/views/layouts/navbar/_admin.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
li.govuk-header__navigation-item class=('active' if controller_name == 'form_answers')
= link_to "Nominations", admin_form_answers_path, class: 'govuk-header__link'

- if policy(:statistics).index?
li.govuk-header__navigation-item class=('active' if controller_name == 'nominations')
= link_to "Statistics", admin_statistics_nominations_path, class: 'govuk-header__link'

- if policy(:user).index?
li.govuk-header__navigation-item class=('active' if %w[users admins assessors].include?(controller_name))
= link_to "Users", admin_users_path, class: 'govuk-header__link'
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@
end
end

namespace :statistics do
resources :nominations, only: [:index, :create], path_names: { create: :send }
end

resources :protected_files, path: "/files", only: :show
end

Expand Down

0 comments on commit 0573e18

Please sign in to comment.