From e91e3213d72f2b9cf489cb0e0fd19d8731e12522 Mon Sep 17 00:00:00 2001 From: benji Date: Thu, 31 Dec 2015 17:30:57 +0100 Subject: [PATCH] Prepare some things for production phase --- app/assets/stylesheets/overview.css.scss | 3 +-- app/controllers/welcome_controller.rb | 6 +++--- app/models/ability.rb | 2 +- app/models/barcode.rb | 2 +- app/models/product.rb | 2 +- app/models/user.rb | 9 +++++++++ app/views/orders/overview.html.haml | 15 +++++++-------- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/overview.css.scss b/app/assets/stylesheets/overview.css.scss index 37b2b72..b62f65f 100644 --- a/app/assets/stylesheets/overview.css.scss +++ b/app/assets/stylesheets/overview.css.scss @@ -20,7 +20,6 @@ } } -.warning { - border: 2px solid; +.guest { margin-bottom: 20px; } diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 6fff436..bfd4737 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -8,9 +8,9 @@ class WelcomeController < ApplicationController if user_signed_in? || params[:token] != Rails.application.secrets.koelkast_token redirect_to root_path return - else - koelkast = User.find_by(name: "koelkast") - sign_in_and_redirect koelkast end + + koelkast = User.koelkast + sign_in_and_redirect koelkast end end diff --git a/app/models/ability.rb b/app/models/ability.rb index c489408..17d3ced 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -4,7 +4,7 @@ class Ability def initialize(user) return unless user - initialize_admin if user.admin? + initialize_admin if user.admin? initialize_koelkast if user.koelkast? initialize_user(user) diff --git a/app/models/barcode.rb b/app/models/barcode.rb index 80e595f..1e03f54 100644 --- a/app/models/barcode.rb +++ b/app/models/barcode.rb @@ -16,5 +16,5 @@ class Barcode < ActiveRecord::Base belongs_to :product validates :product, presence: true - validates :code, presence: true, uniqueness: true + validates :code, presence: true, uniqueness: true end diff --git a/app/models/product.rb b/app/models/product.rb index 2128b62..497f64a 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -21,7 +21,7 @@ class Product < ActiveRecord::Base include Avatarable has_many :order_items - has_many :barcodes + has_many :barcodes, dependent: :destroy accepts_nested_attributes_for :barcodes enum category: %w(food beverages other) diff --git a/app/models/user.rb b/app/models/user.rb index 5f035fd..af1ab09 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -56,6 +56,8 @@ class User < ActiveRecord::Base end end + # Static Users + def self.guest @guest || find_or_create_by(name: "Guest") do |user| user.avatar = File.new(File.join("app", "assets", "images", "guest.png")) @@ -65,4 +67,11 @@ class User < ActiveRecord::Base def guest? self == User.guest end + + def self.koelkast + @koelkast || find_or_create_by(name: "Koelkast") do |user| + user.avatar = File.new(File.join("app", "assets", "images", "logo.png")) + user.koelkast = true + end + end end diff --git a/app/views/orders/overview.html.haml b/app/views/orders/overview.html.haml index a6d3d3d..2407cb4 100644 --- a/app/views/orders/overview.html.haml +++ b/app/views/orders/overview.html.haml @@ -1,13 +1,12 @@ -.warning.center - %h1 TESTFASE | GELIEVE STREEPJES TE BLIJVEN ZETTEN | TESTFASE .row .col-md-1 - %h5 Recent - #last - - @last.each do |user| - = image_tag user.avatar(:small), class: "img-responsive img-circle img-thumbnail" + - unless @last.empty? + %h5 Recent + #last + - @last.each do |user| + = image_tag user.avatar(:small), class: "img-responsive img-circle img-thumbnail" .col-md-11 - .row.text-center - =link_to "Not a Zeus Account? Order as a guest.", new_guest_order_path, class: "btn btn-primary btn-lg" + .row.text-center.guest + =link_to "Not a Zeus Account? Order as a guest.", new_guest_order_path, class: "btn btn-default btn-lg" .row = render @users