All the little details

This commit is contained in:
2015-02-20 19:21:25 +01:00
parent cde551dc7f
commit d9e69beb5f
38 changed files with 256 additions and 57 deletions
@@ -2,7 +2,14 @@ App.SectionsHeaderComponent = Ember.Component.extend
sections: (-> @get('targetObject.store').all('section') ).property() sections: (-> @get('targetObject.store').all('section') ).property()
actions: actions:
setSection: (section)-> setSection: (section)->
if section and section is @get('section')
# click on already active section
#return @transitionTo('section', section.id)
return App.Router.router.transitionTo('section', section)
@$('dd').removeClass('active') @$('dd').removeClass('active')
@$("[data-section=#{if section then section.id else 'all'}]").addClass('active') @$("[data-section=#{if section then section.id else 'all'}]").addClass('active')
@set('section', section) @set('section', section)
didInsertElement: -> @send("setSection", @get('section')) didInsertElement: ->
@$('dd').removeClass('active')
section = @get('section')
@$("[data-section=#{if section then section.id else 'all'}]").addClass('active')
@@ -19,12 +19,6 @@ App.ApplicationController = Ember.Controller.extend
actions: actions:
signOut: -> signOut: ->
window.location = Routes.destroy_employee_session_path() window.location = Routes.destroy_employee_session_path()
markSupplierClosed: ->
return unless supplier = @get('supplier')
supplier.close()
markSupplierOpen: ->
return unless supplier = @get('supplier')
supplier.open_the_place()
showSupplierStatusInfo: -> showSupplierStatusInfo: ->
@modal 'supplier_status_info', @modal 'supplier_status_info',
model: @get('supplier') model: @get('supplier')
@@ -5,15 +5,15 @@ App.IndexController = Ember.ObjectController.extend
lists: (-> @store.all('list')).property() lists: (-> @store.all('list')).property()
orders: (-> @store.all('order')).property() orders: (-> @store.all('order')).property()
sections: (-> @store.all('section')).property() sections: (-> @store.all('section')).property()
active_section: Ember.computed.alias 'controllers.application.active_section'
active_lists: (-> active_lists: (->
if @get('controllers.application.active_section.id') if section_id = @get('active_section.id')
lists = @get('lists').filter (l)=>( l.get('section.id') == @get('controllers.application.active_section.id') && l.get('state') == 'active' ) lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' )
else else
lists = @get('lists').filterProperty('state', 'active') lists = @get('lists').filterProperty('state', 'active')
lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
).property('lists.@each.state', 'controllers.application.active_section.id') ).property('lists.@each.state', 'active_section.id')
active_section: (-> @get('controllers.application.active_section')).property('controllers.application.active_section')
active_orders: (-> active_orders: (->
if @get('active_section.id') if @get('active_section.id')
orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') ) orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') )
@@ -9,9 +9,10 @@
if model = @get('model') if model = @get('model')
translation_params = model.serialize() if model.serialize translation_params = model.serialize() if model.serialize
return tspan(@title_path, translation_params).htmlSafe() if @title_path
# return translated title_path if directly set by options # return translated title_path if directly set by options
return tspan(@get('modal_options.title_path'), translation_params).htmlSafe() if @get('modal_options.title_path') return tspan(@get('modal_options.title_path'), translation_params).htmlSafe() if @get('modal_options.title_path')
# return translated title_path if directly set by controller
return tspan(@title_path, translation_params).htmlSafe() if @title_path
# infer title path based on controller name App.modals.AddSectionController => add_section # infer title path based on controller name App.modals.AddSectionController => add_section
underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()` underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()`
# find translated title or humanize the controller name # find translated title or humanize the controller name
@@ -19,7 +20,7 @@
tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe() tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe()
else else
underscored.capitalize().replace(/_/, ' ') underscored.capitalize().replace(/_/, ' ')
).property('model.id') ).property('model.id', 'modal_options.title_path')
save_error: (error)-> save_error: (error)->
switch error.status switch error.status
when 403 when 403
@@ -27,6 +28,8 @@
else else
@set 'alert_message', 'Something went wrong' @set 'alert_message', 'Something went wrong'
save_success: -> save_success: ->
if save_callback = @get('modal_options.save')
save_callback.apply(@)
@set 'alert_message', '' @set 'alert_message', ''
@send 'closeModal' @send 'closeModal'
@@ -53,9 +56,12 @@
@get('model').save().then @save_success.bind(@), @save_error.bind(@) @get('model').save().then @save_success.bind(@), @save_error.bind(@)
#@send 'closeModal' unless @preventClose #@send 'closeModal' unless @preventClose
destroy: -> destroy: ->
my_scope = @
destroy_callback = @get('modal_options.destroy')
@modal 'confirm', @modal 'confirm',
title_path: @get('modal_options.destroy_text_path') || 'general.destroy.text' title_path: @get('modal_options.destroy_text_path') || 'general.destroy.text'
model: @get('model') model: @get('model')
ok: -> ok: ->
@get('model').destroyRecord() @get('model').destroyRecord()
destroy_callback.call(my_scope) if destroy_callback
@send 'closeModal' unless @preventClose @send 'closeModal' unless @preventClose
@@ -1,6 +1,7 @@
App.modals.SelectEmployeeController = App.modals.BaseController.extend App.modals.SelectEmployeeController = App.modals.BaseController.extend
employee: null employee: null
employees: (-> @store.all 'employee').property() title_path: 'employee.select_modal.title'
employees: (-> @store.all('employee').filterBy('active') ).property()
actions: actions:
selectEmployee: (employee)-> selectEmployee: (employee)->
@set 'employee', employee @set 'employee', employee
@@ -1,6 +1,14 @@
App.ScheduleController = Ember.ArrayController.extend App.ScheduleController = Ember.ArrayController.extend
event_changed: (event)-> event_changed: (event)->
@store.find('employee-shift', event.id).then (employee_shift)-> @store.find('employee-shift', event.id).then (employee_shift)->
employee_shift.set 'start_on', event.start.toDate() employee_shift.set 'start_from', event.start.toDate()
employee_shift.set 'end_on', event.end.toDate() employee_shift.set 'end_on', event.end.toDate()
employee_shift.save() employee_shift.save()
editEvent: (id, callbacks)->
if employee_shift = @store.all('employee-shift').findBy('id', id)
@modal 'employee_shift',
title_path: 'employee_shift.modal.title'
destroy_text_path: 'employee_shift.modal.destroy_confirmation'
model: employee_shift
save: -> callbacks.save.call(@, employee_shift) if callbacks.save
destroy: -> callbacks.destroy.call(@, employee_shift) if callbacks.destroy
@@ -9,9 +9,6 @@ App.SectionsIndexController = Ember.ArrayController.extend
qrPath: (section_id)-> qrPath: (section_id)->
Routes.qr_codes_suppliers_tables_path section_id: section_id Routes.qr_codes_suppliers_tables_path section_id: section_id
actions: actions:
showDashboardOrders: (section)->
@set 'controllers.application.active_section', section
@transitionToRoute('index')
addSection: -> @modal 'add_section', model: @get('model') addSection: -> @modal 'add_section', model: @get('model')
goToSection: (section)-> goToSection: (section)->
@set 'controllers.application.active_section', section @set 'controllers.application.active_section', section
@@ -0,0 +1,11 @@
App.MomentTransform = DS.Transform.extend
deserialize: (serialized)->
return serialized unless serialized
m = moment(serialized)
m._ambigTime = true if serialized.length < 11
m
serialize: (deserialized)->
return deserialized unless deserialized
deserialized = moment(deserialized) unless deserialized._isAMomentObject
deserialized.toISOString()
@@ -1,12 +1,19 @@
attr = DS.attr attr = DS.attr
App.EmployeeShift = DS.Model.extend App.EmployeeShift = DS.Model.extend
start_on: attr('date') start_from: attr('moment')
end_on: attr('date') end_on: attr('moment')
employee: DS.belongsTo 'employee' employee: DS.belongsTo 'employee'
description: attr('string')
calendar_event: (-> calendar_event: (->
id: @id id: @id
title: @get('employee.name') title: @get('title')
start: @get('start_on') start: @get('start_from')
end: @get('end_on') end: @get('end_on')
color: @get('employee.color') color: @get('employee.color')
).property('start_on', 'end_on') ).property('start_from', 'end_on', 'title')
title: Ember.computed 'employee.name', 'description', ->
if @get('description')
[@get('employee.name'), @get('description')].join(' - ')
else
@get 'employee.name'
@@ -54,7 +54,8 @@ App.ApplicationRoute = Ember.Route.extend
defaultModalOptions = defaultModalOptions =
closeOnOverlay: true closeOnOverlay: true
closeOnModalClick: false closeOnModalClick: false
controller.set 'modal_options', $.extend(defaultModalOptions, options) modal_options = Ember.Object.create($.extend(defaultModalOptions, options))
controller.set 'modal_options', modal_options
@render "modals/#{modalName}", @render "modals/#{modalName}",
into: 'application' into: 'application'
outlet: 'modal' outlet: 'modal'
@@ -80,6 +81,19 @@ App.ApplicationRoute = Ember.Route.extend
controller.set 'flash_message', order.get('display_with_table') controller.set 'flash_message', order.get('display_with_table')
setTimeout (-> $('body').removeClass('new-order')), 4000 setTimeout (-> $('body').removeClass('new-order')), 4000
try ion.sound.play('water_droplet') try ion.sound.play('water_droplet')
showDashboardOrders: (section)->
@controllerFor('application').set 'active_section', section
@transitionTo 'index'
markSupplierClosed: ->
controller = @controllerFor('application')
return unless supplier = controller.get('supplier')
controller.modal 'confirm',
title_path: 'supplier.close_for_orders_confirmation'
model: supplier
ok: -> supplier.close()
markSupplierOpen: ->
return unless supplier = @controllerFor('application').get('supplier')
supplier.open_the_place()
events: events:
list_needs_help: (data) -> list_needs_help: (data) ->
if list = @store.getById('list', data.id) if list = @store.getById('list', data.id)
@@ -3,5 +3,5 @@ dl.sections-header-container.sub-nav
each s in sections each s in sections
dd data-section=s.id dd data-section=s.id
a.section-header-title{action "setSection" s} href="#" = s.title a.section-header-title{action "setSection" s} href="#" = s.title
= link-to "section" s.id class="section-jumper" /= link-to "section" s.id class="section-jumper"
span.fa.fa-chevron-circle-right span.fa.fa-chevron-circle-right
@@ -6,7 +6,7 @@ header.top-menu
= link-to 'index' class="top-menu-root" = link-to 'index' class="top-menu-root"
= image_tag "icons/logo-small.png" = image_tag "icons/logo-small.png"
= link-to "menu" class="top-menu-menu" = link-to "menu" class="top-menu-menu"
= t 'supplier.top_menu.menu' = t 'top_menu.menu'
= link-to "sections" class="top-menu-sections" = link-to "sections" class="top-menu-sections"
= t 'models.plural.section' = t 'models.plural.section'
= link-to "tables" class="top-menu-tables" = link-to "tables" class="top-menu-tables"
@@ -16,7 +16,14 @@ header.top-menu
= link-to "employees" class="top-menu-employees" = link-to "employees" class="top-menu-employees"
= t 'models.plural.employee' = t 'models.plural.employee'
= link-to "schedule" class="top-menu-schedule" = link-to "schedule" class="top-menu-schedule"
= t 'supplier.top_menu.schedule' = t 'top_menu.schedule'
if supplier.open
a.supplier-is-closed-indication.is-open{ action "markSupplierClosed" }: span.fa.fa-beer.fa-2x
else
a.supplier-is-closed-indication.is-closed{ action "markSupplierOpen" }
span.fa-stack.fa-lg
i.fa.fa-beer.fa-stack-1x
i.fa.fa-ban.fa-stack-2x.text-alert
.extra-info{action "showSupplierStatusInfo"} .extra-info{action "showSupplierStatusInfo"}
.supplier-info-row .supplier-info-row
.counter.supplier-orders-placed-count .counter.supplier-orders-placed-count
@@ -1,5 +1,9 @@
.row: .small-12.columns .row: .small-12.columns
= sections-header sectionBinding="controller.controllers.application.active_section" = sections-header sectionBinding="controller.controllers.application.active_section"
unless controllers.application.supplier.open
.alert-box.alert.radius data-alert=true
= t 'supplier.you_are_currently_closed_alert'
a{ action "markSupplierOpen" }= t 'supplier.open_for_orders'
.page-header .page-header
div.dashboard-section-selection div.dashboard-section-selection
/App.HomeSectionSelectorView selectionBinding="controller.controllers.application.active_section" content=controller.sections prompt=controllers.application.supplier.name /App.HomeSectionSelectorView selectionBinding="controller.controllers.application.active_section" content=controller.sections prompt=controllers.application.supplier.name
@@ -6,7 +6,7 @@ p=t 'employee.modal.body_header'
= errors model.errors.name = errors model.errors.name
.form-row.name .form-row.name
.form-label=t 'attributes.employee.email' .form-label=t 'attributes.employee.email'
.form-field .form-field.half
= input type="email" valueBinding="model.email" action="save" = input type="email" valueBinding="model.email" action="save"
= errors model.errors.email = errors model.errors.email
if isNotSelf if isNotSelf
@@ -0,0 +1,15 @@
p=t 'employee_shift.modal.body_header'
.form-row.name
.form-label= t 'models.employee'
.form-field= model.employee.name
.form-row.description
.form-label=t 'attributes.employee_shift.description'
.form-field
= input valueBinding="model.description"
= errors model.errors.description
hr
button.modal-close{action "close"}=t 'employee_shift.modal.close_button'
button.modal-confirm.right{action "save"} disabled=model.isInvalid
=t 'employee_shift.modal.save_button'
button.modal-destroy.right{action "destroy"}
=t 'employee_shift.modal.destroy_button'
@@ -4,14 +4,9 @@
= view "section-tab-header" context=section = view "section-tab-header" context=section
can manage sections can manage sections
a.add-section{action "addSection"}: span a.add-section{action "addSection"}: span
can manage sections .section-manage-tables.pull-right
.section-manage-tables.pull-right a.go-to-orders-list{ action "showDashboardOrders" model }: span
App.DropdownLink title="Action" can manage sections
ul
li: a{action "addTables"}: span.section-add-tables-icon=t 'section.add_tables.button_label'
li: a{action "arrangeTables"}: span.section-arrange-tables-icon=t 'section.arrange_tables.modal.title'
li: a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}" target="_blank": span.qr-icon=t 'table.print_qr_codes'
li: a.section-destroy{action "destroySection"}: span.section-remove-icon=t 'helpers.links.destroy'
if editmode if editmode
= input type="text" valueBinding="title" class="section-edit-title-field" = input type="text" valueBinding="title" class="section-edit-title-field"
App.NumberField valueBinding="width" class="dimension section-edit-width-field" App.NumberField valueBinding="width" class="dimension section-edit-width-field"
@@ -20,6 +15,12 @@ can manage sections
a.section-rollback-button{ action "rollbackEditable" }: span a.section-rollback-button{ action "rollbackEditable" }: span
a.section-normal-mode-button{ action "finishEditable" }: span a.section-normal-mode-button{ action "finishEditable" }: span
else else
App.DropdownLink title="Action"
ul
li: a{action "addTables"}: span.section-add-tables-icon=t 'section.add_tables.button_label'
li: a{action "arrangeTables"}: span.section-arrange-tables-icon=t 'section.arrange_tables.modal.title'
li: a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}" target="_blank": span.qr-icon=t 'table.print_qr_codes'
li: a.section-destroy{action "destroySection"}: span.section-remove-icon=t 'helpers.links.destroy'
a.section-edit-mode-button{ action "makeEditable" }: span a.section-edit-mode-button{ action "makeEditable" }: span
= view "section-tables" contentBinding="tables" = view "section-tables" contentBinding="tables"
@@ -31,7 +31,7 @@
/td.currency=currency list.price /td.currency=currency list.price
/td.timestamp=time list.created_at /td.timestamp=time list.created_at
td.actions td.actions
a.section-dashboard-orders{action showDashboardOrders section}: span a.section-dashboard-orders.go-to-orders-list{action "showDashboardOrders" section}: span
a.table-qr-codes{path qr_codes_suppliers_tables section_id=section.id} target="_blank": span.qr-icon a.table-qr-codes{path qr_codes_suppliers_tables section_id=section.id} target="_blank": span.qr-icon
else else
.row: .small-12.columns .row: .small-12.columns
@@ -16,9 +16,9 @@ App.ScheduleView = Ember.View.extend
ok: -> ok: ->
# this context is SelectEmployeeController # this context is SelectEmployeeController
if employee = @get('employee') if employee = @get('employee')
shift = controller.store.createRecord 'employee-shift', start_on: start.toDate(), end_on: end.toDate() shift = controller.store.createRecord 'employee-shift', start_from: start, end_on: end
shift.set 'employee', employee shift.set 'employee', employee
shift.save() shift.save().then ->
placeholder.fullCalendar('renderEvent', shift.get('calendar_event'), true) placeholder.fullCalendar('renderEvent', shift.get('calendar_event'), true)
editable: true editable: true
defaultView: 'agendaWeek' defaultView: 'agendaWeek'
@@ -26,5 +26,12 @@ App.ScheduleView = Ember.View.extend
timezone: 'UTC' timezone: 'UTC'
eventDrop: controller.event_changed.bind(controller) eventDrop: controller.event_changed.bind(controller)
eventResize: controller.event_changed.bind(controller) eventResize: controller.event_changed.bind(controller)
eventClick: (event)->
controller.editEvent event.id,
save: (shift)->
placeholder.fullCalendar('removeEvents', [event.id])
placeholder.fullCalendar('renderEvent', shift.get('calendar_event'), true)
destroy: (shift)->
placeholder.fullCalendar('removeEvents', [event.id])
@@ -14,6 +14,14 @@ App.SectionTablesView = Ember.View.extend DragNDrop.Droppable,
@$el = $(@get('element')) @$el = $(@get('element'))
width = @$el.width() width = @$el.width()
height = width * @get('controller.model.height') / @get('controller.model.width') height = width * @get('controller.model.height') / @get('controller.model.width')
viewport_height = $(window).height() - 52
if height > viewport_height
# Fit screen
correction = viewport_height / height
width = correction * width
@$el.css('width', width)
height = correction * height
@set 'element_width', width @set 'element_width', width
@set 'element_height', height @set 'element_height', height
@$el.css('height', height) @$el.css('height', height)
@@ -25,7 +25,6 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() +
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>; window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>; window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
var path_mapping = { var path_mapping = {
user_root: '/user', user_root: '/user',
join_occupied_table: '/user/join_occupied_table', join_occupied_table: '/user/join_occupied_table',
@@ -21,6 +21,7 @@
@ttry = (path, vars={})-> @ttry = (path, vars={})->
@t(path, $.extend(vars, emptyWhenNotFound: true)) @t(path, $.extend(vars, emptyWhenNotFound: true))
# return translation in the form # return translation in the form
# <span data-t="models.table">Tafel</span> # <span data-t="models.table">Tafel</span>
@tspan = (path, vars={}) -> "<span data-t='#{path}' data-t-attributes='#{JSON.stringify(vars)}'>#{t(path, vars)}</span>" @tspan = (path, vars={}) -> "<span data-t='#{path}' data-t-attributes='#{JSON.stringify(vars)}'>#{t(path, vars)}</span>"
@@ -39,8 +40,11 @@
try try
result = result[part] for part in parts result = result[part] for part in parts
catch err catch err
console.log "[TRANSLATION] Cannot find translation: #{path}"
result = parts[parts.length - 1].capitalize() result = parts[parts.length - 1].capitalize()
result = if vars.emptyWhenNotFound then "" else parts[parts.length - 1].capitalize() result = if vars.emptyWhenNotFound then "" else parts[parts.length - 1].capitalize()
unless result?
console.log "[TRANSLATION] Cannot find translation: #{path}"
return "" if result is "" return "" if result is ""
return parts[parts.length - 1].capitalize() unless result return parts[parts.length - 1].capitalize() unless result
@@ -1254,6 +1254,12 @@ $alert-color: #ee3e41
// Prevent empty columns from collapsing // Prevent empty columns from collapsing
.column, .columns .column, .columns
min-height: 1px min-height: 1px
.alert-box
&.alert
a
font-weight: bold
padding-left: 10px
color: white
$button-margin: rem-calc(10) $button-margin: rem-calc(10)
$button-qr-code-color: #555 $button-qr-code-color: #555
@@ -14,6 +14,10 @@ $side-spacing: 0px
float: left float: left
.draggable .draggable
cursor: move !important cursor: move !important
.text-alert
color: $alert-color
.text-danger
color: $warning-color
input.dimension input.dimension
width: 52px width: 52px
.location_picker_map .location_picker_map
@@ -53,3 +53,7 @@ $button-spacing: 8px
@extend .fa @extend .fa
@extend .fa-2x @extend .fa-2x
@extend .fa-times @extend .fa-times
.go-to-orders-list
span
@extend .fa
@extend .fa-list-alt
@@ -43,6 +43,11 @@ header.top-menu
margin-left: 8px margin-left: 8px
@media #{$small-only} @media #{$small-only}
margin-left: 5px margin-left: 5px
.supplier-is-closed-indication
float: right
margin-right: 8px
&.is-open
line-height: 60px
.extra-info .extra-info
position: absolute position: absolute
top: 0 top: 0
@@ -1,3 +1,8 @@
.go-to-orders-list
display: inline-block
margin-right: 7px
span
@extend .fa-lg
.section-title .section-title
font-size: 24px font-size: 24px
padding: 4px 0px padding: 4px 0px
@@ -47,6 +47,3 @@ a.table-qr-codes
+button($bg: $secondary-color) +button($bg: $secondary-color)
+button-icon-only +button-icon-only
margin-right: 0.7rem margin-right: 0.7rem
span
@extend .fa
@extend .fa-list-alt
@@ -1,7 +1,8 @@
module Suppliers module Suppliers
class EmployeeShiftsController < Suppliers::ApplicationController class EmployeeShiftsController < Suppliers::ApplicationController
def index def index
render json: current_supplier.employee_shifts, each_serializer: Suppliers::EmployeeShiftSerializer @employee_shifts = EmployeeShift.for_supplier(current_supplier, relevant_from: 1.week.ago)
render json: @employee_shifts, each_serializer: Suppliers::EmployeeShiftSerializer
end end
def create def create
@employee_shift.supplier = current_supplier @employee_shift.supplier = current_supplier
@@ -14,10 +15,16 @@ module Suppliers
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
end end
def destroy
head :forbidden and return unless @employee_shift.supplier_id == current_supplier.id
@employee_shift.destroy
head :ok
end
private private
def employee_shift_params def employee_shift_params
params.require(:employee_shift).permit(:start_on, :end_on, :employee_id) params.require(:employee_shift).permit(:start_from, :end_on, :employee_id, :description)
end end
end end
+13 -2
View File
@@ -2,8 +2,19 @@ class EmployeeShift
include SimplyStored::Couch include SimplyStored::Couch
include ActiveModel::SerializerSupport include ActiveModel::SerializerSupport
property :start_on, type: Time property :start_from
property :end_on, type: Time property :end_on
property :description
belongs_to :supplier belongs_to :supplier
belongs_to :employee belongs_to :employee
view :relevants_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'EmployeeShift' && doc.start_from && doc.end_on){
emit([doc.supplier_id, doc.end_on], 1)
}
}|, reduce_function: '_sum'
def self.for_supplier(supplier, relevant_from: 1.week.ago)
database.view relevants_view(startkey: [supplier.id, relevant_from], endkey: [supplier.id, {}], reduce: false, include_docs: true)
end
end end
@@ -1,5 +1,5 @@
class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer
self.root = :employee_shift self.root = :employee_shift
#embed :ids, include: true #embed :ids, include: true
attributes :start_on, :end_on, :employee_id attributes :start_from, :end_on, :employee_id, :description
end end
@@ -6,16 +6,17 @@ end
module MethodPrependAndAppend module MethodPrependAndAppend
def before_method(m, &blk) def before_method(m, &blk)
alias_method :"#{m}_before_extending", m alias_method :"#{m}_before_extending_before", m
define_method m do define_method m do |*args|
instance_eval(&blk) instance_eval(&blk)
send :"#{m}_before_extending" send :"#{m}_before_extending_before", *args
end end
end end
def after_method(m, &blk) def after_method(m, &blk)
alias_method :"#{m}_before_extending", m alias_method :"#{m}_before_extending_after", m
define_method m do define_method m do |*args|
result = send :"#{m}_before_extending" result = send :"#{m}_before_extending_after", *args
instance_eval(result, &blk) instance_eval(result, &blk)
end end
end end
+7
View File
@@ -13,6 +13,7 @@ en:
join_request: Join request join_request: Join request
user_feedback: User feedback user_feedback: User feedback
employee: Employee employee: Employee
employee_shift: Shift
plural: plural:
user: Users user: Users
supplier: Restaurants supplier: Restaurants
@@ -26,6 +27,7 @@ en:
join_request: Join requests join_request: Join requests
user_feedback: User feedbacks user_feedback: User feedbacks
employee: Employees employee: Employees
employee_shift: Shifts
attributes: attributes:
product_category: product_category:
name: Name name: Name
@@ -72,3 +74,8 @@ en:
employee: employee:
name: Name name: Name
email: 'E-mail' email: 'E-mail'
manager: 'Manager?'
active: 'Active?'
color: Color
employee_shift:
description: Description
+11
View File
@@ -12,6 +12,7 @@ nl:
section: Afdeling section: Afdeling
join_request: Deelname verzoek join_request: Deelname verzoek
employee: Werknemer employee: Werknemer
employee_shift: Shift
plural: plural:
user: Gebruikers user: Gebruikers
supplier: Restaurants supplier: Restaurants
@@ -24,6 +25,7 @@ nl:
section: Afdelingen section: Afdelingen
join_request: Deelname verzoeken join_request: Deelname verzoeken
employee: Werknemers employee: Werknemers
employee_shift: Shifts
attributes: attributes:
product_category: product_category:
name: Naam name: Naam
@@ -61,6 +63,10 @@ nl:
location: 'Locatie' location: 'Locatie'
time_zone: Tijdzone time_zone: Tijdzone
iens_profile: Iens profiel id iens_profile: Iens profiel id
address: Addres
postal_code: Postcode
city: Stad
country: Land
table: table:
number: Nummer number: Nummer
from_number: Vanaf nummer from_number: Vanaf nummer
@@ -71,3 +77,8 @@ nl:
employee: employee:
name: Naam name: Naam
email: 'E-mail' email: 'E-mail'
manager: 'Manager?'
active: 'Actief?'
color: Kleur
employee_shift:
description: Toelichting
+13 -1
View File
@@ -30,6 +30,7 @@ en:
price: Price price: Price
supplier: supplier:
close_for_orders: Close the shop close_for_orders: Close the shop
close_for_orders_confirmation: If you close the shop, you cannot receive orders. Are you sure?
open_for_orders: 'Open up the place!' open_for_orders: 'Open up the place!'
you_are_currently_closed_alert: 'You are currently closed and not able to take orders' you_are_currently_closed_alert: 'You are currently closed and not able to take orders'
settings: Settings settings: Settings
@@ -190,7 +191,18 @@ en:
title: 'Delete ${models.employee} %{name}?' title: 'Delete ${models.employee} %{name}?'
modal: modal:
new_title: New ${models.employee} new_title: New ${models.employee}
new_title: Edit ${models.employee} edit_title: Edit ${models.employee}
body_header: '' body_header: ''
close_button: Close close_button: Close
save_button: Save save_button: Save
select_modal:
title: Select ${models.employee}
close_button: Close
employee_shift:
modal:
title: Edit ${models.employee_shift}
body_header: ''
close_button: Close
save_button: Save
destroy_button: Destroy
destroy_confirmation: Are you sure?
+14 -1
View File
@@ -20,6 +20,7 @@ nl:
no_orders: Geen actieve ${models.plural.order} no_orders: Geen actieve ${models.plural.order}
top_menu: top_menu:
menu: Menu menu: Menu
schedule: Schema
active_lists: active_lists:
title: Actieve lijsten title: Actieve lijsten
price: Prijs price: Prijs
@@ -28,6 +29,7 @@ nl:
price: Prijs price: Prijs
supplier: supplier:
close_for_orders: De zaak afsluiten voor bestellingen close_for_orders: De zaak afsluiten voor bestellingen
close_for_orders_confirmation: If you close the shop, you cannot receive orders! Are you sure?
open_for_orders: 'Open de zaak!' open_for_orders: 'Open de zaak!'
you_are_currently_closed_alert: 'Je bent momenteel gesloten en kan geen orders ontvangen' you_are_currently_closed_alert: 'Je bent momenteel gesloten en kan geen orders ontvangen'
settings: Instellingen settings: Instellingen
@@ -192,7 +194,18 @@ nl:
title: '${models.employee} %{name} verwijderen?' title: '${models.employee} %{name} verwijderen?'
modal: modal:
new_title: ${models.employee} aanmaker new_title: ${models.employee} aanmaker
new_title: Bewerk ${models.employee} edit_title: Bewerk ${models.employee}
body_header: '' body_header: ''
close_button: Cancel close_button: Cancel
save_button: Save save_button: Save
select_modal:
title: Select ${models.employee}
close_button: Close
employee_shift:
modal:
title: ${models.employee_shift} bewerken
body_header: ''
close_button: Sluit
save_button: Save
destroy_button: Verwijder
destroy_confirmation: 'Weet je zeker dat je de ${models.employee_shift} wilt verwijderen?'
+4
View File
@@ -0,0 +1,4 @@
FactoryGirl.define do
factory :employee_shift do
end
end
+22
View File
@@ -0,0 +1,22 @@
require 'spec_helper'
describe EmployeeShift do
describe '.for_supplier' do
it 'returns the proper employee shifts' do
supplier1 = create :supplier
supplier2 = create :supplier
es1 = create :employee_shift, supplier: supplier1, start_from: 9.days.ago, end_on: 5.days.ago
es2 = create :employee_shift, supplier: supplier2, start_from: 9.days.ago, end_on: 5.days.ago
es3 = create :employee_shift, supplier: supplier2, start_from: 9.days.ago, end_on: 8.days.ago
es4 = create :employee_shift, supplier: supplier2, start_from: 1.day.from_now, end_on: 1.day.from_now + 2.hours
es5 = create :employee_shift, supplier: supplier2, end_on: 1.day.from_now
results = EmployeeShift.for_supplier(supplier2)
results.should_not include(es1), 'different supplier'
results.should include(es2), 'end day within a week ago'
results.should_not include(es3), 'end day more than a week ago'
results.should include(es4) , 'Most relevant case'
results.should_not include(es5) , 'missing start_from'
end
end
end