@ -2,24 +2,40 @@ module MergeRequestsHelper
include GovukLinkHelper
include GovukVisuallyHiddenHelper
def display_value_or_placeholder ( value , placeholder = " You didn't answer this question " )
def display_value_or_placeholder ( value , placeholder = " No answer provided " )
value . presence || content_tag ( :span , placeholder , class : " app-!-colour-muted " )
end
def enter_value_link ( page , merge_request )
govuk_link_to ( merge_request_details_link_message ( page ) , send ( " #{ page } _merge_request_path " , merge_request , referrer : " check_answers " ) , class : " govuk-link govuk-link--no-visited-state " )
end
def merge_request_details_link_message ( page )
messages = {
" existing_absorbing_organisation " = > " Answer absorbing organisation is already active " ,
" helpdesk_ticket " = > " Enter helpdesk ticket number " ,
}
messages [ page ] || " Enter #{ lowercase_first_letter ( page . humanize ) } "
end
def merge_request_action_text_helper ( attribute , merge_request )
merge_request . send ( attribute ) . blank? ? " " : " Change "
end
def request_details ( merge_request )
[
{ label : " Requester " , value : display_value_or_placeholder ( merge_request . requester & . name ) } ,
{ label : " Helpdesk ticket " , value : merge_request . helpdesk_ticket . present? ? link_to ( " #{ merge_request . helpdesk_ticket } (opens in a new tab) " , " https://mhclgdigital.atlassian.net/browse/ #{ merge_request . helpdesk_ticket } " , target : " _blank " , rel : " noopener noreferrer " ) : display_value_or_placeholder ( nil ) , action : merge_request_action ( merge_request , " helpdesk_ticket " ) } ,
{ label : " Helpdesk ticket " , value : merge_request . helpdesk_ticket . present? ? link_to ( " #{ merge_request . helpdesk_ticket } (opens in a new tab) " , " https://mhclgdigital.atlassian.net/browse/ #{ merge_request . helpdesk_ticket } " , target : " _blank " , rel : " noopener noreferrer " ) : display_value_or_placeholder ( nil , enter_value_link ( " helpdesk_ticket " , merge_request ) ) , action : merge_request_action ( merge_request , " helpdesk_ticket " ) } ,
{ label : " Status " , value : status_tag ( merge_request . status ) } ,
]
end
def merge_details ( merge_request )
[
{ label : " Absorbing organisation " , value : display_value_or_placeholder ( merge_request . absorbing_organisation_name ) , action : merge_request_action ( merge_request , " absorbing_organisation " ) } ,
{ label : " Merging organisations " , value : merge_request . merge_request_organisations . any? ? merge_request . merge_request_organisations . map ( & :merging_organisation_name ) . join ( " <br> " ) . html_safe : display_value_or_placeholder ( nil ) , action : merge_request_action ( merge_request , " merging_organisations " ) } ,
{ label : " Merge date " , value : display_value_or_placeholder ( merge_request . merge_date ) , action : merge_request_action ( merge_request , " merge_date " ) } ,
{ label : " Absorbing organisation already active? " , value : display_value_or_placeholder ( merge_request . existing_absorbing_organisation_label ) , action : merge_request_action ( merge_request , " existing_absorbing_organisation " ) } ,
{ label : " Absorbing organisation " , value : display_value_or_placeholder ( merge_request . absorbing_organisation_name , enter_value_link ( " absorbing_organisation " , merge_request ) ) , action : merge_request_action ( merge_request , " absorbing_organisation " ) } ,
{ label : " Merging organisations " , value : merge_request . merge_request_organisations . any? ? merge_request . merge_request_organisations . map ( & :merging_organisation_name ) . join ( " <br> " ) . html_safe : display_value_or_placeholder ( nil , enter_value_link ( " merging_organisations " , merge_request ) ) , action : merge_request_action ( merge_request , " merging_organisations " ) } ,
{ label : " Merge date " , value : display_value_or_placeholder ( merge_request . merge_date , enter_value_link ( " merge_date " , merge_request ) ) , action : merge_request_action ( merge_request , " merge_date " ) } ,
{ label : " Absorbing organisation already active? " , value : display_value_or_placeholder ( merge_request . existing_absorbing_organisation_label , enter_value_link ( " existing_absorbing_organisation " , merge_request ) ) , action : merge_request_action ( merge_request , " existing_absorbing_organisation " ) } ,
]
end
@ -75,9 +91,10 @@ module MergeRequestsHelper
end
end
def merge_request_action ( merge_request , page )
def merge_request_action ( merge_request , page , attribute = nil )
attribute = page if attribute . nil?
unless merge_request . status == " request_merged " || merge_request . status == " processing "
{ text : " Change " , href : send ( " #{ page } _merge_request_path " , merge_request , referrer : " check_answers " ) , visually_hidden_text : page . humanize }
{ text : merge_request_action_text_helper ( attribute , merge_request ) , href : send ( " #{ page } _merge_request_path " , merge_request , referrer : " check_answers " ) , visually_hidden_text : page . humanize }
end
end