Fixed the search by date functionality

This commit is contained in:
Kevin Crider 2013-09-29 11:36:23 -04:00
parent 7e90d0f373
commit 33c0dff8a4
3 changed files with 52 additions and 60 deletions

View File

@ -5,31 +5,24 @@ class EventsController extends AppController {
public $components = array('Paginator');
public function index() {
$this->loadModel('Monitor');
$this->loadModel('Monitor');
$this->loadModel('Frame');
$conditions = array();
$this->set('thumb_width', Configure::read('ZM_WEB_LIST_THUMB_WIDTH'));
$named = $this->extractNamedParams(
array('MonitorId', 'StartTime' )
);
if ($named) {
foreach ($named as $key => $value) {
switch ($key) {
case "StartTime":
$StartTime = array("$key BETWEEN FROM_UNIXTIME($value[0]) and FROM_UNIXTIME($value[1])");
array_push($conditions, $StartTime);
break;
case "MonitorId":
$$key = array($key => $value);
array_push($conditions, $$key);
break;
}
}
};
if (isset($this->params['url']['data'])) {
$params = $this->params['url']['data'];
if (isset($params['StartDate']) ) {
$params['StartDate'] = strtotime($params['StartDate']);
if ($params['StartDate'] > 0) {array_push($conditions, array('UNIX_TIMESTAMP(Event.StartTime) >= '.$params['StartDate']));}
}
if (isset($params['EndDate']) ) {
$params['EndDate'] = strtotime($params['EndDate']);
if ($params['EndDate'] > 0) {array_push($conditions, array('UNIX_TIMESTAMP(Event.EndTime) <= '.$params['EndDate']));}
}
}
$this->paginate = array(
'fields' => array('Event.Name', 'Event.Length', 'Event.MonitorId', 'Event.Id', 'Monitor.Name', 'Event.MaxScore', 'Event.Width', 'Event.Height', 'Event.StartTime', 'Event.TotScore', 'Event.AvgScore', 'Event.Cause', 'Event.AlarmFrames', 'TIMESTAMPDIFF (SECOND, Event.StartTime, Event.EndTime) AS Duration' ),
@ -40,19 +33,12 @@ public function index() {
$data = $this->paginate('Event');
$this->set('events', $data);
$this->set('monitors', $this->Monitor->find('all', array('fields' => array('Monitor.Name') )));
$this->set('monitors', $this->Monitor->find('all', array('fields' => array('Monitor.Name'))));
foreach ($data as $key => $value) {
$thumbData[$key] = $this->Frame->createListThumbnail($value['Event']);
$this->set('thumbData', $thumbData);
}
$prepend = array('00','01','02','03','04','05','06','07','08','09');
$hours = array_merge($prepend,range(10, 23));
$minutes = array_merge($prepend,range(10, 59));
$seconds = $minutes;
$this->set('hours', $hours);
$this->set('minutes', $minutes);
}
public function view($id = null) {

View File

@ -3,7 +3,7 @@
<div class="panel-body">
<div id="sidebar">
<?php
echo $this->Form->create('Events', array('default' => false, 'inputDefaults' => array(
echo $this->Form->create('Events', array('action' => 'index', 'default' => false, 'inputDefaults' => array(
'legend' => false,
'label' => false,
'div' => false,
@ -35,21 +35,22 @@ unset($monitor);
Start Date
<div class="form-group">
<div class="input-group date datetime">
<input type="text" class="form-control" id="EventStartDate">
<input type="text" class="form-control" id="EventStartDate" name="data[StartDate]">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
End Date
<div class="form-group">
<div class="input-group date datetime">
<input type="text" class="form-control" id="EventEndDate">
<input type="text" class="form-control" id="EventEndDate" name="data[EndDate]">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
</div>
<?php echo $this->Form->end(array('label' => 'Search', 'id' => 'EventsButtonSearch', 'class' => 'btn btn-default')); ?>
<?php echo $this->Form->end(array('label' => 'Search', 'class' => 'btn btn-default')); ?>
<?php /*echo $this->Form->end(array('label' => 'Search', 'id' => 'EventsButtonSearch', 'class' => 'btn btn-default'));*/ ?>
<?php echo $this->Html->link('Delete Selected','#',array('class' => 'btn btn-default', 'onClick' => '$("#EventsDeleteSelectedForm").submit();')); ?>
</div>
@ -104,3 +105,23 @@ foreach ($events as $key => $value) {
<ul class="pagination">
<?php echo $this->Paginator->numbers(array('tag' => 'li', 'separator' => false, 'currentClass' => 'active', 'currentTag' => 'span')); ?>
</ul>
<?
/*
$data = $this->Js->get('#EventsIndexForm')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#EventsIndexForm')->event(
'submit',
$this->Js->request(
array('action' => 'index'),
array(
'update' => '#Events',
'data' => $data,
'async' => true,
'dataExpression' => true,
'method' => 'POST'
)
)
);
echo $this->Js->writeBuffer();
*/
?>

View File

@ -89,35 +89,20 @@ $(document).ready(function() {
});
$("#EventsButtonSearch").button();
$("#EventsIndexForm").submit(function() {
$base_url = '/events/index/';
$('#EventsIndexForm').submit(function() {
//$('#EventsDeleteSelectedForm').load('/events/index #Events', $('#EventsIndexForm').serialize());
var data = $('#EventsIndexForm').serialize();
$.ajax({
url: '/events/index',
data: data
}).done(function(data) {
var content = $(data).find('#Events');
console.log(content);
$('#EventsDeleteSelectedForm').html(content);
});
});
$( "li.ui-selected" ).each(function() {
$monitor_id = $(this).attr('id').split('_');
$base_url = $base_url + 'MonitorId:'+$monitor_id[1]+'/';
});
$start_date = $("#EventStartDate").val();
$start_hour = $("#EventStartHour").val();
$start_min = $("#EventStartMinute").val();
$end_date = $("#EventEndDate").val();
$end_hour = $("#EventEndHour").val();
$end_min = $("#EventEndMinute").val();
var start = $start_date + ' ' + $start_hour + ':' + $start_min;
var end = $end_date + ' ' + $end_hour + ':' + $end_min;
var start_epoch = new Date(start).getTime()/1000.0;
var end_epoch = new Date(end).getTime()/1000.0;
$base_url = $base_url + 'StartTime:'+start_epoch+'/';
$base_url = $base_url + 'StartTime:'+end_epoch+'/';
$('#Events').load($base_url + ' #Events');
});
$( "#EventStartDate" ).datepicker({
$( "#EventStartDate" ).datepicker({
changeMonth: true,
changeYear: true,
defaultDate: -1,