Show Number of Events for last 24 hours

email-send-options-from-account
Moe 2021-10-27 10:14:24 -07:00
parent b554a5fc09
commit 72da06a78f
4 changed files with 91 additions and 23 deletions

View File

@ -1245,5 +1245,6 @@
"Playback": "Playback", "Playback": "Playback",
"Backup": "Backup", "Backup": "Backup",
"Close All Monitors": "Close All Monitors", "Close All Monitors": "Close All Monitors",
"Daily Events": "Daily Events",
"Cloud": "Cloud" "Cloud": "Cloud"
} }

View File

@ -974,29 +974,54 @@ module.exports = function(s,config,lang,app,io){
const monitorId = req.params.id const monitorId = req.params.id
const groupKey = req.params.ke const groupKey = req.params.ke
const hasRestrictions = userDetails.sub && userDetails.allmonitors !== '1'; const hasRestrictions = userDetails.sub && userDetails.allmonitors !== '1';
s.sqlQueryBetweenTimesWithPermissions({ const monitorRestrictions = s.getMonitorRestrictions(user.details,monitorId)
table: 'Events', const preliminaryValidationFailed = (
user: user, user.permissions.watch_videos === "0" ||
groupKey: req.params.ke, hasRestrictions &&
monitorId: req.params.id, (!userDetails.video_view || userDetails.video_view.indexOf(monitorId)===-1)
startTime: req.query.start, );
endTime: req.query.end, if(req.query.onlyCount === '1' && !preliminaryValidationFailed){
startTimeOperator: req.query.startOperator, const response = {ok: true}
endTimeOperator: req.query.endOperator, s.knexQuery({
limit: req.query.limit, action: "count",
endIsStartTo: true, columns: "mid",
parseRowDetails: true, table: "Events",
noFormat: true, where: [
noCount: true, ['ke','=',groupKey],
rowName: 'events', ['time','>=',req.query.start],
preliminaryValidationFailed: ( ['time','<=',req.query.end],
user.permissions.watch_videos === "0" || monitorRestrictions
hasRestrictions && ]
(!userDetails.video_view || userDetails.video_view.indexOf(monitorId)===-1) },(err,r) => {
) if(err){
},(response) => { s.debugLog(err)
res.end(s.prettyPrint(response)) 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))
})
}
}) })
}) })
/** /**

View File

@ -13,9 +13,27 @@ $(document).ready(function(){
$.each(videos,function(n,row){ $.each(videos,function(n,row){
drawRowToList(row) drawRowToList(row)
}) })
getCountOfEvents({
monitorId: options.monitorId,
})
callback(data) 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(){ monitorList.change(function(){
var theSelected = `${monitorList.val()}` var theSelected = `${monitorList.val()}`
loadVideos({ loadVideos({

View File

@ -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(){ $(document).ready(function(){
$('body') $('body')
.on('click','.open-video',function(){ .on('click','.open-video',function(){