Polls' stats migrated from Madrid's fork and sortable functions added for tables
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
//= require map
|
//= require map
|
||||||
//= require polls
|
//= require polls
|
||||||
//= require sortable
|
//= require sortable
|
||||||
|
//= require table_sortable
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
App.Comments.initialize();
|
App.Comments.initialize();
|
||||||
@@ -113,6 +114,7 @@ var initialize_modules = function() {
|
|||||||
App.Map.initialize();
|
App.Map.initialize();
|
||||||
App.Polls.initialize();
|
App.Polls.initialize();
|
||||||
App.Sortable.initialize();
|
App.Sortable.initialize();
|
||||||
|
App.TableSortable.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|||||||
23
app/assets/javascripts/table_sortable.js.coffee
Normal file
23
app/assets/javascripts/table_sortable.js.coffee
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
App.TableSortable =
|
||||||
|
getCellValue: (row, index) ->
|
||||||
|
$(row).children('td').eq(index).text()
|
||||||
|
|
||||||
|
comparer: (index) ->
|
||||||
|
(a, b) ->
|
||||||
|
valA = App.TableSortable.getCellValue(a, index)
|
||||||
|
valB = App.TableSortable.getCellValue(b, index)
|
||||||
|
return if $.isNumeric(valA) and $.isNumeric(valB) then valA - valB else valA.localeCompare(valB)
|
||||||
|
|
||||||
|
initialize: ->
|
||||||
|
$('table.sortable th').click ->
|
||||||
|
table = $(this).parents('table').eq(0)
|
||||||
|
rows = table.find('tr:gt(0)').not('tfoot tr').toArray().sort(App.TableSortable.comparer($(this).index()))
|
||||||
|
@asc = !@asc
|
||||||
|
if !@asc
|
||||||
|
rows = rows.reverse()
|
||||||
|
i = 0
|
||||||
|
while i < rows.length
|
||||||
|
table.append rows[i]
|
||||||
|
i++
|
||||||
|
return
|
||||||
|
|
||||||
@@ -36,4 +36,9 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def polls
|
||||||
|
@polls = ::Poll.current
|
||||||
|
@participants = ::Poll::Voter.where(poll: @polls)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
87
app/views/admin/stats/polls.html.erb
Normal file
87
app/views/admin/stats/polls.html.erb
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
|
||||||
|
<h2 id="top"><%= t("admin.stats.polls.title")%></h2>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<div class="row stats-numbers">
|
||||||
|
<div class="small-12 medium-3 column">
|
||||||
|
<p class="featured">
|
||||||
|
<%= t("admin.stats.polls.web_participants") %><br>
|
||||||
|
<span id="web_participants" class="number">
|
||||||
|
<%= @participants.web.select(:user_id).distinct.count %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 medium-3 column end">
|
||||||
|
<p class="featured">
|
||||||
|
<%= t("admin.stats.polls.total_participants") %><br>
|
||||||
|
<span id="participants" class="number">
|
||||||
|
<%= @participants.select(:user_id).distinct.count %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2><%= t("admin.stats.polls.all") %></h2>
|
||||||
|
<table id="polls" class="stack sortable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.stats.polls.table.poll_name") %></th>
|
||||||
|
<th class="name text-right"><%= t("admin.stats.polls.total_participants") %></th>
|
||||||
|
<th class="name text-right"><%= t("admin.stats.polls.table.origin_web") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<% @polls.each do |poll| %>
|
||||||
|
<tr id="<%= dom_id(poll) %>">
|
||||||
|
<td class="name">
|
||||||
|
<a href="#<%= dom_id(poll) %>_questions"><%= poll.name %></a>
|
||||||
|
</td>
|
||||||
|
<td class="name text-right">
|
||||||
|
<%= poll.voters.select(:user_id).distinct.count %>
|
||||||
|
</td>
|
||||||
|
<td class="name text-right">
|
||||||
|
<%= poll.voters.web.select(:user_id).distinct.count %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<% @polls.each do |poll| %>
|
||||||
|
<h3 id="<%= dom_id(poll) %>_questions">
|
||||||
|
<%= t("admin.stats.polls.poll_questions", poll: poll.name) %>
|
||||||
|
</h3>
|
||||||
|
<table class="stack sortable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.stats.polls.table.question_name") %></th>
|
||||||
|
<th class="name text-right">
|
||||||
|
<%= t("admin.stats.polls.table.origin_web") %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<% poll.questions.each do |question| %>
|
||||||
|
<tr id="<%= dom_id(question) %>">
|
||||||
|
<td class="name">
|
||||||
|
<%= question.title %>
|
||||||
|
</td>
|
||||||
|
<td class="name text-right">
|
||||||
|
<%= ::Poll::Answer.by_question(question).count %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<tfoot>
|
||||||
|
<tr id="<%= dom_id(poll) %>_questions_total">
|
||||||
|
<th></th>
|
||||||
|
<th class="name text-right">
|
||||||
|
<strong>
|
||||||
|
<%= t("admin.stats.polls.table.origin_total") %>:
|
||||||
|
<%= ::Poll::Answer.where(question: poll.questions)
|
||||||
|
.select(:author_id).distinct.count %>
|
||||||
|
</strong>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
<h1 class="inline-block"><%= t "admin.stats.show.stats_title" %></h1>
|
<h1 class="inline-block"><%= t "admin.stats.show.stats_title" %></h1>
|
||||||
|
|
||||||
<div class="float-right clear">
|
<div class="float-right clear">
|
||||||
|
<%= link_to t("admin.stats.show.polls"),
|
||||||
|
polls_admin_stats_path, class: "button hollow" %>
|
||||||
<%= link_to t("admin.stats.show.direct_messages"),
|
<%= link_to t("admin.stats.show.direct_messages"),
|
||||||
direct_messages_admin_stats_path, class: "button hollow" %>
|
direct_messages_admin_stats_path, class: "button hollow" %>
|
||||||
<%= link_to t("admin.stats.show.proposal_notifications"),
|
<%= link_to t("admin.stats.show.proposal_notifications"),
|
||||||
|
|||||||
@@ -323,6 +323,7 @@ Rails.application.routes.draw do
|
|||||||
resource :stats, only: :show do
|
resource :stats, only: :show do
|
||||||
get :proposal_notifications, on: :collection
|
get :proposal_notifications, on: :collection
|
||||||
get :direct_messages, on: :collection
|
get :direct_messages, on: :collection
|
||||||
|
get :polls, on: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :legislation do
|
namespace :legislation do
|
||||||
|
|||||||
Reference in New Issue
Block a user