Merge pull request #2095 from consul/2052-admin_results_and_stats

Admin results and stats
This commit is contained in:
Raimond Garcia
2017-10-23 13:42:40 +02:00
committed by GitHub
7 changed files with 47 additions and 4 deletions

View File

@@ -58,9 +58,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end
def poll_params
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
geozone_ids: [],
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted,
:summary, :description, :results_enabled, :stats_enabled,
geozone_ids: [],
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end
def search_params

View File

@@ -53,6 +53,17 @@
</div>
</div>
<% if controller_name == "polls" && action_name == "edit" %>
<div class="row">
<fieldset class="fieldset">
<legend><%= t('admin.polls.new.show_results_and_stats') %></legend>
<%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %>
<%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %>
<p class="small"><%= t('admin.polls.new.results_and_stats_reminder') %></p>
</fieldset>
</div>
<% end %>
<div class="row">
<div class="small-12 medium-4 column">
<%= f.submit t("admin.polls.#{admin_submit_action(@poll)}.submit_button"),

View File

@@ -569,6 +569,10 @@ en:
geozone_restricted: "Restricted to districts"
new:
title: "New poll"
show_results_and_stats: "Show results and stats"
show_results: "Show results"
show_stats: "Show stats"
results_and_stats_reminder: "Marking these checkboxes the results and/or stats of this poll will be publicly available and every user will see them."
submit_button: "Create poll"
edit:
title: "Edit poll"

View File

@@ -569,6 +569,10 @@ es:
geozone_restricted: "Restringida a los distritos"
new:
title: "Nueva votación"
show_results_and_stats: "Mostrar resultados y estadísticas"
show_results: "Mostrar resultados"
show_stats: "Mostrar estadísticas"
results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas de esta votación serán públicos y podrán verlos todos los usuarios."
submit_button: "Crear votación"
edit:
title: "Editar votación"

View File

@@ -0,0 +1,6 @@
class AddResultsAndStatsToPolls < ActiveRecord::Migration
def change
add_column :polls, :results_enabled, :boolean, default: false
add_column :polls, :stats_enabled, :boolean, default: false
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171017221546) do
ActiveRecord::Schema.define(version: 20171020163240) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -759,6 +759,8 @@ ActiveRecord::Schema.define(version: 20171017221546) do
t.integer "comments_count", default: 0
t.integer "author_id"
t.datetime "hidden_at"
t.boolean "results_enabled", default: false
t.boolean "stats_enabled", default: false
end
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree

View File

@@ -60,6 +60,10 @@ feature 'Admin polls' do
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..."
fill_in 'poll_description', with: "Upcomming poll's description. This poll..."
expect(page).to_not have_css("#poll_results_enabled")
expect(page).to_not have_css("#poll_stats_enabled")
click_button "Create poll"
expect(page).to have_content "Poll created successfully"
@@ -79,14 +83,25 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']")
expect(page).to have_css("#poll_results_enabled")
expect(page).to have_css("#poll_stats_enabled")
fill_in "poll_name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
check 'poll_results_enabled'
check 'poll_stats_enabled'
click_button "Update poll"
expect(page).to have_content "Poll updated successfully"
expect(page).to have_content "Next Poll"
expect(page).to have_content I18n.l(end_date.to_date)
click_link "Edit poll"
expect(page).to have_field('poll_results_enabled', checked: true)
expect(page).to have_field('poll_stats_enabled', checked: true)
end
scenario 'Edit from index' do