Skip to content

Commit

Permalink
Merge pull request #3512 from consul/backport-stats
Browse files Browse the repository at this point in the history
Change stats layout
  • Loading branch information
javierm committed May 21, 2019
2 parents f489181 + dc8c4a9 commit 82e3c41
Show file tree
Hide file tree
Showing 61 changed files with 1,935 additions and 856 deletions.
Binary file added app/assets/images/stats_booth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_investments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_mail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_man.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/stats_woman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//= require app
//= require check_all_none
//= require comments
//= require dropdown
//= require foundation_extras
//= require ie_alert
//= require location_changer
//= require moderator_comment
Expand Down Expand Up @@ -93,7 +93,7 @@ var initialize_modules = function() {
App.Votes.initialize();
App.AllowParticipation.initialize();
App.Tags.initialize();
App.Dropdown.initialize();
App.FoundationExtras.initialize();
App.LocationChanger.initialize();
App.CheckAllNone.initialize();
App.PreventDoubleSubmission.initialize();
Expand Down
4 changes: 0 additions & 4 deletions app/assets/javascripts/dropdown.js.coffee

This file was deleted.

5 changes: 5 additions & 0 deletions app/assets/javascripts/foundation_extras.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
App.FoundationExtras =

initialize: ->
$(document).foundation()
$(window).trigger "load.zf.sticky"
3 changes: 3 additions & 0 deletions app/assets/stylesheets/_consul_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ $tab-content-border: $border;
$orbit-bullet-diameter: 0.8rem;

$pagination-radius: $global-radius;

$show-header-for-stacked: true;

1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@import "legislation";
@import "legislation_process";
@import "community";
@import "stats";
@import "custom";
@import "c3";
@import "annotator.min";
Expand Down
15 changes: 1 addition & 14 deletions app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1988,15 +1988,8 @@
.polls-results-stats {

.sidebar {
border-bottom: 1px solid $border;
margin-bottom: $line-height;

@include breakpoint(medium) {
border-bottom: 0;
border-right: 1px solid $border;
}

.menu {
.menu:not(.vertical) {
padding: 0;

li a {
Expand Down Expand Up @@ -2030,10 +2023,4 @@
}
}
}

.number {
font-size: rem-calc(60);
font-weight: bold;
line-height: rem-calc(60);
}
}
215 changes: 215 additions & 0 deletions app/assets/stylesheets/stats.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
.participation-stats {

@include breakpoint(medium) {

.stats-content {
border-left: 1px solid $border;
}
}

.sidebar {
border-bottom: 1px solid $border;
margin-bottom: $line-height;

@include breakpoint(medium) {
border-bottom: 0;
}

ul {
margin-left: $line-height / 2;
margin-top: 0;
padding: 0;
}
}

.section-title {
font-size: rem-calc(24);
border-bottom: 1px solid $border;
}

.stats-group {
margin-bottom: $line-height;
margin-top: $line-height;
}

.number-with-info {
display: inline-block;

&::before {
display: inline-block;
margin-right: $line-height / 2;
vertical-align: top;
}

&.total-participants::before {
content: image-url("stats_users.png");
}

&.male::before {
content: image-url("stats_man.png");
}

&.female::before {
content: image-url("stats_woman.png");
}

&.total-investments::before {
content: image-url("stats_investments.png");
}

&.web::before {
content: image-url("stats_web.png");
}

&.booth::before {
content: image-url("stats_booth.png");
}

&.mail::before {
content: image-url("stats_mail.png");
}

.content {
display: inline-block;
margin-right: $line-height * 2;
}

.number {
display: block;
font-size: rem-calc(36);
font-weight: bold;
line-height: rem-calc(36);
}

.info {
color: $text-medium;
font-size: $small-font-size;
font-style: italic;
}

&.total-participants {

.number {
font-size: rem-calc(60);
line-height: rem-calc(60);
}
}
}

.progress {
background: #ebf0f4;
border-radius: rem-calc(20);
height: $line-height / 2;
}

.progress-meter {
background: #52a4ee;
border-bottom-left-radius: rem-calc(20);
border-top-left-radius: rem-calc(20);
}

.gender-and-channel {

thead,
tbody {
border: 0;
}

thead,
tr,
th {
background-color: transparent;
}

td,
th {
text-align: center;
text-transform: uppercase;

&::before {
display: inline-block;
transform: scale(0.6);
vertical-align: middle;
}
}

th {
font-weight: bold;
font-size: rem-calc(21);

&.gender {
opacity: 0;
}

&.web::before {
content: image-url("stats_web.png");
}

&.booth::before {
content: image-url("stats_booth.png");
}

&.mail::before {
content: image-url("stats_mail.png");
}
}

td {

&.gender {
font-weight: bold;
font-size: rem-calc(21);
text-align: left;
}

&.male::before {
content: image-url("stats_man.png");
}

&.female::before {
content: image-url("stats_woman.png");
}
}
}
}

table {

&.survey-districts {

@include breakpoint(medium down) {
thead {
font-size: rem-calc(12);

th {
width: 25%;
word-break: break-all;
}
}
}

tr th {
border: 1px solid $border;
text-align: center;
}

.phase-subheader {
font-size: rem-calc(11);
font-weight: normal;
}

.success {
background: #c1fdd2;
}

.border-left-success {
background: #c1fdd2;
border-left: 2px solid #58ff87;
}

.border-right-success {
background: #c1fdd2;
border-right: 2px solid #58ff87;
}
}
}
6 changes: 1 addition & 5 deletions app/controllers/budgets/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ class StatsController < ApplicationController

def show
authorize! :read_stats, @budget
@stats = load_stats
@stats = Budget::Stats.new(@budget)
@headings = @budget.headings.sort_by_name
end

private

def load_stats
Budget::Stats.new(@budget).generate
end

def load_budget
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/polls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def show
end

def stats
@stats = Poll::Stats.new(@poll).generate
@stats = Poll::Stats.new(@poll)
end

def results
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/stats_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ def budget_investments_chart_tag(opt = {})
opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
content_tag :div, "", opt
end

def number_to_stats_percentage(number, options = {})
number_to_percentage(number, { strip_insignificant_zeros: true, precision: 2 }.merge(options))
end

def number_with_info_tags(number, text, html_class: "")
content_tag :p, class: "number-with-info #{html_class}".strip do
content_tag :span, class: "content" do
content_tag(:span, number, class: "number") + content_tag(:span, text, class: "info")
end
end
end
end
1 change: 0 additions & 1 deletion app/models/abilities/administrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def initialize(user)
can [:hide, :update, :toggle_selection], Budget::Investment
can [:valuate, :comment_valuation], Budget::Investment
can :create, Budget::ValuatorAssignment
can :read_stats, Budget, phase: "reviewing_ballots"

can [:search, :edit, :update, :create, :index, :destroy], Banner

Expand Down
2 changes: 1 addition & 1 deletion app/models/abilities/everyone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(user)
can [:read], Budget::Group
can [:read, :print, :json_data], Budget::Investment
can [:read_results, :read_executions], Budget, phase: "finished"
can :read_stats, Budget, phase: "finished"
can(:read_stats, Budget) { |budget| budget.valuating_or_later? }
can :new, DirectMessage
can [:read, :debate, :draft_publication, :allegations, :result_publication,
:proposals, :milestones], Legislation::Process, published: true
Expand Down
9 changes: 7 additions & 2 deletions app/models/budget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Budget < ApplicationRecord

include Measurable
include Sluggable
include StatsVersionable

translates :name, touch: true
include Globalizable
Expand Down Expand Up @@ -125,16 +126,20 @@ def published_prices?
Budget::Phase::PUBLISHED_PRICES_PHASES.include?(phase)
end

def valuating_or_later?
current_phase&.valuating_or_later?
end

def publishing_prices_or_later?
publishing_prices? || balloting_or_later?
current_phase&.publishing_prices_or_later?
end

def balloting_process?
balloting? || reviewing_ballots?
end

def balloting_or_later?
balloting_process? || finished?
current_phase&.balloting_or_later?
end

def heading_price(heading)
Expand Down
Loading

0 comments on commit 82e3c41

Please sign in to comment.