diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/admin_helper.rb | 5 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 42 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 69 | ||||
-rw-r--r-- | app/helpers/track_helper.rb | 122 |
4 files changed, 226 insertions, 12 deletions
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 059cebdfa..151e53758 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -33,5 +33,10 @@ module AdminHelper link_to(eye, user_path(user), :title => "view user's page on public website") + " " + link_to(h(user.name), admin_user_show_path(user), :title => "view full details") end + + def comment_visibility(comment) + comment.visible? ? 'Visible' : 'Hidden' + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 154697377..33525cb3d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -136,5 +136,47 @@ module ApplicationHelper nil end end + + def event_description(event) + body_link = public_body_link_absolute(event.info_request.public_body) + user_link = request_user_link_absolute(event.info_request) + date = simple_date(event.created_at) + case event.event_type + when 'sent' + _('Request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :date => date) + when 'followup_sent' + case event.calculated_state + when 'internal_review' + _('Internal review request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :date => date) + when 'waiting_response' + _('Clarification sent to {{public_body_name}} by {{info_request_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :date => date) + else + _('Follow up sent to {{public_body_name}} by {{info_request_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :date => date) + end + when 'response' + _('Response by {{public_body_name}} to {{info_request_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :date => date) + when 'comment' + _('Request to {{public_body_name}} by {{info_request_user}}. Annotated by {{event_comment_user}} on {{date}}.', + :public_body_name => body_link, + :info_request_user => user_link, + :event_comment_user => user_link_absolute(event.comment.user), + :date => date) + end + end end diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 405886a85..dd6ffa805 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -18,8 +18,8 @@ module LinkToHelper request_url(info_request, {:only_path => true}.merge(options)) end - def request_link(info_request, cls=nil ) - link_to h(info_request.title), request_path(info_request), :class => cls + def request_link(info_request, cls=nil) + link_to info_request.title, request_path(info_request), :class => cls end def request_details_path(info_request) @@ -75,15 +75,15 @@ module LinkToHelper end def public_body_link_short(public_body) - link_to h(public_body.short_or_long_name), public_body_path(public_body) + link_to public_body.short_or_long_name, public_body_path(public_body) end def public_body_link(public_body, cls=nil) - link_to h(public_body.name), public_body_path(public_body), :class => cls + link_to public_body.name, public_body_path(public_body), :class => cls end def public_body_link_absolute(public_body) # e.g. for in RSS - link_to h(public_body.name), public_body_url(public_body) + link_to public_body.name, public_body_url(public_body) end # Users @@ -96,19 +96,19 @@ module LinkToHelper end def user_link(user, cls=nil) - link_to h(user.name), user_path(user), :class => cls + link_to user.name, user_path(user), :class => cls end def user_link_for_request(request, cls=nil) if request.is_external? user_name = request.external_user_name || _("Anonymous user") if !request.external_url.nil? - link_to h(user_name), request.external_url + link_to user_name, request.external_url else user_name end else - link_to h(request.user.name), user_path(request.user), :class => cls + link_to request.user.name, user_path(request.user), :class => cls end end @@ -116,7 +116,7 @@ module LinkToHelper if request.is_external? external_text || (request.external_user_name || _("Anonymous user")) + " (external)" else - link_to(h(internal_text || request.user.name), admin_user_show_url(request.user)) + link_to(internal_text || request.user.name, admin_user_show_url(request.user)) end end @@ -279,13 +279,58 @@ module LinkToHelper end end - # Basic date format - def simple_date(date) + # Public: Usually-correct format for a DateTime-ish object + # To define a new new format define the `simple_date_{FORMAT}` method + # + # date - a DateTime, Date or Time + # opts - a Hash of options (default: { format: :html}) + # :format - :html returns a HTML <time> tag + # :text returns a plain String + # + # Examples + # + # simple_date(Time.now) + # # => "<time>..." + # + # simple_date(Time.now, :format => :text) + # # => "March 10, 2014" + # + # Returns a String + # Raises ArgumentError if the format is unrecognized + def simple_date(date, opts = {}) + opts = { :format => :html }.merge(opts) + date_formatter = "simple_date_#{ opts[:format] }" + + if respond_to?(date_formatter) + send(date_formatter, date) + else + raise ArgumentError, "Unrecognised format :#{ opts[:format] }" + end + end + + # Usually-correct HTML formatting of a DateTime-ish object + # Use LinkToHelper#simple_date with desired formatting options + # + # date - a DateTime, Date or Time + # + # Returns a String + def simple_date_html(date) + date = date.in_time_zone unless date.is_a? Date + time_tag date, simple_date_text(date), :title => date.to_s + end + + # Usually-correct plain text formatting of a DateTime-ish object + # Use LinkToHelper#simple_date with desired formatting options + # + # date - a DateTime, Date or Time + # + # Returns a String + def simple_date_text(date) date = date.in_time_zone.to_date unless date.is_a? Date date_format = _("simple_date_format") date_format = :long if date_format == "simple_date_format" - return I18n.l(date, :format => date_format) + I18n.l(date, :format => date_format) end def simple_time(date) diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb new file mode 100644 index 000000000..ca698926c --- /dev/null +++ b/app/helpers/track_helper.rb @@ -0,0 +1,122 @@ +module TrackHelper + + def already_subscribed_notice(track_thing) + case track_thing.track_type + when 'request_updates' + _("You are already subscribed to '{{link_to_request}}', a request.", + :link_to_request => request_link(track_thing.info_request)) + when 'all_new_requests' + _('You are already subscribed to any <a href="{{new_requests_url}}">new requests</a>.', + :new_requests_url => request_list_path) + when 'all_successful_requests' + _('You are already subscribed to any <a href="{{successful_requests_url}}">successful requests</a>.', + :successful_requests_url => request_list_successful_path ) + when 'public_body_updates' + _("You are already subscribed to '{{link_to_authority}}', a public authority.", + :link_to_authority => public_body_link(track_thing.public_body)) + when 'user_updates' + _("You are already subscribed to '{{link_to_user}}', a person.", + :link_to_user => user_link(track_thing.tracked_user)) + when 'search_query' + _('You are already subscribed to <a href="{{search_url}}">this search</a>.', + :search_url => search_path([track_thing.track_query, 'newest', 'advanced'])) + end + end + + def subscribe_email_notice(track_thing) + case track_thing.track_type + when 'request_updates' + _("You will now be emailed updates about '{{link_to_request}}', a request.", + :link_to_request => request_link(track_thing.info_request)) + when 'all_new_requests' + _('You will now be emailed updates about any <a href="{{new_requests_url}}">new requests</a>.', + :new_requests_url => request_list_path) + when 'all_successful_requests' + _('You will now be emailed updates about <a href="{{successful_requests_url}}">successful requests</a>.', + :successful_requests_url => request_list_successful_path ) + when 'public_body_updates' + _("You will now be emailed updates about '{{link_to_authority}}', a public authority.", + :link_to_authority => public_body_link(track_thing.public_body)) + when 'user_updates' + _("You will now be emailed updates about '{{link_to_user}}', a person.", + :link_to_user => user_link(track_thing.tracked_user)) + when 'search_query' + _("You will now be emailed updates about <a href=\"{{search_url}}\">this search</a>.", + :search_url => search_path([track_thing.track_query, 'newest', 'advanced'])) + end + end + + def subscribe_follow_notice(track_thing) + wall_url_user = show_user_wall_path(:url_name => track_thing.tracking_user.url_name) + case track_thing.track_type + when 'request_updates' + _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_request}}\', a request.', + :link_to_request => request_link(track_thing.info_request), + :wall_url_user => wall_url_user) + when 'all_new_requests' + _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{new_requests_url}}">new requests</a>.', + :new_requests_url => request_list_path, + :wall_url_user => wall_url_user) + when 'all_successful_requests' + _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{successful_requests_url}}">successful requests</a>.', + :successful_requests_url => request_list_successful_path, + :wall_url_user => wall_url_user) + when 'public_body_updates' + _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_authority}}\', a public authority.', + :wall_url_user => wall_url_user, + :link_to_authority => public_body_link(track_thing.public_body)) + when 'user_updates' + _('You are now <a href="{{wall_url_user}}">following</a> updates about \'{{link_to_user}}\', a person.', + :wall_url_user => wall_url_user, + :link_to_user => user_link(track_thing.tracked_user)) + when 'search_query' + _('You are now <a href="{{wall_url_user}}">following</a> updates about <a href="{{search_url}}">this search</a>.', + :wall_url_user => wall_url_user, + :search_url => search_path([track_thing.track_query, 'newest', 'advanced'])) + end + end + + def unsubscribe_notice(track_thing) + case track_thing.track_type + when 'request_updates' + _("You are no longer following '{{link_to_request}}', a request.", + :link_to_request => request_link(track_thing.info_request)) + when 'all_new_requests' + _('You are no longer following <a href="{{new_requests_url}}">new requests</a>.', + :new_requests_url => request_list_path) + when 'all_successful_requests' + _('You are no longer following <a href="{{successful_requests_url}}">successful requests</a>.', + :successful_requests_url => request_list_successful_path ) + when 'public_body_updates' + _("You are no longer following '{{link_to_authority}}', a public authority.", + :link_to_authority => public_body_link(track_thing.public_body)) + when 'user_updates' + _("You are no longer following '{{link_to_user}}', a person.", + :link_to_user => user_link(track_thing.tracked_user)) + when 'search_query' + _('You are no longer following <a href="{{search_url}}">this search</a>.', + :search_url => search_path([track_thing.track_query, 'newest', 'advanced'])) + end + end + + def track_description(track_thing) + case track_thing.track_type + when 'request_updates' + _("'{{link_to_request}}', a request", + :link_to_request => request_link(track_thing.info_request)) + when 'all_new_requests' + link_to(_('new requests'), request_list_path) + when 'all_successful_requests' + link_to(_('successful requests'), request_list_successful_path) + when 'public_body_updates' + _("'{{link_to_authority}}', a public authority", + :link_to_authority => public_body_link(track_thing.public_body)) + when 'user_updates' + _("'{{link_to_user}}', a person", + :link_to_user => user_link(track_thing.tracked_user)) + when 'search_query' + link_to(track_thing.track_query_description, + search_path([track_thing.track_query, 'newest', 'advanced'])) + end + end +end |