Skip to content

Commit

Permalink
filter top IP list on a service (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyaskopp committed Dec 3, 2021
1 parent e4c18e6 commit 0621ffa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/db/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ function createFilter(filter){
header.push(date_str);
date_i = date_i.add(1,filter.period.level+'s');
}
if(typeof filter.service_id !== 'undefined'){
if(typeof filter.service !== 'undefined'){
logger.warn('result contains only single/all services');
query.pivot_ip.filter_service = ' AND lg.service_id = $<filter.service_id> ';
query.pivot_val.filter_service = ' AND data.service_id = $<filter.service_id> ';
values.service_id = filter.service_id;
query.pivot_ip.filter_service = ' AND lg.service_id = $<filter.service> ';
query.pivot_val.filter_service = ' AND data.service_id = $<filter.service> ';
values.service = filter.service;
}

return {
Expand Down
18 changes: 14 additions & 4 deletions app/routes/adminRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,22 @@ router.get('/admin/ips', function (req, res, next) {
level: req.query.level || 'month',
start: req.query.start || (new Date().getFullYear())+'-01-01',
end: req.query.end || (new Date().getFullYear()+1)+'-01-01',
min_exist: req.query.min_exist || 8000
min_exist: req.query.min_exist || 8000,
service: req.query.service,
service_exc: req.query.service_exc
};
var table_params = [];

logger.error(val);
for (const [k,v] of Object.entries(val)){
table_params.push(`${k}=${v}`);
logger.warn(typeof v);
if(v != '' && typeof v !== 'undefined') {
table_params.push(`${k}=${v}`);
} else {
val[k] = undefined;
}
}
res.render('ips', {
adminController.getServices(user.user_id).then(services => {
res.render('ips', {
user: user,
ips_active: true,
measures: [
Expand All @@ -161,9 +169,11 @@ router.get('/admin/ips', function (req, res, next) {
}
],
levels: ["month", "day"],
services: services.map(s => [s.service_id, s.name]),
val: val,
table_params: table_params.join('&')
});
})
});

router.get('/admin/ip/:ip', function (req, res, next) {
Expand Down
10 changes: 9 additions & 1 deletion app/routes/apiRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,16 @@ router.get('/api/ips', function (req, res, next) {
error : 'Permission Denied.'
});
} else {
var filter = {};
['service', 'service_exc'].forEach( key => {
var value = Number(req.query[key]);
if(!(isNaN(value) || value === Infinity || String(Math.floor(value)) !== req.query[key])){
filter[key] = value;
}
});

dataController.getTopIPs(user.user_id,
{},
filter,
(req.query.start || (new Date().getFullYear())+'-01-01')+' 00:00:00',
(req.query.end || (new Date().getFullYear()+1)+'-01-01')+' 00:00:00',
req.query.measure || 'units',
Expand Down
17 changes: 17 additions & 0 deletions app/views/ips.pug
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ block content
input#end.validate(name="end" type="date" required="" aria-required="true" value=val.end )
label(for="end") End date (excluded)
span.helper-text(data-error="Date Required")
.row
.input-field.col.s6
i.material-icons.prefix important_devices
.select-wrapper
select.browser-default#service(name="service")
option(value="", selected= (typeof val.service=='undefined' || val.service=='') ? 'selected' : false) ALL
each s in services
option(value=s[0], selected= (s[0]==val.service) ? 'selected' : false)= s[1]
label(for="service") Service include
.input-field.col.s6
i.material-icons.prefix delete
.select-wrapper
select.browser-default#service_exc(name="service_exc" disabled='disabled')
option(value="", selected= (typeof val.service_exc=='undefined' || val.service_exc=='') ? 'selected' : false) NONE
each s in services
option(value=s[0], selected= (s[0]==val.service_exc) ? 'selected' : false)= s[1]
label(for="service_exc") Service exclude
.row
.input-field.col.s12
button.btn.grey.waves-effect.col.s12.white-text(type="submit")
Expand Down

0 comments on commit 0621ffa

Please sign in to comment.