diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 51de9c678..611ecc546 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -73,6 +73,7 @@ //= require map //= require polls //= require sortable +//= require table_sortable var initialize_modules = function() { App.Comments.initialize(); @@ -113,6 +114,7 @@ var initialize_modules = function() { App.Map.initialize(); App.Polls.initialize(); App.Sortable.initialize(); + App.TableSortable.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/table_sortable.js.coffee b/app/assets/javascripts/table_sortable.js.coffee new file mode 100644 index 000000000..331f794a4 --- /dev/null +++ b/app/assets/javascripts/table_sortable.js.coffee @@ -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 + \ No newline at end of file diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 5a50d03b4..91e266b77 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -36,4 +36,9 @@ class Admin::StatsController < Admin::BaseController @users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count end -end \ No newline at end of file + def polls + @polls = ::Poll.current + @participants = ::Poll::Voter.where(poll: @polls) + end + +end diff --git a/app/views/admin/stats/polls.html.erb b/app/views/admin/stats/polls.html.erb new file mode 100644 index 000000000..c2b0b8481 --- /dev/null +++ b/app/views/admin/stats/polls.html.erb @@ -0,0 +1,87 @@ +<%= back_link_to %> + +
+ <%= t("admin.stats.polls.web_participants") %>
+
+ <%= @participants.web.select(:user_id).distinct.count %>
+
+
+ <%= t("admin.stats.polls.total_participants") %>
+
+ <%= @participants.select(:user_id).distinct.count %>
+
+
| <%= t("admin.stats.polls.table.poll_name") %> | +<%= t("admin.stats.polls.total_participants") %> | +<%= t("admin.stats.polls.table.origin_web") %> | +
|---|---|---|
| + <%= poll.name %> + | ++ <%= poll.voters.select(:user_id).distinct.count %> + | ++ <%= poll.voters.web.select(:user_id).distinct.count %> + | +
| <%= t("admin.stats.polls.table.question_name") %> | ++ <%= t("admin.stats.polls.table.origin_web") %> + | +
|---|---|
| + <%= question.title %> + | ++ <%= ::Poll::Answer.by_question(question).count %> + | +
| + | + + <%= t("admin.stats.polls.table.origin_total") %>: + <%= ::Poll::Answer.where(question: poll.questions) + .select(:author_id).distinct.count %> + + | +