Change erb to haml

This commit is contained in:
benji 2015-09-17 14:05:33 +02:00
parent 5e666d8cb8
commit ef75909298
75 changed files with 443 additions and 711 deletions

28
Gemfile
View file

@ -4,22 +4,18 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2'
# Use SCSS for stylesheets
# Assets
gem 'sass-rails', '~> 4.0.3'
gem 'bootstrap-sass', '3.2.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
# Haml for templating!
gem "haml-rails", "~> 0.9"
# Responders
gem 'responders', '~> 2.0'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
@ -35,12 +31,9 @@ group :production do
end
group :test do
gem 'capybara'
gem 'launchy'
gem 'codeclimate-test-reporter', require: nil
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'faker', '1.4.2'
gem 'coveralls', require: false
end
group :development do
@ -61,6 +54,8 @@ group :development do
end
group :development, :test do
gem 'factory_girl_rails'
gem 'faker', '1.4.2'
gem 'pry-rails'
gem 'pry-byebug'
end
@ -88,18 +83,9 @@ gem 'cancancan'
# Safety first
gem 'paper_trail', '~> 4.0.0.beta'
# Windoos sux
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
# Coveralls
gem 'coveralls', require: false
# Default avatar for users
gem 'identicon'
# Slack
gem 'tarumi'
# Run stuff in the background
gem 'daemons'
gem 'delayed_job', '~> 4.0'

View file

@ -36,7 +36,6 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.7)
airbrake (4.1.0)
builder
multi_json
@ -76,12 +75,6 @@ GEM
capistrano (~> 3.0)
sshkit (~> 1.2)
capistrano-stats (1.1.1)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
chunky_png (1.3.4)
climate_control (0.0.3)
activesupport (>= 3.0)
@ -135,8 +128,21 @@ GEM
ffi (1.9.6-x64-mingw32)
globalid (0.3.2)
activesupport (>= 4.1.0)
haml (4.0.7)
tilt
haml-rails (0.9.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
hashie (3.4.0)
hike (1.2.3)
html2haml (2.0.0)
erubis (~> 2.7.0)
haml (~> 4.0.0)
nokogiri (~> 1.6.0)
ruby_parser (~> 3.5)
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
@ -152,8 +158,6 @@ GEM
thor (>= 0.14, < 2.0)
json (1.8.2)
jwt (1.4.1)
launchy (2.4.3)
addressable (~> 2.3)
loofah (2.0.1)
nokogiri (>= 1.5.9)
mail (2.6.3)
@ -267,6 +271,8 @@ GEM
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
ruby_parser (3.7.1)
sexp_processor (~> 4.1)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
@ -276,6 +282,7 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sexp_processor (4.6.0)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
@ -298,9 +305,6 @@ GEM
colorize (>= 0.7.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
tarumi (0.0.1)
activesupport
httparty
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
@ -311,8 +315,6 @@ GEM
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2015.1)
tzinfo (>= 1.0.0)
uglifier (2.7.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
@ -320,8 +322,6 @@ GEM
rack (>= 1.0)
will_paginate (3.0.7)
win32console (1.3.2)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
@ -339,7 +339,6 @@ DEPENDENCIES
capistrano-rails (~> 1.1)
capistrano-rbenv
capistrano-rvm
capybara
codeclimate-test-reporter
coffee-rails (~> 4.0.0)
coveralls
@ -349,11 +348,11 @@ DEPENDENCIES
devise
factory_girl_rails
faker (= 1.4.2)
haml-rails (~> 0.9)
httparty
identicon
jbuilder (~> 2.0)
jquery-rails
launchy
mysql2
omniauth-oauth2
paper_trail (~> 4.0.0.beta)
@ -367,9 +366,7 @@ DEPENDENCIES
sdoc (~> 0.4.0)
spring
sqlite3
tarumi
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
will_paginate (= 3.0.7)

View file

@ -22,9 +22,9 @@ class Order < ActiveRecord::Base
after_create :create_api_job
validates :user, presence: true
validates :order_items, presence: true
validates :price_cents, presence: true
validates_associated :order_items
validate :product_presence
accepts_nested_attributes_for :order_items
@ -49,4 +49,8 @@ class Order < ActiveRecord::Base
Delayed::Job.enqueue job, priority: priority, run_at: run_at
end
def product_presence
errors.add(:base, "You have to order at least one product.") if order_items.map(&:count).sum.zero?
end
end

View file

@ -1,14 +0,0 @@
<% if object.errors.any? %>
<div class="panel panel-danger form-errors">
<div class="panel-heading">
<%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.name.downcase %> from being saved:
</div>
<div class="panel-body">
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
</div>
<% end %>

View file

@ -0,0 +1,9 @@
- if object.errors.any?
.panel.panel-danger.form-errors
.panel-heading
= pluralize(object.errors.count, "error")
prohibited this #{object.class.name.downcase} from being saved:
.panel-body
%ul
- object.errors.full_messages.each do |msg|
%li= msg

View file

@ -1,32 +0,0 @@
<div id="flash">
<% if flash[:error] %>
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Error!</strong> <%= flash[:error] %>
</div>
<% end %>
<% if flash[:success] %>
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Success!</strong> <%= raw flash[:success] %>
</div>
<% end %>
<% if flash[:notice] %>
<div class="alert alert-info alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Notice!</strong> <%= flash[:notice] %>
</div>
<% end %>
<% if flash[:warning] %>
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Warning!</strong> <%= flash[:warning] %>
</div>
<% end %>
<% if flash[:alert] %>
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Error!</strong> <%= flash[:alert] %>
</div>
<% end %>
</div>

View file

@ -0,0 +1,26 @@
#flash
- if flash[:error]
.alert.alert-danger.alert-dismissable
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
%strong Error!
= flash[:error]
- if flash[:success]
.alert.alert-success.alert-dismissable
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
%strong Success!
= raw flash[:success]
- if flash[:notice]
.alert.alert-info.alert-dismissable
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
%strong Notice!
= flash[:notice]
- if flash[:warning]
.alert.alert-warning.alert-dismissable
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
%strong Warning!
= flash[:warning]
- if flash[:alert]
.alert.alert-danger.alert-dismissable
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} ×
%strong Error!
= flash[:alert]

View file

@ -1,17 +0,0 @@
<h2>Sign in</h2>
<%= render partial: 'flash' %>
<div class="sign-in">
<%= f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.text_field :name %>
<%= f.password_field :password %>
<% if devise_mapping.rememberable? %>
<%= f.check_box :remember_me %>
<% end %>
<%= f.submit "Sign in" %>
<% end %>
</div>
<%= render "devise/shared/links" %>

View file

@ -0,0 +1,10 @@
%h2 Sign in
= render partial: 'flash'
.sign-in
= f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
= f.text_field :name
= f.password_field :password
- if devise_mapping.rememberable?
= f.check_box :remember_me
= f.submit "Sign in"
= render "devise/shared/links"

View file

@ -1,21 +0,0 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), class: "btn btn-large btn-primary" %><br />
<% end -%>
<% end -%>

