-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Views & policies for nomination statistics
- Loading branch information
Showing
7 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/controllers/admin/statistics/nominations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters