working ember... again
This commit is contained in:
+4
-1
@@ -96,7 +96,10 @@ class Order
|
||||
|
||||
def close!
|
||||
self.state = 'closed' if placed? || active?
|
||||
save
|
||||
if save
|
||||
broadcast_user user.id, 'order_closed', id: id
|
||||
broadcast_supplier supplier_id, 'order_closed', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def as_json(*args)
|
||||
|
||||
@@ -56,7 +56,7 @@ class Supplier
|
||||
end
|
||||
|
||||
def active_lists(options = {})
|
||||
return @active_lists if @active_lists.present?
|
||||
return @active_lists if @active_lists
|
||||
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(id)
|
||||
@active_lists.include_relations(table: :section, orders: {product_orders: :product})
|
||||
@active_lists
|
||||
|
||||
+12
-1
@@ -12,7 +12,7 @@ class Table
|
||||
has_many :lists
|
||||
|
||||
attr_protected :supplier_id
|
||||
attr_accessor :active_list_id
|
||||
attr_accessor :active_list_id, :active_list
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
#validates :list_id, presence: true
|
||||
@@ -68,9 +68,20 @@ class Table
|
||||
end
|
||||
|
||||
def active_list
|
||||
# nil memoizing
|
||||
return @active_list if @active_list_is_set
|
||||
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
|
||||
end
|
||||
|
||||
def active_list=(val)
|
||||
@active_list_is_set = true
|
||||
@active_list = val
|
||||
end
|
||||
|
||||
def active_list_id
|
||||
@active_list_id || active_list.try(:id)
|
||||
end
|
||||
|
||||
def reserved?
|
||||
false
|
||||
end
|
||||
|
||||
+27
-1
@@ -5,7 +5,14 @@ class User
|
||||
property :active_list_id
|
||||
property :admin, type: :boolean, default: false
|
||||
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :token_authenticatable # , :registerable
|
||||
#FACEBOOK
|
||||
property :provider
|
||||
property :uid
|
||||
property :oauth_token
|
||||
property :oauth_expires_at
|
||||
property :auth_data
|
||||
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :token_authenticatable, :omniauthable, :omniauth_providers => [:facebook] # , :registerable
|
||||
|
||||
property :authentication_token
|
||||
|
||||
@@ -17,6 +24,25 @@ class User
|
||||
|
||||
view :by_authentication_token, key: :authentication_token
|
||||
view :by_email, key: :email
|
||||
view :by_facebook, key: [:provider, :uid]
|
||||
|
||||
def self.find_for_facebook_oauth(auth_data, user)
|
||||
user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first
|
||||
user || create(
|
||||
provider: auth_data.provider,
|
||||
uid: auth_data.uid,
|
||||
name: auth_data.info.nickname,
|
||||
email: auth_data.info.email,
|
||||
password: Devise.friendly_token[0,20],
|
||||
oauth_token: user.oauth_token = auth.credentials.token,
|
||||
oauth_expires_at: Time.at(auth_data.credentials.expires_at),
|
||||
auth_data: auth_data
|
||||
)
|
||||
end
|
||||
|
||||
def self.from_omniauth(auth)
|
||||
binding.pry
|
||||
end
|
||||
|
||||
def list_is_closed!
|
||||
self.active_list_id = nil
|
||||
|
||||
Reference in New Issue
Block a user