Fixes for event stream and section view actions

This commit is contained in:
2014-07-28 15:13:18 +02:00
parent 2c4c51fe77
commit 48e1850200
17 changed files with 76 additions and 40 deletions
@@ -5,7 +5,7 @@ Qsupplier.App.Table = DS.Model.extend
height: attr 'number' height: attr 'number'
position_x: attr 'number' position_x: attr 'number'
position_y: attr 'number' position_y: attr 'number'
occupied: attr 'boolean' # occupied: attr 'boolean'
section: DS.belongsTo('section') section: DS.belongsTo('section')
#active_list: DS.belongsTo('list', key: 'active_list') #active_list: DS.belongsTo('list', key: 'active_list')
active_list: DS.belongsTo('list') active_list: DS.belongsTo('list')
@@ -13,3 +13,4 @@ Qsupplier.App.Table = DS.Model.extend
#active_list: (-> #active_list: (->
#@get('list') #@get('list')
#).property('list') #).property('list')
occupied: (-> !!@get('active_list')).property('active_list.id')
@@ -1,5 +1,6 @@
Qsupplier.App.ApplicationView = Ember.View.extend Qsupplier.App.ApplicationView = Ember.View.extend
didInsertElement: -> didInsertElement: ->
Qsupplier.watch_events()
selector_mappings = selector_mappings =
'.top-menu-root': '/' '.top-menu-root': '/'
'.top-menu-lists': 'lists' '.top-menu-lists': 'lists'
@@ -22,7 +22,7 @@ Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
(@content.get('position_y') || 0) * @containerHeight() / section_height (@content.get('position_y') || 0) * @containerHeight() / section_height
).property('content.section.height', 'content.position_y') ).property('content.section.height', 'content.position_y')
style: (-> style: (->
"position:absolute;width:83px;height:48px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px" "position:absolute;width:83px;height:48px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px"
).property('offsetX', 'offsetY') ).property('offsetX', 'offsetY')
@@ -48,11 +48,11 @@ Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
@$el = @$() @$el = @$()
#@$('.table-actions').hide() #@$('.table-actions').hide()
#title = @$('.table-actions .title').clone() #title = @$('.table-actions .title').clone()
content = @$('.table-actions') @$('.table-actions').hide()
#@$('.table-actions .title').remove() #@$('.table-actions .title').remove()
content.hide()
@$el.on 'click', => @$el.on 'click', =>
content.toggle() if @$el.hasClass('occupied') and not @get('controller.editmode') # duplication of .table-actions because variable gets unshadowed
@$('.table-actions').toggle() if @$el.hasClass('occupied') and not @get('controller.editmode')
#@$el.qtip #@$el.qtip
#content: #content:
#text: content #text: content
@@ -2,7 +2,7 @@ root = exports ? this
root.Qsupplier= root.Qsupplier=
watch_events: -> watch_events: ->
faye = new Faye.Client(event_host) faye = new Faye.Client(event_host)
faye.subscribe "/supplier/"+supplier_id, (e)=> faye.subscribe "/supplier/#{supplier_id}", (e)=>
console.log "Event: #{e.event}" console.log "Event: #{e.event}"
console.log e.data console.log e.data
if(e.event == 'new_order') if(e.event == 'new_order')
@@ -14,14 +14,17 @@ root.Qsupplier=
# console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list" # console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list"
list = order.get('list') list = order.get('list')
list.get('orders').addRecord order list.get('orders').addRecord order
if table = list.get('table')
if table.get('active_list') isnt list
table.set 'active_list', list
, 200 , 200
else if(e.event == 'list_needs_help') else if(e.event == 'list_needs_help')
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id) if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
list.markNeedsHelp() list.markNeedsHelp()
# old stuff # old stuff
$('#list-needs-help-indicator-'+e.data.id).removeClass('hide') # $('#list-needs-help-indicator-'+e.data.id).removeClass('hide')
$('#list-is-helped-button-'+e.data.id).removeClass('hide') # $('#list-is-helped-button-'+e.data.id).removeClass('hide')
$('.section-table-list-'+e.data.id).addClass('needs_help') # $('.section-table-list-'+e.data.id).addClass('needs_help')
else if(e.event == 'list_needs_payment') else if(e.event == 'list_needs_payment')
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id) if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
list.markNeedsPayment() list.markNeedsPayment()
@@ -34,7 +37,6 @@ root.Qsupplier=
else if e.event == 'list_update' else if e.event == 'list_update'
if Qsupplier.App if Qsupplier.App
list = Qsupplier.App.List.updateOrAdd(e.data.list) list = Qsupplier.App.List.updateOrAdd(e.data.list)
debugger
else if e.event == 'list_closed' else if e.event == 'list_closed'
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id) if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
list.markClosed() list.markClosed()
@@ -48,10 +50,10 @@ root.Qsupplier=
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id) if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
list.markHelped() list.markHelped()
list_id = e.data.id # list_id = e.data.id
$('#list-needs-help-indicator-'+list_id).addClass('hide') # $('#list-needs-help-indicator-'+list_id).addClass('hide')
$('#list-is-helped-button-'+list_id).addClass('hide') # $('#list-is-helped-button-'+list_id).addClass('hide')
$('.section-table-list-'+list_id).removeClass('needs_help') # $('.section-table-list-'+list_id).removeClass('needs_help')
else if e.event == 'order_being_processed' else if e.event == 'order_being_processed'
if Qsupplier.App and order = Qsupplier.App.Order.findCached(e.data.id) if Qsupplier.App and order = Qsupplier.App.Order.findCached(e.data.id)
order.markActive() order.markActive()
@@ -22,7 +22,7 @@ App.ApplicationSerializer = DS.ActiveModelSerializer.extend
else else
@_super record, json, relationship @_super record, json, relationship
App.Store = DS.Store.extend App.ApplicationStore = DS.Store.extend
adapter: DS.RESTAdapter.extend adapter: DS.RESTAdapter.extend
namespace: 'user' namespace: 'user'
# user underscored paths # user underscored paths
+6 -6
View File
@@ -30,19 +30,19 @@ class List
view :active_by_table_id_view, type: :custom, map_function: %|function(doc){ view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){ if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.table_id, 1); emit(doc.table_id, 1);
} }
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){ view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){ if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.supplier_id, 1); emit(doc.supplier_id, 1);
} }
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
view :active_by_section_id_view, type: :custom, map_function: %|function(doc){ view :active_by_section_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){ if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
emit(doc.section_id, 1); emit(doc.section_id, 1);
} }
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
@@ -50,7 +50,7 @@ class List
if(doc.ruby_class == 'List' && doc.state == 'active'){ if(doc.ruby_class == 'List' && doc.state == 'active'){
emit([doc.supplier_id, doc.section_id], 1); emit([doc.supplier_id, doc.section_id], 1);
} }
}], reduce_function: '_sum' }], reduce_function: '_sum'
view :for_user_view, type: :custom, map_function: %|function(doc){ view :for_user_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){ if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){
@@ -219,7 +219,7 @@ class List
def approve_join_request_for_user!(user) def approve_join_request_for_user!(user)
if join_request_user_ids.include?(user.id) if join_request_user_ids.include?(user.id)
join_request_user_ids.delete(user.id) join_request_user_ids.delete(user.id)
user.active_list_id = self.id user.active_list_id = self.id
add_user(user) add_user(user)
user.save user.save
self.is_dirty self.is_dirty
@@ -342,7 +342,7 @@ class List
ho[:state] = order.state ho[:state] = order.state
list_total += ho[:total_amount] list_total += ho[:total_amount]
h[:orders] << ho h[:orders] << ho
end end
h[:total_amount] = list_total.round(2) h[:total_amount] = list_total.round(2)
@with_orders_as_json = h @with_orders_as_json = h
end end
@@ -1,7 +1,7 @@
class SupplierExtendedTableSerializer < Qwaiter::Serializer class SupplierExtendedTableSerializer < Qwaiter::Serializer
root 'table' root 'table'
embed :ids, include: true embed :ids, include: true
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied, :active_list_id attributes :number, :width, :height, :position_x, :position_y, :section_id, :active_list_id
#def list_id #def list_id
#object.active_list_id || object.active_list.try(:id) #object.active_list_id || object.active_list.try(:id)
+1 -1
View File
@@ -1,6 +1,6 @@
class SupplierTableSerializer < Qwaiter::Serializer class SupplierTableSerializer < Qwaiter::Serializer
self.root = :table self.root = :table
embed :ids, include: true embed :ids, include: true
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied, :needs_help attributes :number, :width, :height, :position_x, :position_y, :section_id, :needs_help
has_one :supplier, serializer: SupplierSupplierSerializer has_one :supplier, serializer: SupplierSupplierSerializer
end end
+1 -1
View File
@@ -1,6 +1,6 @@
- content_for :head do - content_for :head do
= javascript_include_tag 'supplier/app/application' = javascript_include_tag 'supplier/app/application'
- content_for :footer do /- content_for :footer do
javascript: javascript:
$(function(){ $(function(){
Qsupplier.watch_events(); Qsupplier.watch_events();
@@ -1,4 +1,4 @@
-# DEPRICATED -# DEPRICATED now in ember app
ul#table-actions-list ul#table-actions-list
- if @list - if @list
- if @list.needs_help? - if @list.needs_help?
@@ -1,4 +1,4 @@
- model_class = Section /- model_class = Section
- content_for :head do - content_for :head do
= javascript_include_tag 'supplier/app/application' = javascript_include_tag 'supplier/app/application'
/- content_for :row do /- content_for :row do
@@ -8,7 +8,7 @@
.section-manage-tables.pull-right= link_to content_tag(:span, '', class: 'icon-pencil'), manage_tables_suppliers_section_path(@section), class: 'btn btn-mini' .section-manage-tables.pull-right= link_to content_tag(:span, '', class: 'icon-pencil'), manage_tables_suppliers_section_path(@section), class: 'btn btn-mini'
- for table in @tables - for table in @tables
.section-table.hide[ .section-table.hide[
class="section-table-list-#{table.active_list_id}" id="section-table-#{table.id}" class="section-table-list-#{table.active_list_id}" id="section-table-#{table.id}"
data-position-x=table.position_x data-position-y=table.position_y data-table-id=table.id] data-position-x=table.position_x data-position-y=table.position_y data-table-id=table.id]
.table-number = table.number .table-number = table.number
.status-icons .status-icons
@@ -19,7 +19,7 @@
- @tables.each do |table| - @tables.each do |table|
.section-table-menu-content class="section-table-menu-#{table.id} section-table-list-#{table.active_list_id}" .section-table-menu-content class="section-table-menu-#{table.id} section-table-list-#{table.active_list_id}"
button.btn.btn-info.list-is-helped.hide Question answered! button.btn.btn-info.list-is-helped.hide Question answered!
#add-tables-modal.modal.hide.fade tabindex=-1 role=:dialog aria-labeledby='add-tables-modal-label' aria-hidden=true /#add-tables-modal.modal.hide.fade tabindex=-1 role=:dialog aria-labeledby='add-tables-modal-label' aria-hidden=true
.modal-header .modal-header
button.close type=:button data-dismiss=:modal aria-hidden=true x button.close type=:button data-dismiss=:modal aria-hidden=true x
h3#add-tables-modal-label data-t='section.add_tables.modal.title' = t('supplier.section.add_tables.modal.title') h3#add-tables-modal-label data-t='section.add_tables.modal.title' = t('supplier.section.add_tables.modal.title')
@@ -37,7 +37,7 @@
.modal-footer .modal-footer
button.btn data-dismiss="modal" aria-hidden=true data-t='section.add_tables.modal.close_button' button.btn data-dismiss="modal" aria-hidden=true data-t='section.add_tables.modal.close_button'
button.btn.btn-primary onclick="Qsupplier.add_tables_to_active_section()" data-t='section.add_tables.modal.add_button' button.btn.btn-primary onclick="Qsupplier.add_tables_to_active_section()" data-t='section.add_tables.modal.add_button'
#arrange-tables-modal.modal.hide.fade tabindex=-1 role=:dialog aria-labeledby='add-tables-modal-label' aria-hidden=true /#arrange-tables-modal.modal.hide.fade tabindex=-1 role=:dialog aria-labeledby='add-tables-modal-label' aria-hidden=true
button.close type=:button data-dismiss=:modal aria-hidden=true x button.close type=:button data-dismiss=:modal aria-hidden=true x
h3#arrange-tables-modal-label data-t='section.arrange_tables.modal.title' = t('supplier.section.arrange_tables.modal.title') h3#arrange-tables-modal-label data-t='section.arrange_tables.modal.title' = t('supplier.section.arrange_tables.modal.title')
.modal-body .modal-body
@@ -66,7 +66,7 @@
.modal-footer .modal-footer
button.btn data-dismiss="modal" aria-hidden=true data-t='section.arrange_tables.modal.close_button' button.btn data-dismiss="modal" aria-hidden=true data-t='section.arrange_tables.modal.close_button'
button.btn.btn-primary onclick="Qsupplier.arrange_tables_of_active_section()" data-t='section.arrange_tables.modal.arrange_button' button.btn.btn-primary onclick="Qsupplier.arrange_tables_of_active_section()" data-t='section.arrange_tables.modal.arrange_button'
- content_for :footer do /- content_for :footer do
javascript: javascript:
var current_section_id = '#{@section.id}'; var current_section_id = '#{@section.id}';
var current_section_width = #{@section.width}; var current_section_width = #{@section.width};
@@ -93,7 +93,7 @@
container.html(data); // Create a container to parse translation data container.html(data); // Create a container to parse translation data
setTranslations(container); setTranslations(container);
this.set('content.text', container.html()); this.set('content.text', container.html());
}, },
once: false once: false
}, },
title: { title: {
@@ -30,6 +30,8 @@ Feature: Supplier section view
When the list is marked as in need of payment When the list is marked as in need of payment
Then the section table should be marked as in need of payment Then the section table should be marked as in need of payment
And I wait 0.5 seconds
When I click on the close list button in the section table table popup When I click on the close list button in the section table table popup
And I wait 1 second And I wait 1 second
Then the section table should not have any active list markings anymore Then the section table should not have any active list markings anymore
@@ -64,6 +66,18 @@ Feature: Supplier section view
When I click the supplier section normal mode button When I click the supplier section normal mode button
Then the supplier last section properties should be updated to the new values Then the supplier last section properties should be updated to the new values
@javascript
Scenario: A new order is created when the view is already loaded
Given there is a confirmed and open supplier
And there is a table in the section
And there is a product
And I am signed in as supplier
When I visit the supplier section path
And A new order is placed
Then the table should be marked as occupied and having an active order
When the supplier clicks on the table having the new list
Then the supplier table actions of the new list should be visible
# capybara-webkit 1.1.0 drag to is not yet supported it seems # capybara-webkit 1.1.0 drag to is not yet supported it seems
@javascript @broken @javascript @broken
Scenario: Dragging a table to another section Scenario: Dragging a table to another section
@@ -0,0 +1,5 @@
step "A new order is placed" do
@user ||= create :user
@list = create :list, state: 'active', supplier: @supplier, table: @table, section: @section, user_ids: [@user.id]
@order = @list.place_order products: {@product.id => 2}, user: @user
end
@@ -5,3 +5,7 @@ step "the product :product_name has description :product_description" do |produc
product.save or raise "Cannot save product: #{product.errors.full_messages.to_sentence}" product.save or raise "Cannot save product: #{product.errors.full_messages.to_sentence}"
@product ||= product @product ||= product
end end
step 'there is a product' do
@product = create :product, price: 2.22, supplier: @supplier
end
@@ -3,6 +3,10 @@ step 'there is a table' do
@table ||= create :table, section: @section, supplier: @supplier @table ||= create :table, section: @section, supplier: @supplier
end end
step 'there is a table in the section' do
step 'there is a table'
end
step "the other user sees the table menu" do step "the other user sees the table menu" do
Capybara.session_name = :other_user Capybara.session_name = :other_user
route_should_be 'user#list_products_for_table' route_should_be 'user#list_products_for_table'
@@ -7,10 +7,6 @@ step "there are :count supplier products" do |count|
@products = create_list :product, count.to_i, supplier: @supplier @products = create_list :product, count.to_i, supplier: @supplier
end end
step 'there is a product' do
@product = create :product, supplier: @supplier
end
step "the supplier fills in the new product form selecting the first product category" do step "the supplier fills in the new product form selecting the first product category" do
find('#product_name').set 'New product' find('#product_name').set 'New product'
find('#product_code').set 'NL0487' find('#product_code').set 'NL0487'
@@ -31,6 +31,11 @@ step "the section table should not be marked as in need of help" do
table['class'].should_not include 'needs_help' table['class'].should_not include 'needs_help'
end end
step 'Then the table should be marked as occupied and having an active order' do
classes = find(".section-table-#{@table.id}")['class'].split(/\s+/)
expect(classes & %w[occupied active_order]).to eq & %w[occupied active_order]
end
step "I click on section table as a supplier" do step "I click on section table as a supplier" do
table = page.find(".section-table-#{@table.id}") table = page.find(".section-table-#{@table.id}")
table.click table.click
@@ -41,27 +46,31 @@ step "the section table should be marked as in need of payment" do
end end
step "A popup having table options should appear in supplier section area" do step "A popup having table options should appear in supplier section area" do
page.should have_selector(".table-actions-#{@table.id}") page.should have_selector(".section-table-#{@table.id} .table-actions")
end end
step "I click on the mark list as helped in the section table popup as supplier" do step "I click on the mark list as helped in the section table popup as supplier" do
btn = page.find(".list-is-helped-button-#{@list.id}") # btn = page.find(".list-is-helped-button-#{@list.id}")
btn.click page.find(".section-table-#{@table.id} .mark_list_as_helped").click
# btn.click
end end
step "the section table popup should no longer have the mark list as helped button" do step "the section table popup should no longer have the mark list as helped button" do
page.should_not have_selector(".list-is-helped-button-#{@list.id}") page.should_not have_selector(".section-table-#{@table.id} .mark_list_as_helped")
end end
step "I click on the close list button in the section table table popup" do step "I click on the close list button in the section table table popup" do
# first click on the table to open the table actions popup
table = page.find(".section-table-#{@table.id}") table = page.find(".section-table-#{@table.id}")
table.click table.click
page.find(".table-actions-#{@table.id} .close-list").click # now click the close list button inside the table actions popup
page.find(".section-table-#{@table.id} .table-actions .close-list-button").click
end end
step "the section table should not have any active list markings anymore" do step "the section table should not have any active list markings anymore" do
table = page.find(".section-table-#{@table.id}") table = page.find(".section-table-#{@table.id}")
css_class = table['class'] css_class = table['class']
binding.pry
css_class.should_not include 'needs_help' css_class.should_not include 'needs_help'
css_class.should_not include 'occupied' css_class.should_not include 'occupied'
css_class.should_not include 'active_order' css_class.should_not include 'active_order'