aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-11-28 15:49:22 +0000
committerLouise Crow <louise.crow@gmail.com>2014-12-15 17:30:32 +0000
commit7f1a02e62d38b7944eb30d6351f88d0e97f5366d (patch)
tree5ca02d0729c3870ba680c8b31991e69273279bc5
parentfdcd1c204c5e20bcea3a132f4f24da4e4f23bbb4 (diff)
Add index method for listing existing holidays
-rw-r--r--app/assets/stylesheets/admin.scss24
-rw-r--r--app/controllers/admin_holidays_controller.rb14
-rw-r--r--app/views/admin_holidays/_holiday.html.erb7
-rw-r--r--app/views/admin_holidays/index.html.erb26
-rw-r--r--spec/controllers/admin_holidays_controller_spec.rb32
-rw-r--r--spec/factories/holidays.rb8
6 files changed, 111 insertions, 0 deletions
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss
index 104f10c75..69fce108c 100644
--- a/app/assets/stylesheets/admin.scss
+++ b/app/assets/stylesheets/admin.scss
@@ -119,5 +119,29 @@ body.admin {
padding: 3px 0;
}
+ /* Holidays */
+ .day_select {
+ width: 75px;
+ }
+
+ .holiday-description, .holiday-day, .holiday-buttons, .holiday-destroy {
+ padding: 6px 4px;
+ }
+
+ .holiday-description, .holiday-day, .holiday-buttons{
+ display: inline-block;
+ }
+
+ .holiday-description {
+ width: 300px;
+ }
+ .holiday-day {
+ width: 240px;
+ text-align: center;
+ }
+ .holiday-buttons{
+ width: 200px;
+ text-align: right;
+ }
}
diff --git a/app/controllers/admin_holidays_controller.rb b/app/controllers/admin_holidays_controller.rb
new file mode 100644
index 000000000..74fce2a89
--- /dev/null
+++ b/app/controllers/admin_holidays_controller.rb
@@ -0,0 +1,14 @@
+class AdminHolidaysController < AdminController
+
+ def index
+ get_all_holidays
+ end
+
+ private
+
+ def get_all_holidays
+ @holidays_by_year = Holiday.all.group_by { |holiday| holiday.day.year }
+ @years = @holidays_by_year.keys.sort.reverse
+ end
+
+end
diff --git a/app/views/admin_holidays/_holiday.html.erb b/app/views/admin_holidays/_holiday.html.erb
new file mode 100644
index 000000000..78818f411
--- /dev/null
+++ b/app/views/admin_holidays/_holiday.html.erb
@@ -0,0 +1,7 @@
+<td>
+ <div class="holiday-description"><%= holiday.description %></div>
+ <div class="holiday-day"><%= holiday.day %></div>
+ <div class="holiday-buttons">
+ <%= link_to 'Edit', edit_admin_holiday_path(holiday), :class => "btn edit-button" %>
+ </div>
+</td>
diff --git a/app/views/admin_holidays/index.html.erb b/app/views/admin_holidays/index.html.erb
new file mode 100644
index 000000000..be1f672de
--- /dev/null
+++ b/app/views/admin_holidays/index.html.erb
@@ -0,0 +1,26 @@
+<% @title = 'Public Holidays' %>
+<h1><%= @title %></h1>
+
+<div class="btn-toolbar">
+ <div class="btn-group">
+ <%= link_to 'New holiday', new_admin_holiday_path, :class => "btn btn-primary", :id => 'new-holiday-button' %>
+ </div>
+ <div class="btn-group">
+ <%= link_to 'Create holidays from suggestions or iCal feed', new_admin_holiday_import_path, :class => "btn btn-warning" %>
+ </div>
+</div>
+
+<div id="existing-holidays">
+ <% @years.each do |year| %>
+ <h2><%= year %></h2>
+ <table class="table table-striped table-condensed">
+ <tbody>
+ <% @holidays_by_year[year].sort_by(&:day).each do |holiday| %>
+ <%= content_tag_for(:tr, holiday, prefix=nil, 'data-target' => edit_admin_holiday_path(holiday)) do %>
+ <%= render :partial => 'holiday', :locals => { :holiday => holiday }%>
+ <% end %>
+ <% end %>
+ </tbody>
+ </table>
+ <% end %>
+</div>
diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb
new file mode 100644
index 000000000..b3b813790
--- /dev/null
+++ b/spec/controllers/admin_holidays_controller_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe AdminHolidaysController do
+
+ describe :index do
+
+ before do
+ @holiday_one = FactoryGirl.create(:holiday, :day => Date.new(2010, 1, 1))
+ @holiday_two = FactoryGirl.create(:holiday, :day => Date.new(2011, 2, 2))
+ @holiday_three = FactoryGirl.create(:holiday, :day => Date.new(2011, 3, 3))
+ end
+
+ it 'gets a hash of holidays keyed by year' do
+ get :index
+ assigns(:holidays_by_year)[2010].should include(@holiday_one)
+ assigns(:holidays_by_year)[2011].should include(@holiday_two)
+ assigns(:holidays_by_year)[2011].should include(@holiday_three)
+ end
+
+ it 'gets a list of years with holidays' do
+ get :index
+ assigns(:years).should include(2010)
+ assigns(:years).should include(2011)
+ end
+
+ it 'renders the index template' do
+ get :index
+ expect(response).to render_template('index')
+ end
+
+ end
+end
diff --git a/spec/factories/holidays.rb b/spec/factories/holidays.rb
new file mode 100644
index 000000000..531130c8a
--- /dev/null
+++ b/spec/factories/holidays.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+
+ factory :holiday do
+ day Date.new(2010, 1, 1)
+ description "New Year's Day"
+ end
+
+end