Skip to content

Commit

Permalink
Added People/Person for guests and other addressbookentries. User is …
Browse files Browse the repository at this point in the history
…inheriting from Person
  • Loading branch information
Ayonix committed Apr 11, 2013
1 parent b2b9e6e commit efd4d3e
Show file tree
Hide file tree
Showing 20 changed files with 301 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/people.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/people.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the People controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
54 changes: 54 additions & 0 deletions app/controllers/people_controller.rb
@@ -0,0 +1,54 @@
class PeopleController < ApplicationController
before_action :set_person, only: [:show, :edit, :update]
before_action :signed_in_user

# GET /users
def index
@people = Person.all
end

# GET /users/1
def show
end

# GET /users/new
def new
@person = Person.new
end

# GET /users/1/edit
def edit
end

# POST /users
def create
@person = Person.new(person_params)

if @person.save
redirect_to @person, notice: 'Person was successfully created.'
else
render action: 'new'
end
end

# PATCH/PUT /users/1
def update
if @person.update(person_params)
login @person
redirect_to @person, notice: 'User was successfully updated.'
else
render action: 'edit'
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_person
@person = Person.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def person_params
params.require(:person).permit(:firstname, :lastname, :street, :zip, :city, :email, :phone, :birthday, :misc)
end
end
2 changes: 2 additions & 0 deletions app/helpers/people_helper.rb
@@ -0,0 +1,2 @@
module PeopleHelper
end
23 changes: 23 additions & 0 deletions app/models/person.rb
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: people
#
# id :integer not null, primary key
# firstname :string(255)
# lastname :string(255)
# street :string(255)
# zip :string(255)
# city :string(255)
# email :string(255)
# phone :string(255)
# birthday :date
# misc :text
# loginname :string(255)
# remember_token :string(255)
# type :string(255)
# created_at :datetime
# updated_at :datetime
#

class Person < ActiveRecord::Base
end
8 changes: 5 additions & 3 deletions app/models/user.rb
@@ -1,9 +1,8 @@
# == Schema Information
#
# Table name: users
# Table name: people
#
# id :integer not null, primary key
# loginname :string(255)
# firstname :string(255)
# lastname :string(255)
# street :string(255)
Expand All @@ -13,12 +12,15 @@
# phone :string(255)
# birthday :date
# misc :text
# loginname :string(255)
# remember_token :string(255)
# type :string(255)
# created_at :datetime
# updated_at :datetime
#

require 'net/ldap'
class User < ActiveRecord::Base
class User < Person
has_many :tabs
before_save :create_remember_token

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.erb
Expand Up @@ -12,7 +12,7 @@
<li class="active"><a href="#">Aktiv</a></li>
<li><%= link_to 'Protokolle', minutes_path %></li>
<% if signed_in? %>
<li><%= link_to 'Adressbuch', users_path %></li>
<li><%= link_to 'Adressbuch', people_path %></li>
<li class="has-dropdown">
<% if has_group('kuehlschrank') %>
<a href="#">Kühlschrank</a>
Expand Down
36 changes: 36 additions & 0 deletions app/views/people/_form.html.erb
@@ -0,0 +1,36 @@
<%= form_for(@person) do |f| %>
<% if @person.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@person.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% @person.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :firstname %>
<%= f.text_field :firstname %><br />
<%= f.label :lastname %>
<%= f.text_field :lastname %><br />
<%= f.label :street %>
<%= f.text_field :street %><br />
<%= f.label :zip %>
<%= f.text_field :zip %><br />
<%= f.label :city %>
<%= f.text_field :city %><br />
<%= f.label :email %>
<%= f.text_field :email %><br />
<%= f.label :phone %>
<%= f.text_field :phone %><br />
<%= f.label :birthday %>
<%= f.date_field :birthday, :start_year => 1950, :end_year => Date.today.year %><br />
<%= f.label :misc %>
<%= f.text_area :misc %><br />

<div class="actions">
<%= f.submit %>
</div>
<% end %>
11 changes: 11 additions & 0 deletions app/views/people/_person.html.erb
@@ -0,0 +1,11 @@
<tr>
<td><%= person.firstname %></td>
<td><%= person.lastname %></td>
<td><%= person.street %></td>
<td><%= person.zip %></td>
<td><%= person.city %></td>
<td><%= person.email %></td>
<td><%= person.phone %></td>
<td><%= person.birthday %></td>
<td><%= person.misc %></td>
</tr>
6 changes: 6 additions & 0 deletions app/views/people/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing person</h1>

