Merge pull request #1752 from connortechnology/filter_by_runstate

rough in the ability to filter on RunState
This commit is contained in:
Andrew Bauer 2017-06-12 20:54:17 -05:00 committed by GitHub
commit bf04a68085
7 changed files with 40 additions and 3 deletions

View File

@ -204,6 +204,7 @@ CREATE TABLE `Events` (
`Messaged` tinyint(3) unsigned NOT NULL default '0',
`Executed` tinyint(3) unsigned NOT NULL default '0',
`Notes` text,
`StateId` int(10) unsigned NOT NULL,
PRIMARY KEY (`Id`,`MonitorId`),
KEY `MonitorId` (`MonitorId`),
KEY `StartTime` (`StartTime`),

20
db/zm_update-1.31.1.sql Normal file
View File

@ -0,0 +1,20 @@
--
-- This updates a 1.30.0 database to 1.30.1
--
-- Add StateId Column to Events.
--
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Events'
AND table_schema = DATABASE()
AND column_name = 'StateId'
) > 0,
"SELECT 'Column StateId exists in Events'",
"ALTER TABLE Events ADD `StateId` int(10) unsigned default NULL AFTER `Notes`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

View File

@ -77,10 +77,14 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
gettimeofday( &start_time, 0 );
}
static char sql[ZM_SQL_MED_BUFSIZ];
unsigned int state_id = 0;
if ( MYSQL_ROW dbrow = zmDbFetchOne( "SELECT Id FROM States WHERE IsActive=1" ) ) {
state_id = atoi(dbrow[0]);
}
static char sql[ZM_SQL_MED_BUFSIZ];
struct tm *stime = localtime( &start_time.tv_sec );
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes, Videoed ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', '%d' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), videoEvent );
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes, StateId, Videoed ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', '%d' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), state_id, videoEvent );
if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't insert event: %s. sql was (%s)", mysql_error( &dbconn ), sql );
exit( mysql_errno( &dbconn ) );

View File

@ -1 +1 @@
1.31.0
1.31.1

View File

@ -1283,6 +1283,7 @@ function parseFilter( &$filter, $saveToSession=false, $querySep='&' ) {
case 'MaxScore':
case 'Cause':
case 'Notes':
case 'StateId':
case 'Archived':
$filter['sql'] .= 'E.'.$filter['terms'][$i]['attr'];
break;

View File

@ -125,6 +125,7 @@ $SLANG = array(
'AttrMaxScore' => 'Max. Score',
'AttrMonitorId' => 'Monitor Id',
'AttrMonitorName' => 'Monitor Name',
'AttrStateId' => 'Run State',
'AttrServer' => 'Server',
'AttrName' => 'Name',
'AttrNotes' => 'Notes',

View File

@ -92,6 +92,7 @@ $attrTypes = array(
'DiskPercent' => translate('AttrDiskPercent'),
'DiskBlocks' => translate('AttrDiskBlocks'),
'SystemLoad' => translate('AttrSystemLoad'),
'StateId' => translate('AttrStateId'),
'ServerId' => translate('AttrServer'),
);
$opTypes = array(
@ -209,6 +210,15 @@ for ( $i = 0; isset($_REQUEST['filter']) && $i < count($_REQUEST['filter']['term
<script type="text/javascript">Calendar.setup( { inputField: "filter[terms][<?php echo $i ?>][val]", ifFormat: "%Y-%m-%d", showOthers: true, weekNumbers: false });</script>
<?php } ?>
</td>
<?php
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'StateId' ) {
$states = array();
foreach ( dbFetchAll( 'SELECT Id,Name FROM States ORDER BY lower(Name) ASC' ) as $state_row ) {
$states[$state_row['Id']] = $state_row['Name'];
}
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><?php echo buildSelect( "filter[terms][$i][val]", $states ); ?></td>
<?php
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'Weekday' ) {
?>