From 2f44a45bbc5c5ac41c7fb3aebb42f0caf4c6ed1a Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 21 Jan 2015 10:23:46 -0500 Subject: [PATCH] Add searching events by StartTime and MonitorId --- web/skins/bootstrap/js/controllers.js | 53 +++++++++++++++++-- web/skins/bootstrap/views/events.php | 22 +++----- web/skins/bootstrap/views/events_search.html | 54 ++++++++++++++++++++ 3 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 web/skins/bootstrap/views/events_search.html diff --git a/web/skins/bootstrap/js/controllers.js b/web/skins/bootstrap/js/controllers.js index 229605bef..7d62d6ac7 100644 --- a/web/skins/bootstrap/js/controllers.js +++ b/web/skins/bootstrap/js/controllers.js @@ -51,27 +51,70 @@ ZoneMinder.controller('LogController', function($scope, Log) { } }); -ZoneMinder.controller('EventsController', function($scope, Events, $modal) { +ZoneMinder.controller('EventsController', function($scope, Events, Console, $modal) { // First thing, get page 1 of the events. - getEventsPage(1); + $scope.page = 1; + getEvents(null, $scope.page); + + // Get the monitors which popular the sidebar select + Console.getMonitors().then(function(results) { + $scope.monitors = results.data.monitors; + }); + + $scope.filter_url = ''; + + var now = new Date(); + var startdate = new Date(now); + startdate.setMonth(now.getMonth() - 1); + $scope.filter = { + 'StartTime' : startdate, + 'EndTime' : new Date() + }; // If the page is changed, get the new page of events $scope.pageChanged = function(newPage) { - getEventsPage(newPage); + $scope.page = newPage; + getEvents($scope.filter_url, newPage); }; // Call Events.get and pass it the page number // Set the appropriate scope values with the results. // The events.php file takes over and iterates over events // and the painator uses totalEvents and eventPerPage - function getEventsPage(pageNumber) { - Events.get(pageNumber).then(function(results) { + function getEvents(filter, pageNumber) { + Events.get(filter, pageNumber).then(function(results) { $scope.events = results.data.events; $scope.totalEvents = results.data.pagination.count; $scope.eventsPerPage = results.data.pagination.limit; }); } + $scope.filterEvents = function() { + var filters = new Array(); + var url = ''; + + // Push all of the MonitorId's into the filters array + angular.forEach($scope.filter.MonitorId, function(value, key) { + filters.push('MonitorId:'+value); + }); + + var StartTime = $scope.filter.StartTime.toISOString().slice(0, 19).replace('T', ' '); + filters.push('StartTime >=:'+StartTime); + var EndTime = $scope.filter.EndTime.toISOString().slice(0, 19).replace('T', ' '); + filters.push('EndTime <=:'+EndTime); + + console.log(filters); + + angular.forEach(filters, function(value, key) { + url = url + value + '/'; + }); + + length = url.length; + $scope.filter_url = url.substring(0, length - 1); + $scope.page = 1; + getEvents($scope.filter_url, 1); + } + // This is called when a user clicks on an event. // It fires up a modal and passes it the EventId of the clicked event // EventController takes over from there. diff --git a/web/skins/bootstrap/views/events.php b/web/skins/bootstrap/views/events.php index dc03a7b32..b3e5f7679 100644 --- a/web/skins/bootstrap/views/events.php +++ b/web/skins/bootstrap/views/events.php @@ -6,21 +6,16 @@
-
- -
- - - - - -
- -
-
+ + +
-
+
...
@@ -35,6 +30,5 @@
- diff --git a/web/skins/bootstrap/views/events_search.html b/web/skins/bootstrap/views/events_search.html new file mode 100644 index 000000000..01f28043b --- /dev/null +++ b/web/skins/bootstrap/views/events_search.html @@ -0,0 +1,54 @@ +
+ +
+

Monitors

+ +
+ +
+

Date

+
+ +
+
+ + +
+
+ +
+
+ + +
+
+
+
+
+ + + + + +
+ + +