View file

@ -0,0 +1,16 @@
- unless controller_name == 'sessions'
= link_to "Log in", new_session_path(resource_name)
%br/
- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
= link_to "Forgot your password?", new_password_path(resource_name)
%br/
- if devise_mapping.confirmable? && controller_name != 'confirmations'
= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
%br/
- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
%br/
- if devise_mapping.omniauthable?
- resource_class.omniauth_providers.each do |provider|
= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), class: "btn btn-large btn-primary"
%br/

View file

@ -1,14 +0,0 @@
<% unless current_user && current_user.koelkast? %>
<footer class="footer">
<small>
<%= link_to "Tab", root_path %></a>
by <%= link_to "Zeus WPI", "//zeus.ugent.be" %>
</small>
<nav>
<ul>
<li><%= mail_to "bestuur@zeus.ugent.be", "Contact" %></li>
<li><%= link_to "Zeus WPI", "//zeus.ugent.be" %></li>
</ul>
</nav>
</footer>
<% end %>

View file

@ -0,0 +1,9 @@
- unless current_user && current_user.koelkast?
%footer.footer
%small
= link_to "Tab", root_path
by #{link_to "Zeus WPI", "//zeus.ugent.be"}
%nav
%ul
%li= mail_to "bestuur@zeus.ugent.be", "Contact"
%li= link_to "Zeus WPI", "//zeus.ugent.be"

View file

@ -1,75 +0,0 @@
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to "Tap", root_path, class: "navbar-brand nav-logo" %>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<% unless current_user && current_user.koelkast? %>
<div class="collapse navbar-collapse">
<div class="hidden-xs navbar-form navbar-right">
<div class="form-group">
<% if user_signed_in? %>
<%= link_to "Logout", destroy_user_session_path, class: "btn btn-default form-control" %>
<% elsif session[:id] %>
<%= button_to "Logout", user_avatar_path(session[:id]), class: "btn btn-default form-control", method: :delete %>
<% else %>
<%= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" %>
<% end %>
</div>
</div>
<ul class="nav navbar-nav navbar-right">
<li><%= mail_to "tab@zeus.ugent.be", "Send feedback" %></li>
<% if user_signed_in? %>
<% if can? :manage, :all %>
<li>
<%= link_to "Place order", orders_path %>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Products <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><%= link_to "List", products_path %></li>
<li><%= link_to "Add product" , new_product_path %></li>
<li><%= link_to "Add stock", new_stock_path %></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Users <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><%= link_to "List" , users_path %></li>
</ul>
</li>
<% end %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Logged in as <%= current_user.name %> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><%= link_to "Edit avatar", edit_user_path(current_user) %></li>
</ul>
</li>
<li>
<p class="navbar-text">Debt: <%= euro(current_user.debt) %></p>
</li>
<% end %>
</ul>
<div class="visible-xs navbar-form">
<div class="form-group">
<% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete %>
<% else %>
<%= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" %>
<% end %>
</div>
</div>
<% end %>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

