Change order url to invitee ID, add invitee model
This commit is contained in:
30
api/controllers/InviteeController.js
Normal file
30
api/controllers/InviteeController.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* InviteeController
|
||||
*
|
||||
* @module :: Controller
|
||||
* @description :: A set of functions called `actions`.
|
||||
*
|
||||
* Actions contain code telling Sails how to respond to a certain type of request.
|
||||
* (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
|
||||
*
|
||||
* You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
|
||||
* and/or override them with custom routes (`config/routes.js`)
|
||||
*
|
||||
* NOTE: The code you write here supports both HTTP and Socket.io automatically.
|
||||
*
|
||||
* @docs :: http://sailsjs.org/#!documentation/controllers
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Overrides for the settings in `config/controllers.js`
|
||||
* (specific to InviteeController)
|
||||
*/
|
||||
_config: {}
|
||||
|
||||
|
||||
};
|
||||
33
api/models/Invitee.js
Normal file
33
api/models/Invitee.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Invitee
|
||||
*
|
||||
* @module :: Model
|
||||
* @description :: A short summary of how this model works and what it represents.
|
||||
* @docs :: http://sailsjs.org/#!documentation/models
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
attributes: {
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
email: {
|
||||
type: 'email',
|
||||
required: true
|
||||
},
|
||||
order: {
|
||||
type: 'string'
|
||||
},
|
||||
run_id: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
|
||||
afterCreate: function(values, next) {
|
||||
EmailService.sendOrderEmail(values);
|
||||
next();
|
||||
},
|
||||
|
||||
};
|
||||
@@ -20,17 +20,10 @@ module.exports = {
|
||||
type: 'email',
|
||||
required: true
|
||||
},
|
||||
invitees: {
|
||||
type: 'array'
|
||||
},
|
||||
menuUrl: {
|
||||
type: 'url'
|
||||
},
|
||||
restaurant: 'string'
|
||||
},
|
||||
|
||||
afterCreate: function(values, next) {
|
||||
EmailService.sendRunEmails(values);
|
||||
next();
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
// EmailService.js
|
||||
var sendgrid = require("sendgrid");
|
||||
|
||||
exports.sendRunEmails = function(runData) {
|
||||
var emailText = "You've been invited to " + runData.creatorName + "'s lunch run: '"
|
||||
+ runData.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/run/"
|
||||
+ runData.id + "/order/";
|
||||
var options = {
|
||||
fromname: runData.creatorName + " via LunchRun.me",
|
||||
from: sails.config.email.fromAddress,
|
||||
subject: "You've been invited to a lunch run!",
|
||||
replyto: runData.creatorEmail
|
||||
};
|
||||
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
|
||||
exports.sendOrderEmail = function(inviteeData) {
|
||||
Run.findOne({ id: inviteeData.run_id }, function(err, runData) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var idx in runData.invitees) {
|
||||
var invitee = runData.invitees[idx];
|
||||
var specificOptions = options;
|
||||
specificOptions.to = invitee.email;
|
||||
specificOptions.toname = invitee.name;
|
||||
specificOptions.text = emailText + invitee.name;
|
||||
var emailText = "You've been invited to " + runData.creatorName + "'s lunch run: '"
|
||||
+ runData.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/order/"
|
||||
+ inviteeData.id;
|
||||
|
||||
console.log(specificOptions);
|
||||
var options = {
|
||||
fromname: runData.creatorName + " via LunchRun.me",
|
||||
from: sails.config.email.fromAddress,
|
||||
to: inviteeData.email,
|
||||
toname: inviteeData.name,
|
||||
subject: "You've been invited to a lunch run!",
|
||||
replyto: runData.creatorEmail,
|
||||
text: emailText
|
||||
};
|
||||
var sg = sendgrid(sails.config.email.apiUser, sails.config.email.apiKey);
|
||||
|
||||
sg.send(specificOptions, function(err, response) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("message sent from: " + runData.creatorEmail);
|
||||
}
|
||||
});
|
||||
}
|
||||
sg.send(options, function(err, response) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log("message sent from: " + runData.creatorEmail + ", to: " + inviteeData.email);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(options);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ lunchApp.config ['$routeProvider',
|
||||
.when '/run/:id',
|
||||
templateUrl: 'templates/run/show.html',
|
||||
controller: 'RunCtrl'
|
||||
.when '/run/:id/order/:inviteeName',
|
||||
.when '/order/:inviteeId',
|
||||
templateUrl: 'templates/run/create-order.html',
|
||||
controller: 'CreateOrderCtrl'
|
||||
.otherwise
|
||||
|
||||
@@ -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()
|
||||
]
|
||||
|
||||
@@ -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()
|
||||
]
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -55,7 +55,7 @@ block interiorcontent
|
||||
.col-xs-12.col-sm-2.step-num
|
||||
span.glyphicon.glyphicon-list
|
||||
.col-xs-12.col-sm-10
|
||||
.invitee.clearfix(ng-repeat='i in run.invitees')
|
||||
.invitee.clearfix(ng-repeat='i in invitees')
|
||||
ng-form(name='inviteeForm')
|
||||
.row
|
||||
.col-xs-12.col-sm-5
|
||||
@@ -86,5 +86,5 @@ block interiorcontent
|
||||
| Invite another!
|
||||
|
||||
section.submit
|
||||
button.btn.btn-lg.btn-primary.btn-block(ng-click="create(run)",ng-disabled="form.$invalid")
|
||||
button.btn.btn-lg.btn-primary.btn-block(ng-click="create(run,invitees)",ng-disabled="form.$invalid")
|
||||
| Create
|
||||
|
||||
@@ -13,11 +13,11 @@ block interiorcontent
|
||||
div(class='progress-bar {{ progressClass }}',role='progressbar',aria-valuenow="{{ progress }}",aria-minvalue='0',aria-maxvalue='100',style='width:{{ progress }}%',ng-show='progress')
|
||||
| {{ progress }}%
|
||||
|
||||
div.row.run-order-status(ng-repeat="i in run.invitees")
|
||||
div.row.run-order-status(ng-repeat="i in invitees")
|
||||
div(class='name col-sm-3 {{ i.statusClass }}')
|
||||
span.glyphicon.glyphicon-user
|
||||
| {{ i.name }}
|
||||
.order.col-sm-7 {{ i.order }}
|
||||
.fill.col-sm-2
|
||||
a.btn.btn-default.btn-sm.btn-block(href='#/run/{{ run.id }}/order/{{ i.name }}')
|
||||
a.btn.btn-default.btn-sm.btn-block(href='#/order/{{ i.id }}')
|
||||
span.glyphicon.glyphicon-pencil
|
||||
|
||||
Reference in New Issue
Block a user