Basic fullcalendar integration

This commit is contained in:
2015-02-19 20:37:58 +01:00
parent c17442ad77
commit adeedb2f1b
34 changed files with 11018 additions and 8 deletions
@@ -1,4 +1,5 @@
@App.modals.BaseController = Ember.ObjectController.extend
needs: ['application']
alert_message: ""
title: (->
# return title if directly set by options
@@ -0,0 +1,21 @@
App.modals.EmployeeEditController = App.modals.BaseController.extend
isNotSelf: (->
@get('model.id') isnt @get('current_employee.id')
).property('model.id')
colors: (->
# taken from http://www.somacon.com/p142.php
[
'#458B74'
'#838B8B'
'#8B7D6B'
'#00008B'
'#8B2323'
'#8A2BE2'
'#458B00'
'#EEAD0E'
]
).property()
actions:
setColor: (color)->
@set 'model.color', color
@@ -0,0 +1,7 @@
App.modals.SelectEmployeeController = App.modals.BaseController.extend
employee: null
employees: (-> @store.all 'employee').property()
actions:
selectEmployee: (employee)->
@set 'employee', employee
@send 'ok'
@@ -0,0 +1,6 @@
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 'end_on', event.end.toDate()
employee_shift.save()
@@ -0,0 +1,2 @@
Ember.Handlebars.helper 'colorbox', (color, options)->
"<span class='colorbox-container'><span style='background-color:#{color}'></span></span>".htmlSafe()
@@ -0,0 +1,12 @@
attr = DS.attr
App.EmployeeShift = DS.Model.extend
start_on: attr('date')
end_on: attr('date')
employee: DS.belongsTo 'employee'
calendar_event: (->
id: @id
title: @get('employee.name')
start: @get('start_on')
end: @get('end_on')
color: @get('employee.color')
).property('start_on', 'end_on')
@@ -4,6 +4,8 @@ App.Employee= DS.Model.extend Ember.Validations.Mixin,
email: attr 'string'
manager: attr 'boolean', defaultValue: false
active: attr 'boolean', defaultValue: true
color: attr 'string', defaultValue: '#3a87ad'
employee_shifts: DS.hasMany('employee-shift')
validations:
name: {presence: true}
@@ -17,5 +17,6 @@ App.Router.map ->
@route 'orders_display' # chromecast etc
@route 'menu'
@route 'settings'
@route 'schedule'
@route 'empty'
#@resource 'lists', queryParams: ['state']
@@ -1,2 +1,2 @@
App.EmployeesRoute = Ember.Route.extend
model: -> @store.find 'employee'
model: -> @store.all 'employee'
@@ -0,0 +1,2 @@
App.ScheduleRoute = Ember.Route.extend
model: -> @store.find 'employee-shift'
@@ -6,6 +6,9 @@
tr
th.name=t 'attributes.employee.name'
th.email=t 'attributes.employee.email'
th.boolean= t 'attributes.employee.manager'
th.boolean= t 'attributes.employee.active'
th.colorbox= t 'attributes.employee.color'
th.actions=t 'helpers.actions.title'
tbody
each employee in employees
@@ -14,6 +17,9 @@
td.email
= employee.email
= errors employee.errors.email
td.boolean= boolean employee.manager
td.boolean= boolean employee.active
td.colorbox= colorbox employee.color
td.actions
can manage sections
a.table-edit{ action 'editEmployee' employee }: span
@@ -15,6 +15,8 @@ header.top-menu
= t 'models.plural.list'
= link-to "employees" class="top-menu-employees"
= t 'models.plural.employee'
= link-to "schedule" class="top-menu-schedule"
= t 'supplier.top_menu.schedule'
.extra-info{action "showSupplierStatusInfo"}
.supplier-info-row
.counter.supplier-orders-placed-count
@@ -9,6 +9,20 @@ p=t 'employee.modal.body_header'
.form-field
= input type="email" valueBinding="model.email" action="save"
= errors model.errors.email
if isNotSelf
.form-row.active
.form-label= t 'attributes.employee.manager'
.form-field= view "boolean-switch" value=model.manager
.form-row.active
.form-label= t 'attributes.employee.active'
.form-field= view "boolean-switch" value=model.active
.form-row.active
.form-label= t 'attributes.employee.color'
.form-field.full
span.current-color= colorbox model.color
each color in colors
a{action "setColor" color}= colorbox color
hr
button.modal-close{action "close"}=t 'employee.modal.close_button'
button.modal-confirm.right{action "save"} disabled=model.isInvalid
@@ -0,0 +1,7 @@
p Select employee
ul.select-employees
each employee in employees
li.select-employee
= employee.name
a.employee-selector{action "selectEmployee" employee}: span
button.modal-close{action "close"}=t 'employee.select_modal.close_button'
@@ -0,0 +1,2 @@
.row: .small-12.columns
#schedule-placeholder
@@ -0,0 +1,30 @@
App.ScheduleView = Ember.View.extend
classNames: ['schedule-view']
didInsertElement: ->
placeholder = @$('#schedule-placeholder')
controller = @get('controller')
events = controller.get('model').map (employee_shift)->employee_shift.get('calendar_event')
placeholder.fullCalendar
header:
left: 'prev,next,today'
center: 'title'
right: 'month,agendaWeek,agendaDay'
selectable: true
selectHelper: true
select: (start, end)=>
controller.modal 'select_employee',
ok: ->
# this context is SelectEmployeeController
if employee = @get('employee')
shift = controller.store.createRecord 'employee-shift', start_on: start.toDate(), end_on: end.toDate()
shift.set 'employee', employee
shift.save()
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)
@@ -6,6 +6,7 @@
// require foundation FOUNDATION 5 JAVASCRIPT IMPLEMENTATIONS AND EMBER ARE NOT COMPATIBLE, FOUNDATION IS TOO SIMPLISTIC AT THE MOMENT AND DESTROYS DOM EVENTS
//= require js-routes
//= require moment
//= require fullcalendar
//= require translations
// require qwaiter
// require ./qsupplier
@@ -1,5 +1,7 @@
td.boolean
+table-fit
.boolean-true
@extend .fa, .fa-check
&.needs_help
.boolean-true
@extend .fa
@@ -8,6 +10,8 @@ td.boolean
.boolean-true
@extend .fa
@extend .fa-money
td.colorbox
+table-fit
.list-orders-container
.currency
float: right
@@ -1,6 +1,7 @@
//= require qtip
//= require_directory ../base1-shared
//= require pickdate
//= require fullcalendar
@import bourbon
@import ./qconstants
@import ./foundation_and_overrides
@@ -0,0 +1,22 @@
.colorbox-container
line-height: 1px
display: inline-block
span
display: inline-block
.form-field
.current-color
.colorbox-container
padding: 4px
border: 2px solid #777
margin-right: 16px
span
width: 32px
height: 32px
.colorbox-container
margin-right: 8px
span
width: 32px
height: 32px
td .colorbox-container span
width: 16px
height: 16px
@@ -0,0 +1,11 @@
ul.select-employees
list-style: none
li
padding-bottom: 7px
border-bottom: 1px solid #ccc
margin-bottom: 7px
+clearfix
.employee-selector
float: right
span
@extend .fa, .fa-2x, .fa-user-plus
@@ -0,0 +1,24 @@
module Suppliers
class EmployeeShiftsController < Suppliers::ApplicationController
def index
render json: current_supplier.employee_shifts, each_serializer: Suppliers::EmployeeShiftSerializer
end
def create
@employee_shift.supplier = current_supplier
@employee_shift.save
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
end
def update
@employee_shift.update employee_shift_params
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
end
private
def employee_shift_params
params.require(:employee_shift).permit(:start_on, :end_on, :employee_id)
end
end
end
@@ -32,7 +32,8 @@ module Suppliers
# PUT /employees/1.json
def update
@employee = Employee.find(params[:id])
render json: {}, status: 404 unless @employee.supplier_id == current_supplier.id
render json: {}, status: 404 unless current_supplier.employee_ids.include?(@employee.id)
current_supplier.settings_for(@employee).update!(employee_params)
respond_to do |format|
if @employee.update_attributes(employee_params)
format.json { head :no_content }
@@ -57,7 +58,7 @@ module Suppliers
private
def employee_params
params.require(:employee).permit(:name, :email)
params.require(:employee).permit(:name, :email, :active, :manager, :color)
end
end
end
+3 -1
View File
@@ -3,7 +3,8 @@ class Employee
include ActiveModel::SerializerSupport
DEFAULT_SETTINGS = {
'manager' => false,
'active' => true
'active' => true,
'color' => '#3a87ad'
}
attr_accessor *DEFAULT_SETTINGS.keys
attr_reader :settings
@@ -15,6 +16,7 @@ class Employee
property :name
#property :email
has_many :employee_shifts
view :by_email, key: :email
class << self
+9
View File
@@ -0,0 +1,9 @@
class EmployeeShift
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :start_on, type: Time
property :end_on, type: Time
belongs_to :supplier
belongs_to :employee
end
+1
View File
@@ -41,6 +41,7 @@ class Supplier
has_many :orders, dependent: :destroy
has_many :sections, dependent: :destroy
has_and_belongs_to_many :employees, storing_keys: true
has_many :employee_shifts
alias_method :non_enriced_employees, :employees
def employees
+24 -3
View File
@@ -24,7 +24,7 @@ class SupplierEmployeesSettings
end
end
def persist
def to_store!
supplier.employee_settings_storage = dictionary
end
@@ -42,7 +42,7 @@ class SupplierEmployeesSettings
alias_method :orig_setter, :[]=
def []=(*args)
orig_setter(*args)
all_employees_settings.persist
all_employees_settings.to_store!
end
end
@@ -74,7 +74,7 @@ class SupplierEmployeesSettings
if employee = all_employees_settings.supplier.employees.find{|e| e.id == id}
employee.public_send("#{attribute}=", value)
end
all_employees_settings.supplier.save if persist
persist! if persist
self
end
@@ -86,6 +86,27 @@ class SupplierEmployeesSettings
set attribute, value, persist: true
end
def update(params)
Employee::DEFAULT_SETTINGS.keys.each do |attribute|
if params.has_key?(attribute)
new_value = params.delete(attribute)
set attribute, new_value
end
end
params
end
def update!(params)
update params
persist!
params
end
def persist!
all_employees_settings.supplier.is_dirty
all_employees_settings.supplier.save
end
# Parse a method name to its underlying operations
# settings.is_manager?
# is a getter for the attribute manager
@@ -1,5 +1,5 @@
class Suppliers::EmployeeSerializer < Qwaiter::Serializer
self.root = :employee
embed :ids, include: true
attributes :name, :email, :manager, :active
attributes :name, :email, :manager, :active, :color
end
@@ -0,0 +1,5 @@
class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer
self.root = :employee_shift
#embed :ids, include: true
attributes :start_on, :end_on, :employee_id
end
@@ -9,4 +9,5 @@ class Suppliers::SupplierSerializer < Qwaiter::Serializer
end
has_many :sections, serializer: Suppliers::ExtendedSectionSerializer
has_many :product_categories
has_many :employees, serializer: Suppliers::EmployeeSerializer
end