Add concept waiter section

This commit is contained in:
2014-03-23 15:30:21 +01:00
parent 37970e5bef
commit 474d5f88c6
45 changed files with 367 additions and 103 deletions
@@ -0,0 +1 @@
#= require_directory .
@@ -0,0 +1,3 @@
Ember.Handlebars.registerBoundHelper 'currency', (amount, params..., options)->
amount = 0.0 if isNaN(amount) || amount== '' || amount == null
new Handlebars.SafeString('€ ' + parseFloat(amount).toFixed(2))
@@ -1,3 +1,4 @@
Qsupplier.App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#ember-app-container'
@App = Qsupplier.App
@@ -2,6 +2,7 @@
#= require ember
#= require ember-data
#= require_directory ./modifications
#= require shared-ember-helpers/all
#= require ./app
#= require_tree .
@EmberENV = {FEATURES: {'query-params-new': true}}
@@ -1,2 +0,0 @@
Ember.Handlebars.registerBoundHelper 'currency', (amount, params..., options)->
new Handlebars.SafeString Qwaiter.currency(amount)
@@ -0,0 +1,3 @@
@App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#ember-app-container'
@@ -0,0 +1,8 @@
#= require_self
#= require handlebars
#= require ember
#= require ember-data
#= require shared-ember-helpers/all
#= require ./app
#= require_tree .
@EmberENV = {FEATURES: {'query-params-new': true}}
@@ -0,0 +1,11 @@
App.ProductCategoriesController = Ember.ArrayController.extend
needs: ['table']
actions:
addProduct: (product)->
if table = @get('controllers.table.model')
if existing = @store.all('product_order').find((po)->po.get('table') == table and po.get('product') == product)
existing.increment()
else
@store.createRecord 'product_order', table: table, product: product
else
alert "Please select a table first"
@@ -0,0 +1 @@
App.SectionsController = Ember.ArrayController.extend {}
@@ -0,0 +1,8 @@
App.TableController = Ember.ObjectController.extend
orderTotal: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity')
actions:
clearProductOrders: ->
@get('product_orders').every (product_order)->product_order.deleteRecord()
@@ -0,0 +1,12 @@
attr = DS.attr
App.List = DS.Model.extend
state: attr 'string'
needs_help: attr 'boolean'
needs_payment: attr 'boolean'
is_paid: attr 'boolean'
has_active_orders: attr 'boolean'
price: attr 'number'
table_number: attr 'number'
table: DS.belongsTo('table', inverse: 'active_list')
section: DS.belongsTo('section')
section_id: attr('string')
@@ -0,0 +1,6 @@
attr = DS.attr
App.Product = DS.Model.extend
name: attr 'string'
price: attr 'number'
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
@@ -0,0 +1,4 @@
attr = DS.attr
App.ProductCategory = DS.Model.extend
name: attr 'string'
products: DS.hasMany('product')
@@ -0,0 +1,8 @@
attr = DS.attr
App.ProductOrder = DS.Model.extend
quantity: attr 'number', defaultValue: 1
product: DS.belongsTo('product')
table: DS.belongsTo('table')
increment: ->
@set('quantity', @get('quantity') + 1)
total: (-> @get('quantity') * @get('product.price')).property('quantity')
@@ -0,0 +1,6 @@
attr = DS.attr
App.Section = DS.Model.extend
title: attr 'string'
width: attr 'number'
height: attr 'number'
tables: DS.hasMany('table')
@@ -0,0 +1,14 @@
attr = DS.attr
App.Table = DS.Model.extend
number: attr 'number'
width: attr 'number'
height: attr 'number'
position_x: attr 'number'
position_y: attr 'number'
occupied: attr 'boolean'
section: DS.belongsTo('section')
product_orders: DS.hasMany('product_order')
#active_list: DS.belongsTo('list')
#active_list: (->
#@get('list')
#).property('list')
@@ -0,0 +1,11 @@
# For more information see: http://emberjs.com/guides/routing/
# and for queryParams: https://github.com/alexspeller/website/blob/a96d9afe4506454b155cc64299e86e558ce3c9f1/source/guides/routing/query-params.md
App.Router.reopen
location: 'history'
rootURL: '/waiter'
App.Router.map ->
@resource 'sections', ->
@resource 'section', path: ':section_id', ->
@resource 'tables', ->
@resource 'table', path: ':table_id'
@@ -0,0 +1,3 @@
App.ApplicationRoute = Ember.Route.extend
setupController: ->
@controllerFor('product_categories').set 'model', @store.find('product_category')
@@ -0,0 +1,2 @@
App.IndexRoute = Ember.Route.extend
redirect: -> @transitionTo('sections')
@@ -0,0 +1,2 @@
App.SectionsRoute = Ember.Route.extend
model: -> @store.find('section')
@@ -0,0 +1,13 @@
# http://emberjs.com/guides/models/defining-a-store/
DS.RESTAdapter.reopen
namespace: 'waiter'
App.ApplicationSerializer = DS.ActiveModelSerializer
App.CustomAdapter = DS.RESTAdapter.extend
# user underscored paths
pathForType: (type)->
decamelized = Ember.String.decamelize(type)
Ember.String.pluralize(decamelized)
App.Store = DS.Store.extend
adapter: App.CustomAdapter
@@ -0,0 +1,5 @@
.row
.twelve.columns
h1 Qwaiter
hr
.waiter-application-container= outlet
@@ -0,0 +1 @@
@@ -0,0 +1,10 @@
h2 Food!
each product_category in controller
if product_category.products
h5= product_category.name
hr
ul.product_category-products
each product in product_category.products
li
a{action addProduct product } href="#" = product.name
@@ -0,0 +1,8 @@
.row
.section-tables.small-12.medium-6.large-4.columns
h2 Tables
each table in tables
= link-to 'table' table class="panel section-table"
= table.number
.small-12.medium-6.large-4.columns= render 'product_categories'
.large-4.columns= outlet
@@ -0,0 +1,10 @@
dl.sub-nav
dt Section:
each section in controller
dd
= link-to 'section' section
= section.title
else
dd No available sections
hr
= outlet
@@ -0,0 +1,19 @@
hr.hide-for-large-up
if product_orders
a.tiny.button.right{action clearProductOrders} href="#" x
h4
| Table
= number
.panel
ul.product-orders
each product_order in product_orders
li
= product_order.quantity
| x
= product_order.product.name
span.currency=currency product_order.product.price
else
li No products
li.total
| Total
span.currency=currency orderTotal
@@ -0,0 +1,7 @@
#= require jquery
#= require jquery_ujs
#= require ./app/application
#= require foundation
#= require_directory .
#= require_self
$(document).foundation()
@@ -0,0 +1,2 @@
//= require foundation
//= require_directory .
@@ -0,0 +1,3 @@
li
span.currency
float: right
@@ -0,0 +1,2 @@
ul.product_category-products
list-style: none
@@ -0,0 +1,8 @@
ul.product-orders
list-style: none
li
border-bottom: 1px solid #ccc
&.total
border-bottom: none
border-top: 4px solid #333
font-weight: bold
@@ -0,0 +1,15 @@
.section-tables
.section-table
width: 72px
float: left
margin-right: 20px
border: 1px solid #d8d8d8
padding: 0.8rem
background-color: #f2f2f2
margin-bottom: 1rem
text-align: center
&:hover
background-color: #e6e6e6
&.active, &.active:hover
background-color: #333
color: white
+21
View File
@@ -0,0 +1,21 @@
class WaiterController < ApplicationController
layout 'waiter'
def index
end
def sections
json = '{"tables":[{"id":"0903d04a003991835f9f32d1821ee05c","number":102,"width":2.0,"height":2.0,"position_x":14.242294520547945,"position_y":3.1862955032119915,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":true,"active_list_id":"1cef487ec268169687f481cb828924c2"},{"id":"0903d04a003991835f9f32d1821efb50","number":100,"width":2.0,"height":2.0,"position_x":6.5,"position_y":6.5,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d15fa","number":11,"width":2.0,"height":2.0,"position_x":6.5,"position_y":1.5,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","occupied":false,"active_list_id":null},{"id":"0903d04a003991835f9f32d1821ededd","number":103,"width":2.0,"height":2.0,"position_x":9.0,"position_y":6.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"0903d04a003991835f9f32d1821eee07","number":101,"width":2.0,"height":2.0,"position_x":2.3333333333333335,"position_y":6.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d0dbd","number":12,"width":2.0,"height":2.0,"position_x":9.854452054794521,"position_y":2.7054794520547945,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d2221","number":10,"width":2.0,"height":2.0,"position_x":6.4811643835616435,"position_y":2.0034246575342465,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null},{"id":"1a9d4cc551dac96f87a21c97ba3d2cf7","number":1,"width":2.0,"height":2.0,"position_x":2.3333333333333335,"position_y":1.5,"section_id":"222fcd43b55e397d11d92ccb601e70dc","occupied":false,"active_list_id":null}],"lists":[{"id":"1cef487ec268169687f481cb828924c2","state":"active","needs_help":true,"needs_payment":false,"is_paid":false,"price":46.8,"table_id":"0903d04a003991835f9f32d1821ee05c","table_number":102,"section_id":"1a9d4cc551dac96f87a21c97ba1e710b","has_active_orders":true,"user_ids":["8afe7cccf1c690e60aa2ace1bf1d8a71"]}],"sections":[{"id":"1a9d4cc551dac96f87a21c97ba1e710b","title":"Ruimte2","path":[[0.0,0.0],[30.0,12.0],[30.0,12.0],[0.0,12.0]],"width":30.0,"height":12.0,"table_ids":["0903d04a003991835f9f32d1821ee05c","0903d04a003991835f9f32d1821efb50","1a9d4cc551dac96f87a21c97ba3d15fa"]},{"id":"222fcd43b55e397d11d92ccb601e70dc","title":"Buiten","path":[[0.0,0.0],[20.0,20.0],[20.0,20.0],[0.0,20.0]],"width":20.0,"height":20.0,"table_ids":["0903d04a003991835f9f32d1821ededd","0903d04a003991835f9f32d1821eee07","1a9d4cc551dac96f87a21c97ba3d0dbd","1a9d4cc551dac96f87a21c97ba3d2221","1a9d4cc551dac96f87a21c97ba3d2cf7"]}]}'
respond_to do |format|
format.html { redirect_to '/waiter'}
format.json { render json: json }
end
end
def product_categories
respond_to do |format|
format.html { redirect_to '/waiter'}
format.json { render json: ProductCategory.all.include_relation(:product), root: 'product_categories', each_serializer: ProductCategorySerializer }
end
end
end
+1
View File
@@ -1,5 +1,6 @@
class Product
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :name
property :code
+1
View File
@@ -1,5 +1,6 @@
class ProductCategory
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :name
property :position, type: Fixnum, default: 0
@@ -0,0 +1,5 @@
class ProductCategorySerializer < Qwaiter::Serializer
embed :ids, include: true
attributes :name
has_many :products
end
+4
View File
@@ -0,0 +1,4 @@
class ProductSerializer < Qwaiter::Serializer
embed :ids, include: true
attributes :name, :price
end
+13
View File
@@ -0,0 +1,13 @@
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 Qwaiter
/= stylesheet_link_tag "waiter/application", media: "all"
= stylesheet_link_tag "waiter/application"
= javascript_include_tag "vendor/modernizr"
= javascript_include_tag "waiter/application"
body
#ember-app-container