forked from stackroute/LogAggregator-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
measures.js
50 lines (45 loc) · 1.38 KB
/
measures.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
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Namespace = require('../model/db').namespaceModel;
/* GET Measures */
router.get('/', function(req, res) {
if (req.session.oid !== null) {
Namespace.findNamespace(req.session.oid, function(err, namespace) {
if (namespace != null) {
res.send(namespace.measures);
}
});
}
});
/* POST Measures */
router.post('/addMeasure', function(req, res) {
if (req.session.oid !== null) {
Namespace.findNamespace(req.session.oid, function(err, namespace) {
if (namespace != null) {
if (req.body.measureEventSelector == "") {
var fieldEventValue = req.body.measureFieldSelector;
} else {
var fieldEventValue = req.body.measureEventSelector;
}
namespace.measures.push({
displayName: req.body.displaymeasurename,
aggrFunc: req.body.aggregator,
fieldEvent: fieldEventValue,
filterField: req.body.filterfield,
filterValue: req.body.filtervalue,
});
namespace.save(function(err, namespace) {
console.log('namespace saved:', namespace);
});
}
});
}
res.redirect('/');
});
/* Delete Measure */
router.post('/:id', function(req, res) {
console.log("deleted value is", req.params.id);
res.redirect('/');
});
module.exports = router;