Skip to content

Commit

Permalink
Merged Beverages and master
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayonix committed Apr 10, 2013
2 parents b52b832 + fcbeb1a commit dc2d289
Show file tree
Hide file tree
Showing 44 changed files with 454 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ gem 'jbuilder', '~> 1.0.1'


gem 'net-ldap' gem 'net-ldap'
gem 'annotate' gem 'annotate'
gem 'haml'
gem 'haml-rails'


# To use ActiveModel has_secure_password # To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0' # gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ GEM
erubis (2.7.0) erubis (2.7.0)
execjs (1.4.0) execjs (1.4.0)
multi_json (~> 1.0) multi_json (~> 1.0)
haml (4.0.2)
tilt
haml-rails (0.4)
actionpack (>= 3.1, < 4.1)
activesupport (>= 3.1, < 4.1)
haml (>= 3.1, < 4.1)
railties (>= 3.1, < 4.1)
hike (1.2.1) hike (1.2.1)
i18n (0.6.4) i18n (0.6.4)
jbuilder (1.0.2) jbuilder (1.0.2)
Expand Down Expand Up @@ -115,6 +122,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
annotate annotate
coffee-rails (~> 4.0.0.beta1) coffee-rails (~> 4.0.0.beta1)
haml
haml-rails
jbuilder (~> 1.0.1) jbuilder (~> 1.0.1)
jquery-rails jquery-rails
net-ldap net-ldap
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/tabs.js.coffee
Original file line number Original file line Diff line number Diff line change
@@ -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/javascripts/tally_sheets.js.coffee
Original file line number Original file line Diff line number Diff line change
@@ -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/tabs.css.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Tabs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/tally_sheets.css.scss
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the TallySheets controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
58 changes: 58 additions & 0 deletions app/controllers/beverages_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,58 @@
class BeveragesController < ApplicationController
before_action :set_beverage, only: [:show, :edit, :update, :destroy]

# GET /beverages
def index
@beverages = Beverage.all
end

# GET /beverages/1
def show
end

# GET /beverages/new
def new
@beverage = Beverage.new
end

# GET /beverages/1/edit
def edit
end

# POST /beverages
def create
@beverage = Beverage.new(beverage_params)

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

# PATCH/PUT /beverages/1
def update
if @beverage.update(beverage_params)
redirect_to @beverage, notice: 'Beverage was successfully updated.'
else
render action: 'edit'
end
end

# DELETE /beverages/1
def destroy
@beverage.destroy
redirect_to beverages_url, notice: 'Beverage was successfully destroyed.'
end

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

# Never trust parameters from the scary internet, only allow the white list through.
def beverage_params
params.require(:beverage).permit(:name, :description, :available, :price)
end
end
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def new
end end


def create def create
user = User.authenticate(params[:loginname],params[:password]) user, groups = User.authenticate(params[:loginname],params[:password])
unless user.nil? unless user.nil?
login user login user
flash[:success] = "Hello #{user.firstname}!" flash[:success] = "Hello #{user.firstname}!"
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/tabs_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
class TabsController < ApplicationController
def index
end

def create
end

def show
end

def update
end

def new
@tab.beverages << Beverage.available
end

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

# Never trust parameters from the scary internet, only allow the white list through.
def tab_params
params.require(:tab)
end

end
24 changes: 24 additions & 0 deletions app/controllers/tally_sheets_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
class TallySheetsController < ApplicationController
before_action :get_users, :get_beverages
def index
end

def new
@users.each do |user|
user.tabs << Tab.new
end
end

def create
end

private
# TODO: get only the right users
def get_users
@users = User.all
end

def get_beverages
@beverages = Beverage.all.where(:available => true)
end
end
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update] before_action :set_user, only: [:show, :edit, :update]
before_filter :signed_in_user before_action :signed_in_user
before_filter :correct_user, only: [:edit,:update] before_action :correct_user, only: [:edit,:update]


# GET /users # GET /users
def index def index
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/beverages_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
module BeveragesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/tabs_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
module TabsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/tally_sheets_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
module TallySheetsHelper
end
17 changes: 17 additions & 0 deletions app/models/beverage.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: beverages
#
# id :integer not null, primary key
# name :string(255)
# description :text
# available :boolean
# price :decimal(8, 2)
# created_at :datetime
# updated_at :datetime
#

class Beverage < ActiveRecord::Base
has_many :beverage_tabs
has_many :tabs, :through => :beverage_tabs
end
2 changes: 2 additions & 0 deletions app/models/beverage_tab.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
class BeverageTab < ActiveRecord::Base
end
5 changes: 5 additions & 0 deletions app/models/tab.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
class Tab < ActiveRecord::Base
has_many :beverage_tabs
has_many :beverages, :through => :beverage_tabs
belongs_to :user
end
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


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