View file

@ -0,0 +1,53 @@
%nav.navbar.navbar-inverse.navbar-fixed-top{role: "navigation"}
.container-fluid
/ Brand and toggle get grouped for better mobile display
.navbar-header
%button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse", type: "button"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
= link_to "Tap", root_path, class: "navbar-brand nav-logo"
/ Collect the nav links, forms, and other content for toggling
- unless current_user && current_user.koelkast?
.collapse.navbar-collapse
.hidden-xs.navbar-form.navbar-right
.form-group
- if user_signed_in?
= link_to "Logout", destroy_user_session_path, class: "btn btn-default form-control"
- else
= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control"
%ul.nav.navbar-nav.navbar-right
%li= mail_to "tab@zeus.ugent.be", "Send feedback"
- if user_signed_in?
- if can? :manage, :all
%li
= link_to "Place order", orders_path
%li.dropdown
%a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", href: "#", role: "button"}
Products
%span.caret
%ul.dropdown-menu{role: "menu"}
%li= link_to "List", products_path
%li= link_to "Add product" , new_product_path
%li= link_to "Add stock", new_stock_path
%li.dropdown
%a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", href: "#", role: "button"}
Users
%span.caret
%ul.dropdown-menu{role: "menu"}
%li= link_to "List" , users_path
%li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"}
Logged in as #{current_user.name}
%b.caret
%ul.dropdown-menu
%li= link_to "Edit avatar", edit_user_path(current_user)
%li
%p.navbar-text
Debt: #{euro(current_user.debt)}
.visible-xs.navbar-form
.form-group
- if user_signed_in?
= button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete
- else
= link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control"

View file

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Tap - Zeus WPIs drink ordering system</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<% if current_user && current_user.koelkast? && !Rails.env.development? %>
<body oncontextmenu="return false">
<% else %>
<body>
<% end %>
<%= render 'layouts/header' %>
<div class="container">
<div class="container">
<%= yield %>
</div>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>

View file

@ -0,0 +1,14 @@
!!!
%html
%head
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title Tap - Zeus WPIs drink ordering system
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
%body
= render 'layouts/header'
.container
= yield
= render 'layouts/footer'
= debug(params) if Rails.env.development?

View file

@ -1,21 +0,0 @@
<div class="col-md-3 form_products">
<div class="thumbnail<%= ' out-of-stock' if product.stock.zero? %>">
<div class="form_row center">
<div class="form_row_image">
<%= image_tag product.avatar %>
</div>
<div class="caption">
<h6>
<%= kcal_tag product.calories %>
</h6>
<h4 class="text-nowrap">
<%= content_tag :span, product.name %>
<%= content_tag :small, euro(product.price) %>
</h4>
<%= f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter", data: { price: f.object.product.price_cents } %>
<%= f.fields_for :product do |product| %>
<% end %>
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,14 @@
.col-md-3.form_products
%div{class: "thumbnail#{' out-of-stock' if product.stock.zero?}"}
.form_row.center
.form_row_image
= image_tag product.avatar
.caption
%h6
= kcal_tag product.calories
%h4.text-nowrap
= content_tag :span, product.name
= content_tag :small, euro(product.price)
= f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter", data: { price: f.object.product.price_cents }
= f.fields_for :product do |product|
/ This is needed for haml

View file

@ -1,13 +0,0 @@
<tr>
<td class="order_date">
<%= order.created_at.strftime("%d %b %Y at %H:%M") %>
</td>
</tr>
<tr>
<td>
<%= order.to_sentence %>
</td>
<td>
<%= euro_from_cents(order.price_cents) %>
</td>
</tr>

View file

@ -0,0 +1,8 @@
%tr
%td.order_date
= order.created_at.strftime("%d %b %Y at %H:%M")
%tr
%td
= order.to_sentence
%td
= euro_from_cents(order.price_cents)

View file

