Shows goals in progress graphic
This commit is contained in:
Juan Salvador Pérez García
2018-07-06 08:58:10 +02:00
parent 4378331ece
commit 0a790b4479
8 changed files with 105 additions and 25 deletions

View File

@@ -9,16 +9,49 @@
this.url = url; this.url = url;
this.targetId = null; this.targetId = null;
this.groupBy = null; this.groupBy = null;
this.proposalSuccess = null;
this.progressLabel = 'Progress'; this.progressLabel = 'Progress';
this.supportsLabel = 'Supports'; this.supportsLabel = 'Supports';
this.chart = null;
this.goals = null;
this.xColumnValues = null;
this.progressColumnValues = null;
}; };
ProposalGraph.prototype.refresh = function() { ProposalGraph.prototype.refresh = function() {
$.ajax({ this.refreshGoals()
.then(this.refreshData.bind(this))
.done(this.draw.bind(this));
};
ProposalGraph.prototype.refreshGoals = function () {
return $.ajax({
url: '/dashboard/resources.json',
cache: false,
success: function(data) {
this.parseGoals(data);
}.bind(this)
});
};
ProposalGraph.prototype.parseGoals = function(data) {
var i, l;
this.goals = [];
for (i = 0, l = data.length; i < l; i += 1) {
this.goals.push({
value: data[i].required_supports,
text: data[i].title
});
}
};
ProposalGraph.prototype.refreshData = function () {
return $.ajax({
url: this.url, url: this.url,
cache: false, cache: false,
success: function (data) { success: function (data) {
this.draw(data); this.parseData(data);
}.bind(this), }.bind(this),
data: { data: {
group_by: this.groupBy group_by: this.groupBy
@@ -26,29 +59,34 @@
}); });
}; };
ProposalGraph.prototype.draw = function(data) { ProposalGraph.prototype.parseData = function(data) {
var xColumnValues = [ 'x' ], var key;
progressColumnValues = [ this.progressLabel ],
key; this.xColumnValues = [ 'x' ];
this.progressColumnValues = [ this.progressLabel ];
for (key in data) { for (key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
xColumnValues.push(key); this.xColumnValues.push(key);
progressColumnValues.push(data[key]); this.progressColumnValues.push(data[key]);
} }
} }
};
c3.generate({ ProposalGraph.prototype.draw = function(data) {
this.chart = c3.generate({
bindto: '#' + this.targetId, bindto: '#' + this.targetId,
data: { data: {
x: 'x', x: 'x',
columns: [ columns: [
xColumnValues, this.xColumnValues,
progressColumnValues this.progressColumnValues
] ]
}, },
axis: { axis: {
y: { y: {
min: 0,
max: this.proposalSuccess,
label: { label: {
text: this.supportsLabel, text: this.supportsLabel,
position: 'outer-middle' position: 'outer-middle'
@@ -57,6 +95,11 @@
x: { x: {
type: 'category' type: 'category'
} }
},
grid: {
y: {
lines: this.goals
}
} }
}); });
}; };
@@ -68,6 +111,7 @@
graph.groupBy = $(this).data('proposal-graph-group-by'); graph.groupBy = $(this).data('proposal-graph-group-by');
graph.progressLabel = $(this).data('proposal-graph-progress-label'); graph.progressLabel = $(this).data('proposal-graph-progress-label');
graph.supportsLabel = $(this).data('proposal-graph-supports-label'); graph.supportsLabel = $(this).data('proposal-graph-supports-label');
graph.proposalSuccess = parseInt($(this).data('proposal-success'), 10);
graph.refresh(); graph.refresh();
}); });

View File

@@ -9,6 +9,7 @@
@import 'participation'; @import 'participation';
@import 'pages'; @import 'pages';
@import 'proposal'; @import 'proposal';
@import 'proposal-graph';
@import 'poll'; @import 'poll';
@import 'legislation'; @import 'legislation';
@import 'legislation_process'; @import 'legislation_process';

View File

