diff --git a/app/controllers/admin/poll/active_polls_controller.rb b/app/controllers/admin/poll/active_polls_controller.rb new file mode 100644 index 000000000..97665ac2f --- /dev/null +++ b/app/controllers/admin/poll/active_polls_controller.rb @@ -0,0 +1,36 @@ +class Admin::Poll::ActivePollsController < Admin::Poll::BaseController + include Translatable + + before_action :load_active_poll + + def create + if @active_poll.update(active_poll_params) + redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll") + else + render :edit + end + end + + def edit + end + + def update + if @active_poll.update(active_poll_params) + redirect_to admin_polls_url, notice: t("flash.actions.update.active_poll") + else + render :edit + end + end + + + private + + def load_active_poll + @active_poll = ::ActivePoll.first_or_initialize + end + + def active_poll_params + params.require(:active_poll).permit(translation_params(ActivePoll)) + end + +end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 8378b083d..a034846a0 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1,6 +1,8 @@ class PollsController < ApplicationController include PollsHelper + before_action :load_active_poll, only: :index + load_and_authorize_resource has_filters %w[current expired] @@ -34,4 +36,10 @@ class PollsController < ApplicationController def results end + private + + def load_active_poll + @active_poll = ActivePoll.first + end + end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 255020c1f..f64282e6b 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -37,8 +37,12 @@ module AdminHelper ["spending_proposals"].include?(controller_name) end + def menu_poll? + %w[polls active_polls recounts results].include?(controller_name) + end + def menu_polls? - %w[polls questions answers recounts results].include?(controller_name) + menu_poll? || %w[questions answers].include?(controller_name) end def menu_booths? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 486759e03..2da2186cf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,4 +60,11 @@ module ApplicationHelper def kaminari_path(url) "#{root_url.chomp("\/")}#{url}" end + + def render_custom_partial(partial_name) + controller_action = @virtual_path.split("/").last + custom_partial_path = "custom/#{@virtual_path.remove(controller_action)}#{partial_name}" + render custom_partial_path if lookup_context.exists?(custom_partial_path, [], true) + end + end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 83200c621..8135e8ab8 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -64,4 +64,8 @@ module PollsHelper def info_menu? controller_name == "polls" && action_name == "show" end + + def show_polls_description? + @active_poll.present? && @current_filter == "current" + end end diff --git a/app/models/active_poll.rb b/app/models/active_poll.rb new file mode 100644 index 000000000..50e185ea5 --- /dev/null +++ b/app/models/active_poll.rb @@ -0,0 +1,6 @@ +class ActivePoll < ActiveRecord::Base + include Measurable + + translates :description, touch: true + include Globalizable +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index acc59b45a..ca3f0cdef 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -7,7 +7,7 @@ <%= t("admin.menu.title_polls") %>