Edit run functionality
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
lunchApp = angular.module 'lunchApp', [
|
||||
'ngRoute',
|
||||
'lunchControllers',
|
||||
'lunchServices'
|
||||
'lunchServices',
|
||||
'lunchFilters'
|
||||
]
|
||||
|
||||
lunchApp.config ['$routeProvider',
|
||||
|
||||
@@ -17,6 +17,7 @@ lunchControllers.controller 'CreateRunCtrl', ['$scope', '$http', '$location', 's
|
||||
inviteeData.push
|
||||
name: runData.creatorName
|
||||
email: runData.creatorEmail
|
||||
isCreator: true
|
||||
|
||||
socket.post '/run', runData, (runResponse) ->
|
||||
inviteesCreated = 0
|
||||
|
||||
@@ -3,10 +3,6 @@ lunchControllers = angular.module 'lunchControllers'
|
||||
lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams', '$sce',
|
||||
EditRunController = ($scope, socket, $routeParams, $sce) ->
|
||||
$scope.show = false
|
||||
$scope.progress = 0
|
||||
$scope.numOrders = 0
|
||||
$scope.progressClass = 'progress-bar-danger'
|
||||
$scope.showMenuUrl = false
|
||||
|
||||
socket.get '/run/' + $routeParams['id'],
|
||||
(response) ->
|
||||
@@ -16,36 +12,30 @@ lunchControllers.controller 'EditRunCtrl', ['$scope', 'socket', '$routeParams',
|
||||
|
||||
$scope.show = true
|
||||
$scope.run = response
|
||||
$scope.showMenuUrl = response.menuUrl
|
||||
$scope.menuUrl = $sce.trustAsResourceUrl(response.menuUrl)
|
||||
|
||||
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.data.run_id is $routeParams.id
|
||||
invitee = _.findWhere $scope.invitees, id: m.data.id
|
||||
_.extend invitee, m.data
|
||||
$scope.setProgress()
|
||||
$scope.setStatusClasses()
|
||||
$scope.$apply()
|
||||
$scope.addInvitee = () ->
|
||||
$scope.invitees.push {}
|
||||
|
||||
$scope.setStatusClasses = () ->
|
||||
for i in $scope.invitees
|
||||
if i.order
|
||||
i.statusClass = 'done'
|
||||
else
|
||||
i.statusClass = 'incomplete'
|
||||
$scope.removeInvitee = (index) ->
|
||||
$scope.invitees.splice index, 1
|
||||
|
||||
$scope.setProgress = () ->
|
||||
numFilledOrders = _.filter($scope.invitees, (i) -> i.order).length
|
||||
$scope.progress = (numFilledOrders / $scope.numOrders) * 100
|
||||
if $scope.progress >= 100
|
||||
$scope.progressClass = 'progress-bar-success'
|
||||
else
|
||||
$scope.progressClass = 'progress-bar-danger'
|
||||
$scope.update = (run,invitees) ->
|
||||
runData = angular.copy run
|
||||
inviteeData = angular.copy invitees
|
||||
creatorInvitee = _.find inviteeData, (i) -> return i.isCreator
|
||||
creatorInvitee.name = runData.creatorName
|
||||
creatorInvitee.email = runData.creatorEmail
|
||||
|
||||
socket.put '/run/update/' + runData.id, runData, (runResponse) ->
|
||||
inviteesCreated = 0
|
||||
for i in inviteeData
|
||||
socket.put '/invitee/update/' + i.id, i, (inviteeResponse) ->
|
||||
inviteesCreated++
|
||||
if inviteesCreated is inviteeData.length
|
||||
$location.path '/run/' + runResponse.id
|
||||
$scope.$apply()
|
||||
]
|
||||
|
||||
5
assets/linker/js/lunchFilters.coffee
Normal file
5
assets/linker/js/lunchFilters.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
lunchFilters = angular.module 'lunchFilters', []
|
||||
|
||||
lunchFilters.filter 'notCreatorInvitees', () ->
|
||||
return (invitees) ->
|
||||
return _.filter invitees, (i) -> return not i.isCreator
|
||||
@@ -48,7 +48,7 @@
|
||||
.col-xs-12.col-lg-2.step-num
|
||||
span.glyphicon.glyphicon-list(title='Lunch Invitees')
|
||||
.col-xs-12.col-lg-10
|
||||
.invitee.clearfix(ng-repeat='i in invitees')
|
||||
.invitee.clearfix(ng-repeat='i in invitees | notCreatorInvitees')
|
||||
ng-form(name='inviteeForm')
|
||||
.row
|
||||
.col-xs-10.name-wrapper
|
||||
|
||||
@@ -5,9 +5,9 @@ block pagetitle
|
||||
| update your lunch run
|
||||
|
||||
block interiorcontent
|
||||
.create-run-form(ng-controller='CreateRunCtrl')
|
||||
form.row(name='form',novalidate,role='form')
|
||||
.create-run-form(ng-controller='EditRunCtrl')
|
||||
form.row(name='form',novalidate,role='form',ng-show="show")
|
||||
include _form
|
||||
section.submit
|
||||
button.btn.btn-lg.btn-success.btn-block(ng-click="create(run,invitees)",ng-disabled="form.$invalid")
|
||||
button.btn.btn-lg.btn-success.btn-block(ng-click="update(run,invitees)",ng-disabled="form.$invalid")
|
||||
| Update
|
||||
|
||||
Reference in New Issue
Block a user