-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
117 lines (105 loc) · 4.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const express = require('express');
const path = require('path');
const exhbs = require('express-handlebars');
const Handlebars = require('handlebars');
const session = require('express-session');
const passport = require('passport');
const flash = require('connect-flash');
// Var inits
const app = express();
require('./dbconnect');
require('./config/passport');
// Settings
app.set('port',process.env.PORT || 3001);
app.set('views', path.join(__dirname,'views'));
app.engine('hbs',
exhbs({
defaultLayout: 'main',
layoutsDir: path.join(app.get('views'), 'layouts'),
partialsDir: path.join(app.get('views'), 'partials'),
extname: '.hbs',
helpers: {
fillLab: function(equipoLab){
var str = "";
equipoLab.forEach(equipo => {
str += '<tr id=\"'+ equipo._id +'\"role=\"row\" data-toggle=\"modal\" data-target=\"#updateModal\">'
+ '<td class=\"sorting_1\" id=\"desc\">' + equipo.description + '</td>'
+ '<td id=\"type\">' + typesSpa.get(equipo.type) + '</td>'
+ '<td id=\"brand\">' + equipo.brand + '</td>'
+ '<td id=\"model\">' + equipo.model + '</td>'
+ '<td id=\"series\">' + equipo.serial + '</td>'
+ '<td id=\"uaz\">' + equipo.uaz + '</td>'
+ '<td id=\"guard\">' + equipo.guard + '</td>'
+ '<td id=\"location\">' + equipo.location + '</td>'
+ '<td id=\"details\">' + equipo.details + '</td>'
+ '<td id=\"funding\">' + equipo.funding + '</td>'
+ '<td id=\"rfid\">' + equipo.rfid + '</td></tr>'
});
return new Handlebars.SafeString(str);
},
fillTarjetas: function(tarjetas){
var str = "";
tarjetas.forEach(tarjeta => {
str += '<tr id=\"'+ tarjeta._id +'\"role=\"row\" data-toggle=\"modal\" data-target=\"#updateModal\">'
+ '<td class=\"sorting_1\" id=\"desc\">' + tarjeta.description + '</td>'
+ '<td id=\"brand\">' + tarjeta.brand + '</td>'
+ '<td id=\"model\">' + tarjeta.model + '</td>'
+ '<td id=\"series\">' + tarjeta.series + '</td>'
+ '<td id=\"uaz\">' + tarjeta.uaz + '</td></tr>'
});
return new Handlebars.SafeString(str);
}
}
}));
app.set('view engine','.hbs');
// Middlewares
app.use(express.urlencoded({extended:true}));
app.use(session({
secret:'mysecretapp',
saveUninitialized: true,
resave: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// Global variables
app.use((req, res, next) => {
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
});
// mapa de los tipos de inventario con acento para representarse en la tabla.
typesSpa = new Map();
typesSpa.set("cal","Calefacción");
typesSpa.set("comp","Cómputo");
typesSpa.set("tools","Herramientas");
typesSpa.set("lab","Laboratorio");
typesSpa.set("ofc","Oficina");
typesSpa.set("pry","Proyección");
typesSpa.set("net","Redes");
typesSpa.set("sec","Seguridad");
// Routes
app.use(require('./routes/index'));
app.use(require('./routes/calefaccion'));
app.use(require('./routes/computo'));
app.use(require('./routes/tools'));
app.use(require('./routes/laboratorio'));
app.use(require('./routes/oficina'));
app.use(require('./routes/proyeccion'));
app.use(require('./routes/redes'));
app.use(require('./routes/seguridad'));
app.use(require('./routes/tarjetas'));
app.use(require('./routes/users'));
// Static Files
// CORS headers
var options = {
setHeaders: function(res, path, stat){
res.set('Service-Worker-Allowed', '/'),
res.set('Access-Control-Allow-Origin', 'Origin, X-Requested-With, Content-Type, Accept, keep-alive');
}
};
app.use(express.static(__dirname + '/public'));
// Server init
server = app.listen(app.get('port'), () => {
console.log('Server on port ', app.get('port'));
});