Change order url to invitee ID, add invitee model

This commit is contained in:
Ben Ramey
2014-05-13 13:11:43 -05:00
parent e4552ebfe4
commit d02bd6c659
10 changed files with 136 additions and 72 deletions

View File

@@ -5,24 +5,18 @@ lunchControllers.controller 'CreateOrderCtrl', ['$scope','socket','$routeParams'
$scope.show = false
$scope.showMenuUrl = false
socket.get '/run/' + $routeParams['id'],
(response) ->
$scope.show = true
$scope.showMenuUrl = response.menuUrl
socket.get '/invitee/findOne', id: $routeParams['inviteeId'], (inviteeResponse) ->
$scope.invitee = inviteeResponse
$scope.run = response
$scope.invitee = _.find response.invitees, (i) -> i.name.toLowerCase() == $routeParams['inviteeName'].toLowerCase()
$scope.invitees = response.invitees
$scope.$apply()
socket.get '/run/' + inviteeResponse.run_id,
(runResponse) ->
$scope.show = true
$scope.showMenuUrl = runResponse.menuUrl
$scope.run = runResponse
$scope.$apply()
$scope.submit = (invitee) ->
invitees = _.map $scope.invitees, (i) ->
if i.name is invitee.name
return invitee
return i
socket.put '/run/' + $routeParams['id'], { invitees: invitees }, (response) ->
$location.path '/run/' + response.id
socket.put '/invitee/' + $routeParams['inviteeId'], { order: invitee.order }, (response) ->
$location.path '/run/' + $scope.run.id
$scope.$apply()
]

View File

@@ -2,23 +2,31 @@ lunchControllers = angular.module 'lunchControllers'
lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 'socket',
CreateRunController = ($scope, $http, $location, socket) ->
$scope.run =
invitees: []
$scope.run = {}
$scope.invitees = []
$scope.addInvitee = () ->
$scope.run.invitees.push {}
$scope.invitees.push {}
$scope.removeInvitee = (index) ->
$scope.run.invitees.splice index, 1
$scope.invitees.splice index, 1
$scope.create = (run) ->
data = angular.copy run
data.invitees.push
name: data.creatorName
email: data.creatorEmail
socket.post '/run', data, (response) ->
$location.path '/run/' + response.id
$scope.$apply()
$scope.create = (run,invitees) ->
runData = angular.copy run
inviteeData = angular.copy invitees
inviteeData.push
name: runData.creatorName
email: runData.creatorEmail
socket.post '/run', runData, (runResponse) ->
inviteesCreated = 0
for i in inviteeData
i.run_id = runResponse.id
socket.post '/invitee', i, (inviteeResponse) ->
inviteesCreated++
if inviteesCreated is inviteeData.length
$location.path '/run/' + runResponse.id
$scope.$apply()
$scope.addInvitee()
]

View File

@@ -10,10 +10,13 @@ lunchControllers.controller 'RunCtrl', ['$scope', 'socket', '$routeParams', ($sc
(response) ->
$scope.show = true
$scope.run = response
$scope.numOrders = $scope.run.invitees.length
$scope.setStatusClasses()
$scope.setProgress()
$scope.$apply()
socket.get '/invitee', run_id: response.id, (inviteeResponse) ->
$scope.invitees = inviteeResponse
$scope.numOrders = $scope.invitees.length
$scope.setStatusClasses()
$scope.setProgress()
$scope.$apply()
socket.on 'message', (m) ->
if m.verb is 'update' and m.id is $routeParams.id
@@ -23,14 +26,14 @@ lunchControllers.controller 'RunCtrl', ['$scope', 'socket', '$routeParams', ($sc
$scope.$apply()
$scope.setStatusClasses = () ->
for i in $scope.run.invitees
for i in $scope.invitees
if i.order
i.statusClass = 'done'
else
i.statusClass = 'incomplete'
$scope.setProgress = () ->
numFilledOrders = _.filter($scope.run.invitees, (i) -> i.order).length
numFilledOrders = _.filter($scope.invitees, (i) -> i.order).length
$scope.progress = (numFilledOrders / $scope.numOrders) * 100
if $scope.progress >= 100
$scope.progressClass = 'progress-bar-success'