Model relation fixes and mobile device improvements

This commit is contained in:
2015-10-12 14:35:25 +02:00
parent 7ee9504382
commit a6c74f1872
20 changed files with 83 additions and 63 deletions
@@ -50,7 +50,11 @@ App.MenuProductComponent = Ember.Component.extend
removeProductVariant: (product_variant)-> removeProductVariant: (product_variant)->
product_variant.destroyRecord() product_variant.destroyRecord()
didInsertElement: -> didInsertElement: ->
@set 'editMode', true if @get('product.isNew') if @get('product.isNew')
@set 'editMode', true
Ember.run.later =>
@$('input:first').focus()
, 300
namePlaceholder: (-> t "attributes.product.name").property() namePlaceholder: (-> t "attributes.product.name").property()
pricePlaceholder: (-> t "attributes.product.price").property() pricePlaceholder: (-> t "attributes.product.price").property()
codePlaceholder: (-> t "attributes.product.code").property() codePlaceholder: (-> t "attributes.product.code").property()
@@ -1,6 +1,6 @@
App.SectionsHeaderComponent = Ember.Component.extend App.SectionsHeaderComponent = Ember.Component.extend
classNames: ['sections-switcher-container', 'main-section-header'] classNames: ['sections-switcher-container', 'main-section-header']
sections: (-> @get('targetObject.store').peekAll('section') ).property() sections: Ember.computed -> @store.peekAll('section')
actions: actions:
setSection: (section)-> setSection: (section)->
if section and section is @get('active_section') if section and section is @get('active_section')
@@ -1,14 +1,15 @@
App.IndexController = Ember.Controller.extend App.IndexController = Ember.Controller.extend
show_lists: true show_lists: true
show_orders: true show_orders: true
lists: (-> @store.peekAll('list')).property() loading_data: true
lists: Ember.computed -> @store.peekAll('list')
orders: Ember.computed -> @store.peekAll('order') orders: Ember.computed -> @store.peekAll('order')
sections: (-> @store.peekAll('section')).property() sections: Ember.computed -> @store.peekAll('section')
active_section: Ember.computed.alias 'globals.active_section' #active_section: Ember.computed.alias 'globals.active_section'
active_lists: Ember.computed 'lists.@each.state', 'active_section.id', 'lists.@each.table', -> active_lists: Ember.computed 'lists.@each.state', 'globals.active_section.id', 'lists.@each.table', ->
@get('orders') # trigger orders, otherwise observers are not initialized/triggered (active_orders) @get('orders') # trigger orders, otherwise observers are not initialized/triggered (active_orders)
if section_id = @get('active_section.id') if section_id = @get('globals.active_section.id')
lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' ) lists = @get('lists').filter (l)=>( l.get('table.section.id') == section_id && l.get('state') == 'active' )
else else
lists = @get('lists').filterBy('state', 'active') lists = @get('lists').filterBy('state', 'active')
lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness
@@ -27,4 +27,5 @@ App.MenuController = Ember.Controller.extend
model: @store.createRecord('product_category', position: @get('product_categories.length')) model: @store.createRecord('product_category', position: @get('product_categories.length'))
close: -> @get('model').deleteRecord() close: -> @get('model').deleteRecord()
addProduct: (product_category)-> addProduct: (product_category)->
product_category.get('products').addObject @store.createRecord 'product', position: product_category.get('products.length') product = @store.createRecord 'product', position: product_category.get('products.length')
product_category.get('products').addObject product
@@ -14,6 +14,8 @@ App.modals.EmployeeEditController = App.modals.BaseController.extend
'#8A2BE2' '#8A2BE2'
'#458B00' '#458B00'
'#EEAD0E' '#EEAD0E'
'#FF1493'
'#8B0A50'
] ]
).property() ).property()
actions: actions:
@@ -11,6 +11,8 @@ App.modals.SectionAreaController = App.modals.BaseController.extend
'#8A2BE2' '#8A2BE2'
'#458B00' '#458B00'
'#EEAD0E' '#EEAD0E'
'#FF1493'
'#8B0A50'
] ]
).property() ).property()
actions: actions:
@@ -2,5 +2,5 @@ App.OrdersDisplayController = Ember.Controller.extend
sections: Ember.computed -> @store.peekAll('section') sections: Ember.computed -> @store.peekAll('section')
orders: Ember.computed 'model.[]', 'globals.active_section.id', -> orders: Ember.computed 'model.[]', 'globals.active_section.id', ->
orders = @get('model').filterBy('needs_supplier_attention') orders = @get('model').filterBy('needs_supplier_attention')
orders = orders.filterBy('list.section.id', id) if id = @get('globals.active_section.id') orders = orders.filterBy('list.table.section.id', id) if id = @get('globals.active_section.id')
orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
@@ -4,6 +4,7 @@ Globals = Ember.Object.extend
isDragging: false isDragging: false
active_section: null active_section: null
flash_message: '' flash_message: ''
modal_active: false
locale: Qstorage.getItem('locale') locale: Qstorage.getItem('locale')
App.initializer App.initializer
name: 'injectCurrent' name: 'injectCurrent'
@@ -12,10 +12,9 @@ App.List = DS.Model.extend
closed_at: DS.attr('date') closed_at: DS.attr('date')
users: DS.hasMany('user', async: false) users: DS.hasMany('user', async: false)
#table_number: attr 'number' #table_number: attr 'number'
table: DS.belongsTo('table', inverse: 'active_list', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work table: DS.belongsTo('table', inverse: 'active_list', async: true) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
#users: DS.hasMany('user', inverse: 'active_list') #users: DS.hasMany('user', inverse: 'active_list')
orders: DS.hasMany('order', async: false) orders: DS.hasMany('order', async: false)
section: DS.belongsTo('section', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
# COMPUTED PROPERTIES # COMPUTED PROPERTIES
active: Ember.computed.equal 'state', 'active' active: Ember.computed.equal 'state', 'active'
@@ -6,7 +6,7 @@ App.Table = DS.Model.extend
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', async: false)
#active_list: DS.belongsTo('list', key: 'active_list') #active_list: DS.belongsTo('list', key: 'active_list')
active_list: DS.belongsTo('list', async: true) active_list: DS.belongsTo('list', async: true)
#list: DS.belongsTo('list') #list: DS.belongsTo('list')
@@ -4,7 +4,7 @@ App.User= DS.Model.extend
uid: attr('string') uid: attr('string')
provider: attr('string') provider: attr('string')
avatar: attr('string') avatar: attr('string')
list: DS.belongsTo('list') # in ember scope not many to many (yet) lists: DS.hasMany('list') # in ember scope not many to many (yet)
join_requests: DS.hasMany('join_request') join_requests: DS.hasMany('join_request')
avatar_tag: Ember.computed 'avatar', 'name', -> avatar_tag: Ember.computed 'avatar', 'name', ->
avatar = @get('avatar') || "#{$asset_path}/supplier/unknown-avatar.png" avatar = @get('avatar') || "#{$asset_path}/supplier/unknown-avatar.png"
@@ -17,7 +17,8 @@ App.ApplicationRoute = Ember.Route.extend
#@sections = @store.findAll 'section' #@sections = @store.findAll 'section'
#Ember.RSVP.all([@product_categories, @sections]).then (results)=> #Ember.RSVP.all([@product_categories, @sections]).then (results)=>
@supplier.reload().then => @supplier.reload().then =>
@store.query('list', state: 'active') #.then (lists) -> lists.invoke('get', 'table') @store.query('list', state: 'active').then => #.then (lists) -> lists.invoke('get', 'table')
@controllerFor('index').set 'loading_data', false
#@lists = @store.peekAll 'list' #@lists = @store.peekAll 'list'
# product_categories = controller.set 'product_categories', @store.peekAll('product_category') # product_categories = controller.set 'product_categories', @store.peekAll('product_category')
#@store.findAll 'order', state: 'active' included in list #@store.findAll 'order', state: 'active' included in list
@@ -76,11 +77,13 @@ App.ApplicationRoute = Ember.Route.extend
outlet: 'modal' outlet: 'modal'
view: 'modal' view: 'modal'
controller: controller controller: controller
@set 'globals.modal_active', true
closeModal: -> closeModal: ->
@disconnectOutlet @disconnectOutlet
outlet: 'modal' outlet: 'modal'
parentView: 'application' parentView: 'application'
@set 'globals.modal_active', false
confirm: (options = {})-> confirm: (options = {})->
@send 'openModal', 'confirm', @send 'openModal', 'confirm',
model: Ember.Object.create model: Ember.Object.create
@@ -131,7 +134,7 @@ App.ApplicationRoute = Ember.Route.extend
@store.pushPayload(data.payload) @store.pushPayload(data.payload)
if order_id = data.payload.data.id if order_id = data.payload.data.id
order = @store.peekRecord('order', order_id) order = @store.peekRecord('order', order_id)
return if @get('globals.active_section.id') and order.get('list.section.id') isnt @get('globals.active_section.id') return if @get('globals.active_section.id') and order.get('list.table.section.id') isnt @get('globals.active_section.id')
@set 'globals.flash_message', order.get('display_with_table') @set 'globals.flash_message', order.get('display_with_table')
try ion.sound.play('water_droplet') try ion.sound.play('water_droplet')
new_list: (data)-> new_list: (data)->
@@ -34,7 +34,7 @@ if editMode
= t 'product_variant.add_product_variant' = t 'product_variant.add_product_variant'
else else
if showProduct if showProduct
.row .row.show-menu-product-row
.small-3.columns .small-3.columns
span= product.name span= product.name
= errors product.errors.name includeAttribute="product" = errors product.errors.name includeAttribute="product"
@@ -11,6 +11,6 @@
span.currency=currency list.total span.currency=currency list.total
.actions .actions
= button-mark-list-helped content=list = button-mark-list-helped content=list
= button-remove-list-needs-payment content=list /= button-remove-list-needs-payment content=list
= button-close-list content=list = button-close-list content=list
= button-show-list content=list = button-show-list content=list
@@ -8,6 +8,7 @@
= link-to 'section' order.list.table.section class="link-to-section" = link-to 'section' order.list.table.section class="link-to-section"
span=order.list.table.section.title span=order.list.table.section.title
span.currency=currency order.total span.currency=currency order.total
.show-list-button-container= button-show-list content=order.list
span.time= time order.created_at format="HH:mm" span.time= time order.created_at format="HH:mm"
.actions .actions
= button-mark-order-active order=order = button-mark-order-active order=order
@@ -1,3 +1,6 @@
if loading_data
.row: .small-12.columns: .panel: span.loading
else
.row: .small-12.columns .row: .small-12.columns
= sections-header active_section=globals.active_section = sections-header active_section=globals.active_section
if (can "manage" globals.current_supplier) if (can "manage" globals.current_supplier)
@@ -17,9 +17,10 @@ if list.active
.display-field .display-field
= button-change-list-table list=list = button-change-list-table list=list
.display-row .display-row
.display-label   .display-label.show-for-medium-up  
.display-field .display-field
= button-mark-list-helped content=list = button-mark-list-helped content=list
= button-remove-list-needs-payment content=list
= button-close-list content=list = button-close-list content=list
= users-buttons users=list.users = users-buttons users=list.users
if list.sorted_orders if list.sorted_orders
@@ -26,7 +26,7 @@
.time-range .time-range
color: rgb(39, 6, 121) color: rgb(39, 6, 121)
.edit-product-category-button .edit-product-category-button
+push-button($bg: $secondary-color, $padding: 5px) +push-button($bg: $secondary-color)
color: $warning-color color: $warning-color
font-size: 0.7em font-size: 0.7em
vertical-align: top vertical-align: top
@@ -35,7 +35,7 @@
@extend .fa-lg @extend .fa-lg
@extend .fa-edit @extend .fa-edit
.add-product-product_category-button .add-product-product_category-button
+push-button($bg: $secondary-color) +push-button($bg: $primary-color)
font-size: 0.7em font-size: 0.7em
position: absolute position: absolute
right: 10px right: 10px
@@ -51,7 +51,8 @@
color: #444 color: #444
.time-range .time-range
color: rgb(39, 6, 121) color: rgb(39, 6, 121)
.show-menu-product-row
padding: 4px 0
.menu-product-container .menu-product-container
&.inactive &.inactive
color: #777 color: #777
@@ -70,10 +71,10 @@
font-weight: bold font-weight: bold
.edit-product-action .edit-product-action
+push-button($bg: $secondary-color) +push-button($bg: $secondary-color)
padding: 4px font-size: 0.9em
font-size: 0.7em
span span
@extend .fa, .fa-edit @extend .fa
@extend .fa-edit
.rollback-product-action .rollback-product-action
+push-button($bg: $secondary-color) +push-button($bg: $secondary-color)
color: $warning-color color: $warning-color
@@ -43,6 +43,8 @@
+active-list-div +active-list-div
.link-to-section .link-to-section
+active-list-div +active-list-div
.show-list-button-container
+active-list-div(right)
.currency .currency
+active-list-div +active-list-div
font-weight: bold font-weight: bold
@@ -6,5 +6,4 @@ class Suppliers::ListSerializer
has_many :join_requests, serializer: Suppliers::JoinRequestSerializer has_many :join_requests, serializer: Suppliers::JoinRequestSerializer
has_many :users, serializer: Suppliers::UserSerializer has_many :users, serializer: Suppliers::UserSerializer
has_one :table, serializer: Suppliers::TableSerializer has_one :table, serializer: Suppliers::TableSerializer
has_one :section, serializer: Suppliers::SectionSerializer
end end