From c1ea074be4aa8d3b23352fe107bf1418214ff9e8 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Nov 2016 11:46:02 +0100 Subject: [PATCH] adds question, booth and officer tabs for a poll --- app/models/poll.rb | 1 + app/views/admin/poll/polls/_booths.html.erb | 26 +++++++++++ .../admin/poll/polls/_filter_subnav.html.erb | 33 ++++++++++++++ app/views/admin/poll/polls/_officers.html.erb | 43 +++++++++++++++++++ .../admin/poll/polls/_questions.html.erb | 29 +++++++++++++ app/views/admin/poll/polls/show.html.erb | 34 ++++++--------- 6 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 app/views/admin/poll/polls/_booths.html.erb create mode 100644 app/views/admin/poll/polls/_filter_subnav.html.erb create mode 100644 app/views/admin/poll/polls/_officers.html.erb create mode 100644 app/views/admin/poll/polls/_questions.html.erb diff --git a/app/models/poll.rb b/app/models/poll.rb index caa374dc8..1bd3d07ef 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,6 +1,7 @@ class Poll < ActiveRecord::Base has_many :booths has_many :voters, through: :booths, class_name: "Poll::Voter" + has_many :officers, through: :booths, class_name: "Poll::Officer" has_many :questions validates :name, presence: true diff --git a/app/views/admin/poll/polls/_booths.html.erb b/app/views/admin/poll/polls/_booths.html.erb new file mode 100644 index 000000000..ba62bc032 --- /dev/null +++ b/app/views/admin/poll/polls/_booths.html.erb @@ -0,0 +1,26 @@ +
+
+ <% if @poll.booths.empty? %> +
+ <%= t("admin.polls.show.no_booths") %> +
+ <% else %> + +

<%= t("admin.polls.show.booths_title") %>

+ + + + + + + + + + <% @poll.booths.each do |booth| %> + <%= render partial: "admin/poll/booths/booth", locals: { booth: booth } %> + <% end %> + +
<%= t("admin.polls.show.name") %><%= t("admin.polls.show.location") %><%= t("admin.polls.show.officers") %> 
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb new file mode 100644 index 000000000..4c4353a2c --- /dev/null +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -0,0 +1,33 @@ +
+
+
    +
  • + <%= link_to "#tab-questions" do %> +

    + <%# t("proposals.show.comments_tab") %> + Preguntas + (<%= @poll.questions.count %>) +

    + <% end %> +
  • +
  • + <%= link_to "#tab-booths" do %> +

    + <%# t("proposals.show.notifications_tab") %> + Urnas + (<%= @poll.booths.count %>) +

    + <% end %> +
  • +
  • + <%= link_to "#tab-officers" do %> +

    + <%# t("proposals.show.notifications_tab") %> + Presidentes + (<%= @poll.officers.count %>) +

    + <% end %> +
  • +
+
+
\ No newline at end of file diff --git a/app/views/admin/poll/polls/_officers.html.erb b/app/views/admin/poll/polls/_officers.html.erb new file mode 100644 index 000000000..36793c9b3 --- /dev/null +++ b/app/views/admin/poll/polls/_officers.html.erb @@ -0,0 +1,43 @@ +
+
+ <% if @poll.officers.empty? %> +
+ <%= t("admin.polls.show.no_booths") %> +
+ <% else %> + +

<%= t("admin.polls.show.booths_title") %>

+ + + + + + + + + + <% @poll.officers.each do |officer| %> + + + + + + + <% end %> + +
<%= t("admin.polls.show.name") %><%= t("admin.polls.show.location") %><%= t("admin.polls.show.officers") %> 
+ + <%= link_to officer.name, admin_poll_officer_path(@poll, booth) %> + + + <%= officer.name %> + + N <%= t("admin.booths.index.officers") %> + + <%= link_to t("admin.actions.edit"), + edit_admin_poll_officer_path(@poll, officer), + class: "button hollow" %> +
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb new file mode 100644 index 000000000..3572cda85 --- /dev/null +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -0,0 +1,29 @@ +
+
+ <%= link_to "AƱadir pregunta", + new_admin_question_path(poll_id: @poll.id), + class: "button success" %> +
+ <% if @poll.questions.count == 0 %> +
+ <%= t('admin.questions.index.no_questions') %> +
+ <% else %> + + <% @poll.questions.each do |question| %> + + + + + <% end %> +
<%= link_to question.title, admin_question_path(question) %> + <%= link_to t('shared.edit'), + edit_admin_question_path(question), + class: "button hollow" %> + <%= link_to t('shared.delete'), + admin_question_path(question), + class: "button hollow alert", + method: :delete %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index bed01af41..5317b1f0a 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -9,28 +9,18 @@ edit_admin_poll_path(@poll), class: "button hollow float-right" %> -<%= link_to t("admin.polls.show.add_booth"), - new_admin_poll_booth_path(@poll), - class: "button success" %> +
+ <%= render "filter_subnav" %> -<% if @poll.booths.empty? %> -
- <%= t("admin.polls.show.no_booths") %> +
+ <%= render "questions" %>
-<% else %> -

<%= t("admin.polls.show.booths_title") %>

- - - - - - - - - <% @poll.booths.each do |booth| %> - <%= render partial: "admin/poll/booths/booth", locals: { booth: booth } %> - <% end %> - -
<%= t("admin.polls.show.name") %><%= t("admin.polls.show.location") %><%= t("admin.polls.show.officers") %> 
-<% end %> \ No newline at end of file +
+ <%= render "booths" %> +
+ +
+ <%= render 'officers' %> +
+
\ No newline at end of file