has_many :minutes has_many :minutes
Expand All @@ -29,9 +30,12 @@ def self.authenticate(loginname,password)
ldap = Net::LDAP.new(:host => 'ford.fachschaft.cs.uni-kl.de') ldap = Net::LDAP.new(:host => 'ford.fachschaft.cs.uni-kl.de')
ldap.auth("cn=#{loginname},ou=users,dc=fachschaft,dc=informatik,dc=uni-kl,dc=de",password) ldap.auth("cn=#{loginname},ou=users,dc=fachschaft,dc=informatik,dc=uni-kl,dc=de",password)
if ldap.bind if ldap.bind
filter = Net::LDAP::Filter.eq('memberUid', loginname)
groups = ldap.search(:base => 'dc=fachschaft,dc=informatik,dc=uni-kl,dc=de', :filter => filter, :attributes => ['cn']).flat_map(&:cn)

# create a new user if it doesn't exist yet # create a new user if it doesn't exist yet
user = User.find_or_create_by_loginname(loginname) user = User.find_or_create_by(:loginname => loginname)
return user return user, groups
else else
return nil return nil
end end
Expand Down
7 changes: 7 additions & 0 deletions app/views/beverages/_beverage.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
%div
= beverage.name
= beverage.description
= beverage.price
= beverage.available
= link_to 'Edit', edit_beverage_path(beverage)
= link_to 'Delete', beverage_path(beverage), :method => :delete
29 changes: 29 additions & 0 deletions app/views/beverages/_form.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= form_for(@beverage) do |f| %>
<% if @beverage.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@beverage.errors.count, "error") %> prohibited this beverage from being saved:</h2>

<ul>
<% @beverage.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="actions">
<%= f.label :name %>
<%= f.text_field :name %><br />

<%= f.label :description %>
<%= f.text_area :description %><br />

<%= f.label :price %>
<%= f.text_field :price %><br />

<%= f.label :available %>
<%= f.check_box :available %><br />

<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/beverages/edit.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing beverage</h1>

<%= render 'form' %>
<%= link_to 'Show', @beverage %> |
<%= link_to 'Back', beverages_path %>
7 changes: 7 additions & 0 deletions app/views/beverages/index.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Listing beverages</h1>

<%= render @beverages %>

<br />

<%= link_to 'New Beverage', new_beverage_path %>
5 changes: 5 additions & 0 deletions app/views/beverages/new.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New beverage</h1>

<%= render 'form' %>
<%= link_to 'Back', beverages_path %>
5 changes: 5 additions & 0 deletions app/views/beverages/show.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>


<%= link_to 'Edit', edit_beverage_path(@beverage) %> |
<%= link_to 'Back', beverages_path %>
7 changes: 7 additions & 0 deletions app/views/tally_sheets/new.html.haml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
%div
- @users.each do |user|
= form_for [user,tab=user.tabs.build] do |f|
- @beverages.each do |beverage|
= f.fields_for [beverage, tab.beverage_tabs.build] do |b|
= b.text_field :count
= f.submit
2 changes: 1 addition & 1 deletion app/views/users/_form.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= f.label :phone %> <%= f.label :phone %>
<%= f.text_field :phone %><br /> <%= f.text_field :phone %><br />
<%= f.label :birthday %> <%= f.label :birthday %>
<%= f.date_select :birthday, :start_year => 1950, :end_year => Date.today.year %><br /> <%= f.date_field :birthday, :start_year => 1950, :end_year => Date.today.year %><br />
<%= f.label :misc %> <%= f.label :misc %>
<%= f.text_area :misc %><br /> <%= f.text_area :misc %><br />


Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# resources :$deutschername, :as => "$englishname", :controller => "$englishname" # resources :$deutschername, :as => "$englishname", :controller => "$englishname"
Fsintra::Application.routes.draw do Fsintra::Application.routes.draw do
resources :benutzer, except: [:destroy], :as => 'users', :controller => 'users' resources :benutzer, except: [:destroy], :as => 'users', :controller => 'users'
resources :getraenke, :as => 'beverages', :controller => 'beverages'
resources :sessions, only: [:new, :create, :destroy] resources :sessions, only: [:new, :create, :destroy]
get '/login' => 'sessions#new' get '/login' => 'sessions#new'
delete '/logout' => 'sessions#destroy' delete '/logout' => 'sessions#destroy'
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20130408135606_create_beverages.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBeverages < ActiveRecord::Migration
def change
create_table :beverages do |t|
t.string :name
t.text :description
t.boolean :available
t.decimal :price, :precision => 8, :scale => 2

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20130408152025_create_tabs.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateTabs < ActiveRecord::Migration
def change
create_table :tabs do |t|
t.integer :user_id

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20130408152108_create_beverage_tabs.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBeverageTabs < ActiveRecord::Migration
def change
create_table :beverage_tabs do |t|
t.integer :beverage_id
t.integer :tab_id
t.integer :count
t.decimal :price, :precision => 8, :scale => 2

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20130408153509_create_user_tabs_join_table.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateUserTabsJoinTable < ActiveRecord::Migration
def change
create_table :user_tabs, :id => false do |t|
t.integer :user_id
t.integer :tab_id
end
add_index :user_tabs, [:user_id, :tab_id], :unique => true
end
end
Loading

0 comments on commit dc2d289

Please sign in to comment.