@@ -0,0 +1,12 @@
// #proposal-graph > svg > g:nth-child(2) > g.c3-grid.c3-grid-lines > g.c3-ygrid-lines > g:nth-child(2) > line
#proposal-graph {
.c3-ygrid-lines {
line {
stroke: #005c92;
}
text {
fill: #005c92;
}
}
}

View File

@@ -0,0 +1,19 @@
class Dashboard::ResourcesController < Dashboard::BaseController
skip_authorization_check
def index
@resources = ProposalDashboardAction
.active
.resources
.where('required_supports > 0')
.order(required_supports: :asc)
render json: @resources.map { |resource|
{
id: resource.id,
title: resource.title,
required_supports: resource.required_supports
}
}
end
end

View File

@@ -1,11 +1,12 @@
<% content_for :action_title, t('.title') %> <% content_for :action_title, t('.title') %>
<div class="small-12 column"> <div class="row">
<div class="small-12 column">
<div class="button-group"> <div class="button-group">
<%= link_to t('.group_by_year'), progress_proposal_dashboard_index_path(proposal, group_by: 'year'), class: 'button' %>
<%= link_to t('.group_by_month'), progress_proposal_dashboard_index_path(proposal, group_by: 'month'), class: 'button' %>
<%= link_to t('.group_by_week'), progress_proposal_dashboard_index_path(proposal, group_by: 'week'), class: 'button' %>
<%= link_to t('.group_by_date'), progress_proposal_dashboard_index_path(proposal), class: 'button' %> <%= link_to t('.group_by_date'), progress_proposal_dashboard_index_path(proposal), class: 'button' %>
<%= link_to t('.group_by_week'), progress_proposal_dashboard_index_path(proposal, group_by: 'week'), class: 'button' %>
<%= link_to t('.group_by_month'), progress_proposal_dashboard_index_path(proposal, group_by: 'month'), class: 'button' %>
</div>
</div> </div>
</div> </div>
@@ -15,6 +16,7 @@
data-proposal-graph-group-by="<%= params[:group_by] %>" data-proposal-graph-group-by="<%= params[:group_by] %>"
data-proposal-graph-progress-label="<%= t '.progress' %>" data-proposal-graph-progress-label="<%= t '.progress' %>"
data-proposal-graph-supports-label="<%= t '.supports' %>" data-proposal-graph-supports-label="<%= t '.supports' %>"
data-proposal-success="<%= Setting["votes_for_proposal_success"] %>"
class="c3" class="c3"
style="max-height: 320px; position: relative;"></div> style="max-height: 320px; position: relative;"></div>
</div> </div>

View File

@@ -515,10 +515,9 @@ en:
success: The request for the administrator has been successfully sent. success: The request for the administrator has been successfully sent.
progress: progress:
title: Graphic title: Graphic
group_by_year: Group by year group_by_month: Monthly
group_by_month: Group by month group_by_week: Weekly
group_by_week: Group by week group_by_date: Daily
group_by_date: Group by date
progress: Acumulated progress progress: Acumulated progress
supports: Supports supports: Supports
index: index:

View File

@@ -515,10 +515,9 @@ es:
success: La petición ha sido correctamente enviada al administrador. success: La petición ha sido correctamente enviada al administrador.
progress: progress:
title: Gráfico title: Gráfico
group_by_year: Agrupar por año group_by_month: Mensual
group_by_month: Agrupar por meses group_by_week: Semanal
group_by_week: Agrupar por semanas group_by_date: Diario
group_by_date: Agrupar por fechas
progress: Progreso acumulado progress: Progreso acumulado
supports: Apoyos supports: Apoyos
index: index:

View File

@@ -1,3 +1,7 @@
namespace :dashboard do
resources :resources, only: [:index]
end
resources :proposals do resources :proposals do
resources :proposals_dashboard, as: :dashboard, path: :dashboard, only: [:index] do resources :proposals_dashboard, as: :dashboard, path: :dashboard, only: [:index] do
collection do collection do