From b4e727c0e688c204646438aad7bbe771fdd17efd Mon Sep 17 00:00:00 2001 From: Dobie Wollert Date: Mon, 3 Aug 2015 05:00:22 -0400 Subject: [PATCH] latest bits --- app/controllers/clients.js | 277 ++++++++++++++----------- app/controllers/deviceTypes.js | 120 +++++++++++ app/controllers/devices.js | 176 +++++++--------- app/model/device.js | 21 +- app/model/deviceType.js | 16 ++ app/views/index.jade | 4 +- config/routes.js | 18 +- public/js/app.js | 16 +- public/js/controllers.js | 254 +---------------------- public/js/controllers/deviceTypes.js | 251 ++++++++++++++++++++++ public/js/controllers/devices.js | 1 + public/js/services.js | 19 +- public/partials/clients/edit.html | 23 +- public/partials/deviceTypes/add.html | 80 +++++++ public/partials/deviceTypes/edit.html | 80 +++++++ public/partials/deviceTypes/index.html | 41 ++++ public/partials/devices/add.html | 144 ++++++------- public/partials/devices/edit.html | 144 ++++++------- public/partials/devices/index.html | 68 +++--- 19 files changed, 1054 insertions(+), 699 deletions(-) create mode 100644 app/controllers/deviceTypes.js create mode 100644 app/model/deviceType.js create mode 100644 public/js/controllers/deviceTypes.js create mode 100644 public/js/controllers/devices.js create mode 100644 public/partials/deviceTypes/add.html create mode 100644 public/partials/deviceTypes/edit.html create mode 100644 public/partials/deviceTypes/index.html diff --git a/app/controllers/clients.js b/app/controllers/clients.js index c41e8a1..8f9e83b 100644 --- a/app/controllers/clients.js +++ b/app/controllers/clients.js @@ -1,176 +1,211 @@ var mongoose = require('mongoose'), - Client = mongoose.model('Client'), - Workorder = mongoose.model('Workorder'), - Tag = mongoose.model('Tag'); + Client = mongoose.model('Client'), + Workorder = mongoose.model('Workorder'), + Device = mongoose.model('Device'), + Tag = mongoose.model('Tag'); var log = require('log4node'); -var frequencies = ["Medical Device","Sterilizer - TT","Vaporizer","Ice Maker","Anesthesia","Waste Management System","Imaging","Medical Gas Systems","RAE","ERT","N2O Trace Gas","Sterilizer - F","Quarterly","Semi","Annual","legacy","DLLR", "Isolation Panel", "Battery Backup", "Sterilizer - Cleaning"]; +var frequencies = [ + "Medical Device","Sterilizer - TT", + "Vaporizer", + "Ice Maker", + "Anesthesia", + "Waste Management System", + "Imaging", + "Medical Gas Systems", + "RAE", + "ERT", + "N2O Trace Gas", + "Sterilizer - F", + "Quarterly", + "Semi", + "Annual", + "legacy", + "DLLR", + "Isolation Panel", + "Battery Backup", + "Sterilizer - Cleaning" +]; exports.index = function(req, res) { - log.info("clients.index"); - var query = Client.find({ deleted: false }) - .select('name identifier address') - .slice('contacts', 1) - .sort('name') - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(results); - } - }); + log.info("clients.index"); + var query = Client.find({ deleted: false }) + .select('name identifier address') + .slice('contacts', 1) + .sort('name') + .exec(function(err, results) { + if (err) { + res.json(500, err); + } else { + res.json(results); + } + }); } exports.get = function(req, res, next) { - var id = req.param('client_id'); + var id = req.param('client_id'); - log.info("clients.get %s", id); - Client.findById(id) - .exec(function(err, client) { - if (err) return next(err); - if (!client) return next(new Error('Failed to load client ' + id)); + log.info("clients.get %s", id); + Client.findById(id) + .exec(function(err, client) { + if (err) return next(err); + if (!client) return next(new Error('Failed to load client ' + id)); - res.json(client); - }); + res.json(client); + }); } exports.frequencies = function(req, res, next) { - log.info("clients.frequencies"); + log.info("clients.frequencies"); - var query = Client.find({ deleted: false }) - .select('name identifier frequencies') - .slice('contacts', 1) - .sort('name') - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(results); - } - }); + var query = Client.find({ deleted: false }) + .select('name identifier frequencies') + .slice('contacts', 1) + .sort('name') + .exec(function(err, results) { + if (err) { + res.json(500, err); + } else { + res.json(results); + } + }); }; exports.workorders = function(req, res, next) { - var id = req.param('client_id'); - log.info("clients.workorders %s", id); + var id = req.param('client_id'); + log.info("clients.workorders %s", id); - Workorder.find({ client: id, deleted: false }) - .populate({path: 'techs', select: 'name'}) - .sort('-scheduling.start') - .exec(function(err, workorders) { - if (err) return next(err); - if (!workorders) return next(new Error('Failed to load workorders ' + id)); + Workorder.find({ client: id, deleted: false }) + .populate({path: 'techs', select: 'name'}) + .sort('-scheduling.start') + .exec(function(err, workorders) { + if (err) return next(err); + if (!workorders) return next(new Error('Failed to load workorders ' + id)); - res.json(workorders); - }); + res.json(workorders); + }); }; exports.tags = function(req, res, next) { - var id = req.param('client_id'); - log.info("clients.tags %s", id); + var id = req.param('client_id'); + log.info("clients.tags %s", id); - Tag.find({ client: id }) - .exec(function(err, tags) { - if (err) return next(err); - if (!tags) return next(new Error('Failed to load tags ' + id)); + Tag.find({ client: id }) + .exec(function(err, tags) { + if (err) return next(err); + if (!tags) return next(new Error('Failed to load tags ' + id)); - res.json(tags); - }); + res.json(tags); + }); }; +exports.devices = function(req, res, next) { + var id = req.param('client_id'); + log.info("clients.devices %s", id); + + Device.find({client: id, deleted: false }) + .populate({path: 'deviceType'}) + .exec(function(err, devices) { + if (err) return next(err); + if (!devices) return next(new Error('Failed to load devices ' + id)); + + res.json(devices); + }); +} + exports.create = function(req, res, next) { - log.info("clients.create %j", req.body); + log.info("clients.create %j", req.body); - var client = new Client({ - name: req.body.name, - identifier: req.body.identifier.toUpperCase(), - contacts: req.body.contacts, - address: req.body.address, - notes: req.body.notes, - frequencies: {} - }); + var client = new Client({ + name: req.body.name, + identifier: req.body.identifier.toUpperCase(), + contacts: req.body.contacts, + address: req.body.address, + notes: req.body.notes, + frequencies: {} + }); - var freq = {}; + var freq = {}; - for (key in frequencies) { - client.frequencies[frequencies[key]] = [false, false, false, false, false, false, false, false, false, false, false, false]; - } + for (key in frequencies) { + client.frequencies[frequencies[key]] = [false, false, false, false, false, false, false, false, false, false, false, false]; + } - return client.save(function(err) { - if (err) - log.error("Error: %s", err); + return client.save(function(err) { + if (err) + log.error("Error: %s", err); - return res.json(client); - }) + return res.json(client); + }) }; exports.isUnique = function(req, res, next) { - - var field = req.param('field'); - var value = req.param('value'); - var key = req.param('key'); + + var field = req.param('field'); + var value = req.param('value'); + var key = req.param('key'); - if (!field || !value) { - return res.json(400, 'missing field or value'); - } + if (!field || !value) { + return res.json(400, 'missing field or value'); + } - var query = {}; - - if (field === 'identifier') { - query[field] = value.toUpperCase(); - } else { - query[field] = value; - } + var query = {}; + + if (field === 'identifier') { + query[field] = value.toUpperCase(); + } else { + query[field] = value; + } - if (key) { - query['_id'] = { $ne: key }; - } + if (key) { + query['_id'] = { $ne: key }; + } - Client.find(query) - .exec(function(err, result) { - if (err) return next(err); - res.json({ - isUnique: result.length === 0 - }); - }); + Client.find(query) + .exec(function(err, result) { + if (err) return next(err); + res.json({ + isUnique: result.length === 0 + }); + }); }; exports.update = function(req, res, next) { - var id = req.param('client_id'); - log.info("clients.update %s %j", id, req.body); + var id = req.param('client_id'); + log.info("clients.update %s %j", id, req.body); - return Client.findById(id, function(err, client) { - client.name = req.body.name; - client.identifier = req.body.identifier.toUpperCase(); - client.contacts = req.body.contacts; - client.address = req.body.address; - client.frequencies = req.body.frequencies; - client.notes = req.body.notes; + return Client.findById(id, function(err, client) { + client.name = req.body.name; + client.identifier = req.body.identifier.toUpperCase(); + client.contacts = req.body.contacts; + client.address = req.body.address; + client.frequencies = req.body.frequencies; + client.notes = req.body.notes; - return client.save(function(err) { - if (err) - log.error("Error: %s", err); + return client.save(function(err) { + if (err) + log.error("Error: %s", err); - return res.json(client); - }); - }); + return res.json(client); + }); + }); }; exports.destroy = function(req, res, next) { - var id = req.param('client_id'); + var id = req.param('client_id'); - log.info("clients.destroy %s", id); + log.info("clients.destroy %s", id); - return Client.findById(id, function(err, client) { - client.deleted = true; + return Client.findById(id, function(err, client) { + client.deleted = true; - return client.save(function(err) { - if (err) - log.error("Error: %s", err); + return client.save(function(err) { + if (err) + log.error("Error: %s", err); - return res.json(client); - }) - }); + return res.json(client); + }) + }); }; diff --git a/app/controllers/deviceTypes.js b/app/controllers/deviceTypes.js new file mode 100644 index 0000000..7954083 --- /dev/null +++ b/app/controllers/deviceTypes.js @@ -0,0 +1,120 @@ +var mongoose = require('mongoose'), + DeviceType = mongoose.model('DeviceType'); + +var _ = require('lodash'); +var md5 = require('MD5'); + +var log = require('log4node'); + +exports.index = function(req, res, next) { + log.info('device_types.index'); + + DeviceType.find({ deleted: false }) + .exec(returnResult(res)); +}; + +exports.get = function(req, res, next) { + var id = req.param('device_type_id'); + + log.info("device_types.get %s", id); + + DeviceType.findById(id) + .exec(returnResult(res)); +}; + +exports.categories = function(req, res, next) { + log.info("device_types.categories"); + + DeviceType.find({ deleted: false }) + .select('category') + .exec(mutateResult(res, function(data) { + return _.uniq(_.pluck(data, 'category')); + })); +}; + +exports.makes = function(req, res, next) { + log.info("device_types.makes"); + + DeviceType.find({ deleted: false }) + .select('make') + .exec(mutateResult(res, function(data) { + return _.uniq(_.pluck(data, 'make')); + })); +}; + +exports.models = function(req, res, next) { + log.info("device_types.models"); + + DeviceType.find({ deleted: false }) + .select('model') + .exec(mutateResult(res, function(data) { + return _.uniq(_.pluck(data, 'model')); + })); +}; + +exports.create = function(req, res, next) { + log.info("device_types.create %j", res.body); + + var deviceType = new DeviceType(req.body); + deviceType.save(returnResult(res)); +}; + +exports.update = function(req, res, next) { + var id = req.param('device_type_id'); + log.info('device_types.update %s %j', id, req.body); + + DeviceType.findById(id, function(err, deviceType) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else if (!deviceType) { + res.json(404, 'Unknown DeviceType: %s', id); + } else { + _.assign(deviceType, req.body); + deviceType.save(returnResult(res, deviceType)); + } + }); +}; + +exports.upload = function(req, res, next) { + var path = req.files.file.path; + + fs.readFile(path, function(err, data) { + var hash = md5(data); + + fs.writeFile('/srv/biomed-site/images/devices/' + hash, data, function(err) { + if (err) + log.error("Error: %s", err); + + return res.json({ + filename: hash + }); + }); + }); +}; + +function returnResult(res, result) { + return function(err, data) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else { + if (result) { + res.json(result); + } else { + res.json(data); + } + } + } +} + +function mutateResult(res, mutator) { + return function(err, results) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else { + res.json(mutator(results)); + } + } +} \ No newline at end of file diff --git a/app/controllers/devices.js b/app/controllers/devices.js index c3bae86..7018885 100644 --- a/app/controllers/devices.js +++ b/app/controllers/devices.js @@ -6,127 +6,93 @@ var md5 = require('MD5'); var log = require('log4node'); -exports.index = function(req, res) { - log.info('devices.index'); - var query = Device.find({ deleted: false }) - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(results); - } - }); +exports.index = function(req, res, next) { + log.info('devices.index'); + + Device.find({ deleted: false }) + .exec(returnResult(res)); }; exports.get = function(req, res, next) { - var id = req.param('device_id'); + var id = req.param('device_id'); - log.info("devices.get %s", id); - Device.findById(id) - .exec(function(err, device) { - if (err) return next(err); - if (!device) return next(new Error('failed to load device ' + id)); + log.info("devices.get %s", id); - res.json(device); - }); -}; - -exports.deviceTypes = function(req, res, next) { - log.info("devices.deviceTypes"); - - var query = Device.find({ deleted: false }) - .select('deviceType') - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(_.uniq(_.pluck(results, 'deviceType'))); - } - }); -}; - -exports.makes = function(req, res, next) { - log.info("devices.makes"); - - var query = Device.find({ deleted: false }) - .select('make') - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(_.uniq(_.pluck(results, 'make'))); - } - }); -}; - -exports.models = function(req, res, next) { - log.info("devices.models"); - - var query = Device.find({ deleted: false }) - .select('model') - .exec(function(err, results) { - if (err) { - res.json(500, err); - } else { - res.json(_.uniq(_.pluck(results, 'model'))); - } - }); + Device.findById(id) + .exec(returnResult(res)); }; exports.create = function(req, res, next) { - log.info("devices.create %j", res.body); + log.info("devices.create %j", res.body); - var device = new Device({ - deviceType: req.body.deviceType, - make: req.body.make, - model: req.body.model, - technicalData: req.body.technicalData, - links: req.body.links, - partsRecommended: req.body.partsRecommended, - images: req.body.images - }); - - return device.save(function(err) { - if (err) - log.error("Error: %s", err); - return res.json(device); - }); + var device = new Device(req.body); + device.save(returnResult(res)); }; exports.update = function(req, res, next) { - var id = req.param('device_id'); - log.info('devices.update %s %j', id, req.body); + var id = req.param('device_id'); + log.info('devices.update %s %j', id, req.body); - return Device.findById(id, function(err, device) { - device.deviceType = req.body.deviceType; - device.make = req.body.make; - device.model = req.body.model; - device.technicalData = req.body.technicalData; - device.links = req.body.links; - device.partsRecommended = req.body.partsRecommended; - device.images = req.body.images; - - return device.save(function(err) { - if (err) - log.error("Error: %s", err); - return res.json(device); - }); - }); + Device.findById(id, function(err, device) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else if (!device) { + res.json(404, 'Unknown Device: %s', id); + } else { + _.assign(device, req.body); + device.save(returnResult(res, device)); + } + }); }; -exports.upload = function(req, res, next) { - var path = req.files.file.path; +exports.isUnique = function(req, res, next) { + var field = req.param('field'); + var value = req.param('value'); + var key = req.param('key'); - fs.readFile(path, function(err, data) { - var hash = md5(data); + if (!field || !value) { + return res.json(400, 'missing field or value'); + } - fs.writeFile('/srv/biomed-site/images/devices/' + hash, data, function(err) { - if (err) - log.error("Error: %s", err); + var query = {}; + query[field] = value; - return res.json({ - filename: hash - }); - }); - }); + if (key) { + query['_id'] = { $ne: key }; + } + + Device.find(query) + .exec(function(err, result) { + if (err) return next(err); + res.json({ + isUnique: result.length === 0 + }); + }); }; + +function returnResult(res, result) { + return function(err, data) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else { + if (result) { + res.json(result); + } else { + res.json(data); + } + } + } +} + +function mutateResult(res, mutator) { + return function(err, results) { + if (err) { + log.error("Error: %s", err); + res.json(500, err); + } else { + res.json(mutator(results)); + } + } +} \ No newline at end of file diff --git a/app/model/device.js b/app/model/device.js index 244aff5..1cbd44f 100644 --- a/app/model/device.js +++ b/app/model/device.js @@ -1,16 +1,17 @@ var mongoose = require('mongoose') - Schema = mongoose.Schema, - ObjectId = Schema.ObjectId; + Schema = mongoose.Schema, + ObjectId = Schema.ObjectId; var deviceSchema = new Schema({ - deviceType: String, - make: String, - model: String, - technicalData: String, - links: String, - partsRecommended: String, - images: [{ type: String }], - deleted: { type: Boolean, default: false } + client: { type: ObjectId, ref: 'Client' }, + deviceType: { type: ObjectId, ref: 'DeviceType' }, + + biomedId: String, + serialNumber: String, + purchaseDate: Date, + warrantyExpiration: Date, + location: String, + deleted: { type: Boolean, default: false } }); module.exports = mongoose.model('Device', deviceSchema); diff --git a/app/model/deviceType.js b/app/model/deviceType.js new file mode 100644 index 0000000..9d3882c --- /dev/null +++ b/app/model/deviceType.js @@ -0,0 +1,16 @@ +var mongoose = require('mongoose') + Schema = mongoose.Schema, + ObjectId = Schema.ObjectId; + +var deviceTypeSchema = new Schema({ + category: String, + make: String, + model: String, + technicalData: String, + links: String, + partsRecommended: String, + images: [{ type: String }], + deleted: { type: Boolean, default: false } +}); + +module.exports = mongoose.model('DeviceType', deviceTypeSchema); diff --git a/app/views/index.jade b/app/views/index.jade index e847859..3b14b33 100644 --- a/app/views/index.jade +++ b/app/views/index.jade @@ -60,8 +60,8 @@ html(lang="en", ng-app="biomed", ng-controller="PageCtrl") a(href='/accounting') | Accounting - li(data-match-route='/devices.*') - a(href='/devices') + li(data-match-route='/deviceTypes.*') + a(href='/deviceTypes') | Devices li(data-match-route='/posts.*', ng-show="accountHasPermission('system.admin')") diff --git a/config/routes.js b/config/routes.js index 7297478..e4bdf91 100644 --- a/config/routes.js +++ b/config/routes.js @@ -19,6 +19,8 @@ module.exports = function(app, auth, piler, calendar, directory, config) { piler.addJsFile("/js/lib/dropzone.js"); piler.addJsFile("/js/app.js"); piler.addJsFile("/js/controllers.js"); + piler.addJsFile("/js/controllers/devices.js"); + piler.addJsFile("/js/controllers/deviceTypes.js"); piler.addJsFile("/js/directives.js"); piler.addJsFile("/js/filters.js"); piler.addJsFile("/js/services.js"); @@ -47,6 +49,7 @@ module.exports = function(app, auth, piler, calendar, directory, config) { app.get('/api/clients/:client_id', clients.get); app.get('/api/clients/:client_id/workorders', clients.workorders); app.get('/api/clients/:client_id/tags', clients.tags); + app.get('/api/clients/:client_id/devices', clients.devices); app.post('/api/clients', clients.create); app.post('/api/clients/:client_id', clients.update); app.del('/api/clients/:client_id', clients.destroy); @@ -60,14 +63,21 @@ module.exports = function(app, auth, piler, calendar, directory, config) { var devices = require('../app/controllers/devices'); app.get('/api/devices', devices.index); - app.get('/api/devices/deviceTypes', devices.deviceTypes); - app.get('/api/devices/makes', devices.makes); - app.get('/api/devices/models', devices.models); - app.post('/api/devices/images', devices.upload); + app.get('/api/devices/isUnique', devices.isUnique); app.get('/api/devices/:device_id', devices.get); app.post('/api/devices', devices.create); app.post('/api/devices/:device_id', devices.update); + var deviceTypes = require('../app/controllers/deviceTypes'); + app.get('/api/device_types', deviceTypes.index); + app.get('/api/device_types/categories', deviceTypes.categories); + app.get('/api/device_types/makes', deviceTypes.makes); + app.get('/api/device_types/models', deviceTypes.models); + app.post('/api/device_types/images', deviceTypes.upload); + app.get('/api/device_types/:device_type_id', deviceTypes.get); + app.post('/api/device_types', deviceTypes.create); + app.post('/api/device_types/:device_type_id', deviceTypes.update); + var pms = require('../app/controllers/pms'); app.get('/api/pms', pms.index); diff --git a/public/js/app.js b/public/js/app.js index 1ad432e..6c1d0c0 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -61,18 +61,22 @@ angular.module('biomed', ['biomed.filters', 'biomed.services', 'biomed.directive templateUrl: '/partials/clients/edit.html', controller: "ClientEditCtrl" }) - .when('/devices', { - templateUrl: '/partials/devices/index.html', - controller: "DeviceIndexCtrl", + .when('/deviceTypes', { + templateUrl: '/partials/deviceTypes/index.html', + controller: "DeviceTypeIndexCtrl", reloadOnSearch: false }) .when('/devices/add', { templateUrl: '/partials/devices/add.html', controller: "DeviceAddCtrl" }) - .when('/devices/:id', { - templateUrl: '/partials/devices/edit.html', - controller: "DeviceEditCtrl" + .when('/deviceTypes/add', { + templateUrl: '/partials/deviceTypes/add.html', + controller: "DeviceTypeAddCtrl" + }) + .when('/deviceTypes/:id', { + templateUrl: '/partials/deviceTypes/edit.html', + controller: "DeviceTypeEditCtrl" }) .when('/accounting', { templateUrl: '/partials/accounting/index.html', diff --git a/public/js/controllers.js b/public/js/controllers.js index c63d301..2b1a723 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -588,9 +588,7 @@ angular.module('biomed') updatePms(); }); - $scope.tags = Clients.tags($routeParams, function() { - - }); + $scope.devices = Clients.devices($routeParams); $scope.identification = createController(); $scope.address = createController(); @@ -705,256 +703,6 @@ angular.module('biomed') } }) -.controller("DeviceIndexCtrl", function($scope, $filter, $routeParams, Devices, LocationBinder) { - $scope.loading = true; - - var allData = Devices.index(function() { - $scope.loading = false; - $scope.filter(); - }); - - var filteredData = []; - var index = 0; - var initialPageSize = 100; - var pageSize = 5; - - $scope.canLoad = true; - - $scope.$watch('query', function() { - $scope.filter(); - }); - - LocationBinder($scope, ['query']); - - $scope.filter = function() { - filteredData = $filter('orderBy')($filter('filter')(allData, $scope.query), $scope.sort.column, $scope.sort.descending); - index = initialPageSize; - $scope.canLoad = true; - $scope.devices = filteredData.slice(0, initialPageSize); - }; - - $scope.addItems = function() { - $scope.devices = $scope.devices.concat(filteredData.slice(index, index + pageSize)); - index += pageSize; - $scope.canLoad = index < filteredData.length; - } - - $scope.sort = { - column: 'deviceType', - descending: false - }; - - $scope.selectedCls = function(column) { - return column == $scope.sort.column && 'sort-' + $scope.sort.descending; - } - - $scope.changeSorting = function(column) { - var sort = $scope.sort; - if (sort.column == column) { - sort.descending = !sort.descending; - } else { - sort.column = column; - sort.descending = false; - } - - $scope.filter(); - }; -}) - -.controller("DeviceAddCtrl", function($scope, Devices, $location, $filter) { - $scope.model = {}; - - $scope.deviceTypes = Devices.deviceTypes(); - $scope.deviceMakes = Devices.makes(); - - $scope.deviceTypeOpts = { - containerCssClass: 'input-xxlarge', - placeholder: 'Choose a Device Type', - query: function(query) { - var data = $filter('filter')($scope.deviceTypes, query.term); - var results = []; - data.forEach(function(item) { - results.push({id: item, text: item}); - }); - query.callback({results: results }); - }, - createSearchChoice: function(term) { - return { id: term, text: term }; - } - }; - - $scope.makeOpts = { - containerCssClass: 'input-xxlarge', - placeholder: 'Choose a Device Make', - query: function(query) { - var data = $filter('filter')($scope.deviceMakes, query.term); - var results = []; - data.forEach(function(item) { - results.push({id: item, text: item}); - }); - query.callback({results: results }); - }, - createSearchChoice: function(term) { - return { id: term, text: term }; - } - }; - - var images = {}; - - $scope.imageOpts = { - options: { - url: '/api/devices/images', - addRemoveLinks: true - }, - eventHandlers: { - success: function(file, response) { - file.filename = response.filename; - - if (images[file.filename]) { - images[file.filename]++; - this.removeFile(file); - } else { - images[file.filename] = 1; - } - }, - removedfile: function(file) { - images[file.filename]--; - - if (images[file.filename] <= 0) { - delete images[file.filename]; - } - } - } - }; - - $scope.$watch('deviceTypePicker', function() { - if ($scope.deviceTypePicker) { - $scope.model.deviceType = $scope.deviceTypePicker.id; - } else { - $scope.model.deviceType = null; - } - }); - - $scope.$watch('makePicker', function() { - if ($scope.makePicker) { - $scope.model.make = $scope.makePicker.id; - } else { - $scope.model.make = null; - } - }); - - $scope.save = function() { - $scope.model.images = Object.keys(images); - - Devices.create($scope.model, function(result) { -// $location.path("/devices/" + result._id); - $location.path("/devices/"); - }); - }; -}) - -.controller("DeviceEditCtrl", function($scope, Devices, $location, $filter, $routeParams) { - var images = {}; - - $scope.model = Devices.get($routeParams, function() { - $scope.loading = false; - - $scope.existingImages = $scope.model.images; - if ($scope.model.images) { - for (var i = 0; i < $scope.model.images.length; i++) { - images[$scope.model.images[i]] = 1; - } - } - - $scope.deviceTypePicker = {id: $scope.model.deviceType, text: $scope.model.deviceType}; - $scope.makePicker = {id: $scope.model.make, text: $scope.model.make}; - }); - - $scope.deviceTypes = Devices.deviceTypes(); - $scope.deviceMakes = Devices.makes(); - - $scope.deviceTypeOpts = { - containerCssClass: 'input-xxlarge', - placeholder: 'Choose a Device Type', - query: function(query) { - var data = $filter('filter')($scope.deviceTypes, query.term); - var results = []; - data.forEach(function(item) { - results.push({id: item, text: item}); - }); - query.callback({results: results }); - }, - createSearchChoice: function(term) { - return { id: term, text: term }; - } - }; - - $scope.makeOpts = { - containerCssClass: 'input-xxlarge', - placeholder: 'Choose a Device Make', - query: function(query) { - var data = $filter('filter')($scope.deviceMakes, query.term); - var results = []; - data.forEach(function(item) { - results.push({id: item, text: item}); - }); - query.callback({results: results }); - }, - createSearchChoice: function(term) { - return { id: term, text: term }; - } - }; - - $scope.imageOpts = { - options: { - url: '/api/devices/images', - addRemoveLinks: true - }, - eventHandlers: { - success: function(file, response) { - file.filename = response.filename; - - if (images[file.filename]) { - images[file.filename]++; - this.removeFile(file); - } else { - images[file.filename] = 1; - } - }, - removedfile: function(file) { - images[file.filename]--; - - if (images[file.filename] <= 0) { - delete images[file.filename]; - } - } - } - }; - - $scope.$watch('deviceTypePicker', function() { - if ($scope.deviceTypePicker) { - $scope.model.deviceType = $scope.deviceTypePicker.id; - } else { - $scope.model.deviceType = null; - } - }); - - $scope.$watch('makePicker', function() { - if ($scope.makePicker) { - $scope.model.make = $scope.makePicker.id; - } else { - $scope.model.make = null; - } - }); - - $scope.save = function() { - $scope.model.images = Object.keys(images); - - Devices.update({id: $scope.model._id}, $scope.model, function(result) { - $location.path("/devices/"); - }); - }; -}) .controller("AccountingIndexCtrl", function($scope, $filter, $routeParams, Workorders, LocationBinder) { $scope.loading = true; diff --git a/public/js/controllers/deviceTypes.js b/public/js/controllers/deviceTypes.js new file mode 100644 index 0000000..fa5fa54 --- /dev/null +++ b/public/js/controllers/deviceTypes.js @@ -0,0 +1,251 @@ +angular.module('biomed') + +.controller("DeviceTypeIndexCtrl", function($scope, $filter, $routeParams, DeviceTypes, LocationBinder) { + $scope.loading = true; + + var allData = DeviceTypes.index(function() { + $scope.loading = false; + $scope.filter(); + }); + + var filteredData = []; + var index = 0; + var initialPageSize = 100; + var pageSize = 5; + + $scope.canLoad = true; + + $scope.$watch('query', function() { + $scope.filter(); + }); + + LocationBinder($scope, ['query']); + + $scope.filter = function() { + filteredData = $filter('orderBy')($filter('filter')(allData, $scope.query), $scope.sort.column, $scope.sort.descending); + index = initialPageSize; + $scope.canLoad = true; + $scope.devices = filteredData.slice(0, initialPageSize); + }; + + $scope.addItems = function() { + $scope.devices = $scope.devices.concat(filteredData.slice(index, index + pageSize)); + index += pageSize; + $scope.canLoad = index < filteredData.length; + } + + $scope.sort = { + column: 'category', + descending: false + }; + + $scope.selectedCls = function(column) { + return column == $scope.sort.column && 'sort-' + $scope.sort.descending; + } + + $scope.changeSorting = function(column) { + var sort = $scope.sort; + if (sort.column == column) { + sort.descending = !sort.descending; + } else { + sort.column = column; + sort.descending = false; + } + + $scope.filter(); + }; +}) + +.controller("DeviceTypeAddCtrl", function($scope, DeviceTypes, $location, $filter) { + $scope.model = {}; + + $scope.categories = DeviceTypes.categories(); + $scope.deviceMakes = DeviceTypes.makes(); + + $scope.categoryOpts = { + containerCssClass: 'input-xxlarge', + placeholder: 'Choose a Device Type', + query: function(query) { + var data = $filter('filter')($scope.categories, query.term); + var results = []; + data.forEach(function(item) { + results.push({id: item, text: item}); + }); + query.callback({results: results }); + }, + createSearchChoice: function(term) { + return { id: term, text: term }; + } + }; + + $scope.makeOpts = { + containerCssClass: 'input-xxlarge', + placeholder: 'Choose a Device Make', + query: function(query) { + var data = $filter('filter')($scope.deviceMakes, query.term); + var results = []; + data.forEach(function(item) { + results.push({id: item, text: item}); + }); + query.callback({results: results }); + }, + createSearchChoice: function(term) { + return { id: term, text: term }; + } + }; + + var images = {}; + + $scope.imageOpts = { + options: { + url: '/api/deviceTypes/images', + addRemoveLinks: true + }, + eventHandlers: { + success: function(file, response) { + file.filename = response.filename; + + if (images[file.filename]) { + images[file.filename]++; + this.removeFile(file); + } else { + images[file.filename] = 1; + } + }, + removedfile: function(file) { + images[file.filename]--; + + if (images[file.filename] <= 0) { + delete images[file.filename]; + } + } + } + }; + + $scope.$watch('categoryPicker', function() { + if ($scope.categoryPicker) { + $scope.model.category = $scope.categoryPicker.id; + } else { + $scope.model.category = null; + } + }); + + $scope.$watch('makePicker', function() { + if ($scope.makePicker) { + $scope.model.make = $scope.makePicker.id; + } else { + $scope.model.make = null; + } + }); + + $scope.save = function() { + $scope.model.images = Object.keys(images); + + DeviceTypes.create($scope.model, function(result) { + $location.path("/deviceTypes/"); + }); + }; +}) + +.controller("DeviceTypeEditCtrl", function($scope, DeviceTypes, $location, $filter, $routeParams) { + var images = {}; + + $scope.model = DeviceTypes.get($routeParams, function() { + $scope.loading = false; + + $scope.existingImages = $scope.model.images; + if ($scope.model.images) { + for (var i = 0; i < $scope.model.images.length; i++) { + images[$scope.model.images[i]] = 1; + } + } + + $scope.categoryPicker = {id: $scope.model.category, text: $scope.model.category}; + $scope.makePicker = {id: $scope.model.make, text: $scope.model.make}; + }); + + $scope.categories = DeviceTypes.categories(); + $scope.deviceMakes = DeviceTypes.makes(); + + $scope.categoryOpts = { + containerCssClass: 'input-xxlarge', + placeholder: 'Choose a Device Type', + query: function(query) { + var data = $filter('filter')($scope.categories, query.term); + var results = []; + data.forEach(function(item) { + results.push({id: item, text: item}); + }); + query.callback({results: results }); + }, + createSearchChoice: function(term) { + return { id: term, text: term }; + } + }; + + $scope.makeOpts = { + containerCssClass: 'input-xxlarge', + placeholder: 'Choose a Device Make', + query: function(query) { + var data = $filter('filter')($scope.deviceMakes, query.term); + var results = []; + data.forEach(function(item) { + results.push({id: item, text: item}); + }); + query.callback({results: results }); + }, + createSearchChoice: function(term) { + return { id: term, text: term }; + } + }; + + $scope.imageOpts = { + options: { + url: '/api/deviceTypes/images', + addRemoveLinks: true + }, + eventHandlers: { + success: function(file, response) { + file.filename = response.filename; + + if (images[file.filename]) { + images[file.filename]++; + this.removeFile(file); + } else { + images[file.filename] = 1; + } + }, + removedfile: function(file) { + images[file.filename]--; + + if (images[file.filename] <= 0) { + delete images[file.filename]; + } + } + } + }; + + $scope.$watch('categoryPicker', function() { + if ($scope.categoryPicker) { + $scope.model.category = $scope.categoryPicker.id; + } else { + $scope.model.category = null; + } + }); + + $scope.$watch('makePicker', function() { + if ($scope.makePicker) { + $scope.model.make = $scope.makePicker.id; + } else { + $scope.model.make = null; + } + }); + + $scope.save = function() { + $scope.model.images = Object.keys(images); + + DeviceTypes.update({id: $scope.model._id}, $scope.model, function(result) { + $location.path("/deviceTypes/"); + }); + }; +}) \ No newline at end of file diff --git a/public/js/controllers/devices.js b/public/js/controllers/devices.js new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/public/js/controllers/devices.js @@ -0,0 +1 @@ + diff --git a/public/js/services.js b/public/js/services.js index f71f4f5..39e9313 100644 --- a/public/js/services.js +++ b/public/js/services.js @@ -3,23 +3,24 @@ angular.module('biomed.services', []) return $resource('/api/clients/:id/:cmd', { id: "@id", cmd: "@cmd" }, { - index: { method: 'GET', params: {}, isArray: true }, + index: { method: 'GET', params: {}, isArray: true }, frequencies: { method: 'GET', params: { cmd: 'frequencies' }, isArray: true }, - get: { method: 'GET', params: { id: 0} }, - create: { method: 'POST', params: {} }, - update: { method: 'POST', params: { id: 0} }, - destroy: { method: 'DELETE', params: { id: 0 } }, + get: { method: 'GET', params: { id: 0} }, + create: { method: 'POST', params: {} }, + update: { method: 'POST', params: { id: 0} }, + destroy: { method: 'DELETE', params: { id: 0 } }, workorders: { method: 'GET', params: { id: 0, cmd: 'workorders' }, isArray: true }, + devices: { method: 'GET', params: { id: 0, cmd: 'devices' }, isArray: true }, tags: { method: 'GET', params: { id: 0, cmd: 'tags' }, isArray: true }, - isUnique: { method: 'GET', params: { cmd: 'isUnique' } }, + isUnique: { method: 'GET', params: { cmd: 'isUnique' } }, }); }) -.factory("Devices", function($resource) { - return $resource('/api/devices/:id/:cmd', +.factory("DeviceTypes", function($resource) { + return $resource('/api/device_types/:id/:cmd', { id: "@id", cmd: "@cmd" }, { index: { method: 'GET', params: {}, isArray: true }, - deviceTypes: { method: 'GET', params: { cmd: 'deviceTypes' }, isArray: true }, + categories: { method: 'GET', params: { cmd: 'categories' }, isArray: true }, makes: { method: 'GET', params: { cmd: 'makes' }, isArray: true }, models: { method: 'GET', params: { cmd: 'models' }, isArray: true }, get: { method: 'GET', params: { id: 0} }, diff --git a/public/partials/clients/edit.html b/public/partials/clients/edit.html index 7ccaaeb..e7c6424 100644 --- a/public/partials/clients/edit.html +++ b/public/partials/clients/edit.html @@ -8,6 +8,7 @@

{{master.identifier}}

Work Order Meeting + Device
@@ -309,17 +310,17 @@ - There is no information to display. - - {{tag.data.clientDeviceId}} - (Tag:{{tag._id}}) - {{tag.data.device}} - {{tag.data.make}} - {{tag.data.model}} - {{tag.data.serialNumber}} - {{tag.data.purchaseDate}} - {{tag.data.deviceWarrantyExpiration}} - {{tag.data.test}} - {{tag.data.roomNumber}} + There is no information to display. + + {{device.biomedId}} + + {{device.deviceType.make}} + {{device.deviceType.model}} + {{device.serialNumber}} + {{device.purchaseDate | date}} + {{device.warrantyExpiration | date}} + + {{device.location}} diff --git a/public/partials/deviceTypes/add.html b/public/partials/deviceTypes/add.html new file mode 100644 index 0000000..dd15240 --- /dev/null +++ b/public/partials/deviceTypes/add.html @@ -0,0 +1,80 @@ + +
+

New Device

+
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+ +
+
+
diff --git a/public/partials/deviceTypes/edit.html b/public/partials/deviceTypes/edit.html new file mode 100644 index 0000000..0a3f6c3 --- /dev/null +++ b/public/partials/deviceTypes/edit.html @@ -0,0 +1,80 @@ + +
+

Edit Device

+
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+ +
+
+
diff --git a/public/partials/deviceTypes/index.html b/public/partials/deviceTypes/index.html new file mode 100644 index 0000000..3434be6 --- /dev/null +++ b/public/partials/deviceTypes/index.html @@ -0,0 +1,41 @@ + +
+

Devices

+
+ +
+
+
+ Create new Device +
+ Search: +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + +
Device TypeMakeModel
There is no information to display.
{{device.category}}{{device.make}}{{device.model}}Edit
+
+
diff --git a/public/partials/devices/add.html b/public/partials/devices/add.html index a9cf62f..72dd30a 100644 --- a/public/partials/devices/add.html +++ b/public/partials/devices/add.html @@ -1,80 +1,80 @@
-

New Device

+

New Device

-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
-
- -
- -
-
+
+ +
+ +
+
diff --git a/public/partials/devices/edit.html b/public/partials/devices/edit.html index d648af0..0a3f6c3 100644 --- a/public/partials/devices/edit.html +++ b/public/partials/devices/edit.html @@ -1,80 +1,80 @@
-

Edit Device

+

Edit Device

-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
-
- -
- -
-
+
+ +
+ +
+
diff --git a/public/partials/devices/index.html b/public/partials/devices/index.html index 7e4fe94..01a9e91 100644 --- a/public/partials/devices/index.html +++ b/public/partials/devices/index.html @@ -1,41 +1,41 @@
-

Devices

+

Devices

-
-
- Create new Device -
- Search: -
- - -
-
-
- - - - - - - - - - - - - - - - - - - -
Device TypeMakeModel
There is no information to display.
{{device.deviceType}}{{device.make}}{{device.model}}Edit
-
+
+
+ Create new Device +
+ Search: +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + +
Device TypeMakeModel
There is no information to display.
{{device.category}}{{device.make}}{{device.model}}Edit
+