Order admin poll list by starts_at date

This commit is contained in:
decabeza
2019-01-23 14:53:46 +01:00
parent 5ea1275e6a
commit dfd4f60e15
6 changed files with 25 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
before_action :load_geozones, only: [:new, :create, :edit, :update] before_action :load_geozones, only: [:new, :create, :edit, :update]
def index def index
@polls = Poll.order(starts_at: :desc)
end end
def show def show

View File

@@ -4,19 +4,19 @@
<%= link_to poll.name, admin_poll_path(poll) %> <%= link_to poll.name, admin_poll_path(poll) %>
</strong> </strong>
</td> </td>
<td> <td class="text-center">
<%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> <%= l poll.starts_at.to_date %>
</td> </td>
<td class="text-right"> <td class="text-center">
<div class="small-6 column"> <%= l poll.ends_at.to_date %>
</td>
<td>
<%= link_to t("admin.actions.edit"), <%= link_to t("admin.actions.edit"),
edit_admin_poll_path(poll), edit_admin_poll_path(poll),
class: "button hollow expanded" %> class: "button hollow" %>
</div>
<div class="small-6 column">
<%= link_to t("admin.actions.configure"), <%= link_to t("admin.actions.configure"),
admin_poll_path(poll), admin_poll_path(poll),
class: "button hollow expanded" %> class: "button hollow " %>
</div>
</td> </td>
</tr> </tr>

View File

@@ -7,8 +7,9 @@
<% if @polls.any? %> <% if @polls.any? %>
<table> <table>
<thead> <thead>
<th class="small-6"><%= t("admin.polls.index.name") %></th> <th class="small-5"><%= t("admin.polls.index.name") %></th>
<th><%= t("admin.polls.index.dates") %></th> <th class="text-center"><%= t("admin.polls.index.start_date") %></th>
<th class="text-center"><%= t("admin.polls.index.closing_date") %></th>
<th><%= t("admin.actions.actions") %></th> <th><%= t("admin.actions.actions") %></th>
</thead> </thead>
<tbody> <tbody>

View File

@@ -921,6 +921,8 @@ en:
create: "Create poll" create: "Create poll"
name: "Name" name: "Name"
dates: "Dates" dates: "Dates"
start_date: "Start Date"
closing_date: "Closing Date"
geozone_restricted: "Restricted to districts" geozone_restricted: "Restricted to districts"
new: new:
title: "New poll" title: "New poll"

View File

@@ -921,6 +921,8 @@ es:
create: "Crear votación" create: "Crear votación"
name: "Nombre" name: "Nombre"
dates: "Fechas" dates: "Fechas"
start_date: "Fecha de apertura"
closing_date: "Fecha de cierre"
geozone_restricted: "Restringida a los distritos" geozone_restricted: "Restringida a los distritos"
new: new:
title: "Nueva votación" title: "Nueva votación"

View File

@@ -23,13 +23,15 @@ feature 'Admin polls' do
expect(page).to have_content "There are no polls" expect(page).to have_content "There are no polls"
end end
scenario 'Index', :js do scenario "Index show polls list order by starts at date", :js do
3.times { create(:poll) } poll_1 = create(:poll, name: "Poll first", starts_at: 15.days.ago)
poll_2 = create(:poll, name: "Poll second", starts_at: 1.month.ago)
poll_3 = create(:poll, name: "Poll third", starts_at: 2.days.ago)
visit admin_root_path visit admin_root_path
click_link "Polls" click_link "Polls"
within('#polls_menu') do within("#polls_menu") do
click_link "Polls" click_link "Polls"
end end
@@ -42,6 +44,9 @@ feature 'Admin polls' do
expect(page).to have_content poll.name expect(page).to have_content poll.name
end end
end end
expect(poll_3.name).to appear_before(poll_1.name)
expect(poll_1.name).to appear_before(poll_2.name)
expect(page).not_to have_content "There are no polls" expect(page).not_to have_content "There are no polls"
end end