Everything is green

This commit is contained in:
2014-08-15 16:53:36 +02:00
parent 957ea02b5d
commit 3b5d411a89
14 changed files with 76 additions and 62 deletions
@@ -15,12 +15,12 @@ App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
).property('content.id')
offsetX: (->
return 0 unless section_width = @get('content.section.width')
((@get('content.position_x') || 0) * @get('containerWidth') / section_width) - 40
((@get('content.position_x') || 0) * @get('containerWidth') / section_width)
).property('content.section.width', 'content.position_x', 'containerWidth')
offsetY: (->
return 0 unless section_height = @get('content.section.height')
# debugger if @get('content.number') == 11
((@content.get('position_y') || 0) * @get('containerHeight') / section_height) - 20
((@content.get('position_y') || 0) * @get('containerHeight') / section_height)
).property('content.section.height', 'content.position_y', 'containerHeight')
style: (->
@@ -35,8 +35,8 @@ App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
#@$el.css 'left', position.left
#@$el.css 'top', position.top
@content.setProperties
position_x: position.left*@content.get('section').get('width') / @containerWidth()
position_y: position.top *@content.get('section').get('height') / @containerHeight()
position_x: position.left*@get('content.section.width') / @get('containerWidth')
position_y: position.top *@get('content.section.height') / @get('containerHeight')
#@content.get('transaction').commit()
@content.save()
containerWidth: (-> @get('parentView.element_width') ).property('parentView.element_width')
@@ -6,27 +6,33 @@ root.Qsupplier=
<% if Rails.env.test? %>
window.faye_log ||= []
faye_message = {}
faye_message[e.event] = e.data
faye_message[e.event] = JSON.parse(JSON.stringify(e.data))
faye_log.push faye_message
<% elsif Rails.env.development? %>
console.log "Event: #{e.event}"
console.log e.data
<% end %>
if(e.event == 'new_order')
if App
App.store().pushPayload(e.data)
# Fix for ember pushPayload bug not creating the proper relations/triggers
setTimeout ->
if order = App.store().all('order').findProperty('id', e.data.order.id)
# console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list"
list = order.get('list')
list.get('orders').addRecord order
if table = list.get('table')
if table.get('active_list')
table.get('active_list').then (table_list)->
table.set 'active_list', list if table_list isnt list
, 200
else if(e.event == 'list_needs_help')
if e.data
if e.data.supplier_orders_placed_count == 0 or e.data.supplier_orders_placed_count
$('.supplier-orders-placed-count-number').text(e.data.supplier_orders_placed_count)
if e.data.supplier_orders_in_process_count == 0 or e.data.supplier_orders_in_process_count
$('.supplier-orders-in-process-count-number').text(e.data.supplier_orders_in_process_count)
# if(e.event == 'new_order')
# if App
# App.store().pushPayload(e.data)
# # Fix for ember pushPayload bug not creating the proper relations/triggers
# setTimeout ->
# if order = App.store().all('order').findProperty('id', e.data.order.id)
# # console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list"
# list = order.get('list')
# list.get('orders').addRecord order
# if table = list.get('table')
# if table.get('active_list')
# table.get('active_list').then (table_list)->
# table.set 'active_list', list if table_list isnt list
# , 200
if(e.event == 'list_needs_help')
if App and list = App.List.findCached(e.data.id)
list.markNeedsHelp()
# old stuff
@@ -43,8 +49,12 @@ root.Qsupplier=
if list = App.List.findCached(e.data.id)
list.markIsPaid()
else if e.event == 'list_update'
if App
list = App.List.updateOrAdd(e.data.list)
App.store().pushPayload('list', e.data)
App.store().findById('list', e.data.list.id).then (list)->
list.get('table').then (table)->table.set('active_list', list)
# if App
# list = App.List.updateOrAdd(e.data.list)
else if e.event == 'list_closed'
if App and list = App.List.findCached(e.data.id)
list.markClosed()
@@ -89,8 +99,6 @@ root.Qsupplier=
else if e.event == 'order_cancelled'
if App and order = App.Order.findCached(e.data.id)
order.markCancelled()
$('.supplier-orders-placed-count-number').text(e.data.orders_placed_count) if e.data.orders_placed_count == 0 or e.data.orders_placed_count
$('.supplier-orders-in-process-count-number').text(e.data.orders_in_process_count) if e.data.orders_in_process_count == 0 or e.data.orders_in_process_count
# old stuff
@@ -42,8 +42,8 @@ App.ApplicationController = Ember.Controller.extend
order_cancelled: (data)->
if order = App.Order.findCached(data.id)
order.markCancelled()
@events.orders_placed_count.call(@, count: data.orders_placed_count) if data.orders_placed_count == 0 or data.orders_placed_count
@events.orders_in_process_count.call(@, count: data.orders_in_process_count) if data.orders_in_process_count == 0 or data.orders_in_process_count
@events.orders_placed_count.call(@, count: data.supplier_orders_placed_count) if data.supplier_orders_placed_count == 0 or data.supplier_orders_placed_count
@events.orders_in_process_count.call(@, count: data.supplier_orders_in_process_count) if data.supplier_orders_in_process_count == 0 or data.supplier_orders_in_process_count
join_request_rejected: (data)->
# Remove join request from connected users
join_request = @store.all('join_request').findBy 'id', data.id
+5 -4
View File
@@ -146,12 +146,13 @@ class List
self.user_requests_closing = false # if a user requested closing, not needed anymore
self.closed_at = Time.now
if save
broadcast_info = supplier_counter_info.merge(id: id)
for user in users
user.active_list_id = nil
user.save
broadcast_user user.id, 'list_closed', id: id
broadcast_user user.id, 'list_closed', broadcast_info
end
broadcast_supplier supplier_id, 'list_closed', id: id
broadcast_supplier supplier_id, 'list_closed', broadcast_info
end
end
@@ -275,8 +276,8 @@ class List
broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price
broadcast_users 'orders_placed_count', count: orders_placed_count
broadcast_supplier supplier.id, 'list_update', active_model_serializer.new(self).as_json
broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order)
broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json
# broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order)
broadcast_supplier supplier.id, 'orders_placed_count', count: orders_placed_count
order
end
+2 -2
View File
@@ -113,10 +113,10 @@ class Order
broadcast_options = {id: id}
if original_state.placed?
reduced_count = supplier.decrement_orders_placed_count!
broadcast_options[:orders_placed_count] = reduced_count
broadcast_options[:supplier_orders_placed_count] = reduced_count
elsif original_state.active?
reduced_count = supplier.decrement_orders_in_process_count!
broadcast_options[:orders_in_process_count] = reduced_count
broadcast_options[:supplier_orders_in_process_count] = reduced_count
end
list.broadcast_users 'order_cancelled', broadcast_options
broadcast_supplier supplier_id, 'order_cancelled', broadcast_options
@@ -8,9 +8,9 @@ header.top-menu
= link_to image_tag('icons/logo-small.png'), supplier_root_path, class: 'top-menu-root'
= link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path, data: {t: 'models.plural.product_category'}, class: 'top-menu-product_categories'
= link_to Product.model_name.human_plural, suppliers_products_path, data: {t: 'models.plural.product'}, class: 'top-menu-products'
= link_to Section.model_name.human_plural, suppliers_sections_path, data: {t: 'models.plural.section'}, class: 'top-menu-sections'
= link_to Table.model_name.human_plural, suppliers_tables_path, data: {t: 'models.plural.table'}, class: 'top-menu-tables'
= link_to List.model_name.human_plural, suppliers_lists_path, data: {t: 'models.plural.list'}, class: 'top-menu-lists'
= link_to Section.model_name.human_plural, "/supplier#/sections", data: {t: 'models.plural.section'}, class: 'top-menu-sections'
= link_to Table.model_name.human_plural, "/supplier#/tables", data: {t: 'models.plural.table'}, class: 'top-menu-tables'
= link_to List.model_name.human_plural, "/supplier#/lists", data: {t: 'models.plural.list'}, class: 'top-menu-lists'
section.extra-info
.supplier-info-row
.supplier-name= current_supplier.name.presence || current_supplier.email