FogBugz #63: Geburtstage jetzt mit nur optionalem Jahr. Man kennt's ja nicht immer.

This commit is contained in:
gchq 2011-06-02 00:07:53 +02:00
parent e50cf051b5
commit e5e4d9e600
10 changed files with 85 additions and 6 deletions

View file

@ -0,0 +1,6 @@
class BirthdayController < ApplicationController
def index
# start_date =
@birthdays = Contact.where(:birth_date => (Date.today)..(Date.today + 7.days))
end
end

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
class ContactsController < ApplicationController
before_filter :authenticate_user!
@ -11,6 +12,25 @@ class ContactsController < ApplicationController
email = @contact.emails.build
phone = @contact.phones.build
end
# list of valid months and days
@months = Array.new
@months << ['Januar', 1]
@months << ['Februar', 2]
@months << ['März', 3]
@months << ['April', 4]
@months << ['Mai', 5]
@months << ['Juni', 6]
@months << ['Juli', 7]
@months << ['August', 8]
@months << ['September', 9]
@months << ['Oktober', 10]
@months << ['November', 11]
@months << ['Dezember', 12]
@days = Array.new
31.times do |d|
@days << [d + 1, d + 1]
end
end
def create
@ -23,10 +43,10 @@ class ContactsController < ApplicationController
c.place = params[:contact][:place]
c.country = params[:contact][:country]
c.birth_year = params[:birth_date][:year].to_i
c.birth_month = params[:birth_date][:month].to_i
c.birth_day = params[:birth_date][:day].to_i
c.birth_date = Date.civil(c.birth_year, c.birth_month, c.birth_day)
# birthdate comes with the year as optional value
c.birth_year = params[:birth_year].to_i unless params[:birth_year].blank?
c.birth_month = params[:birth_month].to_i
c.birth_day = params[:birth_day].to_i
# emails come as: ["0", {"address"=>"a@b.c"}]
params[:contact][:emails_attributes].map {|k,vs| vs}.each { |val|

View file

@ -0,0 +1,2 @@
module BirthdayHelper
end

View file

@ -4,4 +4,10 @@ class Contact < ActiveRecord::Base
accepts_nested_attributes_for :emails, :reject_if => lambda { |a| a[:address].blank? }, :allow_destroy => true
accepts_nested_attributes_for :phones, :reject_if => lambda { |a| a[:nr].blank? }, :allow_destroy => true
def birth_date_string
s = birth_day or ""
s += birth_month or ""
s += birth_year or ""
end
end

View file

@ -0,0 +1,12 @@
<div class="row">
<div class="twelvecol">
<h1>Birthdays</h1>
<h2>for the next 7 days</h2>
</div>
</div>
<% @birthdays.each do |b| %>
<div class="row">
</row>
<% end %>

View file

@ -50,7 +50,9 @@
<tr>
<td align="right"><%= label_tag(:birth_date, "Birthday") %></td>
<td>
<%= select_date Date.today, :prefix => :birth_date, :start_year => 1900, :end_year => Date.today.year %>
<%= select_tag(:birth_day, options_for_select(@days)) %>
<%= select_tag(:birth_month, options_for_select(@months)) %>
<%= text_field_tag(:birth_year, nil, :placeholder => "Jahr") %>
</td>
</tr>
<tr>

View file

@ -1,4 +1,13 @@
<div class="row">
<div class="twelvecol">
<div align="center">
| <%= link_to 'new', new_contact_path %> &middot; <%= link_to 'birthdays', birthday_index_path %> |
</div>
</div>
</div>
<% @contacts.each do |c| %>
<div class="row contact-summary">
<div class="onecol">
[bild]
@ -27,7 +36,7 @@
<% end %>
</div>
<div class="onecol">
<%= c.birth_date %>
<%= c.birth_date_string %>
</div>
</div>
<% end %>

View file

@ -0,0 +1,9 @@
class RemoveBirthdateAsDate < ActiveRecord::Migration
def self.up
remove_column :contacts, :birth_date
end
def self.down
add_column :contacts, :birth_date, :date
end
end

View file

@ -0,0 +1,9 @@
require 'test_helper'
class BirthdayControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class BirthdayHelperTest < ActionView::TestCase
end