mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added support for tags
This commit is contained in:
@ -5,6 +5,6 @@ module.exports = function(piler) {
|
||||
js: piler.js.renderTags(),
|
||||
css: piler.css.renderTags()
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
50
app/controllers/tags.js
Normal file
50
app/controllers/tags.js
Normal file
@ -0,0 +1,50 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Tag = mongoose.model('Tag');
|
||||
|
||||
module.exports = function(piler) {
|
||||
return {
|
||||
index: function(req, res, next) {
|
||||
|
||||
host = String(req.headers.host);
|
||||
host = host.split(':')[0];
|
||||
|
||||
if (host != 'n.atlb.co') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!req.user) {
|
||||
req.session.redirectUrl = req.url
|
||||
}
|
||||
|
||||
var path = req.path.slice(1);
|
||||
|
||||
Tag.findById(path)
|
||||
.populate('client', 'name identifier address')
|
||||
.exec(function(err, result) {
|
||||
var payload = {
|
||||
user: req.user,
|
||||
id: path,
|
||||
tag: result || undefined,
|
||||
};
|
||||
|
||||
res.render('tag.jade', {
|
||||
css: piler.css.renderTags(),
|
||||
payload: payload
|
||||
});
|
||||
})
|
||||
},
|
||||
post: function(req, res) {
|
||||
|
||||
var tag_id = req.body.tag_id;
|
||||
delete req.body.tag_id;
|
||||
|
||||
Tag.findByIdAndUpdate(tag_id, req.body, { upsert: true }, function(err, result) {
|
||||
if (err) {
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
11
app/model/tag.js
Normal file
11
app/model/tag.js
Normal file
@ -0,0 +1,11 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
ObjectId = Schema.ObjectId;
|
||||
|
||||
var tagSchema = new Schema({
|
||||
_id: String,
|
||||
client: { type: ObjectId, ref: 'Client' },
|
||||
data: {}
|
||||
}, { versionKey: false })
|
||||
|
||||
var Tag = module.exports = mongoose.model('Tag', tagSchema);
|
105
app/views/tag.jade
Normal file
105
app/views/tag.jade
Normal file
@ -0,0 +1,105 @@
|
||||
doctype 5
|
||||
html(lang="en", ng-app="tags", ng-controller="tags.PageCtrl")
|
||||
head
|
||||
title Atlantic Biomedical
|
||||
!{css}
|
||||
script(type='text/javascript')
|
||||
window.payload = !{JSON.stringify(payload)};
|
||||
body
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.js')
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular-resource.js')
|
||||
script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js')
|
||||
script(type='text/javascript', src='/js/lib/select2.js')
|
||||
script(type='text/javascript', src='/js/lib/bootstrap-datepicker.js')
|
||||
script(type='text/javascript', src='/js/lib/moment.js')
|
||||
script(type='text/javascript', src='/js/directives.js')
|
||||
script(type='text/javascript', src='/tags/app.js')
|
||||
|
||||
error-panel
|
||||
.navbar
|
||||
.navbar-inner
|
||||
a.brand(href='/', target='_self') Atlantic Biomedical
|
||||
progress-panel
|
||||
ul.nav.pull-right(ng-show='user')
|
||||
li(ng-show='user.name')
|
||||
a(href='#')
|
||||
i.icon-user
|
||||
| {{user.name.first}} {{user.name.last}}
|
||||
li.photo(ng-show='user.picture', ns-show='user.picture')
|
||||
img(ng-src='{{user.picture}}?sz=50')
|
||||
.navbar.navbar-secondary
|
||||
.navbar-inner
|
||||
ul.nav
|
||||
li
|
||||
a(href='http://www.atlanticbiomedical.com')
|
||||
i.icon-wrench
|
||||
| Contact Us
|
||||
.container-fluid
|
||||
h1(ng-show='tag') Device Tag
|
||||
h1(ng-hide='tag') Create Tag
|
||||
div(ng-hide='user')
|
||||
dl.dl-horizontal(ng-show='tag')
|
||||
dt Client
|
||||
dd {{payload.tag.client.name}} ({{payload.tag.client.identifier}})
|
||||
dt Device
|
||||
dd {{tag.device}}
|
||||
dt Make
|
||||
dd {{tag.make}}
|
||||
dt Model
|
||||
dd {{tag.model}}
|
||||
dt Serial Number
|
||||
dd {{tag.serialNumber}}
|
||||
dt Purchase Date
|
||||
dd {{tag.purchaseDate}}
|
||||
dt Test
|
||||
dd {{tag.test}}
|
||||
dt Room #
|
||||
dd {{tag.roomNumber}}
|
||||
|
||||
a.btn.btn-primary(href='/auth', ng-show='tag')
|
||||
| Edit Tag
|
||||
|
||||
a.btn.btn-primary(href='/auth', ng-hide='tag')
|
||||
| Create Tag
|
||||
|
||||
div(ng-show='user')
|
||||
form.form-horizontal
|
||||
.control-group
|
||||
label.control-label Client
|
||||
.controls
|
||||
select(ng-model='client', required='required', ng-options='client._id as client.name + " (" + client.identifier + ")" for client in clients')
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
.control-group
|
||||
label.control-label Device
|
||||
.controls
|
||||
input.text(ng-model='tag.device')
|
||||
.control-group
|
||||
label.control-label Make
|
||||
.controls
|
||||
input.text(ng-model='tag.make')
|
||||
.control-group
|
||||
label.control-label Model
|
||||
.controls
|
||||
input.text(ng-model='tag.model')
|
||||
.control-group
|
||||
label.control-label Serial Number
|
||||
.controls
|
||||
input.text(ng-model='tag.serialNumber')
|
||||
.control-group
|
||||
label.control-label Purchase Date
|
||||
.controls
|
||||
input.text(type='date', ng-model='tag.purchaseDate')
|
||||
.control-group
|
||||
label.control-label Test
|
||||
.controls
|
||||
input.text(ng-model='tag.test')
|
||||
.control-group
|
||||
label.control-label Room #
|
||||
.controls
|
||||
input.text(ng-model='tag.roomNumber')
|
||||
.control-group
|
||||
button.btn.btn-primary(ng-click='save()') Save
|
@ -9,19 +9,28 @@ module.exports = function(app, passport) {
|
||||
|
||||
app.get('/auth/callback', function(req, res, next) {
|
||||
passport.authenticate('google', function(err, user, info) {
|
||||
var redirectUrl = '/';
|
||||
|
||||
if (err) { return next(err); }
|
||||
if (!user) { return res.redirect('/login/error'); }
|
||||
|
||||
if (req.session.redirectUrl) {
|
||||
redirectUrl = req.session.redirectUrl;
|
||||
req.session.redirectUrl = null;
|
||||
}
|
||||
|
||||
req.logIn(user, function(err) {
|
||||
if (err) { return next(err); }
|
||||
return res.redirect('/');
|
||||
});
|
||||
|
||||
res.redirect(redirectUrl);
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
return {
|
||||
requiresUiLogin: function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
req.session.redirectUrl = req.url;
|
||||
return res.redirect('/login');
|
||||
}
|
||||
next();
|
||||
|
@ -48,12 +48,16 @@ module.exports = function(app, auth, piler, calendar, config) {
|
||||
var messages = require('../app/controllers/messages')(config);
|
||||
app.post('/api/messages/send', messages.send);
|
||||
|
||||
var tags = require('../app/controllers/tags')(piler);
|
||||
app.post('/api/tags', tags.post);
|
||||
|
||||
var login = require('../app/controllers/login')(piler);
|
||||
app.get('/login', login.login);
|
||||
app.get('/login/error', login.error);
|
||||
app.get('/logout', login.logout);
|
||||
|
||||
var home = require('../app/controllers/home')(piler);
|
||||
app.get('/', auth.requiresUiLogin, home.index);
|
||||
app.get('*', auth.requiresUiLogin, home.index);
|
||||
|
||||
app.get('/', tags.index, auth.requiresUiLogin, home.index);
|
||||
app.get('*', tags.index, auth.requiresUiLogin, home.index);
|
||||
};
|
||||
|
@ -16,7 +16,9 @@
|
||||
"jade": "",
|
||||
"googleapis": "",
|
||||
"sprintf": "",
|
||||
"emailjs": ""
|
||||
"emailjs": "",
|
||||
"moment": "",
|
||||
"async": ""
|
||||
},
|
||||
"devDependencies": {
|
||||
"supervisor": ""
|
||||
|
@ -141,7 +141,7 @@ angular.module('biomed.directives', [])
|
||||
var isTouch = 'ontouchstart' in window && !window.navigator.userAgent.match(/PhantomJS/i);
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
restrict: 'AC',
|
||||
require: '?ngModel',
|
||||
link: function postLink(scope, element, attrs, controller) {
|
||||
|
||||
@ -310,6 +310,7 @@ angular.module('biomed.directives', [])
|
||||
var options = {};
|
||||
|
||||
return {
|
||||
restrict: 'AC',
|
||||
require: '?ngModel',
|
||||
compile: function (tElm, tAttrs) {
|
||||
var watch,
|
||||
|
37
public/tags/app.js
Normal file
37
public/tags/app.js
Normal file
@ -0,0 +1,37 @@
|
||||
var tags = {}
|
||||
|
||||
angular.module('tags', ['ngResource', 'biomed.directives'])
|
||||
.factory("Tag", function($resource) {
|
||||
return $resource('/api/tags');
|
||||
})
|
||||
.factory("Clients", function($resource) {
|
||||
return $resource('/api/clients/:id/:cmd',
|
||||
{ id: "@id", cmd: "@cmd" },
|
||||
{
|
||||
index: { method: 'GET', params: {}, isArray: true },
|
||||
});
|
||||
})
|
||||
tags.PageCtrl = function($scope, $window, Tag, Clients) {
|
||||
console.log($window.payload)
|
||||
|
||||
var payload = $scope.payload = $window.payload;
|
||||
|
||||
$scope.tag = payload.tag ? payload.tag.data : undefined;
|
||||
|
||||
if (payload.user) {
|
||||
$scope.user = payload.user;
|
||||
$scope.clients = Clients.index(function() {
|
||||
if (payload.tag && payload.tag.client) {
|
||||
$scope.client = payload.tag.client._id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.save = function() {
|
||||
Tag.save({
|
||||
tag_id: $window.payload.id,
|
||||
client: $scope.client,
|
||||
data: $scope.tag
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user