Cleanup Qsupplier

This commit is contained in:
2014-08-18 09:33:11 +02:00
parent 3b5d411a89
commit 34877d4b8b
8 changed files with 204 additions and 221 deletions
@@ -1,5 +1,5 @@
root = exports ? this
root.Qsupplier=
root.Qsupplier =
watch_events: ->
faye = new Faye.Client(event_host)
faye.subscribe "/supplier/#{supplier_object.id}", (e)=>
@@ -33,55 +33,33 @@ root.Qsupplier=
# 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
# $('#list-needs-help-indicator-'+e.data.id).removeClass('hide')
# $('#list-is-helped-button-'+e.data.id).removeClass('hide')
# $('.section-table-list-'+e.data.id).addClass('needs_help')
list.markNeedsHelp() if list = App.List.findCached(e.data.id)
else if(e.event == 'list_needs_payment')
if App and list = App.List.findCached(e.data.id)
list.markNeedsPayment()
# old stuff
$('#list-needs-payment-indicator-'+e.data.id).removeClass('hide')
$('.section-table-list-'+e.data.id).addClass('needs_payment')
list.markNeedsPayment() if list = App.List.findCached(e.data.id)
else if(e.event == 'list_is_paid')
if list = App.List.findCached(e.data.id)
list.markIsPaid()
list.markIsPaid() if list = App.List.findCached(e.data.id)
else if e.event == 'list_update'
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()
$('.list-row-'+e.data.id).remove()
$('.of-list-'+e.data.id).remove()
table_list_class = 'section-table-list-'+e.data.id
$('.'+table_list_class).removeClass('occupied needs_help needs_payment active_order').removeClass(table_list_class)
else if e.event == 'order_closed'
order.markClosed() if App and order = App.Order.findCached(e.data.id)
else if e.event == 'list_helped'
if App and list = App.List.findCached(e.data.id)
list.markHelped()
list.markClosed() if list = App.List.findCached(e.data.id)
else if e.event == 'order_closed'
order.markClosed() if order = App.Order.findCached(e.data.id)
else if e.event == 'list_helped'
list.markHelped() if list = App.List.findCached(e.data.id)
# list_id = e.data.id
# $('#list-needs-help-indicator-'+list_id).addClass('hide')
# $('#list-is-helped-button-'+list_id).addClass('hide')
# $('.section-table-list-'+list_id).removeClass('needs_help')
else if e.event == 'order_being_processed'
if App and order = App.Order.findCached(e.data.id)
order.markActive()
# $('#order-in-process-button-'+e.data.id).hide()
# $('.order-row-'+e.data.id).removeClass('placed').addClass('active')
order.markActive() if order = App.Order.findCached(e.data.id)
else if e.event == 'order_being_delivered'
if App and order = App.Order.findCached(e.data.id)
order.markDelivered()
# $('.order-row-'+e.data.id).remove()
# $('.section-table-list-'+e.data.list_id).removeClass('active_order')
order.markDelivered() if order = App.Order.findCached(e.data.id)
else if e.event == 'orders_in_process_count'
$('.supplier-orders-in-process-count-number').text e.data.count
else if e.event == 'orders_placed_count'
@@ -97,166 +75,145 @@ root.Qsupplier=
new_table.set('active_list', list) # making reverse association
else if e.event == 'order_cancelled'
if App and order = App.Order.findCached(e.data.id)
order.markCancelled()
order.markCancelled() if order = App.Order.findCached(e.data.id)
# old stuff
#list = new List(e.data.list)
#list_row = $('.list-row-'+list.id())
#list_row.find('.table_number').text(list.table_number()).addClass('changed')
#list_row.find('.section_title').text(e.data.section_title)
#order_rows = $('.of-list-'+list.id())
#order_rows.find('.table_number').text(list.table_number()).addClass('changed')
#order_rows.find('.section_title').text(e.data.section_title)
## Move properties from table in section tables view
#window.last_data = e.data
#from_table = $('#section-table-'+e.data.from_table_id)
#to_table = $('#section-table-'+list.table_id())
#if to_table.length
#to_table.addClass('section-table-list-'+list.id())
#to_table.addClass('occupied')
#to_table.addClass('needs_help') if list.needs_help()
#to_table.addClass('needs_payment') if list.needs_payment()
#to_table.addClass('active_order') if list.has_active_orders()
#from_table.removeClass('occupied needs_help needs_payment active_order section-table-list-'+list.id())
false
move_table_to_active_section: (table_id)->
table_container = $('#section-table-'+table_id)
section_container = $('.section-tables-active')
section_container.append(table_container)
Qsupplier.position_table_in_active_section(section_container, table_container, true)
# Set the section id of the table in the database
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {section_id: current_section_id}},
dataType: 'json'
)
position_table_in_active_section: (section_container, table_container, make_draggable)->
make_draggable ||= false
button_container = table_container.find('.action-button-container')
button_container.html('')
button_container.append($('<button class="btn btn-warning btn-mini">x</button>').click( -> Qsupplier.move_table_to_inactive_section(table_container.data('table-id')) ))
position_x = parseFloat(table_container.data('position-x'))
position_y = parseFloat(table_container.data('position-y'))
table_container.css('left', section_container.width()*position_x/current_section_width)
table_container.css('top', section_container.height()*position_y/current_section_height)
#TODO place element at 0.0 if it happens to be outside the region
table_container.show()
table_container.draggable(
containment: section_container,
stop: ->
position_x = current_section_width * $(this).position().left / section_container.width()
position_y = current_section_height * $(this).position().top / section_container.height()
table_container.data('position-x', position_x)
table_container.data('position-y', position_y)
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {position_x: position_x, position_y: position_y}},
dataType: 'json'
)
) if make_draggable
move_table_to_inactive_section: (table_id)->
table_container = $('#section-table-'+table_id)
table_container.css('left', 'auto')
table_container.css('top', 'auto')
section_container = $('.section-tables-inactive')
section_container.prepend(table_container)
button_container = table_container.find('.action-button-container')
button_container.html('')
button_container.append($('<button class="btn btn-primary btn-mini">+</button>').click( -> Qsupplier.move_table_to_active_section(table_container.data('table-id')) ))
#TODO make ajax call safe
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {section_id: ''}},
dataType: 'json'
)
load_active_lists: () ->
$.get('/supplier/active_lists.json?section_id='+($('.section_selector').val() || ''), (res) =>
body = $('#active-lists-table tbody')
body.find('tr').remove()
foot = $('#active-lists-table tfoot')
for list in res.lists
body.append @mustache('#active-list-template', new List(list))
)
mark_list_as_helped: (list_id)->
$.post('/supplier/mark_list_as_helped', {list_id: list_id}, (res)->
)
close_list: (list_id)->
$.post('/supplier/close_list', {list_id: list_id}, (res)->
)
load_active_orders: () ->
$.get('/supplier/active_orders.json?section_id='+($('.section_selector').val() || ''), (res) =>
body = $('#active-orders-table tbody')
body.html('')
foot = $('#active-orders-table tfoot')
return unless res.orders
for order in res.orders
ord = new Order(order)
body.append @mustache('#active-order-template', ord)
)
mark_order_in_process: (order_id)->
$.post('/supplier/mark_order_in_process', {order_id: order_id})
mark_order_delivered: (order_id)->
$.post('/supplier/order_is_delivered', {order_id: order_id})
load_list: (list_id) ->
$.get(data_host + '/supplier/lists/'+list_id+'.json?old_style=1', (res) ->
body = $('#list-table tbody')
foot = $('#list-table tfoot')
Qsupplier.build_list_table(body, foot, res)
)
build_list_table: (body, foot, res) ->
body.html('')
return unless res.orders
for order in res.orders
body.append @mustache('#list-order-template', new Order(order))
foot.find('.list-total').html(currency(res.total_amount))
update_section_tables_view: (section_id)->
$.get(data_host + '/supplier/sections/'+section_id+'/tables_view.json', (res)->
for table in res.tables
to = $('#section-table-'+table._id)
if table.occupied then to.addClass('occupied') else to.removeClass('occupied')
if table.needs_help then to.addClass('needs_help') else to.removeClass('needs_help')
if table.needs_payment then to.addClass('needs_payment') else to.removeClass('needs_payment')
if table.active_order then to.addClass('active_order') else to.removeClass('active_order')
)
add_tables_to_active_section: ->
number_start = $('#add-tables-number-start').val()
number_end = $('#add-tables-number-end').val()
$.post('/supplier/sections/'+current_section_id+'/add_tables', {number_start: number_start, number_end: number_end}, -> window.location.reload())
#$('#add-tables-modal').modal('hide')
false
arrange_tables_of_active_section: ->
option = $('input[name=arrange-table-option]:checked').val()
by_row_count = parseInt($('#arrange-tables-by-row-count').val())
by_column_count = parseInt($('#arrange-tables-by-column-count').val())
if(option == "by_row")
return @alert(t('section.arrange_tables.by_row_no_row_count')) unless by_row_count && by_row_count > 0
if(option == "by_column")
return @alert(t('section.arrange_tables.by_column_no_column_count')) unless by_column_count && by_column_count > 0
$.post '/supplier/sections/'+current_section_id+'/arrange_tables', {option: option, row_count: by_row_count, column_count: by_column_count}, (response)=>
if response.ok then window.location.reload() else @alert(t(response.message))
false
mustache: (selector, locals)->
html = $(selector).html()
return '' unless html
template = Handlebars.compile(html)
container = $('<div></div>')
container.html(template(locals))
setTranslations(container)
return container.html()
locs = $.extend(locals,
currency: ->
(val)->
currency(Mustache.render(val, this))
)
Mustache.to_html(html, locs)
alert: Qwaiter.alert
# move_table_to_active_section: (table_id)->
# table_container = $('#section-table-'+table_id)
# section_container = $('.section-tables-active')
# section_container.append(table_container)
# Qsupplier.position_table_in_active_section(section_container, table_container, true)
#
# # Set the section id of the table in the database
# $.ajax(
# type: 'PUT',
# url: '/supplier/tables/'+table_container.data('table-id'),
# data: {table: {section_id: current_section_id}},
# dataType: 'json'
# )
# position_table_in_active_section: (section_container, table_container, make_draggable)->
# make_draggable ||= false
# button_container = table_container.find('.action-button-container')
# button_container.html('')
# button_container.append($('<button class="btn btn-warning btn-mini">x</button>').click( -> Qsupplier.move_table_to_inactive_section(table_container.data('table-id')) ))
# position_x = parseFloat(table_container.data('position-x'))
# position_y = parseFloat(table_container.data('position-y'))
# table_container.css('left', section_container.width()*position_x/current_section_width)
# table_container.css('top', section_container.height()*position_y/current_section_height)
# #TODO place element at 0.0 if it happens to be outside the region
# table_container.show()
# table_container.draggable(
# containment: section_container,
# stop: ->
# position_x = current_section_width * $(this).position().left / section_container.width()
# position_y = current_section_height * $(this).position().top / section_container.height()
# table_container.data('position-x', position_x)
# table_container.data('position-y', position_y)
# $.ajax(
# type: 'PUT',
# url: '/supplier/tables/'+table_container.data('table-id'),
# data: {table: {position_x: position_x, position_y: position_y}},
# dataType: 'json'
# )
# ) if make_draggable
# move_table_to_inactive_section: (table_id)->
# table_container = $('#section-table-'+table_id)
# table_container.css('left', 'auto')
# table_container.css('top', 'auto')
# section_container = $('.section-tables-inactive')
# section_container.prepend(table_container)
# button_container = table_container.find('.action-button-container')
# button_container.html('')
# button_container.append($('<button class="btn btn-primary btn-mini">+</button>').click( -> Qsupplier.move_table_to_active_section(table_container.data('table-id')) ))
# #TODO make ajax call safe
# $.ajax(
# type: 'PUT',
# url: '/supplier/tables/'+table_container.data('table-id'),
# data: {table: {section_id: ''}},
# dataType: 'json'
# )
#
# load_active_lists: () ->
# $.get('/supplier/active_lists.json?section_id='+($('.section_selector').val() || ''), (res) =>
# body = $('#active-lists-table tbody')
# body.find('tr').remove()
# foot = $('#active-lists-table tfoot')
# for list in res.lists
# body.append @mustache('#active-list-template', new List(list))
# )
# mark_list_as_helped: (list_id)->
# $.post('/supplier/mark_list_as_helped', {list_id: list_id}, (res)->
# )
# close_list: (list_id)->
# $.post('/supplier/close_list', {list_id: list_id}, (res)->
# )
#
# load_active_orders: () ->
# $.get('/supplier/active_orders.json?section_id='+($('.section_selector').val() || ''), (res) =>
# body = $('#active-orders-table tbody')
# body.html('')
# foot = $('#active-orders-table tfoot')
# return unless res.orders
# for order in res.orders
# ord = new Order(order)
# body.append @mustache('#active-order-template', ord)
# )
# mark_order_in_process: (order_id)->
# $.post('/supplier/mark_order_in_process', {order_id: order_id})
# mark_order_delivered: (order_id)->
# $.post('/supplier/order_is_delivered', {order_id: order_id})
#
# load_list: (list_id) ->
# $.get(data_host + '/supplier/lists/'+list_id+'.json?old_style=1', (res) ->
# body = $('#list-table tbody')
# foot = $('#list-table tfoot')
# Qsupplier.build_list_table(body, foot, res)
# )
# build_list_table: (body, foot, res) ->
# body.html('')
# return unless res.orders
# for order in res.orders
# body.append @mustache('#list-order-template', new Order(order))
# foot.find('.list-total').html(currency(res.total_amount))
# update_section_tables_view: (section_id)->
# $.get(data_host + '/supplier/sections/'+section_id+'/tables_view.json', (res)->
# for table in res.tables
# to = $('#section-table-'+table._id)
# if table.occupied then to.addClass('occupied') else to.removeClass('occupied')
# if table.needs_help then to.addClass('needs_help') else to.removeClass('needs_help')
# if table.needs_payment then to.addClass('needs_payment') else to.removeClass('needs_payment')
# if table.active_order then to.addClass('active_order') else to.removeClass('active_order')
#
# )
# add_tables_to_active_section: ->
# number_start = $('#add-tables-number-start').val()
# number_end = $('#add-tables-number-end').val()
# $.post('/supplier/sections/'+current_section_id+'/add_tables', {number_start: number_start, number_end: number_end}, -> window.location.reload())
# #$('#add-tables-modal').modal('hide')
# false
# arrange_tables_of_active_section: ->
# option = $('input[name=arrange-table-option]:checked').val()
# by_row_count = parseInt($('#arrange-tables-by-row-count').val())
# by_column_count = parseInt($('#arrange-tables-by-column-count').val())
# if(option == "by_row")
# return @alert(t('section.arrange_tables.by_row_no_row_count')) unless by_row_count && by_row_count > 0
# if(option == "by_column")
# return @alert(t('section.arrange_tables.by_column_no_column_count')) unless by_column_count && by_column_count > 0
# $.post '/supplier/sections/'+current_section_id+'/arrange_tables', {option: option, row_count: by_row_count, column_count: by_column_count}, (response)=>
# if response.ok then window.location.reload() else @alert(t(response.message))
# false
# mustache: (selector, locals)->
# html = $(selector).html()
# return '' unless html
# template = Handlebars.compile(html)
# container = $('<div></div>')
# container.html(template(locals))
# setTranslations(container)
# return container.html()
# locs = $.extend(locals,
# currency: ->
# (val)->
# currency(Mustache.render(val, this))
# )
# Mustache.to_html(html, locs)
# alert: Qwaiter.alert
-1
View File
@@ -1,7 +1,6 @@
doctype html
html lang="en"
head
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"
meta name="viewport" content="width=device-width, initial-scale=1.0"
title= content_for?(:title) ? yield(:title) : application_title
@@ -102,3 +102,19 @@ Feature: Supplier main board
When I click on the close list button in the supplier dashboard
And confirm the supplier close list modal
Then the supplier placed orders counter should be reduced
@javascript
Scenario: Selecting a specific section limits the result to the lists and orders of those sections
Given there is an active list and order
And there is another section with table
And I am signed in as supplier
When a new order on a table in another section is created
Then I should see the list and the new list
And I should see the order and the new order
When I select the section in the supplier dashboard
Then I should see the list and order but not the new list and new order
When I select the other section in the supplier dashboard
Then I should see the new list and new order but not the list and order
When I reset the section selector in the supplier dashboard
Then I should see the list and the new list
And I should see the order and the new order
+12 -19
View File
@@ -2,7 +2,7 @@ Feature: Supplier section view
@javascript
Scenario: the section view displays tables and keeps their status information
And there is an active list and order
Given there is an active list and order
And I am signed in as supplier
When I visit the supplier section path
@@ -37,24 +37,6 @@ Feature: Supplier section view
And I wait 1 second
Then the section table should not have any active list markings anymore
And the list should be marked as closed
And I wait 3 seconds
@javascript
Scenario: Selecting a specific section limits the result to the lists and orders of those sections
Given there is an active list and order
And there is another section with table
And I am signed in as supplier
And a new order on a table in another section is created
Then I should see the list and the new list
And I should see the order and the new order
When I select the section in the supplier dashboard
Then I should see the list and order but not the new list and new order
When I select the other section in the supplier dashboard
Then I should see the new list and new order but not the list and order
When I reset the section selector in the supplier dashboard
Then I should see the list and the new list
And I should see the order and the new order
@javascript
Scenario: Going to edit mode and change section properties
@@ -82,6 +64,17 @@ Feature: Supplier section view
When the supplier clicks on the table having the new list in the section view
Then the supplier table actions of the new list should be visible
@javascript
Scenario: List moves table in section view when the table changes
Given there is an active list and order
And there is another table in the section
And I am signed in as supplier
And I visit the supplier section path
Then the list should be linked to the original table in the section view
When the list changes to another table
Then the list should be linked to the other table in the section view
And the section table should not have any active list markings anymore
# capybara-webkit 1.1.0 drag to is not yet supported it seems
@javascript @broken
Scenario: Dragging a table to another section
@@ -21,6 +21,10 @@ step "the user has an active list with a/an :order_status order" do |order_statu
end
end
step "the list changes to another table" do
@list.move_to_table! @other_table
end
step "the list should be marked as closed" do
@list.reload
@list.state.should == 'closed'
@@ -16,3 +16,7 @@ end
step "the other user does not see order buttons" do
page.should_not have_selector '.order-product-button'
end
step "there is another table in the section" do
@other_table = create :table, number: 126, section: @section, supplier: @supplier
end
@@ -131,7 +131,7 @@ step "I click on the section main board section jumper" do
end
step "the active list changes to another table in another section" do
@list.move_to_table! @other_table
step "the list changes to another table"
end
step "the supplier main board table number should be updated to the new table number" do
@@ -132,3 +132,13 @@ end
step "the supplier table actions of the new list should be visible" do
page.should have_selector ".section-table-#{@table.id} .table-actions .close-list-button"
end
step "the list should be linked to the original table in the section view" do
step "the section table should be marked as having an active order"
end
step "the list should be linked to the other table in the section view" do
table = page.find(".section-table-#{@other_table.id}")
table['class'].should include 'active_order'
table['class'].should include 'occupied'
end