@ -1,10 +0,0 @@
<div class="col-md-3 form_total">
<strong>Total price</strong>
<div class="input-group">
<span class="input-group-addon">&euro;</span>
<%= content_tag :span, "", id: "order_price", class: "input-group-addon" %>
<span class="input-group-btn">
<%= f.submit "Order!", class: "btn btn-primary big-form-button", skip_wrapper: true %>
</span>
</div>
</div>

View file

@ -0,0 +1,7 @@
.col-md-3.form_total
%strong Total price
.input-group
%span.input-group-addon €
= content_tag :span, "", id: "order_price", class: "input-group-addon"
%span.input-group-btn
= f.submit "Order!", class: "btn btn-primary big-form-button", skip_wrapper: true

View file

@ -1,15 +0,0 @@
<h3>Order for <%= @user.name %> (Huidige schuld: <%= euro(@user.debt) %>)</h3>
<div class="row">
<%= f_form_for [@user, @order] do |f| %>
<%= f.error_messages %>
<div class="col-md-12">
<%= f.fields_for :order_items do |op_field| %>
<%= render op_field.object, f: op_field, product: op_field.object.product %>
<% end %>
</div>
<%= render 'orders/price', f: f %>
<% end %>
</div>

View file

@ -0,0 +1,9 @@
%h3
Order for #{@user.name} (Huidige schuld: #{euro(@user.debt)})
.row
= f_form_for [@user, @order] do |f|
= f.error_messages
.col-md-12
= f.fields_for :order_items do |op_field|
= render op_field.object, f: op_field, product: op_field.object.product
= render 'orders/price', f: f

View file

@ -1,7 +0,0 @@
<%= render partial: 'flash' %>
<div class="row">
<% @users.each do |user| %>
<%= render 'users/new_order', user: user %>
<% end %>
</div>

View file

@ -0,0 +1,4 @@
= render partial: 'flash'
.row
- @users.each do |user|
= render 'users/new_order', user: user

View file

@ -1,16 +0,0 @@
<div class="row">
<div class="col-md-6 col-md-offset-3 sign-in">
<%= f_form_for @product, html: { multipart: true } do |f| %>
<%= f.error_messages %>
<%= f.text_field :name %>
<%= f.price_field :price %>
<%= f.collection_select :category, Product.categories.keys %>
<%= f.number_field :stock %>
<%= f.number_field :calories %>
<%= f.file_field :avatar %>
<%= f.submit %>
<% end %>
</div>
</div>

View file

@ -0,0 +1,11 @@
.row
.col-md-6.col-md-offset-3.sign-in
= f_form_for @product, html: { multipart: true } do |f|
= f.error_messages
= f.text_field :name
= f.price_field :price
= f.collection_select :category, Product.categories.keys
= f.number_field :stock
= f.number_field :calories
= f.file_field :avatar
= f.submit

View file

@ -1,22 +0,0 @@
<div role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#all" role="tab" data-toggle="tab">All</a></li>
<% @categories.each do |o, i| %>
<li role="presentation"><a href="#<%= o %>" aria-controls="<%= o %>" role="tab" data-toggle="tab"><%= o.titleize %></a></li>
<% end %>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<br />
<div role="tabpanel" class="tab-pane active" id="all">
<%= render @products %>
</div>
<% @categories.each do |o, i| %>
<div role="tabpanel" class="tab-pane" id="<%= o %>">
<%= render @products.where(category: i) %>
</div>
<% end %>
</div>
</div>

View file

@ -0,0 +1,16 @@
%div{role: "tabpanel"}
/ Nav tabs
%ul.nav.nav-tabs{role: "tablist"}
%li.active{role: "presentation"}
%a{"data-toggle" => "tab", href: "#all", role: "tab"} All
- @categories.each do |o, i|
%li{role: "presentation"}
%a{"aria-controls" => o, "data-toggle" => "tab", href: "##{o}", role: "tab"}= o.titleize
/ Tab panes
.tab-content
%br/
#all.tab-pane.active{role: "tabpanel"}
= render @products
- @categories.each do |o, i|
.tab-pane{id: o, role: "tabpanel"}
= render @products.where(category: i)

View file

@ -1,14 +0,0 @@
<%- if controller_name == 'products' && current_user && current_user.admin? %>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
<% end -%>
<%- if controller_name == 'users' %>
<div class="product_dagschotel">
<% if current_user.dagschotel != product %>
<%= link_to "Make dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-default" %>
<% else %>
<%= link_to "Huidige dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-success", disabled: true %>
<% end %>
</div>
<% end -%>

View file

@ -0,0 +1,9 @@
- if controller_name == 'products' && current_user && current_user.admin?
= link_to "Edit", edit_product_path(product), class: "btn btn-default"
= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'}
- if controller_name == 'users'
.product_dagschotel
- if current_user.dagschotel != product
= link_to "Make dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-default"
- else
= link_to "Huidige dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-success", disabled: true