<%= render 'form' %>
<%= link_to 'Show', @person %> |
<%= link_to 'Back', persons_path %>
39 changes: 39 additions & 0 deletions app/views/people/index.html.erb
@@ -0,0 +1,39 @@
<div class="actions">
<h1 style=""><%=t '.heading' %></h1>
<a href="<%= new_person_path %>" class="button small round secondary">
<span class="icon-plus"> Neuen Eintrag Anlegen</span>
</a>
</div>

<table>
<colgroup>
<col width="24%">
<col width="24%">
<col width="24%">
<col width="24%">
<col width="2%">
<col width="2%">
</colgroup>
<thead>
<tr>
<th><%=t Person.human_attribute_name :firstname %></th>
<th><%=t Person.human_attribute_name :lastname %></th>
<th><%=t Person.human_attribute_name :email %></th>
<th><%=t Person.human_attribute_name :phone %></th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<% @people.each do |person| %>
<tr>
<td><%= person.firstname %></td>
<td><%= person.lastname %></td>
<td><%= person.email %></td>
<td><%= person.phone %></td>
<td class="center no-linebreak">
<a href="<%= person_path(person) %>"><span class="icon-info-circled">Details</span></a>
</td>
</tr>
<% end %>
</tbody>
</table>
5 changes: 5 additions & 0 deletions app/views/people/new.html.erb
@@ -0,0 +1,5 @@
<h1>New user</h1>

<%= render 'form' %>
<%= link_to 'Back', users_path %>
6 changes: 6 additions & 0 deletions app/views/people/show.html.erb
@@ -0,0 +1,6 @@
<p id="notice"><%= notice %></p>

<%= render @person %>

<br />
<%= link_to 'Back', people_path %>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -2,6 +2,7 @@
# resources :$deutschername, :as => "$englishname", :controller => "$englishname"
Fsintra::Application.routes.draw do
resources :benutzer, except: [:destroy], :as => 'users', :controller => 'users'
resources :personen, except: [:destroy], :as => 'people', :controller => 'people'
resources :rechnungen, :as => 'tabs', :controller => 'tabs' do
get 'offen' => 'tabs#unpaid', :on => :collection
put 'ist_bezahlt' => 'tabs#set_paid', :on => :member
Expand Down
20 changes: 20 additions & 0 deletions db/migrate/20130411150027_create_people.rb
@@ -0,0 +1,20 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :firstname
t.string :lastname
t.string :street
t.string :zip
t.string :city
t.string :email
t.string :phone
t.date :birthday
t.text :misc
t.string :loginname
t.string :remember_token
t.string :type

t.timestamps
end
end
end
19 changes: 18 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130410205254) do
ActiveRecord::Schema.define(version: 20130411150027) do

create_table "beverage_tabs", force: true do |t|
t.integer "beverage_id"
Expand Down Expand Up @@ -65,6 +65,23 @@
t.integer "minute_id"
end

create_table "people", force: true do |t|
t.string "firstname"
t.string "lastname"
t.string "street"
t.string "zip"
t.string "city"
t.string "email"
t.string "phone"
t.date "birthday"
t.text "misc"
t.string "loginname"
t.string "remember_token"
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "tabs", force: true do |t|
t.integer "user_id"
t.datetime "created_at"
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/people_controller_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class PeopleControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
50 changes: 50 additions & 0 deletions test/fixtures/people.yml
@@ -0,0 +1,50 @@
# == Schema Information
#
# Table name: people
#
# id :integer not null, primary key
# firstname :string(255)
# lastname :string(255)
# street :string(255)
# zip :string(255)
# city :string(255)
# email :string(255)
# phone :string(255)
# birthday :date
# misc :text
# loginname :string(255)
# remember_token :string(255)
# type :string(255)
# created_at :datetime
# updated_at :datetime
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
firstname: MyString
lastname: MyString
street: MyString
zip: MyString
city: MyString
email: MyString
phone: MyString
birthday: 2013-04-11
misc: MyText
loginname: MyString
remember_token: MyString
type:

two:
firstname: MyString
lastname: MyString
street: MyString
zip: MyString
city: MyString
email: MyString
phone: MyString
birthday: 2013-04-11
misc: MyText
loginname: MyString
remember_token: MyString
type:
4 changes: 4 additions & 0 deletions test/helpers/people_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class PeopleHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/models/person_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class PersonTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit efd4d3e

Please sign in to comment.