From c8a3cb9df99bf0fbce3d59a8efbe41e33a698891 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 19 Nov 2014 15:53:07 +0000 Subject: [PATCH] Initial refactor of console view to use api & angular * Move eventCounts to the API and bind with angular * Display the console as a grid, rather than a table * Show only information we want to see --- web/skins/bootstrap/js/app.js | 8 ++ web/skins/bootstrap/js/controllers.js | 13 +- web/skins/bootstrap/views/console.php | 195 ++++---------------------- 3 files changed, 47 insertions(+), 169 deletions(-) diff --git a/web/skins/bootstrap/js/app.js b/web/skins/bootstrap/js/app.js index 1a2dd7ed7..2f09cb32f 100644 --- a/web/skins/bootstrap/js/app.js +++ b/web/skins/bootstrap/js/app.js @@ -25,3 +25,11 @@ ZoneMinder.factory('Event', function($http) { }; }); +ZoneMinder.factory('Console', function($http) { + return { + getConsoleEvents: function(interval) { + return $http.get('/api/events/consoleEvents/'+interval+'.json'); + } + }; +}); + diff --git a/web/skins/bootstrap/js/controllers.js b/web/skins/bootstrap/js/controllers.js index 778b3697e..01a5fc3bc 100644 --- a/web/skins/bootstrap/js/controllers.js +++ b/web/skins/bootstrap/js/controllers.js @@ -2,7 +2,6 @@ var ZoneMinder = angular.module('ZoneMinderControllers', []); ZoneMinder.controller('HeaderController', function($scope, Header) { Header.getLogState(function(results) { - console.log(results); }); Header.getDaemonStatus(function(results) { @@ -34,3 +33,15 @@ ZoneMinder.controller('EventController', function($scope, $location, Event) { }); }); + +ZoneMinder.controller('ConsoleController', function($scope, Console) { + // Ask the API for events that have happened in the last week + Console.getConsoleEvents('1 week').then(function(results) { + // For each result, assign it to $scope[Counts$monitorId] + for (var key in results['data']['results']) { + var mid = key; + var count = results['data']['results'][key]; + $scope['Counts' + mid] = count; + } + }); +}); diff --git a/web/skins/bootstrap/views/console.php b/web/skins/bootstrap/views/console.php index 387bc5bcf..44f4cc126 100644 --- a/web/skins/bootstrap/views/console.php +++ b/web/skins/bootstrap/views/console.php @@ -18,57 +18,6 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // -$eventCounts = array( - array( - "title" => $SLANG['Events'], - "filter" => array( - "terms" => array( - ) - ), - ), - array( - "title" => $SLANG['Hour'], - "filter" => array( - "terms" => array( - array( "attr" => "DateTime", "op" => ">=", "val" => "-1 hour" ), - ) - ), - ), - array( - "title" => $SLANG['Day'], - "filter" => array( - "terms" => array( - array( "attr" => "DateTime", "op" => ">=", "val" => "-1 day" ), - ) - ), - ), - array( - "title" => $SLANG['Week'], - "filter" => array( - "terms" => array( - array( "attr" => "DateTime", "op" => ">=", "val" => "-7 day" ), - ) - ), - ), - array( - "title" => $SLANG['Month'], - "filter" => array( - "terms" => array( - array( "attr" => "DateTime", "op" => ">=", "val" => "-1 month" ), - ) - ), - ), - array( - "title" => $SLANG['Archived'], - "filter" => array( - "terms" => array( - array( "attr" => "Archived", "op" => "=", "val" => "1" ), - ) - ), - ), -); - - $group = NULL; if ( ! empty($_COOKIE['zmGroup']) ) { if ( $group = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_COOKIE['zmGroup'])) ) @@ -107,16 +56,6 @@ for ( $i = 0; $i < count($monitors); $i++ ) $monitors[$i]['zmc'] = zmcStatus( $monitors[$i] ); $monitors[$i]['zma'] = zmaStatus( $monitors[$i] ); $monitors[$i]['ZoneCount'] = dbFetchOne( 'select count(Id) as ZoneCount from Zones where MonitorId = ?', 'ZoneCount', array($monitors[$i]['Id']) ); - $counts = array(); - for ( $j = 0; $j < count($eventCounts); $j++ ) - { - $filter = addFilterTerm( $eventCounts[$j]['filter'], count($eventCounts[$j]['filter']['terms']), array( "cnj" => "and", "attr" => "MonitorId", "op" => "=", "val" => $monitors[$i]['Id'] ) ); - parseFilter( $filter ); - $counts[] = "count(if(1".$filter['sql'].",1,NULL)) as EventCount$j"; - $monitors[$i]['eventCounts'][$j]['filter'] = $filter; - } - $sql = "select ".join($counts,", ")." from Events as E where MonitorId = ?"; - $counts = dbFetchOne( $sql, NULL, array($monitors[$i]['Id']) ); if ( $monitors[$i]['Function'] != 'None' ) { $cycleCount++; @@ -125,7 +64,6 @@ for ( $i = 0; $i < count($monitors); $i++ ) if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth; if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight; } - if ( $counts ) $monitors[$i] = array_merge( $monitors[$i], $counts ); $seqIdList[] = $monitors[$i]['Id']; $displayMonitors[] = $monitors[$i]; } @@ -190,125 +128,46 @@ xhtmlHeaders( __FILE__, $SLANG['Console'] );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+ -
- - - - - - - - - - - - - - - +
+
+
+ disabled="disabled"/> +

()

+
+ +
+ + +

recent events

+
+
+
- - - - - - - - - - - -
-
'.$SLANG['Fn'.$monitor['Function']].( empty($monitor['Enabled']) ? ', disabled' : '' ) .'', canEdit( 'Monitors' ) ) ?>'.$monitor['Device'].' ('.$monitor['Channel'].')', canEdit( 'Monitors' ) ) ?>'.preg_replace( '/^.*@/', '', $monitor['Host'] ).'', canEdit( 'Monitors' ) ) ?>'.preg_replace( '/^.*\//', '', $monitor['Path'] ).'', canEdit( 'Monitors' ) ) ?>'.preg_replace( '/^.*\//', '', $monitor['Path'] ).'', canEdit( 'Monitors' ) ) ?>'.$shortpath.'', canEdit( 'Monitors' ) ) ?>'.preg_replace( '/^.*\//', '', $monitor['Path'] ).'', canEdit( 'Monitors' ) ) ?>  ', $monitor['Sequence']>$minSequence ) ?>', $monitor['Sequence']<$maxSequence ) ?> disabled="disabled"/>
+
+ + + + - +