From 460e8f0be0676baf19be0f7fdc327529861e0bf0 Mon Sep 17 00:00:00 2001 From: Dobie Wollert Date: Wed, 4 Sep 2013 03:05:47 -0400 Subject: [PATCH] latest digs --- app/controllers/clients.js | 2 +- app/controllers/messages.js | 11 ++-- app/controllers/workorders.js | 48 ++++++++++++--- app/model/client.js | 3 +- app/model/workorder.js | 3 +- app/views/tag.jade | 32 +++++++--- config/auth.js | 15 ++++- config/calendar.js | 46 ++++++++++---- logs/crash.log | 94 +++++++++++++++++++++++++++++ mapreduce.js | 4 ++ public/partials/clients/edit.html | 10 +-- public/partials/workorders/add.html | 7 ++- 12 files changed, 229 insertions(+), 46 deletions(-) diff --git a/app/controllers/clients.js b/app/controllers/clients.js index f22885a..3f9490e 100644 --- a/app/controllers/clients.js +++ b/app/controllers/clients.js @@ -137,4 +137,4 @@ exports.destroy = function(req, res, next) { return res.json(client); }) }); -}; \ No newline at end of file +}; diff --git a/app/controllers/messages.js b/app/controllers/messages.js index 3b06555..bbe14dc 100644 --- a/app/controllers/messages.js +++ b/app/controllers/messages.js @@ -14,8 +14,7 @@ module.exports = function(config) { return { send: function(req, res) { - console.log(req.body); - + console.log(req); var userId = req.body.user; if (!userId) { return res.json(404, null); @@ -25,8 +24,10 @@ module.exports = function(config) { User.findById(userId, function(err, user) { if (err) return res.json(500, err); + var sender = req.user; + server.send({ - text: generateMessage(user, req.body), + text: generateMessage(sender, user, req.body), from: config.email.user, to: generateToLine(user), subject: 'Message from portal' @@ -47,8 +48,9 @@ function generateToLine(user) { return user.name.first + " " + user.name.last + " <" + user.email + ">"; } -function generateMessage(user, message) { +function generateMessage(sender, user, message) { var template = + "From: %(sender)s\n" + "Message For: %(user)s\n" + "\n" + "Name: %(name)s\n" + @@ -60,6 +62,7 @@ function generateMessage(user, message) { "%(notes)s\n"; var resources = { + sender: sender.name.first + " " + sender.name.last, user: user.name.first + " " + user.name.last, name: message.name || '', company: message.company || '', diff --git a/app/controllers/workorders.js b/app/controllers/workorders.js index 7e94f44..4400980 100644 --- a/app/controllers/workorders.js +++ b/app/controllers/workorders.js @@ -47,9 +47,12 @@ module.exports = function(calendar) { }, create: function(req, res, next) { + console.log(req.body); + var date = new Date(); + var workorder = new Workorder({ client: req.body.client, - createdOn: new Date(), + createdOn: date, createdBy: req.user, reason: req.body.reason, maintenanceType: req.body.maintenanceType || "", @@ -105,7 +108,9 @@ module.exports = function(calendar) { end: workorder.scheduling.end, attendees: generateAttendees(techs) }, function(err, result) { - workorder.calendarId = result.id; + if (result) { + workorder.calendarId = result.id; + } callback(err); }); }, @@ -119,7 +124,18 @@ module.exports = function(calendar) { Client.findByIdAndUpdate(req.body.client, { $push: { 'workorders': result.id } }, function(err, ignored) { callback(err, result) }); - } + }, + function(result, callback) { + console.log("Update Client - Pms"); + if (workorder.maintenanceType) { + console.log("Is PM"); + var key = 'pms.' + date.getFullYear() + '-' + date.getMonth() + '.' + workorder.maintenanceType; + var cmd = { $inc: {} }; + cmd.$inc[key] = 1; + console.log(cmd); + Client.findByIdAndUpdate(req.body.client, cmd, function(err, ignored) { callback(err, result) }); + } + }, ], function(err, result) { if (!err) { @@ -145,11 +161,13 @@ module.exports = function(calendar) { workorder = result; workorder.reason = req.body.reason; - maintenanceType: req.body.maintenanceType || ""; + workorder.maintenanceType = req.body.maintenanceType || ""; workorder.remarks = req.body.remarks; workorder.scheduling = req.body.scheduling; workorder.status = req.body.status; - workorder.techs = req.body.techs.map(function(t) { return t._id; }); + workorder.techs = req.body.techs + .filter(function(e) { return e; }) + .map(function(t) { return t._id; }); callback(err); }); @@ -214,11 +232,17 @@ module.exports = function(calendar) { return workorder.save(function(err) { if (!err) { console.log("deleted"); + calendar.deleteEvent(workorder.calendarId, function(err) { + if (!err) { + console.log("Calendar event removed."); + } + + return res.json(workorder); + }); } else { console.log("error"); + return res.json(workorder); } - - return res.json(workorder); }) }); } @@ -231,7 +255,15 @@ function generateSummary(client) { } function generateLocation(client) { - return sprintf("%(street1)s %(street2)s %(city)s, %(state)s. %(zip)s", client.address); + var data = { + street1: client.address.street1 || '', + street2: client.address.street2 || '', + city: client.address.city || '', + state: client.address.state || '', + zip: client.address.zip || '' + }; + + return sprintf("%(street1)s %(street2)s %(city)s, %(state)s. %(zip)s", data); } function generateDescription(client, workorder) { diff --git a/app/model/client.js b/app/model/client.js index d1d508e..db0969a 100644 --- a/app/model/client.js +++ b/app/model/client.js @@ -18,8 +18,9 @@ var clientSchema = new Schema({ email: String }], frequencies: {}, + pms: {}, workorders: [{ type: ObjectId, ref: 'Workorder' }], deleted: { type: Boolean, default: false } }); -module.exports = mongoose.model('Client', clientSchema); \ No newline at end of file +module.exports = mongoose.model('Client', clientSchema); diff --git a/app/model/workorder.js b/app/model/workorder.js index 157ff1e..802ce86 100644 --- a/app/model/workorder.js +++ b/app/model/workorder.js @@ -8,6 +8,7 @@ var workorderSchema = new Schema({ createdOn: Date, createdBy: { type: ObjectId, ref: 'User' }, reason: String, + maintenanceType: String, remarks: String, status: String, scheduling: { @@ -24,4 +25,4 @@ var workorderSchema = new Schema({ deleted: { type: Boolean, default: false } }); -module.exports = mongoose.model('Workorder', workorderSchema); \ No newline at end of file +module.exports = mongoose.model('Workorder', workorderSchema); diff --git a/app/views/tag.jade b/app/views/tag.jade index 61ae07e..6392c9b 100644 --- a/app/views/tag.jade +++ b/app/views/tag.jade @@ -26,9 +26,20 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") .navbar-inner ul.nav li - a(href='http://www.atlanticbiomedical.com') - i.icon-wrench - | Contact Us + a(href='#') + | Contact: + li + a(href='tel://1-800-550-8310') + i.icon-user + | Call + li + a(href='mailto:service@atlanticbiomedical.com') + i.icon-envelope + | Email + li + a(href='http://atlb.co/feature.html') + i.icon-list-alt + | History .container-fluid h1(ng-show='tag') Device Tag h1(ng-hide='tag') Create Tag @@ -46,7 +57,7 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") dd  {{tag.clientDeviceId}} dt Device dd  {{tag.device}} - dt Make + dt Manufacturer dd  {{tag.make}} dt Model dd  {{tag.model}} @@ -56,12 +67,14 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") dd  {{tag.purchaseDate}} dt Warranty Expiration dd  {{tag.deviceWarrantyExpiration}} - dt Test + dt PM Test dd  {{tag.test}} dt Room # dd  {{tag.roomNumber}} dt PO Number dd  {{tag.poNumber}} + dt Move To + dd  {{tag.MoveTo}} a.btn.btn-primary(href='/auth', ng-show='tag') | Edit Tag @@ -87,7 +100,7 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") .controls input.text(ng-model='tag.device') .control-group - label.control-label Make + label.control-label Manufacturer .controls input.text(ng-model='tag.make') .control-group @@ -108,7 +121,7 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") input.text(type='date', ng-model='tag.deviceWarrantyExpiration') .control-group - label.control-label Test + label.control-label PM Test .controls input.text(ng-model='tag.test') .control-group @@ -120,6 +133,11 @@ html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl") label.control-label PO Number .controls input.text(ng-model='tag.poNumber') + + .control-group + label.control-label Move To + .controls + input.text(ng-model='tag.MoveTo') .control-group button.btn.btn-primary(ng-click='save()') Save diff --git a/config/auth.js b/config/auth.js index 97f6dbc..272201c 100644 --- a/config/auth.js +++ b/config/auth.js @@ -1,11 +1,16 @@ module.exports = function(app, passport) { - app.get('/auth', passport.authenticate('google', { + app.get('/auth', function(req, res, next) { + console.dir(req.headers); + req.session.redirectUrl = req.headers['referer']; + + passport.authenticate('google', { accessType: 'offline', scope: [ 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/calendar' - ]})); + ]})(req, res, next); + }); app.get('/auth/callback', function(req, res, next) { var options = { @@ -23,6 +28,10 @@ module.exports = function(app, passport) { req.session.redirectUrl = null; } + if (redirectUrl.indexOf('/login') != -1) { + redirectUrl = '/'; + } + req.logIn(user, function(err) { if (err) { return next(err); } }); @@ -34,7 +43,7 @@ module.exports = function(app, passport) { return { requiresUiLogin: function(req, res, next) { if (!req.isAuthenticated()) { - req.session.redirectUrl = req.url; +// req.session.redirectUrl = req.url; return res.redirect('/login'); } next(); diff --git a/config/calendar.js b/config/calendar.js index 0ee81da..a71b147 100644 --- a/config/calendar.js +++ b/config/calendar.js @@ -16,22 +16,36 @@ module.exports = function(config) { var opts = { baseDiscoveryUrl: 'https://www.googleapis.com/discovery/v1/apis/' }; + function toIsoDate(d) { + function pad(n) { return n < 10 ? '0' + n : n } + return d.getUTCFullYear()+'-' + + pad(d.getUTCMonth()+1)+'-' + + pad(d.getUTCDate())+'T' + + pad(d.getUTCHours())+':' + + pad(d.getUTCMinutes())+':' + + pad(d.getUTCSeconds())+'Z'; + } + return { scheduleEvent: function(event, callback) { console.log("schedule event"); api(function(client, callback) { - var resource = buildResource(event, {}); console.log("Insert Google Calendar"); - console.log(resource); - var request = client.calendar.events.insert({ + var params = { calendarId: 'primary', - resource: resource - }); + }; + + var resource = buildResource(event, { sequence: 1 }); + + var request = client.calendar.events.insert(params, resource); request.withAuthClient(oauth2Client).execute(function(err, result) { + console.log("in request callback"); + console.dir(err); + console.dir(result); callback(err, result); }); }, callback); @@ -57,24 +71,32 @@ module.exports = function(config) { resource.sequence = 1; } - var updateRequest = client.calendar.events.update({ + var updateRequest = client.calendar.events.patch({ calendarId: 'primary', - eventId: event.eventId, - resource: buildResource(event, result) - }); + eventId: event.eventId + }, buildResource(event, result)); updateRequest.withAuthClient(oauth2Client).execute(function(err, result) { callback(err, result); }); }); }, callback); + }, + + deleteEvent: function(eventId, callback) { + api(function(client, callback) { + var request = client.calendar.events.delete({ + calendarId: 'primary', + eventId: eventId + }); + request.withAuthClient(oauth2Client).execute(function(err, result) { + callback(err, result); + }); + }, callback); } }; function buildResource(event, resource) { - console.log(event.start); - console.log(event.end); - resource.summary = event.summary; resource.description = event.description; resource.location = event.location; diff --git a/logs/crash.log b/logs/crash.log index 1f44570..6088648 100755 --- a/logs/crash.log +++ b/logs/crash.log @@ -30,3 +30,97 @@ Server was reset on 07.01.2013 at 02:38:49 Server was reset on 07.01.2013 at 02:44:36 Server was reset on 07.01.2013 at 02:44:36 Server was reset on 07.01.2013 at 02:44:36 +Server was reset on 07.01.2013 at 02:44:36 +Server was reset on 07.01.2013 at 02:44:36 +Server was reset on 07.01.2013 at 02:44:36 +Server was reset on 07.19.2013 at 08:33:09 +Server was reset on 07.19.2013 at 08:33:09 +Server was reset on 07.19.2013 at 09:03:11 +Server was reset on 07.19.2013 at 09:03:11 +Server was reset on 07.19.2013 at 10:01:07 +Server was reset on 07.19.2013 at 10:01:07 +Server was reset on 07.19.2013 at 10:01:07 +Server was reset on 07.19.2013 at 10:01:07 +Server was reset on 07.19.2013 at 10:01:07 +Server was reset on 07.19.2013 at 10:35:47 +Server was reset on 07.19.2013 at 10:35:47 +Server was reset on 07.19.2013 at 10:35:47 +Server was reset on 07.19.2013 at 10:35:47 +Server was reset on 07.19.2013 at 10:35:47 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:09:00 +Server was reset on 07.19.2013 at 11:59:11 +Server was reset on 07.19.2013 at 11:59:11 +Server was reset on 07.19.2013 at 11:59:11 +Server was reset on 07.19.2013 at 11:59:11 +Server was reset on 07.19.2013 at 11:59:11 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.19.2013 at 12:19:27 +Server was reset on 07.22.2013 at 00:15:15 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 07.28.2013 at 21:14:04 +Server was reset on 08.07.2013 at 00:39:34 +Server was reset on 08.07.2013 at 17:07:18 +Server was reset on 08.07.2013 at 22:05:41 +Server was reset on 08.07.2013 at 22:05:41 +Server was reset on 08.07.2013 at 22:05:41 +Server was reset on 08.07.2013 at 22:06:43 +Server was reset on 08.07.2013 at 22:06:43 +Server was reset on 08.24.2013 at 13:17:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 08.27.2013 at 10:54:23 +Server was reset on 09.02.2013 at 06:42:51 +Server was reset on 09.02.2013 at 06:42:51 +Server was reset on 09.02.2013 at 06:42:51 diff --git a/mapreduce.js b/mapreduce.js index d8b8b0c..aa81aa1 100644 --- a/mapreduce.js +++ b/mapreduce.js @@ -86,9 +86,13 @@ var workorders_command = { mongoose.connection.db.executeDbCommand(clients_command, function(err, dbres) { if (err) throw err; + console.log("Clients Done"); + mongoose.connection.db.executeDbCommand(workorders_command, function(err, dbres) { if (err) throw err; + console.log("Workorders Done"); + process.exit(); }); }); diff --git a/public/partials/clients/edit.html b/public/partials/clients/edit.html index 8bf5ba7..d9a7f3d 100644 --- a/public/partials/clients/edit.html +++ b/public/partials/clients/edit.html @@ -285,33 +285,27 @@ -
+
- - - - - + - -
Tag Device ID Device Make Model Serial No.Purchase DateWarranty Exp.
There is no information to display.
{{tag._id}}{{tag.data.clientDeviceId}}{{tag.data.clientDeviceId}} - (Tag:{{tag._id}}) {{tag.data.device}} {{tag.data.make}} {{tag.data.model}} {{tag.data.serialNumber}}{{tag.data.purchaseDate|date}}{{tag.data.deviceWarrantyExpiration|date}}
diff --git a/public/partials/workorders/add.html b/public/partials/workorders/add.html index 46f3ee6..ce5467c 100644 --- a/public/partials/workorders/add.html +++ b/public/partials/workorders/add.html @@ -185,7 +185,12 @@
- +

Note:

+

Please only click save once, your work order is being saved the first time you click the button. There is a small bug preventing the page from returning you back to where you came from. This will be fixed after working hours.

+

If you notice any other issues, or need help with a work order, please feel free to Open a Ticket +

+ +