commit
f2a985e6c0
27 changed files with 266 additions and 79 deletions
|
@ -1,36 +1,39 @@
|
|||
ready = function() {
|
||||
$('[data-quickpay]').on("ajax:success", function (e, data, status, xhr) {
|
||||
$('[data-quickpay]').on("ajax:success", function(e, data, status, xhr) {
|
||||
if (this.id !== "dagschotel_quickpay") {
|
||||
// Last Image
|
||||
var img = $("<img>", {
|
||||
src: $(this).closest(".overviewthumbnail").find(".avatar").attr("src").replace("large", "small"),
|
||||
class: ["img-responsive img-circle img-thumbnail"]
|
||||
})
|
||||
$(img).hide().prependTo($("#last")).fadeIn();
|
||||
if ($("#last").find("img").size() > 10) {
|
||||
$("#last").find("img").last().remove();
|
||||
}
|
||||
$(".alert").fadeOut();
|
||||
|
||||
// Last Image
|
||||
var img = $("<img>", {
|
||||
src: $(this).closest(".overviewthumbnail").find(".avatar").attr("src").replace("large", "small"),
|
||||
class: [ "img-responsive img-circle img-thumbnail" ]
|
||||
})
|
||||
$(img).hide().prependTo($("#last")).fadeIn();
|
||||
if ($("#last").find("img").size() > 10) {
|
||||
$("#last").find("img").last().remove();
|
||||
}
|
||||
$(".alert").fadeOut();
|
||||
// Flash Message
|
||||
var div = $("<div>", {
|
||||
class: ["alert alert-success alert-dismissable"]
|
||||
});
|
||||
$(div).append($("<button>", {
|
||||
text: 'x',
|
||||
class: "close",
|
||||
data: {
|
||||
dismiss: "alert"
|
||||
}
|
||||
}));
|
||||
$(div).append($("<strong>", {
|
||||
text: "Success! "
|
||||
}));
|
||||
$(div).append(data.message);
|
||||
|
||||
// Flash Message
|
||||
var div = $("<div>", {
|
||||
class: [ "alert alert-success alert-dismissable" ]
|
||||
$("#flash").append(div);
|
||||
}
|
||||
|
||||
}).on("ajax:error", function(e, xhr, status, error) {
|
||||
alert("Error while using quickpay ... sorry.");
|
||||
});
|
||||
$(div).append($("<button>", {
|
||||
text: 'x',
|
||||
class: "close",
|
||||
data: { dismiss: "alert" }
|
||||
}));
|
||||
$(div).append($("<strong>", {
|
||||
text: "Success! "
|
||||
}));
|
||||
$(div).append(data.message);
|
||||
|
||||
$("#flash").append(div);
|
||||
|
||||
}) .on("ajax:error", function (e, xhr, status, error) {
|
||||
alert("Error while using quickpay ... sorry.");
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(ready);
|
||||
|
|
16
app/assets/javascripts/remove_dagschotel_button.js
Normal file
16
app/assets/javascripts/remove_dagschotel_button.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
ready = function() {
|
||||
var id = $("#remove_dagschotel").find(".btn");
|
||||
default_value = id.val();
|
||||
|
||||
id.hover(function() {
|
||||
$(this).toggleClass("btn-success");
|
||||
$(this).toggleClass("btn-danger");
|
||||
$(this).val("Remove dagschotel");
|
||||
}, function() {
|
||||
$(this).val(default_value);
|
||||
$(this).toggleClass("btn-success");
|
||||
$(this).toggleClass("btn-danger");
|
||||
});
|
||||
}
|
||||
$(document).ready(ready);
|
||||
$(document).on('page:load', ready);
|
|
@ -1,5 +1,7 @@
|
|||
ready = function() {
|
||||
$('[data-switch]').bootstrapSwitch({ onText: "private", offText: "public" });
|
||||
$.each($('[data-switch]'), function(key, value){
|
||||
$(this).bootstrapSwitch({ offText: value.getAttribute('data-offText'), onText: value.getAttribute('data-onText')});
|
||||
});
|
||||
$('[data-switch]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
$(this).closest('form').submit();
|
||||
});
|
||||
|
|
|
@ -44,3 +44,11 @@ div.out-of-stock {
|
|||
.expand {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dagschotel-edit-image {
|
||||
margin: auto;
|
||||
max-height: 65px;
|
||||
}
|
||||
.dagschotel-edit {
|
||||
max-height: 250px;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: barcodes
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# product_id :integer
|
||||
# code :string default(""), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
||||
class BarcodesController < ApplicationController
|
||||
load_and_authorize_resource :product, only: :create
|
||||
load_and_authorize_resource :barcode, through: :product, shallow: true
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: orders
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# price_cents :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# transaction_id :integer
|
||||
#
|
||||
|
||||
class OrdersController < ApplicationController
|
||||
load_resource :user
|
||||
load_and_authorize_resource :order, through: :user, shallow: true, only: [:overview, :destroy]
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: products
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
class ProductsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# admin :boolean default(FALSE)
|
||||
# dagschotel_id :integer
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# orders_count :integer default(0)
|
||||
# koelkast :boolean default(FALSE)
|
||||
# name :string
|
||||
# private :boolean default(FALSE)
|
||||
# frecency :integer default(0), not null
|
||||
# quickpay_hidden :boolean
|
||||
#
|
||||
|
||||
class UsersController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
before_action :init, only: :show
|
||||
|
@ -39,10 +61,14 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def quickpay
|
||||
authorize! :create, @user.orders.build
|
||||
order = @user.orders.build
|
||||
order.order_items.build(count: 1, product: @user.dagschotel)
|
||||
if order.save
|
||||
render json: { message: "Quick pay succeeded for #{@user.name}." }, status: :ok
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(@user) }
|
||||
format.json { render json: { message: "Quick pay succeeded for #{@user.name}." }, status: :ok }
|
||||
end
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
|
@ -50,11 +76,11 @@ class UsersController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.fetch(:user, {}).permit(:avatar, :private, :dagschotel_id)
|
||||
end
|
||||
def user_params
|
||||
params.fetch(:user, {}).permit(:avatar, :private, :dagschotel_id, :quickpay_hidden)
|
||||
end
|
||||
|
||||
def init
|
||||
@user ||= current_user
|
||||
end
|
||||
def init
|
||||
@user ||= current_user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: products
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
module ProductsHelper
|
||||
def kcal(calories)
|
||||
calories.to_s + " kcal"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# id :integer not null, primary key
|
||||
# order_id :integer
|
||||
# product_id :integer not null
|
||||
# count :integer default("0")
|
||||
# count :integer default(0)
|
||||
#
|
||||
|
||||
class OrderItem < ActiveRecord::Base
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default("0"), not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default("0")
|
||||
# stock :integer default("0"), not null
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default("f")
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
class Product < ActiveRecord::Base
|
||||
|
|
|
@ -6,17 +6,18 @@
|
|||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# admin :boolean
|
||||
# admin :boolean default(FALSE)
|
||||
# dagschotel_id :integer
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# orders_count :integer default("0")
|
||||
# koelkast :boolean default("f")
|
||||
# orders_count :integer default(0)
|
||||
# koelkast :boolean default(FALSE)
|
||||
# name :string
|
||||
# encrypted_password :string default(""), not null
|
||||
# private :boolean default("f")
|
||||
# private :boolean default(FALSE)
|
||||
# frecency :integer default(0), not null
|
||||
# quickpay_hidden :boolean
|
||||
#
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
|
@ -29,8 +30,6 @@ class User < ActiveRecord::Base
|
|||
has_many :products, through: :orders
|
||||
belongs_to :dagschotel, class_name: 'Product'
|
||||
|
||||
validates :dagschotel, presence: true, if: -> { dagschotel_id }
|
||||
|
||||
scope :members, -> { where koelkast: false }
|
||||
scope :publik, -> { where private: false }
|
||||
|
||||
|
|
|
@ -6,4 +6,6 @@
|
|||
- if current_user.dagschotel != product
|
||||
= button_to "Make dagschotel", { controller: 'users', action: 'update', "user[dagschotel_id]" => product.id }, method: :put, class: "btn btn-default"
|
||||
- else
|
||||
%span.btn.btn-success= "Current dagschotel"
|
||||
#remove_dagschotel
|
||||
= button_to "Current dagschotel", { controller: 'users', action: 'update', "user[dagschotel_id]" => "nil" }, method: :put, class: "btn btn-success"
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
.col-md-3
|
||||
.thumbnail.pic
|
||||
.center
|
||||
= image_tag product.avatar
|
||||
.thumbnail.pic.dagschotel-edit
|
||||
= image_tag product.avatar, class: "dagschotel-edit-image img-responsive"
|
||||
.caption
|
||||
= kcal_tag product.calories
|
||||
%h4= product.name
|
||||
|
|
|
@ -13,14 +13,20 @@
|
|||
%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"
|
||||
%li.list-group-item
|
||||
= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block"
|
||||
- if @user.dagschotel
|
||||
%p.center
|
||||
%b or
|
||||
-#%button.btn.btn-default.product{ data: { product: @user.dagschotel} }
|
||||
= link_to quickpay_user_path(@user), id: "dagschotel_quickpay", class: "btn btn-default btn-block" do
|
||||
%p.center Order dagschotel
|
||||
= image_tag @user.dagschotel.avatar, title: "Huidige dagschotel"
|
||||
= render 'errors', object: @user
|
||||
- if can? :edit, @user
|
||||
%ul.list-group
|
||||
%li.list-group-item.text-muted
|
||||
- if @user.dagschotel
|
||||
.center
|
||||
%p= image_tag @user.dagschotel.avatar, title: "Huidige dagschotel"
|
||||
\#{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"
|
||||
|
@ -28,7 +34,12 @@
|
|||
%p Orders can be placed on koelkast for every public account. Private accounts can only order products by logging in here.
|
||||
= f_form_for @user, remote: true do |f|
|
||||
.center
|
||||
= f.check_box :private, skip_label: true, data: { switch: true }
|
||||
= f.check_box :private, skip_label: true, data: { switch: true, offText: "public", onText: "private" }
|
||||
%li.list-group-item.text-muted
|
||||
= f_form_for @user, remote: true do |f|
|
||||
.center
|
||||
= f.label "Show dagschotel on koelkast"
|
||||
= f.check_box :quickpay_hidden, skip_label: true, data: { switch: true, offText: "show", onText: "hide" }
|
||||
%li.list-group-item.text-muted
|
||||
= f_form_for @user do |f|
|
||||
= f.file_field :avatar, skip_label: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.col-md-2.overviewthumbnail
|
||||
- unless user.dagschotel.nil?
|
||||
- if user.dagschotel && !user.quickpay_hidden
|
||||
= link_to quickpay_user_path(user), remote: true, data: { quickpay: true, type: "json" } 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)
|
||||
|
|
5
db/migrate/20160304192839_add_quickpay_hidden_to_user.rb
Normal file
5
db/migrate/20160304192839_add_quickpay_hidden_to_user.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddQuickpayHiddenToUser < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :quickpay_hidden, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160216133104) do
|
||||
ActiveRecord::Schema.define(version: 20160304192839) do
|
||||
|
||||
create_table "barcodes", force: :cascade do |t|
|
||||
t.integer "product_id"
|
||||
|
@ -86,6 +86,7 @@ ActiveRecord::Schema.define(version: 20160216133104) do
|
|||
t.string "name"
|
||||
t.boolean "private", default: false
|
||||
t.integer "frecency", default: 0, null: false
|
||||
t.boolean "quickpay_hidden"
|
||||
end
|
||||
|
||||
add_index "users", ["koelkast"], name: "index_users_on_koelkast"
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: barcodes
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# product_id :integer
|
||||
# code :string default(""), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
||||
# product_barcodes POST /products/:product_id/barcodes(.:format) barcodes#create
|
||||
# barcodes GET /barcodes(.:format) barcodes#index
|
||||
# barcode GET /barcodes/:id(.:format) barcodes#show
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: products
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
# barcode_products GET /products/barcode(.:format) products#barcode
|
||||
# load_barcode_products POST /products/barcode(.:format) products#load_barcode
|
||||
# products GET /products(.:format) products#index
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# admin :boolean default(FALSE)
|
||||
# dagschotel_id :integer
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# orders_count :integer default(0)
|
||||
# koelkast :boolean default(FALSE)
|
||||
# name :string
|
||||
# private :boolean default(FALSE)
|
||||
# frecency :integer default(0), not null
|
||||
# quickpay_hidden :boolean
|
||||
#
|
||||
|
||||
# quickpay_user GET /users/:id/quickpay(.:format) users#quickpay
|
||||
# edit_dagschotel_user GET /users/:id/dagschotel/edit(.:format) users#edit_dagschotel
|
||||
# edit_user GET /users/:id/edit(.:format) users#edit
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# id :integer not null, primary key
|
||||
# order_id :integer
|
||||
# product_id :integer not null
|
||||
# count :integer default("0")
|
||||
# count :integer default(0)
|
||||
#
|
||||
|
||||
FactoryGirl.define do
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default("0"), not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default("0")
|
||||
# stock :integer default("0"), not null
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default("f")
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
require 'faker'
|
||||
|
|
|
@ -6,17 +6,18 @@
|
|||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# admin :boolean
|
||||
# admin :boolean default(FALSE)
|
||||
# dagschotel_id :integer
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# orders_count :integer default("0")
|
||||
# koelkast :boolean default("f")
|
||||
# orders_count :integer default(0)
|
||||
# koelkast :boolean default(FALSE)
|
||||
# name :string
|
||||
# encrypted_password :string default(""), not null
|
||||
# private :boolean default("f")
|
||||
# private :boolean default(FALSE)
|
||||
# frecency :integer default(0), not null
|
||||
# quickpay_hidden :boolean
|
||||
#
|
||||
|
||||
require 'faker'
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# id :integer not null, primary key
|
||||
# order_id :integer
|
||||
# product_id :integer not null
|
||||
# count :integer default("0")
|
||||
# count :integer default(0)
|
||||
#
|
||||
|
||||
describe OrderItem do
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# price_cents :integer default("0"), not null
|
||||
# price_cents :integer default(0), not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# category :integer default("0")
|
||||
# stock :integer default("0"), not null
|
||||
# category :integer default(0)
|
||||
# stock :integer default(0), not null
|
||||
# calories :integer
|
||||
# deleted :boolean default("f")
|
||||
# deleted :boolean default(FALSE)
|
||||
#
|
||||
|
||||
describe Product do
|
||||
|
|
|
@ -6,17 +6,18 @@
|
|||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# admin :boolean
|
||||
# admin :boolean default(FALSE)
|
||||
# dagschotel_id :integer
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# orders_count :integer default("0")
|
||||
# koelkast :boolean default("f")
|
||||
# orders_count :integer default(0)
|
||||
# koelkast :boolean default(FALSE)
|
||||
# name :string
|
||||
# encrypted_password :string default(""), not null
|
||||
# private :boolean default("f")
|
||||
# private :boolean default(FALSE)
|
||||
# frecency :integer default(0), not null
|
||||
# quickpay_hidden :boolean
|
||||
#
|
||||
|
||||
require 'webmock/rspec'
|
||||
|
|
Loading…
Reference in a new issue