make watch view event list more efficient
This commit is contained in:
parent
0b35a6f09a
commit
c13d2ea99f
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
//
|
||||||
|
// This is simplified version of the logic from ajax/events.php
|
||||||
|
// For efficency, sorting and and pagination functionality have been exlcuded
|
||||||
|
//
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
//
|
||||||
|
// INITIALIZE AND CHECK SANITY
|
||||||
|
//
|
||||||
|
|
||||||
|
if ( !canView('Events') ) $message = 'Insufficient permissions for user '.$user['Username'];
|
||||||
|
|
||||||
|
// Mid specifies the monitor id we are searching on
|
||||||
|
if ( empty($_REQUEST['mid']) ) {
|
||||||
|
$message = 'Must specify a monitor Id';
|
||||||
|
} else {
|
||||||
|
$mid = $_REQUEST['mid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit specifies the number of rows to return
|
||||||
|
if ( ( !is_int($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) {
|
||||||
|
$message = 'Invalid value for limit: '.$_REQUEST['limit'];
|
||||||
|
} else {
|
||||||
|
$limit = $_REQUEST['limit'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $message ) {
|
||||||
|
ZM\Error($message);
|
||||||
|
ajaxError($message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort specifies the name of the column to sort on
|
||||||
|
$sort = 'Id';
|
||||||
|
if ( isset($_REQUEST['sort']) ) {
|
||||||
|
$sort = $_REQUEST['sort'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies the sort direction, either asc or desc
|
||||||
|
$order = (isset($_REQUEST['order']) and (strtolower($_REQUEST['order']) == 'asc')) ? 'ASC' : 'DESC';
|
||||||
|
|
||||||
|
//
|
||||||
|
// MAIN LOOP
|
||||||
|
//
|
||||||
|
|
||||||
|
$where = 'WHERE MonitorId = '.$mid;
|
||||||
|
$col_str = 'E.*';
|
||||||
|
$sql = 'SELECT ' .$col_str. ' FROM `Events` AS E '.$where.' ORDER BY '.$sort.' '.$order. ' LIMIT ?';
|
||||||
|
ZM\Debug('Calling the following sql query: ' .$sql);
|
||||||
|
$rows = dbQuery($sql, array($limit));
|
||||||
|
|
||||||
|
$returned_rows = array();
|
||||||
|
foreach ( $rows as $row ) {
|
||||||
|
$event = new ZM\Event($row['Id']);
|
||||||
|
|
||||||
|
$scale = intval(5*100*ZM_WEB_LIST_THUMB_WIDTH / $event->Width());
|
||||||
|
$imgSrc = $event->getThumbnailSrc(array(), '&');
|
||||||
|
$streamSrc = $event->getStreamSrc(array(
|
||||||
|
'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single', 'rate'=>'400'), '&');
|
||||||
|
|
||||||
|
// Modify the row data as needed
|
||||||
|
$row['imgHtml'] = '<img id="thumbnail' .$event->Id(). '" src="' .$imgSrc. '" alt="Event '.$event->Id().'" width="' .validInt($event->ThumbnailWidth()). '" height="' .validInt($event->ThumbnailHeight()).'" stream_src="' .$streamSrc. '" still_src="' .$imgSrc. '"/>';
|
||||||
|
$row['Name'] = validHtmlStr($row['Name']);
|
||||||
|
$row['StartDateTime'] = strftime(STRF_FMT_DATETIME_SHORTER, strtotime($row['StartDateTime']));
|
||||||
|
$row['Length'] = gmdate('H:i:s', $row['Length'] );
|
||||||
|
|
||||||
|
$returned_rows[] = $row;
|
||||||
|
} # end foreach row matching search
|
||||||
|
|
||||||
|
$data['rows'] = $returned_rows;
|
||||||
|
ajaxResponse($data);
|
||||||
|
?>
|
|
@ -37,16 +37,19 @@ var params =
|
||||||
// Called by bootstrap-table to retrieve zm event data
|
// Called by bootstrap-table to retrieve zm event data
|
||||||
function ajaxRequest(params) {
|
function ajaxRequest(params) {
|
||||||
// Maintain legacy behavior by statically setting these parameters
|
// Maintain legacy behavior by statically setting these parameters
|
||||||
params.data.order = 'desc';
|
var data = params.data;
|
||||||
params.data.limit = maxDisplayEvents;
|
data.order = 'desc';
|
||||||
params.data.sort = 'Id';
|
data.limit = maxDisplayEvents;
|
||||||
if ( auth_hash ) params.data.auth = auth_hash;
|
data.sort = 'Id';
|
||||||
|
data.view = 'request';
|
||||||
|
data.request = 'watch';
|
||||||
|
data.mid = monitorId;
|
||||||
|
if ( auth_hash ) data.auth = auth_hash;
|
||||||
|
|
||||||
$j.getJSON(thisUrl + '?view=request&request=events&task=query'+filterQuery, params.data)
|
$j.getJSON(thisUrl, data)
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
var rows = processRows(data.rows);
|
var rows = processRows(data.rows);
|
||||||
// rearrange the result into what bootstrap-table expects
|
params.success(rows);
|
||||||
params.success({total: data.total, totalNotFiltered: data.totalNotFiltered, rows: rows});
|
|
||||||
})
|
})
|
||||||
.fail(logAjaxFail);
|
.fail(logAjaxFail);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue