diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
index 0c8c33c..5e44107 100644
--- a/app/assets/stylesheets/application.css.scss
+++ b/app/assets/stylesheets/application.css.scss
@@ -41,6 +41,8 @@ $gray-medium-light: #eaeaea;
}
+
+
/* forms */
input, textarea, select, .uneditable-input {
@@ -54,6 +56,10 @@ input {
height: auto !important;
}
+/* boostrap */
+body {
+ padding-top: 80px;
+}
/* footer */
@@ -85,3 +91,22 @@ footer ul li {
float: left;
margin-left: 15px;
}
+
+.overview{
+ width: 49%;
+ height: 49%;
+ border-radius: 0px;
+ margin: -2px;
+ padding: 18px;
+ border-color: #000;
+ border: 0px;
+
+ font-weight: bold;
+ font-size: 24px;
+
+
+}
+
+.center{
+ text-align: center;
+}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index f854d35..60c348c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -4,4 +4,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include OrdersHelper
+ include ApplicationHelper
end
diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb
index 3b998b5..cfd9cc8 100644
--- a/app/controllers/orders_controller.rb
+++ b/app/controllers/orders_controller.rb
@@ -1,7 +1,7 @@
class OrdersController < ApplicationController
def overview
- puts current_user
- @users = User.all
+ @users_by_name = User.all.order(:name)
+ @users_by_order = User.all
end
diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb
index 058317c..65b79e7 100644
--- a/app/controllers/products_controller.rb
+++ b/app/controllers/products_controller.rb
@@ -6,16 +6,12 @@ class ProductsController < ApplicationController
def create
@product = Product.new(product_params)
if @product.save
- redirect_to @product
+ redirect_to action: :index
else
- render 'new'
+ render :new
end
end
- def show
- @product = Product.find(params[:id])
- end
-
def index
@products = Product.all
end
@@ -27,7 +23,8 @@ class ProductsController < ApplicationController
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
- redirect_to @product
+ flash[:success] = "Succesfully updated product"
+ redirect_to action: :index
else
render 'edit'
end
@@ -35,14 +32,14 @@ class ProductsController < ApplicationController
def destroy
Product.find(params[:id]).destroy
+ flash[:success] = "Succesfully removed product"
redirect_to products_path
end
private
def product_params
- params.require(:product).permit(:name, :purchase_price, :sale_price,
- :avatar)
+ params.require(:product).permit(:name, :price, :avatar)
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be79..19f22f9 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,71 @@
+require 'digest/md5'
module ApplicationHelper
+
+ def get_color(user)
+ @color = Digest::MD5.hexdigest(user.name)[0..5]
+ end
+
+ def get_inverted_color(user)
+ @inverted_color = Digest::MD5.hexdigest(user.name)[0..5].reverse
+ end
+
+ def get_color_style(user)
+ @style = "background-color: #"+ get_color(user) +"; color: #"+
+ get_inverted_color(user)+ ";"
+ end
+
+ def euro(f)
+ "€#{number_with_precision f, precision: 2}"
+ end
+
+ #tijdelijk voor layout
+ def koelkast(status)
+ @koelkast ||= status
+ end
+
+ # Form helpers
+ def form_errors(object)
+ render partial: "form_errors", locals: {object: object}
+ end
+
+ def form_text_field(f, tag)
+ render partial: "form_text_field", locals: {f: f, tag: tag}
+ end
+
+ def form_password_field(f, tag)
+ render partial: "form_password_field", locals: {f: f, tag: tag}
+ end
+
+ def form_text_area(f, tag)
+ render partial: "form_text_area", locals: {f: f, tag: tag}
+ end
+
+ def form_fancy_text_area(f, tag)
+ render partial: "form_fancy_text_area", locals: {f: f, tag: tag}
+ end
+
+ def form_email_field(f, tag)
+ render partial: "form_email_field", locals: {f: f, tag: tag}
+ end
+
+ def form_date_field(f, tag, id, value)
+ render partial: "form_date_field", locals: {f: f, tag: tag, id: id, value: value}
+ end
+
+ def form_number_field(f, tag)
+ render partial: "form_number_field", locals: {f: f, tag: tag}
+ end
+
+ def form_collection_select(f, *args)
+ # This line enable passing optional arguments such as include_blank to the
+ # partial. If nothing is passed, an empty options hash is appended.
+ args << {} if args.length < 5
+
+ render partial: "form_collection_select", locals: {f: f, args: args}
+ end
+
+ def form_check_box(f, tag)
+ render partial: "form_check_box", locals: {f: f, tag: tag}
+ end
+
end
diff --git a/app/models/product.rb b/app/models/product.rb
index c7c31f7..4463062 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -24,4 +24,14 @@ class Product < ActiveRecord::Base
def count(order)
order_products.find_by(order: order).count
end
+
+ def price
+ (read_attribute(:price) || 0) / 100.0
+ end
+
+ def price=(value)
+ if value.is_a? String then value.sub!(',', '.') end
+ write_attribute(:price, (value.to_f * 100).to_int)
+ end
+
end
diff --git a/app/views/application/_errors.html.erb b/app/views/application/_errors.html.erb
index d7c0fb2..6a3452e 100644
--- a/app/views/application/_errors.html.erb
+++ b/app/views/application/_errors.html.erb
@@ -1,5 +1,14 @@
-
- <% model.errors.full_messages.each do |e| %>
- <%= content_tag(:li, e) %>
- <% end %>
-
+<% if model.errors.any? %>
+
+
+ <%= pluralize(model.errors.count, "error") %> prohibited this <%= model.class.name.downcase %> from being saved:
+
+
+
+ <% model.errors.full_messages.each do |msg| %>
+
<%= msg %>
+ <% end %>
+
+
+
+<% end %>
diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb
new file mode 100644
index 0000000..312b24d
--- /dev/null
+++ b/app/views/application/_flash.html.erb
@@ -0,0 +1,26 @@
+
+ <% if flash[:error] %>
+
+
+ Error! <%= flash[:error] %>
+
+ <% end %>
+ <% if flash[:success] %>
+
+
+ Success! <%= flash[:success] %>
+
+ <% end %>
+ <% if flash[:notice] %>
+
+
+ Notice! <%= flash[:notice] %>
+
+ <% end %>
+ <% if flash[:warning] %>
+
+
+ Warning! <%= flash[:warning] %>
+
+ <% end %>
+
diff --git a/app/views/application/_form_check_box.html.erb b/app/views/application/_form_check_box.html.erb
new file mode 100644
index 0000000..8d8e429
--- /dev/null
+++ b/app/views/application/_form_check_box.html.erb
@@ -0,0 +1,6 @@
+
+
+ <%= f.check_box tag %>
+
diff --git a/app/views/application/_form_collection_select.html.erb b/app/views/application/_form_collection_select.html.erb
new file mode 100644
index 0000000..99bd7e5
--- /dev/null
+++ b/app/views/application/_form_collection_select.html.erb
@@ -0,0 +1,5 @@
+<%# To pass options to the collection_select, add {options} as the last argument %>
+