From 68b2c8114bd78d6937a01059d18ce38c2725e67e Mon Sep 17 00:00:00 2001 From: Dobie Wollert Date: Sun, 23 Aug 2015 22:40:30 -0700 Subject: [PATCH] More features --- app/controllers/devices.js | 1 - app/controllers/testRuns.js | 9 +++++++++ app/controllers/workorders.js | 12 ++++++------ app/model/device.js | 1 + public/js/controllers/testRuns.js | 4 +++- public/partials/checkLists/add.html | 1 + public/partials/clients/edit.html | 14 ++++++++++++-- public/partials/testRuns/add.html | 6 ++++++ 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/controllers/devices.js b/app/controllers/devices.js index 9ad8ef4..d059c44 100644 --- a/app/controllers/devices.js +++ b/app/controllers/devices.js @@ -32,7 +32,6 @@ exports.get = function(req, res, next) { Device.findById(id) .populate('deviceType', 'category make model checkList') - .populate('deviceType.checkList', 'name fields') .populate('client', 'name identifier') .exec(returnResult(res)); }; diff --git a/app/controllers/testRuns.js b/app/controllers/testRuns.js index 9429e99..b441520 100644 --- a/app/controllers/testRuns.js +++ b/app/controllers/testRuns.js @@ -115,6 +115,15 @@ module.exports = function(config) { } testRun.save(returnResult(res)); + + Device.findById(testRun.device, function(err, device) { + if (err) { + log.error("Failed to fetch device for testRun: %s", err); + } else { + device.lastTestRun = testRun; + device.save(); + } + }); }, update: function(req, res, next) { diff --git a/app/controllers/workorders.js b/app/controllers/workorders.js index 878704b..c31373c 100644 --- a/app/controllers/workorders.js +++ b/app/controllers/workorders.js @@ -108,12 +108,12 @@ module.exports = function(config, calendar) { }); }, function(callback) { - Device.find({client: req.body.client, deleted: false }) - .populate({path: 'deviceType'}) - .exec(function(err, results) { - devices = results; - callback(err); - }); + Device.find({'_id': { $in: req.body.devices }}) + .populate({path: 'deviceType'}) + .exec(function(err, results) { + devices = results; + callback(err); + }); }, function(callback) { User.find({ diff --git a/app/model/device.js b/app/model/device.js index 65aa8d7..e3ec1c7 100644 --- a/app/model/device.js +++ b/app/model/device.js @@ -13,6 +13,7 @@ var deviceSchema = new Schema({ location: String, frequencyType: String, frequencySchedule: [], + lastTestRun: {}, deleted: { type: Boolean, default: false } }); diff --git a/public/js/controllers/testRuns.js b/public/js/controllers/testRuns.js index 12cba84..e2e0dce 100644 --- a/public/js/controllers/testRuns.js +++ b/public/js/controllers/testRuns.js @@ -40,6 +40,8 @@ function testRunAddController($scope, Devices, CheckLists, TestRuns, $location, field.result = (field.value == 'true'); } else if (field.type == 'range') { field.result = field.value >= field.min && field.value <= field.max; + } else if (field.type == 'text') { + field.result = true; } $scope.model.result &= field.result; @@ -55,4 +57,4 @@ function testRunAddController($scope, Devices, CheckLists, TestRuns, $location, function testRunViewController($scope, Devices, CheckLists, TestRuns, $location, $filter, $routeParams) { $scope.model = TestRuns.get($routeParams); -} \ No newline at end of file +} diff --git a/public/partials/checkLists/add.html b/public/partials/checkLists/add.html index 0d97f78..d2ad07a 100644 --- a/public/partials/checkLists/add.html +++ b/public/partials/checkLists/add.html @@ -38,6 +38,7 @@ diff --git a/public/partials/clients/edit.html b/public/partials/clients/edit.html index 3e5896f..101774a 100644 --- a/public/partials/clients/edit.html +++ b/public/partials/clients/edit.html @@ -305,7 +305,8 @@ Serial No. Purchase Date Warranty Expiration - PM Test + PM Test + Last Test Run Location @@ -319,7 +320,16 @@ {{device.serialNumber}} {{device.purchaseDate | date}} {{device.warrantyExpiration | date}} - + New + +
+ + {{device.lastTestRun.date | date}} | + Passed + Failed + +
+ {{device.location}} diff --git a/public/partials/testRuns/add.html b/public/partials/testRuns/add.html index 95e174b..250bbd5 100644 --- a/public/partials/testRuns/add.html +++ b/public/partials/testRuns/add.html @@ -32,6 +32,12 @@ +
+ +
+ +
+