Files
nairobi/app/helpers/proposals_helper.rb
Javi Martín 11816f833d Use a flex layout to render participation processes lists
This way we simplify the HTML, which had some `if...else` blocks that
were hard to follow because there were opening tags inside these blocks
while the closing tags were outside these blocks.

We're also making the CSS container-dependent instead of
window-dependent. Since there are between one and three elements inside
the panel, we accomplish this by making the element with the content
take its own line if the width of the panel is smaller than 35rem.

Note we're trying to keep the layout similar to what it was; since we're
no longer using negative margins (like the ones in the `.row` selector),
the votes element now gets a width of 22.5% instead of 25%.

Also note we're using the column-gap property for flexbox because the
`flex-with-gap` mixin doesn't work so well with elements that have
borders. Since the column-gap property for flexbox is now supperted by
more than 98% of the browsers (which wasn't the case when we started
using the `flex-with-gap` mixin), the `flex-with-gap` mixin has become
obsolete.

Finally, note we're removing the `max-width: 12rem` rule in the images.
I'm not sure why we introduced this rule in the first place, and it
didn't play so well to the new layout. I considered using code like
`max-width: min(100%, 12rem)`, but, since I'm not sure why `12rem` was
there in the first place, I'm not sure whether this approach was better,
and it sure made things more complex.
2025-03-06 18:49:39 +01:00

79 lines
2.0 KiB
Ruby

module ProposalsHelper
def progress_bar_percentage(proposal)
case proposal.cached_votes_up
when 0 then 0
when 1..Proposal.votes_needed_for_success
(proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success).floor
else 100
end
end
def supports_percentage(proposal)
percentage = (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success)
case percentage
when 0 then "0%"
when 0..0.1 then "0.1%"
when 0.1..100 then number_to_percentage(percentage, strip_insignificant_zeros: true, precision: 1)
else "100%"
end
end
def namespaced_proposal_path(proposal, options = {})
@namespace_proposal_path ||= namespace
case @namespace_proposal_path
when "management"
management_proposal_path(proposal, options)
else
proposal_path(proposal, options)
end
end
def retire_proposals_options
Proposal::RETIRE_OPTIONS.map { |option| [t("proposals.retire_options.#{option}"), option] }
end
def empty_recommended_proposals_message_text(user)
if user.interests.any?
t("proposals.index.recommendations.without_results")
else
t("proposals.index.recommendations.without_interests")
end
end
def author_of_proposal?(proposal)
author_of?(proposal, current_user)
end
def current_editable?(proposal)
current_user && proposal.editable_by?(current_user)
end
def proposals_minimal_view_path
proposals_path(view: proposals_secondary_view)
end
def proposals_default_view?
@view == "default"
end
def proposals_current_view
@view
end
def proposals_secondary_view
proposals_current_view == "default" ? "minimal" : "default"
end
def show_proposal_votes?
params[:selected].blank?
end
def show_featured_proposals?
params[:selected].blank? && @featured_proposals.present?
end
def show_recommended_proposals?
params[:selected].blank? && feature?("user.recommendations") && @recommended_proposals.present?
end
end