diff --git a/app/assets/javascripts/supplier/app/.ctrlp b/app/assets/javascripts/supplier/app/.ctrlp new file mode 100644 index 00000000..e69de29b diff --git a/app/assets/javascripts/supplier/app/components/sections_header_component.js.coffee b/app/assets/javascripts/supplier/app/components/sections_header_component.js.coffee index 126597a1..855accaf 100644 --- a/app/assets/javascripts/supplier/app/components/sections_header_component.js.coffee +++ b/app/assets/javascripts/supplier/app/components/sections_header_component.js.coffee @@ -2,7 +2,14 @@ App.SectionsHeaderComponent = Ember.Component.extend sections: (-> @get('targetObject.store').all('section') ).property() actions: 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') @$("[data-section=#{if section then section.id else 'all'}]").addClass('active') @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') diff --git a/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee index 086112a4..6225e7e2 100644 --- a/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/application_controller.js.coffee @@ -19,12 +19,6 @@ App.ApplicationController = Ember.Controller.extend actions: signOut: -> 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: -> @modal 'supplier_status_info', model: @get('supplier') diff --git a/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee index 46c72260..f1af67b8 100644 --- a/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/index_controller.js.coffee @@ -5,15 +5,15 @@ App.IndexController = Ember.ObjectController.extend lists: (-> @store.all('list')).property() orders: (-> @store.all('order')).property() sections: (-> @store.all('section')).property() + active_section: Ember.computed.alias 'controllers.application.active_section' active_lists: (-> - if @get('controllers.application.active_section.id') - lists = @get('lists').filter (l)=>( l.get('section.id') == @get('controllers.application.active_section.id') && l.get('state') == 'active' ) + if section_id = @get('active_section.id') + lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' ) else lists = @get('lists').filterProperty('state', 'active') 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: (-> if @get('active_section.id') orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') ) diff --git a/app/assets/javascripts/supplier/app/controllers/modals/base_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/base_controller.js.coffee index 4ddf5c8a..98ea26e5 100644 --- a/app/assets/javascripts/supplier/app/controllers/modals/base_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/modals/base_controller.js.coffee @@ -9,9 +9,10 @@ if model = @get('model') 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 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 underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()` # find translated title or humanize the controller name @@ -19,7 +20,7 @@ tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe() else underscored.capitalize().replace(/_/, ' ') - ).property('model.id') + ).property('model.id', 'modal_options.title_path') save_error: (error)-> switch error.status when 403 @@ -27,6 +28,8 @@ else @set 'alert_message', 'Something went wrong' save_success: -> + if save_callback = @get('modal_options.save') + save_callback.apply(@) @set 'alert_message', '' @send 'closeModal' @@ -53,9 +56,12 @@ @get('model').save().then @save_success.bind(@), @save_error.bind(@) #@send 'closeModal' unless @preventClose destroy: -> + my_scope = @ + destroy_callback = @get('modal_options.destroy') @modal 'confirm', title_path: @get('modal_options.destroy_text_path') || 'general.destroy.text' model: @get('model') ok: -> @get('model').destroyRecord() + destroy_callback.call(my_scope) if destroy_callback @send 'closeModal' unless @preventClose diff --git a/app/assets/javascripts/supplier/app/controllers/modals/select_employee_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/select_employee_controller.js.coffee index 6425a965..16aca424 100644 --- a/app/assets/javascripts/supplier/app/controllers/modals/select_employee_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/modals/select_employee_controller.js.coffee @@ -1,6 +1,7 @@ App.modals.SelectEmployeeController = App.modals.BaseController.extend employee: null - employees: (-> @store.all 'employee').property() + title_path: 'employee.select_modal.title' + employees: (-> @store.all('employee').filterBy('active') ).property() actions: selectEmployee: (employee)-> @set 'employee', employee diff --git a/app/assets/javascripts/supplier/app/controllers/schedule_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/schedule_controller.js.coffee index 0451802c..b9f176f4 100644 --- a/app/assets/javascripts/supplier/app/controllers/schedule_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/schedule_controller.js.coffee @@ -1,6 +1,14 @@ App.ScheduleController = Ember.ArrayController.extend event_changed: (event)-> @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.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 diff --git a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee index 41da9c33..1374c93f 100644 --- a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee @@ -9,9 +9,6 @@ App.SectionsIndexController = Ember.ArrayController.extend qrPath: (section_id)-> Routes.qr_codes_suppliers_tables_path section_id: section_id actions: - showDashboardOrders: (section)-> - @set 'controllers.application.active_section', section - @transitionToRoute('index') addSection: -> @modal 'add_section', model: @get('model') goToSection: (section)-> @set 'controllers.application.active_section', section diff --git a/app/assets/javascripts/supplier/app/helpers/momentTransform.js.coffee b/app/assets/javascripts/supplier/app/helpers/momentTransform.js.coffee new file mode 100644 index 00000000..7d6196bf --- /dev/null +++ b/app/assets/javascripts/supplier/app/helpers/momentTransform.js.coffee @@ -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() diff --git a/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee b/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee index d002d91b..97ae7b1a 100644 --- a/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee +++ b/app/assets/javascripts/supplier/app/models/employee-shift.js.coffee @@ -1,12 +1,19 @@ attr = DS.attr App.EmployeeShift = DS.Model.extend - start_on: attr('date') - end_on: attr('date') + start_from: attr('moment') + end_on: attr('moment') employee: DS.belongsTo 'employee' + description: attr('string') calendar_event: (-> id: @id - title: @get('employee.name') - start: @get('start_on') + title: @get('title') + start: @get('start_from') end: @get('end_on') 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' diff --git a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb index 884b3e30..cd81ea81 100644 --- a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb +++ b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee.erb @@ -54,7 +54,8 @@ App.ApplicationRoute = Ember.Route.extend defaultModalOptions = closeOnOverlay: true 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}", into: 'application' outlet: 'modal' @@ -80,6 +81,19 @@ App.ApplicationRoute = Ember.Route.extend controller.set 'flash_message', order.get('display_with_table') setTimeout (-> $('body').removeClass('new-order')), 4000 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: list_needs_help: (data) -> if list = @store.getById('list', data.id) diff --git a/app/assets/javascripts/supplier/app/templates/components/sections-header.emblem b/app/assets/javascripts/supplier/app/templates/components/sections-header.emblem index 244ef4c6..cc06eb21 100644 --- a/app/assets/javascripts/supplier/app/templates/components/sections-header.emblem +++ b/app/assets/javascripts/supplier/app/templates/components/sections-header.emblem @@ -3,5 +3,5 @@ dl.sections-header-container.sub-nav each s in sections dd data-section=s.id 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 diff --git a/app/assets/javascripts/supplier/app/templates/global/_top_menu.emblem b/app/assets/javascripts/supplier/app/templates/global/_top_menu.emblem index 5cc14e3d..dc4eee53 100644 --- a/app/assets/javascripts/supplier/app/templates/global/_top_menu.emblem +++ b/app/assets/javascripts/supplier/app/templates/global/_top_menu.emblem @@ -6,7 +6,7 @@ header.top-menu = link-to 'index' class="top-menu-root" = image_tag "icons/logo-small.png" = link-to "menu" class="top-menu-menu" - = t 'supplier.top_menu.menu' + = t 'top_menu.menu' = link-to "sections" class="top-menu-sections" = t 'models.plural.section' = link-to "tables" class="top-menu-tables" @@ -16,7 +16,14 @@ header.top-menu = link-to "employees" class="top-menu-employees" = t 'models.plural.employee' = 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"} .supplier-info-row .counter.supplier-orders-placed-count diff --git a/app/assets/javascripts/supplier/app/templates/index.emblem b/app/assets/javascripts/supplier/app/templates/index.emblem index 64011c77..13686d41 100644 --- a/app/assets/javascripts/supplier/app/templates/index.emblem +++ b/app/assets/javascripts/supplier/app/templates/index.emblem @@ -1,5 +1,9 @@ .row: .small-12.columns = 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 div.dashboard-section-selection /App.HomeSectionSelectorView selectionBinding="controller.controllers.application.active_section" content=controller.sections prompt=controllers.application.supplier.name diff --git a/app/assets/javascripts/supplier/app/templates/modals/employee_edit.emblem b/app/assets/javascripts/supplier/app/templates/modals/employee_edit.emblem index ae9bfff6..0f5476fe 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/employee_edit.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/employee_edit.emblem @@ -6,7 +6,7 @@ p=t 'employee.modal.body_header' = errors model.errors.name .form-row.name .form-label=t 'attributes.employee.email' - .form-field + .form-field.half = input type="email" valueBinding="model.email" action="save" = errors model.errors.email if isNotSelf diff --git a/app/assets/javascripts/supplier/app/templates/modals/employee_shift.emblem b/app/assets/javascripts/supplier/app/templates/modals/employee_shift.emblem new file mode 100644 index 00000000..839d2be4 --- /dev/null +++ b/app/assets/javascripts/supplier/app/templates/modals/employee_shift.emblem @@ -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' diff --git a/app/assets/javascripts/supplier/app/templates/section.emblem b/app/assets/javascripts/supplier/app/templates/section.emblem index 7882089d..abb50e3d 100644 --- a/app/assets/javascripts/supplier/app/templates/section.emblem +++ b/app/assets/javascripts/supplier/app/templates/section.emblem @@ -4,14 +4,9 @@ = view "section-tab-header" context=section can manage sections a.add-section{action "addSection"}: span -can manage sections - .section-manage-tables.pull-right - 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' +.section-manage-tables.pull-right + a.go-to-orders-list{ action "showDashboardOrders" model }: span + can manage sections if editmode = input type="text" valueBinding="title" class="section-edit-title-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-normal-mode-button{ action "finishEditable" }: span 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 = view "section-tables" contentBinding="tables" diff --git a/app/assets/javascripts/supplier/app/templates/sections/index.emblem b/app/assets/javascripts/supplier/app/templates/sections/index.emblem index 53d9c572..b975380f 100644 --- a/app/assets/javascripts/supplier/app/templates/sections/index.emblem +++ b/app/assets/javascripts/supplier/app/templates/sections/index.emblem @@ -31,7 +31,7 @@ /td.currency=currency list.price /td.timestamp=time list.created_at 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 else .row: .small-12.columns diff --git a/app/assets/javascripts/supplier/app/views/schedule.js.coffee b/app/assets/javascripts/supplier/app/views/schedule.js.coffee index 6b211cec..52bf2588 100644 --- a/app/assets/javascripts/supplier/app/views/schedule.js.coffee +++ b/app/assets/javascripts/supplier/app/views/schedule.js.coffee @@ -16,15 +16,22 @@ App.ScheduleView = Ember.View.extend ok: -> # this context is SelectEmployeeController 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.save() - placeholder.fullCalendar('renderEvent', shift.get('calendar_event'), true) + shift.save().then -> + placeholder.fullCalendar('renderEvent', shift.get('calendar_event'), true) editable: true defaultView: 'agendaWeek' events: events timezone: 'UTC' eventDrop: 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]) diff --git a/app/assets/javascripts/supplier/app/views/section_tables_view.js.coffee b/app/assets/javascripts/supplier/app/views/section_tables_view.js.coffee index 45e0bec3..77262a40 100644 --- a/app/assets/javascripts/supplier/app/views/section_tables_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section_tables_view.js.coffee @@ -14,6 +14,14 @@ App.SectionTablesView = Ember.View.extend DragNDrop.Droppable, @$el = $(@get('element')) width = @$el.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_height', height @$el.css('height', height) diff --git a/app/assets/javascripts/supplier/foundation1/application.js.erb b/app/assets/javascripts/supplier/foundation1/application.js.erb index b3121e8b..ae08e194 100644 --- a/app/assets/javascripts/supplier/foundation1/application.js.erb +++ b/app/assets/javascripts/supplier/foundation1/application.js.erb @@ -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.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>; - var path_mapping = { user_root: '/user', join_occupied_table: '/user/join_occupied_table', diff --git a/app/assets/javascripts/translations.js.coffee.erb b/app/assets/javascripts/translations.js.coffee.erb index ce800d50..2fd85514 100644 --- a/app/assets/javascripts/translations.js.coffee.erb +++ b/app/assets/javascripts/translations.js.coffee.erb @@ -21,6 +21,7 @@ @ttry = (path, vars={})-> @t(path, $.extend(vars, emptyWhenNotFound: true)) + # return translation in the form # Tafel @tspan = (path, vars={}) -> "#{t(path, vars)}" @@ -39,8 +40,11 @@ try result = result[part] for part in parts catch err + console.log "[TRANSLATION] Cannot find translation: #{path}" result = 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 parts[parts.length - 1].capitalize() unless result diff --git a/app/assets/stylesheets/supplier/foundation1/_foundation_and_overrides.css.sass b/app/assets/stylesheets/supplier/foundation1/_foundation_and_overrides.css.sass index 2eb43aaa..a42f48cb 100644 --- a/app/assets/stylesheets/supplier/foundation1/_foundation_and_overrides.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_foundation_and_overrides.css.sass @@ -1254,6 +1254,12 @@ $alert-color: #ee3e41 // Prevent empty columns from collapsing .column, .columns min-height: 1px +.alert-box + &.alert + a + font-weight: bold + padding-left: 10px + color: white $button-margin: rem-calc(10) $button-qr-code-color: #555 diff --git a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass index a936e393..54ba2067 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass @@ -14,6 +14,10 @@ $side-spacing: 0px float: left .draggable cursor: move !important +.text-alert + color: $alert-color +.text-danger + color: $warning-color input.dimension width: 52px .location_picker_map diff --git a/app/assets/stylesheets/supplier/foundation1/components/_dashboard.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_dashboard.css.sass index 4689e83d..96661c15 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_dashboard.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_dashboard.css.sass @@ -53,3 +53,7 @@ $button-spacing: 8px @extend .fa @extend .fa-2x @extend .fa-times +.go-to-orders-list + span + @extend .fa + @extend .fa-list-alt diff --git a/app/assets/stylesheets/supplier/foundation1/components/_menu_main.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_menu_main.css.sass index 027dac2c..7365c188 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_menu_main.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_menu_main.css.sass @@ -43,6 +43,11 @@ header.top-menu margin-left: 8px @media #{$small-only} margin-left: 5px + .supplier-is-closed-indication + float: right + margin-right: 8px + &.is-open + line-height: 60px .extra-info position: absolute top: 0 diff --git a/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass index 5c52847d..6d5c8992 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_section_tables.css.sass @@ -1,3 +1,8 @@ +.go-to-orders-list + display: inline-block + margin-right: 7px + span + @extend .fa-lg .section-title font-size: 24px padding: 4px 0px diff --git a/app/assets/stylesheets/supplier/foundation1/components/_tables.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_tables.css.sass index aa655803..26f1613d 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_tables.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_tables.css.sass @@ -47,6 +47,3 @@ a.table-qr-codes +button($bg: $secondary-color) +button-icon-only margin-right: 0.7rem - span - @extend .fa - @extend .fa-list-alt diff --git a/app/controllers/suppliers/employee_shifts_controller.rb b/app/controllers/suppliers/employee_shifts_controller.rb index d4133e4c..2820d82a 100644 --- a/app/controllers/suppliers/employee_shifts_controller.rb +++ b/app/controllers/suppliers/employee_shifts_controller.rb @@ -1,7 +1,8 @@ module Suppliers class EmployeeShiftsController < Suppliers::ApplicationController 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 def create @employee_shift.supplier = current_supplier @@ -14,10 +15,16 @@ module Suppliers render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer end + def destroy + head :forbidden and return unless @employee_shift.supplier_id == current_supplier.id + @employee_shift.destroy + head :ok + end + private 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 diff --git a/app/models/employee_shift.rb b/app/models/employee_shift.rb index 0b98ff79..c745feb3 100644 --- a/app/models/employee_shift.rb +++ b/app/models/employee_shift.rb @@ -2,8 +2,19 @@ class EmployeeShift include SimplyStored::Couch include ActiveModel::SerializerSupport - property :start_on, type: Time - property :end_on, type: Time + property :start_from + property :end_on + property :description belongs_to :supplier 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 diff --git a/app/serializers/suppliers/employee_shift_serializer.rb b/app/serializers/suppliers/employee_shift_serializer.rb index 0fe4927c..4ae9e432 100644 --- a/app/serializers/suppliers/employee_shift_serializer.rb +++ b/app/serializers/suppliers/employee_shift_serializer.rb @@ -1,5 +1,5 @@ class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer self.root = :employee_shift #embed :ids, include: true - attributes :start_on, :end_on, :employee_id + attributes :start_from, :end_on, :employee_id, :description end diff --git a/config/initializers/monkey_patches.rb b/config/initializers/language_additions.rb similarity index 50% rename from config/initializers/monkey_patches.rb rename to config/initializers/language_additions.rb index 6f743353..5308ce06 100644 --- a/config/initializers/monkey_patches.rb +++ b/config/initializers/language_additions.rb @@ -6,16 +6,17 @@ end module MethodPrependAndAppend def before_method(m, &blk) - alias_method :"#{m}_before_extending", m - define_method m do + alias_method :"#{m}_before_extending_before", m + define_method m do |*args| instance_eval(&blk) - send :"#{m}_before_extending" + send :"#{m}_before_extending_before", *args end end + def after_method(m, &blk) - alias_method :"#{m}_before_extending", m - define_method m do - result = send :"#{m}_before_extending" + alias_method :"#{m}_before_extending_after", m + define_method m do |*args| + result = send :"#{m}_before_extending_after", *args instance_eval(result, &blk) end end diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml index 68f42d9e..6344ec1d 100644 --- a/config/locales/models.en.yml +++ b/config/locales/models.en.yml @@ -13,6 +13,7 @@ en: join_request: Join request user_feedback: User feedback employee: Employee + employee_shift: Shift plural: user: Users supplier: Restaurants @@ -26,6 +27,7 @@ en: join_request: Join requests user_feedback: User feedbacks employee: Employees + employee_shift: Shifts attributes: product_category: name: Name @@ -72,3 +74,8 @@ en: employee: name: Name email: 'E-mail' + manager: 'Manager?' + active: 'Active?' + color: Color + employee_shift: + description: Description diff --git a/config/locales/models.nl.yml b/config/locales/models.nl.yml index 17ac26a0..4643fc6e 100644 --- a/config/locales/models.nl.yml +++ b/config/locales/models.nl.yml @@ -12,6 +12,7 @@ nl: section: Afdeling join_request: Deelname verzoek employee: Werknemer + employee_shift: Shift plural: user: Gebruikers supplier: Restaurants @@ -24,6 +25,7 @@ nl: section: Afdelingen join_request: Deelname verzoeken employee: Werknemers + employee_shift: Shifts attributes: product_category: name: Naam @@ -61,6 +63,10 @@ nl: location: 'Locatie' time_zone: Tijdzone iens_profile: Iens profiel id + address: Addres + postal_code: Postcode + city: Stad + country: Land table: number: Nummer from_number: Vanaf nummer @@ -71,3 +77,8 @@ nl: employee: name: Naam email: 'E-mail' + manager: 'Manager?' + active: 'Actief?' + color: Kleur + employee_shift: + description: Toelichting diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index 309d675b..d9dc1148 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -30,6 +30,7 @@ en: price: Price supplier: 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!' you_are_currently_closed_alert: 'You are currently closed and not able to take orders' settings: Settings @@ -190,7 +191,18 @@ en: title: 'Delete ${models.employee} %{name}?' modal: new_title: New ${models.employee} - new_title: Edit ${models.employee} + edit_title: Edit ${models.employee} body_header: '' close_button: Close 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? diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index 655601dc..da9aeb2d 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -20,6 +20,7 @@ nl: no_orders: Geen actieve ${models.plural.order} top_menu: menu: Menu + schedule: Schema active_lists: title: Actieve lijsten price: Prijs @@ -28,6 +29,7 @@ nl: price: Prijs supplier: 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!' you_are_currently_closed_alert: 'Je bent momenteel gesloten en kan geen orders ontvangen' settings: Instellingen @@ -192,7 +194,18 @@ nl: title: '${models.employee} %{name} verwijderen?' modal: new_title: ${models.employee} aanmaker - new_title: Bewerk ${models.employee} + edit_title: Bewerk ${models.employee} body_header: '' close_button: Cancel 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?' diff --git a/spec/factories/employee_shift_factory.rb b/spec/factories/employee_shift_factory.rb new file mode 100644 index 00000000..8643af4b --- /dev/null +++ b/spec/factories/employee_shift_factory.rb @@ -0,0 +1,4 @@ +FactoryGirl.define do + factory :employee_shift do + end +end diff --git a/spec/models/employee_shift_spec.rb b/spec/models/employee_shift_spec.rb new file mode 100644 index 00000000..b21fb969 --- /dev/null +++ b/spec/models/employee_shift_spec.rb @@ -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