Show Number of Events for last 24 hours
parent
b554a5fc09
commit
72da06a78f
|
@ -1245,5 +1245,6 @@
|
|||
"Playback": "Playback",
|
||||
"Backup": "Backup",
|
||||
"Close All Monitors": "Close All Monitors",
|
||||
"Daily Events": "Daily Events",
|
||||
"Cloud": "Cloud"
|
||||
}
|
||||
|
|
|
@ -974,29 +974,54 @@ module.exports = function(s,config,lang,app,io){
|
|||
const monitorId = req.params.id
|
||||
const groupKey = req.params.ke
|
||||
const hasRestrictions = userDetails.sub && userDetails.allmonitors !== '1';
|
||||
s.sqlQueryBetweenTimesWithPermissions({
|
||||
table: 'Events',
|
||||
user: user,
|
||||
groupKey: req.params.ke,
|
||||
monitorId: req.params.id,
|
||||
startTime: req.query.start,
|
||||
endTime: req.query.end,
|
||||
startTimeOperator: req.query.startOperator,
|
||||
endTimeOperator: req.query.endOperator,
|
||||
limit: req.query.limit,
|
||||
endIsStartTo: true,
|
||||
parseRowDetails: true,
|
||||
noFormat: true,
|
||||
noCount: true,
|
||||
rowName: 'events',
|
||||
preliminaryValidationFailed: (
|
||||
user.permissions.watch_videos === "0" ||
|
||||
hasRestrictions &&
|
||||
(!userDetails.video_view || userDetails.video_view.indexOf(monitorId)===-1)
|
||||
)
|
||||
},(response) => {
|
||||
res.end(s.prettyPrint(response))
|
||||
})
|
||||
const monitorRestrictions = s.getMonitorRestrictions(user.details,monitorId)
|
||||
const preliminaryValidationFailed = (
|
||||
user.permissions.watch_videos === "0" ||
|
||||
hasRestrictions &&
|
||||
(!userDetails.video_view || userDetails.video_view.indexOf(monitorId)===-1)
|
||||
);
|
||||
if(req.query.onlyCount === '1' && !preliminaryValidationFailed){
|
||||
const response = {ok: true}
|
||||
s.knexQuery({
|
||||
action: "count",
|
||||
columns: "mid",
|
||||
table: "Events",
|
||||
where: [
|
||||
['ke','=',groupKey],
|
||||
['time','>=',req.query.start],
|
||||
['time','<=',req.query.end],
|
||||
monitorRestrictions
|
||||
]
|
||||
},(err,r) => {
|
||||
if(err){
|
||||
s.debugLog(err)
|
||||
response.ok = false
|
||||
}else{
|
||||
response.count = r[0]['count(`mid`)']
|
||||
}
|
||||
s.closeJsonResponse(res,response)
|
||||
})
|
||||
}else{
|
||||
s.sqlQueryBetweenTimesWithPermissions({
|
||||
table: 'Events',
|
||||
user: user,
|
||||
groupKey: req.params.ke,
|
||||
monitorId: req.params.id,
|
||||
startTime: req.query.start,
|
||||
endTime: req.query.end,
|
||||
startTimeOperator: req.query.startOperator,
|
||||
endTimeOperator: req.query.endOperator,
|
||||
limit: req.query.limit,
|
||||
endIsStartTo: true,
|
||||
parseRowDetails: true,
|
||||
noFormat: true,
|
||||
noCount: true,
|
||||
rowName: 'events',
|
||||
preliminaryValidationFailed: preliminaryValidationFailed
|
||||
},(response) => {
|
||||
res.end(s.prettyPrint(response))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
/**
|
||||
|
|
|
@ -13,9 +13,27 @@ $(document).ready(function(){
|
|||
$.each(videos,function(n,row){
|
||||
drawRowToList(row)
|
||||
})
|
||||
getCountOfEvents({
|
||||
monitorId: options.monitorId,
|
||||
})
|
||||
callback(data)
|
||||
})
|
||||
}
|
||||
function getCountOfEvents(options){
|
||||
var monitorId = options.monitorId
|
||||
var loadedMonitor = loadedMonitors[monitorId]
|
||||
options.onlyCount = '1';
|
||||
if(!options.startDate)options.startDate = moment().subtract(24, 'hour').utc()._d
|
||||
if(!options.endDate)options.endDate = moment().add(1, 'hour').utc()._d
|
||||
getEvents(options,function(data){
|
||||
var eventDesignationText = `${lang['All Monitors']}`
|
||||
if(monitorId){
|
||||
eventDesignationText = `${loadedMonitor ? loadedMonitor.name : monitorId}`
|
||||
}
|
||||
$('.events_from_last_24_which_monitor').text(eventDesignationText)
|
||||
$('.events_from_last_24').text(data.count)
|
||||
})
|
||||
}
|
||||
monitorList.change(function(){
|
||||
var theSelected = `${monitorList.val()}`
|
||||
loadVideos({
|
||||
|
|
|
@ -155,6 +155,30 @@ function getVideos(options,callback){
|
|||
})
|
||||
})
|
||||
}
|
||||
function getEvents(options,callback){
|
||||
options = options ? options : {}
|
||||
var requestQueries = []
|
||||
var monitorId = options.monitorId
|
||||
var limit = options.limit || 5000
|
||||
var eventStartTime
|
||||
var eventEndTime
|
||||
// var startDate = options.startDate
|
||||
// var endDate = options.endDate
|
||||
if(options.startDate){
|
||||
eventStartTime = formattedTimeForFilename(options.startDate,false)
|
||||
requestQueries.push(`start=${eventStartTime}`)
|
||||
}
|
||||
if(options.endDate){
|
||||
eventEndTime = formattedTimeForFilename(options.endDate,false)
|
||||
requestQueries.push(`end=${eventEndTime}`)
|
||||
}
|
||||
if(options.onlyCount){
|
||||
requestQueries.push(`onlyCount=1`)
|
||||
}
|
||||
$.get(`${getApiPrefix(`events`)}${monitorId ? `/${monitorId}` : ''}?${requestQueries.join('&')}`,function(eventData){
|
||||
callback(eventData)
|
||||
})
|
||||
}
|
||||
$(document).ready(function(){
|
||||
$('body')
|
||||
.on('click','.open-video',function(){
|
||||
|
|
Loading…
Reference in New Issue