View file

@ -1,14 +0,0 @@
<div class="col-md-3">
<div class="thumbnail pic">
<div class="form_row_image">
<%= image_tag product.avatar %>
</div>
<div class="caption">
<%= kcal_tag product.calories %>
<h4><%= product.name %></h4>
<h3><%= euro(product.price) %></h3>
<h6>(In stock: <%= product.stock %>)</h6>
<%= render 'products/links', product: product %>
</div>
</div>
</div>

View file

@ -0,0 +1,11 @@
.col-md-3
.thumbnail.pic
.form_row_image
= image_tag product.avatar
.caption
= kcal_tag product.calories
%h4= product.name
%h3= euro(product.price)
%h6
(In stock: #{product.stock})
= render 'products/links', product: product

View file

@ -1,2 +0,0 @@
<h1>Update product</h1>
<%= render "form" %>

View file

@ -0,0 +1,2 @@
%h1 Update product
= render "form"

View file

@ -1 +0,0 @@
$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render "products_list/product_edit_row", product: @product %>")

View file

@ -0,0 +1 @@
$("#products_row_#{dom_id(@product)}").replaceWith("#{j render "products_list/product_edit_row", product: @product}")

View file

@ -1,3 +0,0 @@
<h1>All products</h1>
<%= render partial: 'flash' %>
<%= render 'products/index' %>

View file

@ -0,0 +1,3 @@
%h1 All products
= render partial: 'flash'
= render 'products/index'

View file

@ -1,2 +0,0 @@
<h1>New product</h1>
<%= render "form" %>

View file

@ -0,0 +1,2 @@
%h1 New product
= render "form"

View file

@ -1,6 +0,0 @@
<% if @product.errors.any? %>
$('#products-errors').html("<%= j render 'errors', object: @product %>")
<% else %>
$('#products-errors').html('')
$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>");
<% end %>

View file

@ -0,0 +1,5 @@
- if @product.errors.any?
$('#products-errors').html("#{j render 'errors', object: @product}")
- else
$('#products-errors').html('')
$("#products_row_#{dom_id(@product)}").replaceWith("#{j render 'products_list/product_row', product: @product}");

View file

@ -1,22 +0,0 @@
<tr id="products_row_<%= dom_id(product) %>">
<%= f_form_for product, remote: true do |f| %>
<td><%= image_tag product.avatar(:small) %></td>
<td><%= f.text_field :name, skip_label: true %></td>
<td><%= f.price_field :price, skip_label: true %></td>
<td><%= f.number_field :stock, skip_label: true %></td>
<td><%= f.check_box :deleted, skip_label: true %></td>
<td><%= f.number_field :calories, skip_label: true %></td>
<td><%= f.button "Update", class: "btn btn-primary" %></td>
<%= javascript_tag do %>
var id = "#edit_<%= dom_id(product) %>";
var inputs = $(id).parent().find('input');
$(id).parent().find('button').on('click', function(e) {
e.preventDefault();
$(id).append(inputs.clone());
$(id).append('<input type="hidden" name="_method" value="patch">');
$(id).submit();
});
<% end %>
<% end %>
</tr>

View file

@ -0,0 +1,21 @@
%tr{:id => "products_row_#{dom_id(product)}"}
= f_form_for product, remote: true do |f|
%td= image_tag product.avatar(:small)
%td= f.text_field :name, skip_label: true
%td= f.price_field :price, skip_label: true
%td= f.number_field :stock, skip_label: true
%td= f.check_box :deleted, skip_label: true
%td= f.number_field :calories, skip_label: true
%td= f.button "Update", class: "btn btn-primary"
= javascript_tag do
var id = "#edit_#{dom_id(product)}";
var inputs = $(id).parent().find('input');
$(id).parent().find('button').on('click', function(e) {
e.preventDefault();
$(id).append(inputs.clone());
$(id).append('
%input{:name => "_method", :type => "hidden", :value => "patch"}>/
');
$(id).submit();
});

View file

@ -1,9 +0,0 @@
<tr id="products_row_<%= dom_id(product) %>">
<td><%= image_tag product.avatar(:small) %></td>
<td><%= product.name %></td>
<td><%= euro(product.price) %></td>
<td><%= product.stock %></td>
<td><span class="glyphicon <%= product.deleted ? "glyphicon-check" : "glyphicon-unchecked" %>"></span></td>
<td><%= product.calories %></td>
<td><%= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true %></td>
</tr>

View file

@ -0,0 +1,9 @@
%tr{:id => "products_row_#{dom_id(product)}"}
%td= image_tag product.avatar(:small)
%td= product.name
%td= euro(product.price)
%td= product.stock
%td
%span{:class => "glyphicon #{product.deleted ? "glyphicon-check" : "glyphicon-unchecked"}"}
%td= product.calories
%td= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true

View file

@ -1,21 +0,0 @@
<div id="products-errors"></div>
<div class="row products">
<div class="col-md-8 col-md-offset-2">
<h1>Products</h1>
<%= render partial: 'flash' %>
<%= link_to "Add Stock", new_stock_path, class: "btn btn-default" %>
<table id="products-table" class="table table-striped">
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
<th>Deleted</th>
<th>Kilocalorieën</th>
<th></th>
</tr>
<%= render partial: 'products_list/product_row', collection: @products, as: :product %>
</table>
</div>
</div>

View file

@ -0,0 +1,16 @@
#products-errors
.row.products
.col-md-8.col-md-offset-2
%h1 Products
= render partial: 'flash'
= link_to "Add Stock", new_stock_path, class: "btn btn-default"
%table#products-table.table.table-striped
%tr
%th
%th Name
%th Price
%th Stock
%th Deleted
%th Kilocalorieën
%th
= render partial: 'products_list/product_row', collection: @products, as: :product

View file

@ -1,13 +0,0 @@
<% unless @stock.valid? %>
<div class="panel panel-danger form-errors">
<div class="panel-heading">
<%= "#{pluralize(@stock.errors.count + @stock.stock_entries.map(&:errors).map(&:count).sum, "error")} prohibited this stock from being saved:" %>
</div>
<div class="panel-body">
<ul>
<%= @stock.errors.full_messages.map{ |m| content_tag(:li, m) }.join.html_safe %>
<%= @stock.stock_entries.map{ |se| se.errors.full_messages.map{ |e| "#{se.product.name}: #{e}" } }.flatten.map{ |m| content_tag(:li, m) }.join.html_safe %>
</ul>
</div>
</div>
<% end %>

View file

@ -0,0 +1,8 @@
- unless @stock.valid?
.panel.panel-danger.form-errors
.panel-heading
= "#{pluralize(@stock.errors.count + @stock.stock_entries.map(&:errors).map(&:count).sum, "error")} prohibited this stock from being saved:"
.panel-body
%ul
= @stock.errors.full_messages.map{ |m| content_tag(:li, m) }.join.html_safe
= @stock.stock_entries.map{ |se| se.errors.full_messages.map{ |e| "#{se.product.name}: #{e}" } }.flatten.map{ |m| content_tag(:li, m) }.join.html_safe

View file

@ -1,20 +0,0 @@
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>Add stock</h2>
<%= f_form_for @stock do |f| %>
<%= render 'stocks/errors' %>
<%= f.fields_for :stock_entries do |se_field| %>
<div class="row">
<div class="col-sm-3">
<%= image_tag se_field.object.product.avatar %>
</div>
<div class="col-sm-9">
<%= se_field.hidden_field :product_id %>
<%= se_field.number_field :count, skip_label: true %>
</div>
</div>
<% end %>
<%= f.submit "Insert stock", class: 'btn btn-primary' %>
<% end %>
</div>
</div>

View file

@ -0,0 +1,13 @@
.row
.col-md-6.col-md-offset-3
%h2 Add stock
= f_form_for @stock do |f|
= render 'stocks/errors'
= f.fields_for :stock_entries do |se_field|
.row
.col-sm-3
= image_tag se_field.object.product.avatar
.col-sm-9
= se_field.hidden_field :product_id
= se_field.number_field :count, skip_label: true
= f.submit "Insert stock", class: 'btn btn-primary'

View file

@ -1,10 +0,0 @@
<div class="col-md-2 overviewthumbnail">
<% unless user.dagschotel.nil? %>
<%= link_to quickpay_user_path(user) do %>
<%= image_tag user.dagschotel.avatar(:dagschotel), class: "img-circle dagschotel" %>
<% end %>
<% end %>
<%= link_to image_tag(user.avatar(:large) , class: "img-circle avatar"), new_user_order_path(user) %>
<%= link_to user.name , new_user_order_path(user), class: "btn btn-info", style: get_color_style(user) %>
</div>

View file

@ -0,0 +1,6 @@
.col-md-2.overviewthumbnail
- unless user.dagschotel.nil?
= link_to quickpay_user_path(user) do
= image_tag user.dagschotel.avatar(:dagschotel), class: "img-circle dagschotel"
= link_to image_tag(user.avatar(:large) , class: "img-circle avatar"), new_user_order_path(user)
= link_to user.name , new_user_order_path(user), class: "btn btn-info", style: get_color_style(user)

View file

@ -1,32 +0,0 @@
<div class="col-sm-3">
<div>
<h2>
<%= @user.name %>
<% if can? :edit, @user %>
<%= link_to content_tag(:small, content_tag(:span, "", class: "glyphicon glyphicon-cog")), edit_user_path(@user) %>
<% end %>
</h2>
</div>
<%= content_tag :div, image_tag(@user.avatar, class: "img-circle img-thumbnail center"), class: "user_avatar center" %>
<ul class="list-group">
<li class="list-group-item text-muted">Orders</li>
<li class="list-group-item"><strong>Orders placed</strong><span class="badge"><%= @user.orders_count %></span></li>
<li class="list-group-item"><strong>Products ordered</strong><span class="badge"><%= @user.products_group_by_id.map(&:count).sum %></span></li>
<% if can? :create, @user.orders.build %>
<li class="list-group-item"><%= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block" %></li>
<% end %>
</ul>
<% if can? :edit, @user %>
<ul class="list-group">
<li class="list-group-item text-muted">
<% if @user.dagschotel %>
Huidige dagschotel
<%= image_tag @user.dagschotel.avatar %>
<%= link_to "Change dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block" %>
<% else %>
<%= link_to "Set dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block" %>
<% end %>
</li>
</ul>
<% end %>
</div>

View file

@ -0,0 +1,26 @@
.col-sm-3
%div
%h2
= @user.name
- if can? :edit, @user
= link_to content_tag(:small, content_tag(:span, "", class: "glyphicon glyphicon-cog")), edit_user_path(@user)
= content_tag :div, image_tag(@user.avatar, class: "img-circle img-thumbnail center"), class: "user_avatar center"
%ul.list-group
%li.list-group-item.text-muted Orders
%li.list-group-item
%strong Orders placed
%span.badge= @user.orders_count
%li.list-group-item
%strong Products ordered
%span.badge= @user.products_group_by_id.map(&:count).sum
- if can? :create, @user.orders.build
%li.list-group-item= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block"
- if can? :edit, @user
%ul.list-group
%li.list-group-item.text-muted
- if @user.dagschotel
Huidige dagschotel
\#{image_tag @user.dagschotel.avatar}
\#{link_to "Change dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block"}
- else
= link_to "Set dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block"

View file

@ -1,11 +0,0 @@
<tr>
<td><%= user.id %></td>
<td><%= image_tag user.avatar(:small) %></td>
<td><%= user.name %></td>
<td><%= euro(user.debt) %></td>
<% if current_user.admin? %>
<td>
<%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } %>
</td>
<% end %>
</tr>

View file

@ -0,0 +1,8 @@
%tr
%td= user.id
%td= image_tag user.avatar(:small)
%td= user.name
%td= euro(user.debt)
- if current_user.admin?
%td
= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" }

View file

@ -1,20 +0,0 @@
<%= render 'flash' %>
<div class="row">
<%= render 'sidebar' %>
<div class="col-sm-9">
<h2>Edit your settings</h2>
<%= f_form_for @user do |f| %>
<%= f.error_messages %>
<%= f.file_field :avatar %>
<p>
If you check this option, nobody will be able to order stuff for you through koelkast.
Only on your account things can be ordered.
<p>
<%= f.check_box :private %>
<%= f.submit "Update" %>
<% end %>
</div>
</div>

View file

@ -0,0 +1,14 @@
= render 'flash'
.row
= render 'sidebar'
.col-sm-9
%h2 Edit your settings
= f_form_for @user do |f|
= f.error_messages
= f.file_field :avatar
%p
If you check this option, nobody will be able to order stuff for you through koelkast.
Only on your account things can be ordered.
%p
= f.check_box :private
= f.submit "Update"

View file

@ -1,2 +0,0 @@
<h3>Choose new Dagschotel</h4>
<%= render 'products/index' %>

View file

@ -0,0 +1,3 @@
%h3
Choose new Dagschotel
= render 'products/index'

View file

@ -1,17 +0,0 @@
<div class="row users">
<div class="col-md-8 col-md-offset-2">
<h1>All users</h1>
<%= render partial: 'flash' %>
<table id="users-table" class="table table-striped">
<tr>
<th>ID</th>
<th></th>
<th>Nickname</th>
<th>Debt</th>
<th></th>
</tr>
<%= render @users %>
</table>
</div>
</div>

View file

@ -0,0 +1,12 @@
.row.users
.col-md-8.col-md-offset-2
%h1 All users
= render partial: 'flash'
%table#users-table.table.table-striped
%tr
%th ID
%th
%th Nickname
%th Debt
%th
= render @users

View file

@ -1,27 +0,0 @@
<%= render partial: 'flash' %>
<div class="row">
<%= render 'sidebar' %>
<div id="user_info" class="col-sm-9">
<% if (all_orders = @user.all_orders(params[:page])).any? %>
<h4>Previously ordered</h4>
Total:
<ul>
<li>
<%= @user.products_group_by_category.map{|c| pluralize(c.count, c.category)}.to_sentence %>
</li>
</ul>
Specifics:
<%= content_tag :ul do %>
<% @user.products_group_by_id.each do |p| %>
<%= content_tag :li, pluralize(p.count, p.name) %>
<% end %>
<% end %>
<h4>All orders (<%= @user.orders_count %>)</h4>
<table class="orders"><%= render all_orders %></table>
<%= will_paginate all_orders %>
</div>
<% end %>
</div>
</div>

View file

@ -0,0 +1,18 @@
= render partial: 'flash'
.row
= render 'sidebar'
#user_info.col-sm-9
- if (all_orders = @user.all_orders(params[:page])).any?
%h4 Previously ordered
Total:
%ul
%li
= @user.products_group_by_category.map{|c| pluralize(c.count, c.category)}.to_sentence
Specifics:
= content_tag :ul do
- @user.products_group_by_id.each do |p|
= content_tag :li, pluralize(p.count, p.name)
%h4
All orders (#{@user.orders_count})
%table.orders= render all_orders
= will_paginate all_orders

View file

@ -1,8 +0,0 @@
<h2>Login</h2>
<%= render 'flash' %>
If this is the first time you log in, an account will be created for you.
<div>
<br />
<%= link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary" %><br />
</div>

View file

@ -0,0 +1,7 @@
%h2 Login
= render 'flash'
If this is the first time you log in, an account will be created for you.
%div
%br/
= link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary"
%br/

View file

@ -5,113 +5,3 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
require 'faker'
require 'identicon'
DEFAULT_PASSWORD = "password"
products = [
{
name: "Twix",
price: 0.4,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/1.jpg', 'r')
},
{
name: "M&M Peanuts",
price: 0.6,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/2.jpg', 'r')
},
{
name: "Snickers",
price: 0.4,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/3.jpg', 'r')
},
{
name: "Fanta",
price: 0.6,
category: "beverages",
stock: 30,
avatar: File.new('public/seeds/products/4.jpg', 'r')
},
{
name: "Ice Tea",
price: 0.7,
category: "beverages",
stock: 30,
avatar: File.new('public/seeds/products/5.jpg', 'r')
},
{
name: "Cola",
price: 0.6,
category: "beverages",
stock: 30,
avatar: File.new('public/seeds/products/6.jpg', 'r')
},
{
name: "Abrikozencake",
price: 0.4,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/7.jpg', 'r')
},
{
name: "Kinder Delice",
price: 0.4,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/8.jpg', 'r')
},
{
name: "Kinder Bueno",
price: 0.6,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/9.jpg', 'r')
},
{
name: "Arizona Ice Tea",
price: 1.0,
category: "beverages",
stock: 30,
avatar: File.new('public/seeds/products/10.png', 'r')
},
{
name: "Dinosauruskoeken",
price: 0.5,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/11.jpg', 'r')
},
{
name: "Chocolade - melk",
price: 0.7,
category: "food",
stock: 30,
avatar: File.new('public/seeds/products/12.jpg', 'r')
}
]
products.each do |attr|
Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar]
end
User.create(
uid: "koelkast",
password: "password",
password_confirmation: "password",
avatar: Identicon.data_url_for("koelkast"),
koelkast: true
)
20.times do |i|
name = Faker::Name.name
User.create(
uid: name,
avatar: Identicon.data_url_for(name)
)
end

9
lib/tasks/devseeds.rake Normal file
View file

@ -0,0 +1,9 @@
unless Rails.env.production?
require 'factory_girl'
require 'faker'
Dir[Rails.root.join("spec/factories/*.rb")].each {|f| require f}
task :sow => :environment do
FactoryGirl.create_list(:user, 20)
FactoryGirl.create_list(:product, 20)
end
end

View file

@ -22,11 +22,11 @@ require 'identicon'
FactoryGirl.define do
factory :product do
name { Faker::Name.name }
name { Faker::Name.name }
price_cents { rand 120 }
stock { 30 + rand(30) }
calories { rand 20 }
avatar { Identicon.data_url_for name }
stock { 30 + rand(30) }
calories { rand 20 }
avatar { Identicon.data_url_for name }
factory :invalid_product do
name nil

View file

@ -39,6 +39,7 @@ FactoryGirl.define do
factory :koelkast do
koelkast true
name "koelkast"
end
end
end