Permalink
Browse files

Merged Beverages and master

  • Loading branch information...
2 parents b52b832 + fcbeb1a commit dc2d28930ac2c2dca8b7f999990d5c8171ff6382 Ayonix committed Apr 10, 2013
Showing with 454 additions and 6 deletions.
  1. +2 −0 Gemfile
  2. +9 −0 Gemfile.lock
  3. +3 −0 app/assets/javascripts/tabs.js.coffee
  4. +3 −0 app/assets/javascripts/tally_sheets.js.coffee
  5. +3 −0 app/assets/stylesheets/tabs.css.scss
  6. +3 −0 app/assets/stylesheets/tally_sheets.css.scss
  7. +58 −0 app/controllers/beverages_controller.rb
  8. +1 −1 app/controllers/sessions_controller.rb
  9. +29 −0 app/controllers/tabs_controller.rb
  10. +24 −0 app/controllers/tally_sheets_controller.rb
  11. +2 −2 app/controllers/users_controller.rb
  12. +2 −0 app/helpers/beverages_helper.rb
  13. +2 −0 app/helpers/tabs_helper.rb
  14. +2 −0 app/helpers/tally_sheets_helper.rb
  15. +17 −0 app/models/beverage.rb
  16. +2 −0 app/models/beverage_tab.rb
  17. +5 −0 app/models/tab.rb
  18. +6 −2 app/models/user.rb
  19. +7 −0 app/views/beverages/_beverage.html.haml
  20. +29 −0 app/views/beverages/_form.html.erb
  21. +6 −0 app/views/beverages/edit.html.erb
  22. +7 −0 app/views/beverages/index.html.erb
  23. +5 −0 app/views/beverages/new.html.erb
  24. +5 −0 app/views/beverages/show.html.erb
  25. +7 −0 app/views/tally_sheets/new.html.haml
  26. +1 −1 app/views/users/_form.html.erb
  27. +1 −0 config/routes.rb
  28. +12 −0 db/migrate/20130408135606_create_beverages.rb
  29. +9 −0 db/migrate/20130408152025_create_tabs.rb
  30. +12 −0 db/migrate/20130408152108_create_beverage_tabs.rb
  31. +9 −0 db/migrate/20130408153509_create_user_tabs_join_table.rb
  32. +29 −0 db/schema.rb
  33. +49 −0 test/controllers/beverages_controller_test.rb
  34. +7 −0 test/controllers/tabs_controller_test.rb
  35. +7 −0 test/controllers/tally_sheets_controller_test.rb
  36. +13 −0 test/fixtures/beverage_tabs.yml
  37. +26 −0 test/fixtures/beverages.yml
  38. +7 −0 test/fixtures/tabs.yml
  39. +4 −0 test/helpers/beverages_helper_test.rb
  40. +4 −0 test/helpers/tabs_helper_test.rb
  41. +4 −0 test/helpers/tally_sheets_helper_test.rb
  42. +7 −0 test/models/beverage_tab_test.rb
  43. +7 −0 test/models/beverage_test.rb
  44. +7 −0 test/models/tab_test.rb
View
@@ -29,6 +29,8 @@ gem 'jbuilder', '~> 1.0.1'
gem 'net-ldap'
gem 'annotate'
+gem 'haml'
+gem 'haml-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
@@ -40,6 +40,13 @@ GEM
erubis (2.7.0)
execjs (1.4.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)
i18n (0.6.4)
jbuilder (1.0.2)
@@ -115,6 +122,8 @@ PLATFORMS
DEPENDENCIES
annotate
coffee-rails (~> 4.0.0.beta1)
+ haml
+ haml-rails
jbuilder (~> 1.0.1)
jquery-rails
net-ldap
@@ -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/
@@ -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/
@@ -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/
@@ -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/
@@ -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
@@ -3,7 +3,7 @@ def new
end
def create
- user = User.authenticate(params[:loginname],params[:password])
+ user, groups = User.authenticate(params[:loginname],params[:password])
unless user.nil?
login user
flash[:success] = "Hello #{user.firstname}!"
@@ -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
@@ -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
@@ -1,7 +1,7 @@
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update]
- before_filter :signed_in_user
- before_filter :correct_user, only: [:edit,:update]
+ before_action :signed_in_user
+ before_action :correct_user, only: [:edit,:update]
# GET /users
def index
@@ -0,0 +1,2 @@
+module BeveragesHelper
+end
@@ -0,0 +1,2 @@
+module TabsHelper
+end
@@ -0,0 +1,2 @@
+module TallySheetsHelper
+end
View
@@ -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
@@ -0,0 +1,2 @@
+class BeverageTab < ActiveRecord::Base
+end
View
@@ -0,0 +1,5 @@
+class Tab < ActiveRecord::Base
+ has_many :beverage_tabs
+ has_many :beverages, :through => :beverage_tabs
+ belongs_to :user
+end
View
@@ -20,6 +20,7 @@
require 'net/ldap'
class User < ActiveRecord::Base
+ has_many :tabs
before_save :create_remember_token
has_many :minutes
@@ -29,9 +30,12 @@ def self.authenticate(loginname,password)
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)
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
- user = User.find_or_create_by_loginname(loginname)
- return user
+ user = User.find_or_create_by(:loginname => loginname)
+ return user, groups
else
return nil
end
@@ -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
@@ -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 %>
@@ -0,0 +1,6 @@
+<h1>Editing beverage</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @beverage %> |
+<%= link_to 'Back', beverages_path %>
@@ -0,0 +1,7 @@
+<h1>Listing beverages</h1>
+
+<%= render @beverages %>
+
+<br />
+
+<%= link_to 'New Beverage', new_beverage_path %>
@@ -0,0 +1,5 @@
+<h1>New beverage</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', beverages_path %>
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_beverage_path(@beverage) %> |
+<%= link_to 'Back', beverages_path %>
@@ -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
@@ -26,7 +26,7 @@
<%= f.label :phone %>
<%= f.text_field :phone %><br />
<%= 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.text_area :misc %><br />
View
@@ -2,6 +2,7 @@
# resources :$deutschername, :as => "$englishname", :controller => "$englishname"
Fsintra::Application.routes.draw do
resources :benutzer, except: [:destroy], :as => 'users', :controller => 'users'
+ resources :getraenke, :as => 'beverages', :controller => 'beverages'
resources :sessions, only: [:new, :create, :destroy]
get '/login' => 'sessions#new'
delete '/logout' => 'sessions#destroy'
@@ -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
@@ -0,0 +1,9 @@
+class CreateTabs < ActiveRecord::Migration
+ def change
+ create_table :tabs do |t|
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+end
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit dc2d289

Please sign in to comment.