diff --git a/app/assets/javascripts/dashboard_graphs.js b/app/assets/javascripts/dashboard_graphs.js index 10317a8a6..e779dc118 100644 --- a/app/assets/javascripts/dashboard_graphs.js +++ b/app/assets/javascripts/dashboard_graphs.js @@ -9,16 +9,49 @@ this.url = url; this.targetId = null; this.groupBy = null; + this.proposalSuccess = null; this.progressLabel = 'Progress'; this.supportsLabel = 'Supports'; + this.chart = null; + this.goals = null; + this.xColumnValues = null; + this.progressColumnValues = null; }; 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, cache: false, success: function (data) { - this.draw(data); + this.parseData(data); }.bind(this), data: { group_by: this.groupBy @@ -26,29 +59,34 @@ }); }; - ProposalGraph.prototype.draw = function(data) { - var xColumnValues = [ 'x' ], - progressColumnValues = [ this.progressLabel ], - key; + ProposalGraph.prototype.parseData = function(data) { + var key; + + this.xColumnValues = [ 'x' ]; + this.progressColumnValues = [ this.progressLabel ]; for (key in data) { if (data.hasOwnProperty(key)) { - xColumnValues.push(key); - progressColumnValues.push(data[key]); + this.xColumnValues.push(key); + this.progressColumnValues.push(data[key]); } } + }; - c3.generate({ + ProposalGraph.prototype.draw = function(data) { + this.chart = c3.generate({ bindto: '#' + this.targetId, data: { x: 'x', columns: [ - xColumnValues, - progressColumnValues + this.xColumnValues, + this.progressColumnValues ] }, axis: { y: { + min: 0, + max: this.proposalSuccess, label: { text: this.supportsLabel, position: 'outer-middle' @@ -57,6 +95,11 @@ x: { type: 'category' } + }, + grid: { + y: { + lines: this.goals + } } }); }; @@ -68,6 +111,7 @@ graph.groupBy = $(this).data('proposal-graph-group-by'); graph.progressLabel = $(this).data('proposal-graph-progress-label'); graph.supportsLabel = $(this).data('proposal-graph-supports-label'); + graph.proposalSuccess = parseInt($(this).data('proposal-success'), 10); graph.refresh(); }); diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 25c749e1b..52495ee85 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -9,6 +9,7 @@ @import 'participation'; @import 'pages'; @import 'proposal'; +@import 'proposal-graph'; @import 'poll'; @import 'legislation'; @import 'legislation_process'; diff --git a/app/assets/stylesheets/proposal-graph.scss b/app/assets/stylesheets/proposal-graph.scss new file mode 100644 index 000000000..a1132527a --- /dev/null +++ b/app/assets/stylesheets/proposal-graph.scss @@ -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; + } + } + } diff --git a/app/controllers/dashboard/resources_controller.rb b/app/controllers/dashboard/resources_controller.rb new file mode 100644 index 000000000..42154d55c --- /dev/null +++ b/app/controllers/dashboard/resources_controller.rb @@ -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 diff --git a/app/views/proposals_dashboard/progress.html.erb b/app/views/proposals_dashboard/progress.html.erb index 729b874b5..083027c40 100644 --- a/app/views/proposals_dashboard/progress.html.erb +++ b/app/views/proposals_dashboard/progress.html.erb @@ -1,11 +1,12 @@ <% content_for :action_title, t('.title') %> -