diff --git a/app/assets/stylesheets/policies/_policies.scss b/app/assets/stylesheets/policies/_policies.scss index 2c9137f90..31c0bb2cf 100644 --- a/app/assets/stylesheets/policies/_policies.scss +++ b/app/assets/stylesheets/policies/_policies.scss @@ -1,3 +1,4 @@ @import "policies-list"; @import "policies-new"; @import "policy-voter-comparision"; +@import "policy-voter-comparision-summary"; diff --git a/app/assets/stylesheets/policies/_policy-voter-comparision-summary.scss b/app/assets/stylesheets/policies/_policy-voter-comparision-summary.scss new file mode 100644 index 000000000..3ab83837d --- /dev/null +++ b/app/assets/stylesheets/policies/_policy-voter-comparision-summary.scss @@ -0,0 +1,58 @@ +.policy-comparision-summary { + + .policy-comparision-summary-position { + + } + + .policy-comparision-summary-bars { + padding-top: 7px; + + .policy-comparision-summary-bar { + height: 20px; + float: left; + margin-right: 1px; + + &.very-strongly-for { + background-color: $color-very-strongly-for; + } + + &.strongly-for { + background-color: $color-strongly-for; + } + + &.moderately-for { + background-color: $color-moderately-for; + } + + &.mixed-position { + background-color: $color-mixed-position; + } + + &.moderately-against { + background-color: $color-moderately-against; + } + + &.strongly-against { + background-color: $color-strongly-against; + } + + &.very-strongly-against { + background-color: $color-very-strongly-against; + } + + &.never-voted { + background-color: #444; + } + + } + + } + + .policy-comparision-summary-percent { + + } + + .policy-comparision-summary-description { + + } +} \ No newline at end of file diff --git a/app/models/policy.rb b/app/models/policy.rb index 9ecd7f51b..ffb9f565f 100644 --- a/app/models/policy.rb +++ b/app/models/policy.rb @@ -125,6 +125,47 @@ def current_members_never_voted current_members(policy_person_distances.never_voted) end + def current_members_vote_counts + very_strongly_for_count = current_members_very_strongly_for.count || 0 + strongly_for_count = current_members_strongly_for.count || 0 + moderately_for_count = current_members_moderately_for.count || 0 + for_count = very_strongly_for_count + strongly_for_count + moderately_for_count + + very_strongly_against_count = current_members_very_strongly_against.count || 0 + strongly_against_count = current_members_strongly_against.count || 0 + moderately_against_count = current_members_moderately_against.count || 0 + against_count = very_strongly_against_count + strongly_against_count + moderately_against_count + + for_and_against_count = current_members_for_and_against.count || 0 + never_count = current_members_never_voted.count || 0 + + # total count must be at least 1 to prevent div by 0 errors + total_count = [1, for_count + against_count + for_and_against_count + never_count].max + + for_percent = (for_count.to_f / total_count.to_f) * 100 + against_percent = (against_count.to_f / total_count.to_f) * 100 + for_and_against_percent = (for_and_against_count.to_f / total_count.to_f) * 100 + never_percent = (never_count.to_f / total_count.to_f) * 100 + + { + "very_strongly_for_count" => very_strongly_for_count, + "strongly_for_count" => strongly_for_count, + "moderately_for_count" => moderately_for_count, + "for_count" => for_count, + "for_percent" => for_percent, + "very_strongly_against_count" => very_strongly_against_count, + "strongly_against_count" => strongly_against_count, + "moderately_against_count" => moderately_against_count, + "against_count" => against_count, + "against_percent" => against_percent, + "for_and_against_count" => for_and_against_count, + "for_and_against_percent" => for_and_against_percent, + "never_count" => never_count, + "never_percent" => never_percent, + "total_count" => total_count, + } + end + def alert_watches(version) watches.each do |watch| AlertMailer.policy_updated(self, version, watch.user).deliver diff --git a/app/views/policies/_policy_comparison_summary.html.haml b/app/views/policies/_policy_comparison_summary.html.haml new file mode 100644 index 000000000..9143b8378 --- /dev/null +++ b/app/views/policies/_policy_comparison_summary.html.haml @@ -0,0 +1,91 @@ +- policy_counts = policy.current_members_vote_counts + +%p.lead + How they voted + %span.small + = surround "(", ")" do + = "total of #{pluralize(policy_counts['total_count'], 'voter')}" + + +.policy-comparision-summary.row + .policy-comparision-summary-position.col-md-1.col-xs-2 + For + + .policy-comparision-summary-bars.col-md-3.col-xs-8 + .policy-comparision-summary-bar.very-strongly-for{style: "width: #{[policy_counts['very_strongly_for_count'] * 2, 1].max}px;"} + .policy-comparision-summary-bar.strongly-for{style: "width: #{[policy_counts['strongly_for_count'] * 2, 1].max}px;"} + .policy-comparision-summary-bar.moderately-for{style: "width: #{[policy_counts['moderately_for_count'] * 2, 1].max}px;"} + + .policy-comparision-summary-percent.col-md-1.col-xs-2 + = number_to_percentage(policy_counts['for_percent'], precision: 1) + + .policy-comparision-summary-description.col-md-7.col-sm-12 + = policy_counts['for_count'] + in favour + = precede "(" do + = policy_counts['very_strongly_for_count'] + = succeed "," do + = link_to "very strongly for", "#" + "Voted very strongly for".parameterize + = policy_counts['strongly_for_count'] + = succeed "," do + = link_to "strongly for", "#" + "Voted strongly for".parameterize + = policy_counts['moderately_for_count'] + = succeed ")" do + = link_to "moderately for", "#" + "Voted moderately for".parameterize + +.policy-comparision-summary.row + .policy-comparision-summary-position.col-md-1.col-xs-2 + Against + + .policy-comparision-summary-bars.col-md-3.col-xs-8 + .policy-comparision-summary-bar.very-strongly-against{style: "width: #{[policy_counts['very_strongly_against_count'] * 2, 1].max}px;"} + .policy-comparision-summary-bar.strongly-against{style: "width: #{[policy_counts['strongly_against_count'] * 2, 1].max}px;"} + .policy-comparision-summary-bar.moderately-against{style: "width: #{[policy_counts['moderately_against_count'] * 2, 1].max}px;"} + + .policy-comparision-summary-percent.col-md-1.col-xs-2 + = number_to_percentage(policy_counts['against_percent'], precision: 1) + + .policy-comparision-summary-description.col-md-7.col-sm-12 + = policy_counts['against_count'] + against + = precede "(" do + = policy_counts['very_strongly_against_count'] + = succeed "," do + = link_to "very strongly against", "#" + "Voted very strongly against".parameterize + = policy_counts['strongly_against_count'] + = succeed "," do + = link_to "strongly against", "#" + "Voted strongly against".parameterize + = policy_counts['moderately_against_count'] + = succeed ")" do + = link_to "moderately against", "#" + "Voted moderately against".parameterize + + +.policy-comparision-summary.row + .policy-comparision-summary-position.col-md-1.col-xs-2 + Mixed + + .policy-comparision-summary-bars.col-md-3.col-xs-8 + .policy-comparision-summary-bar.mixed-position{style: "width: #{[policy_counts['for_and_against_count'] * 2, 1].max}px;"} + + .policy-comparision-summary-percent.col-md-1.col-xs-2 + = number_to_percentage(policy_counts['for_and_against_percent'], precision: 1) + + .policy-comparision-summary-description.col-md-7.col-sm-12 + = policy_counts['for_and_against_count'] + = link_to "mixed", "#" + "Voted a mixture of for and against".parameterize + for and against + +.policy-comparision-summary.row + .policy-comparision-summary-position.col-md-1.col-xs-2 + Never + + .policy-comparision-summary-bars.col-md-3.col-xs-8 + .policy-comparision-summary-bar.never-voted{style: "width: #{[policy_counts['never_count'] * 2, 1].max}px;"} + + .policy-comparision-summary-percent.col-md-1.col-xs-2 + = number_to_percentage(policy_counts['never_percent'], precision: 1) + + .policy-comparision-summary-description.col-md-7.col-sm-12 + = policy_counts['never_count'] + = link_to "never", "#" + "Never voted on".parameterize + voted on this issue diff --git a/app/views/policies/show.html.haml b/app/views/policies/show.html.haml index bb9864fcb..a77e08750 100644 --- a/app/views/policies/show.html.haml +++ b/app/views/policies/show.html.haml @@ -6,8 +6,13 @@ = render 'page_header', policy: @policy - if @policy.divisions.count > 0 - %p.lead - = link_to pluralize(@policy.divisions.count, "relevant division"), {anchor: 'divisions'}, title: 'Skip to Relevant Divisions for this policy.' + + = render 'policy_comparison_summary', policy: @policy + %br + %p.small + Grouped by agreement score, based on + = succeed "." do + = link_to pluralize(@policy.divisions.count, "relevant division"), {anchor: 'divisions'}, title: 'Skip to Relevant Divisions for this policy.' %section.page-section#members .policy-comparisions diff --git a/spec/fixtures/static_pages/policy.php?id=1.html b/spec/fixtures/static_pages/policy.php?id=1.html index 612df1c27..984b2c086 100644 --- a/spec/fixtures/static_pages/policy.php?id=1.html +++ b/spec/fixtures/static_pages/policy.php?id=1.html @@ -91,7 +91,94 @@
-1 relevant division +How they voted + +(total of 2 voters) + +
++Grouped by agreement score, based on +1 relevant division.
-2 relevant divisions +How they voted + +(total of 1 voter) + +
++Grouped by agreement score, based on +2 relevant divisions.