commit
ffda2a4b26
11
app/assets/javascripts/remove_button.js
Normal file
11
app/assets/javascripts/remove_button.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
ready = function() {
|
||||||
|
$('[data-remove]').each(function() {
|
||||||
|
var button = $(this);
|
||||||
|
setTimeout(function() {
|
||||||
|
$(button).remove();
|
||||||
|
}, $(button).data("remove") * 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(ready);
|
||||||
|
$(document).on('page:load', ready);
|
|
@ -1,6 +1,6 @@
|
||||||
class OrdersController < ApplicationController
|
class OrdersController < ApplicationController
|
||||||
load_resource :user
|
load_resource :user
|
||||||
load_and_authorize_resource :order, through: :user, shallow: true
|
load_and_authorize_resource :order, through: :user
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@products = Product.all.for_sale.order(:name)
|
@products = Product.all.for_sale.order(:name)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class UsersController < ApplicationController
|
||||||
order = @user.orders.build
|
order = @user.orders.build
|
||||||
order.order_items.build(count: 1, product: @user.dagschotel)
|
order.order_items.build(count: 1, product: @user.dagschotel)
|
||||||
if order.save
|
if order.save
|
||||||
flash[:success] = "Quick pay succeeded. #{view_context.link_to("Undo", [@user, order], method: :delete)}."
|
flash[:success] = "Quick pay succeeded."
|
||||||
else
|
else
|
||||||
flash[:error] = order.errors.full_messages.first
|
flash[:error] = order.errors.full_messages.first
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,11 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def euro_from_cents(f)
|
def euro_from_cents(f)
|
||||||
euro(f / 100.0)
|
if f
|
||||||
|
euro(f / 100.0)
|
||||||
|
else
|
||||||
|
"undefined"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def euro(f)
|
def euro(f)
|
||||||
|
|
|
@ -19,8 +19,8 @@ class Ability
|
||||||
can :create, Order do |order|
|
can :create, Order do |order|
|
||||||
order.try(:user) == user
|
order.try(:user) == user
|
||||||
end
|
end
|
||||||
can :delete, Order do |order|
|
can :destroy, Order do |order|
|
||||||
order.try(:user) == user && order.created_at > Rails.application.config.call_api_after.ago
|
order.try(:user) == user && order.deletable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,14 @@ class Order < ActiveRecord::Base
|
||||||
}.to_sentence
|
}.to_sentence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def deletable
|
||||||
|
self.created_at > Rails.application.config.call_api_after.ago
|
||||||
|
end
|
||||||
|
|
||||||
|
def sec_until_remove
|
||||||
|
self.created_at.to_i - (Time.now - Rails.application.config.call_api_after).to_i
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def calculate_price
|
def calculate_price
|
||||||
|
|
|
@ -51,9 +51,8 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
if result.code == 200
|
if result.code == 200
|
||||||
JSON.parse(result.body)["balance"]
|
JSON.parse(result.body)["balance"]
|
||||||
else
|
|
||||||
0
|
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
.alert.alert-success.alert-dismissable
|
.alert.alert-success.alert-dismissable
|
||||||
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
||||||
%strong Success!
|
%strong Success!
|
||||||
= raw flash[:success]
|
= flash[:success]
|
||||||
- if flash[:notice]
|
- if flash[:notice]
|
||||||
.alert.alert-info.alert-dismissable
|
.alert.alert-info.alert-dismissable
|
||||||
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
||||||
|
|
|
@ -6,3 +6,8 @@
|
||||||
= order.to_sentence
|
= order.to_sentence
|
||||||
%td
|
%td
|
||||||
= euro_from_cents(order.price_cents)
|
= euro_from_cents(order.price_cents)
|
||||||
|
%td
|
||||||
|
- if order.deletable
|
||||||
|
= button_to "Cancel order (until #{(order.created_at + Rails.application.config.call_api_after).strftime("%H:%M")})", user_order_path(@user, order), method: :delete,
|
||||||
|
class: "btn btn-danger", data: { remove: order.sec_until_remove }
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,13 @@ module Tab002
|
||||||
|
|
||||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||||
# config.time_zone = 'Central Time (US & Canada)'
|
config.time_zone = 'Brussels'
|
||||||
|
|
||||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||||
# config.i18n.default_locale = :de
|
# config.i18n.default_locale = :de
|
||||||
config.active_record.raise_in_transactional_callbacks = true
|
config.active_record.raise_in_transactional_callbacks = true
|
||||||
config.active_job.queue_adapter = :delayed_job
|
config.active_job.queue_adapter = :delayed_job
|
||||||
config.call_api_after = 5.minutes
|
config.call_api_after = 35.minutes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue