Fix 69
This commit is contained in:
parent
344f259efd
commit
8099de435b
10 changed files with 37 additions and 10 deletions
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
|
||||
load_resource :user
|
||||
load_and_authorize_resource :order, through: :user, shallow: true
|
||||
load_and_authorize_resource :order, through: :user
|
||||
|
||||
def new
|
||||
@products = Product.all.for_sale.order(:name)
|
||||
|
|
|
@ -29,7 +29,7 @@ class UsersController < ApplicationController
|
|||
order = @user.orders.build
|
||||
order.order_items.build(count: 1, product: @user.dagschotel)
|
||||
if order.save
|
||||
flash[:success] = "Quick pay succeeded. #{view_context.link_to("Undo", [@user, order], method: :delete)}."
|
||||
flash[:success] = "Quick pay succeeded."
|
||||
else
|
||||
flash[:error] = order.errors.full_messages.first
|
||||
end
|
||||
|
|
|
@ -10,7 +10,11 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def euro_from_cents(f)
|
||||
euro(f / 100.0)
|
||||
if f
|
||||
euro(f / 100.0)
|
||||
else
|
||||
"undefined"
|
||||
end
|
||||
end
|
||||
|
||||
def euro(f)
|
||||
|
|
|
@ -19,8 +19,8 @@ class Ability
|
|||
can :create, Order do |order|
|
||||
order.try(:user) == user
|
||||
end
|
||||
can :delete, Order do |order|
|
||||
order.try(:user) == user && order.created_at > Rails.application.config.call_api_after.ago
|
||||
can :destroy, Order do |order|
|
||||
order.try(:user) == user && order.deletable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,6 +33,14 @@ class Order < ActiveRecord::Base
|
|||
}.to_sentence
|
||||
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
|
||||
|
||||
def calculate_price
|
||||
|
|
|
@ -51,9 +51,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
if result.code == 200
|
||||
JSON.parse(result.body)["balance"]
|
||||
else
|
||||
0
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
.alert.alert-success.alert-dismissable
|
||||
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
||||
%strong Success!
|
||||
= raw flash[:success]
|
||||
= flash[:success]
|
||||
- if flash[:notice]
|
||||
.alert.alert-info.alert-dismissable
|
||||
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", type: "button"} ×
|
||||
|
|
|
@ -6,3 +6,8 @@
|
|||
= order.to_sentence
|
||||
%td
|
||||
= 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.
|
||||
# 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.
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||
# config.i18n.default_locale = :de
|
||||
config.active_record.raise_in_transactional_callbacks = true
|
||||
config.active_job.queue_adapter = :delayed_job
|
||||
config.call_api_after = 5.minutes
|
||||
config.call_api_after = 35.minutes
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue