Skip to content

Commit

Permalink
Text extraction for print views
Browse files Browse the repository at this point in the history
Continuing #233, this commit handles more extraction of text into
message catalogues, focussing on the print views
  • Loading branch information
ijdickinson committed Aug 10, 2020
1 parent 3322737 commit 09075ea
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
20 changes: 13 additions & 7 deletions app/presenters/compare_locations_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@ def initialize(user_compare_selections, query_results)
delegate :as_json, to: :user_compare_selections
delegate :selected_locations, to: :user_compare_selections

def headline_summary
ind = I18n.t(indicator.slug)
stat = I18n.t(statistic.label_key).downcase
def headline_summary # rubocop:disable Metrics/AbcSize
ind = I18n.t("indicator.#{indicator.slug}")
stat = I18n.t("statistic.#{statistic.label_key}").downcase
from = user_compare_selections.from_date.strftime('%b %Y')
to = user_compare_selections.to_date.strftime('%b %Y')

"<strong>#{ind}</strong> for <strong>#{stat}</strong>, #{from} to #{to}".html_safe
<<~HEADLINE
<strong>#{ind}</strong>
#{I18n.t('preposition.for')}
<strong>#{stat}</strong>,
#{from} #{I18n.t('preposition.to')} #{to}
HEADLINE
.html_safe
end

def locations_summary
if (1..2).cover?(selected_locations.length)
selected_locations.map(&:label).join(' and ')
selected_locations.map(&:label).join(" #{I18n.t('connective.and')} ")
else
"#{selected_locations.length} locations"
I18n.t('compare.print.locations_summary', n_locations: selected_locations.length)
end
end

Expand Down Expand Up @@ -91,7 +97,7 @@ def indicator

def unavailable_statistic_indicator?
if indicator.volume? && !statistic.volume?
"We're sorry, #{indicator.label.downcase} is not available for #{statistic.label}."
I18n.t('compare.print.unavailable', indicator_name: indicator.label.downcase, statistic_name: statistic.label)
else
false
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/download_column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def initialize(options)
def label # rubocop:disable Metrics/AbcSize
return options[:label] if options[:label]

ind_key = options[:ind]&.slug
stat_key = options[:stat].label_key
ind_key = "indicator.#{options[:ind]&.slug}"
stat_key = "statistic.#{options[:stat].label_key}"
sep = options[:sep] || ' '

ind_key ? "#{I18n.t(ind_key)}#{sep}#{I18n.t(stat_key)}".html_safe : I18n.t(stat_key)
Expand Down
19 changes: 10 additions & 9 deletions app/presenters/print_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ class PrintPresenter < DownloadPresenter # rubocop:disable Metrics/ClassLength
end
),
DownloadColumn.new(
label: 'Reporting<br />period'.html_safe,
label: I18n.t('browse.print.reporting_period').html_safe,
format: lambda do |row|
val = row['ukhpi:refPeriodDuration'].first == 3 ? 'quarterly' : 'monthly'
key = row['ukhpi:refPeriodDuration'].first == 3 ? 'quarterly' : 'monthly'
val = I18n.t("browse.print.#{key}")
"<div class='u-text-centre'>#{val}</div>".html_safe
end
),
DownloadColumn.new(
label: 'Sales volume',
label: I18n.t('statistic.volume'),
format: lambda do |row|
val = row['ukhpi:salesVolume'].first
"<div class='u-text-right'>#{val}</div>".html_safe
end
)
].freeze

SALES_VOLUME_COL = PRINT_COLUMNS.map(&:label).index('Sales volume')
SALES_VOLUME_COL = 2 # PRINT_COLUMNS.map(&:label).index('Sales volume')

def locations
@locations ||=
Expand All @@ -41,9 +42,9 @@ def locations_summary # rubocop:disable Metrics/AbcSize
if locations.one?
locations.first.label
elsif locations.length == 2
"#{locations.first.label} and #{locations[1].label}"
"#{locations.first.label} #{I18n.t('connectives.and')} #{locations[1].label}"
else
"#{locations.length} locations"
I18n.t('compare.print.locations_summary', num_locattions: locations.length)
end
end

Expand All @@ -56,7 +57,7 @@ def indicators
def indicator_summary
indicators
.map(&:label)
.join(' and ')
.join(I18n.t('connective.and'))
end

def statistics
Expand All @@ -68,7 +69,7 @@ def statistics
def statistic_summary
statistics
.map(&:label)
.join(' and ')
.join(I18n.t('connective.and'))
end

def themes
Expand All @@ -80,7 +81,7 @@ def themes
def theme_summary
themes
.map(&:label)
.join(' and ')
.join(I18n.t('connective.and'))
end

def dates
Expand Down
2 changes: 1 addition & 1 deletion app/views/compare/print.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%thead
%tr
%th{ scope: 'col' }
Date
= I18n.t('compare.print.date')
- @view_state.selected_locations.each do |loc|
%th{ scope: 'col' }
= loc.label
Expand Down
7 changes: 4 additions & 3 deletions app/views/layouts/print.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
%meta{ charset: 'utf-8' }
%meta{ 'http-equiv' => 'x-ua-compatible', content: 'ie=edge' }
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no' }
%title UK House Price Index
%title
= I18n.t('common.header.app_title')
= stylesheet_link_tag 'application', media: 'all'
= csrf_meta_tags
= render partial: 'common/favicons'
Expand All @@ -30,11 +31,11 @@
.content
%nav#proposition-menu
%a#proposition-name{ href: '/app/ukhpi' }
%strong UK House Price Index
%strong
= I18n.t('common.header.app_title')

.o-lr-top-bar


= render partial: 'common/flash_message'

%main
Expand Down
12 changes: 12 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ en:
volume_property_status: "* Sales volume for new buildings vs. existing properties"
volume_funding_status: "* Sales volume for cash sales vs. mortgage sales"

print:
reporting_period: "* Reporting<br />period"

main_heading: "* House Price Statistics"

edit:
Expand Down Expand Up @@ -61,6 +64,12 @@ en:
show:
heading: "* Compare UKHPI statistics across locations"
prompt: "* Select up to five locations to compare any UKHPI statistic, for a range of dates."
print:
locations_summary: "* #{n_locations} locations"
unavailable: "* We're sorry, #{indicator_name} is not available for #{statistic_name}."
date: "* Date"
quarterly: "* quarterly"
monthly: "* monthly"

theme:
property_type: "* Type of property"
Expand Down Expand Up @@ -129,6 +138,9 @@ en:
compare: "* compare"
update_comparison: "* update comparison"

connective:
and: "* and"

js:
action:
download: "* Download this data"
Expand Down

0 comments on commit 09075ea

Please sign in to comment.