summaryrefslogtreecommitdiff
path: root/www/js/TimelineModalCtrl.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/TimelineModalCtrl.js')
-rw-r--r--www/js/TimelineModalCtrl.js198
1 files changed, 107 insertions, 91 deletions
diff --git a/www/js/TimelineModalCtrl.js b/www/js/TimelineModalCtrl.js
index 6531117e..6bf0822b 100644
--- a/www/js/TimelineModalCtrl.js
+++ b/www/js/TimelineModalCtrl.js
@@ -3,13 +3,8 @@
/* jslint browser: true*/
/* global saveAs, cordova,StatusBar,angular,console,ionic, moment, vis , Chart, DJS*/
-
-
-
-angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '$rootScope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$q', '$sce', 'carouselUtils', '$ionicPopup', '$translate', function ($scope, $rootScope, zm, NVRDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $q, $sce, carouselUtils, $ionicPopup, $translate) {
-
-
-
+angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '$rootScope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$q', '$sce', 'carouselUtils', '$ionicPopup', '$translate', function($scope, $rootScope, zm, NVRDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $q, $sce, carouselUtils, $ionicPopup, $translate)
+{
var Graph2d;
var tcGraph;
@@ -29,64 +24,68 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
//$scope.graphType = "all";
$scope.errorDetails = "";
-
-
//----------------------------------------------------------------
// Alarm notification handling
//----------------------------------------------------------------
- $scope.handleAlarms = function () {
+ $scope.handleAlarms = function()
+ {
$rootScope.isAlarm = !$rootScope.isAlarm;
- if (!$rootScope.isAlarm) {
+ if (!$rootScope.isAlarm)
+ {
$rootScope.alarmCount = "0";
- $ionicHistory.nextViewOptions({
+ $ionicHistory.nextViewOptions(
+ {
disableBack: true
});
- $state.go("events", {
+ $state.go("events",
+ {
"id": 0,
- "playEvent":false
- }, {
+ "playEvent": false
+ },
+ {
reload: true
});
return;
}
};
-
-
//-------------------------------------------------------
// we use this to reload the connkey if authkey changed
//------------------------------------------------------
-
- $rootScope.$on("auth-success", function () {
+ $rootScope.$on("auth-success", function()
+ {
NVRDataModel.debug("EventModalCtrl: Re-login detected, resetting everything & re-generating connkey");
-
});
-
- $scope.scrollUp = function () {
+ $scope.scrollUp = function()
+ {
//console.log ("SWIPE UP");
$ionicScrollDelegate.$getByHandle("timeline-modal-delegate").scrollTop(true);
};
- $scope.scrollDown = function () {
+ $scope.scrollDown = function()
+ {
//console.log ("SWIPE DOWN");
$ionicScrollDelegate.$getByHandle("timeline-modal-delegate").scrollBottom(true);
};
+ $scope.switchType = function()
+ {
- $scope.switchType = function () {
-
- if ($scope.graphType == $translate.instant('kGraphAll')) {
+ if ($scope.graphType == $translate.instant('kGraphAll'))
+ {
current_data = onlyalarm_data;
$scope.graphType = $translate.instant('kGraphAlarmed');
NVRDataModel.debug("Alarm array has " + onlyalarm_data.labels.length + " frames");
btype = 'bar';
//console.log (JSON.stringify(onlyalarm_data));
- } else {
+ }
+ else
+ {
current_data = data;
// tcGraph.data =
$scope.graphType = $translate.instant('kGraphAll');
@@ -99,8 +98,8 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
ld.timelineModalGraphType = $scope.graphType;
NVRDataModel.setLogin(ld);
-
- $timeout(function () {
+ $timeout(function()
+ {
/*
if ($scope.graphType == 'alarmed')
@@ -110,44 +109,42 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
tcGraph.update();*/
tcGraph.destroy();
console.log("GRAPH TYPE IS " + btype);
- tcGraph = new Chart(ctx, {
+ tcGraph = new Chart(ctx,
+ {
type: btype,
data: current_data,
options: options
});
});
-
-
};
-
//-------------------------------------------------------
// Tapping on a frame shows this image
//------------------------------------------------------
- $scope.showImage = function (p, r, f, fid, e, imode, id) {
+ $scope.showImage = function(p, r, f, fid, e, imode, id)
+ {
var img;
console.log("Image Mode " + imode);
if (imode == 'path')
img = "<img width='100%' ng-src='" + p + "/index.php?view=image&path=" + r + f + "'>";
- else {
+ else
+ {
img = "<img width='100%' ng-src='" + p + "/index.php?view=image&fid=" + id + "'>";
// console.log ("IS MULTISERVER SO IMAGE IS " + img);
}
- $rootScope.zmPopup = $ionicPopup.alert({
+ $rootScope.zmPopup = $ionicPopup.alert(
+ {
title: 'frame:' + fid + '/Event:' + e,
template: img,
cssClass: 'popup95'
});
};
-
-
-
-
- $scope.$on('modal.removed', function (e, m) {
+ $scope.$on('modal.removed', function(e, m)
+ {
if (m.id != 'analyze')
return;
@@ -160,7 +157,8 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
// init drawing here
//------------------------------------------------------
- $scope.$on('modal.shown', function (e, m) {
+ $scope.$on('modal.shown', function(e, m)
+ {
if (m.id != 'analyze')
return;
@@ -171,7 +169,8 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
$scope.dataReady = false;
NVRDataModel.getKeyConfigParams(0)
- .then(function (data) {
+ .then(function(data)
+ {
//console.log ("***GETKEY: " + JSON.stringify(data));
eventImageDigits = parseInt(data);
NVRDataModel.log("Image padding digits reported as " + eventImageDigits);
@@ -184,41 +183,42 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
//$scope.eventdetails = JSON.stringify($scope.event);
});
-
//-------------------------------------------------------
// okay, really init drawing here
//------------------------------------------------------
- function processEvent() {
+ function processEvent()
+ {
var eid = $scope.event.Event.Id;
//eid = 22302;
var ld = NVRDataModel.getLogin();
var apiurl = ld.apiurl + "/events/" + eid + ".json";
NVRDataModel.log("Getting " + apiurl);
$http.get(apiurl)
- .then(function (success) {
+ .then(function(success)
+ {
//$scope.eventdetails = JSON.stringify(success);
drawGraphTC(success.data);
},
- function (error) {
+ function(error)
+ {
$scope.errorDetails = $translate.instant('kGraphError');
NVRDataModel.log("Error in timeline frames " + JSON.stringify(error));
});
}
-
//-------------------------------------------------------
// I was kidding, this is where it really is drawn
// scout's promise
//------------------------------------------------------
- function drawGraphTC(event) {
+ function drawGraphTC(event)
+ {
$scope.eid = event.event.Event.Id;
$scope.alarm_images = [];
-
data = {
labels: [],
datasets: [
@@ -239,9 +239,9 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
data: [],
frames: []
- },
+ },
- ]
+ ]
};
onlyalarm_data = {
@@ -255,24 +255,28 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
hoverBorderColor: 'rgba(249, 105, 14,1.0)',
data: [],
frames: []
- },
+ },
- ]
+ ]
};
// Chart.js Options
options = {
legend: false,
- scales: {
- yAxes: [{
- ticks: {
+ scales:
+ {
+ yAxes: [
+ {
+ ticks:
+ {
// beginAtZero:true,
min: -1,
},
- }],
- xAxes: [{
+ }],
+ xAxes: [
+ {
display: false
- }]
+ }]
},
responsive: true,
@@ -281,10 +285,11 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleGridLineWidth: 1,
-
- hover: {
+ hover:
+ {
mode: 'single',
- onHover: function (obj) {
+ onHover: function(obj)
+ {
if (obj.length > 0)
tapOrHover(obj[0]._index);
}
@@ -300,13 +305,14 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
// NVRDataModel.log ("Changing graph width to " + $scope.graphWidth);
- for (var i = 0; i < event.event.Frame.length; i++) {
-
+ for (var i = 0; i < event.event.Frame.length; i++)
+ {
data.labels.push(event.event.Frame[i].TimeStamp);
//data.labels.push(' ');
data.datasets[0].data.push(event.event.Frame[i].Score);
- data.datasets[0].frames.push({
+ data.datasets[0].frames.push(
+ {
x: event.event.Frame[i].TimeStamp,
y: event.event.Frame[i].Score,
eid: event.event.Event.Id,
@@ -319,12 +325,14 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
});
- if (event.event.Frame[i].Type == "Alarm") {
+ if (event.event.Frame[i].Type == "Alarm")
+ {
onlyalarm_data.labels.push(event.event.Frame[i].TimeStamp);
//data.labels.push(' ');
onlyalarm_data.datasets[0].data.push(event.event.Frame[i].Score);
- onlyalarm_data.datasets[0].frames.push({
+ onlyalarm_data.datasets[0].frames.push(
+ {
x: event.event.Frame[i].TimeStamp,
y: event.event.Frame[i].Score,
eid: event.event.Event.Id,
@@ -345,39 +353,48 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
cv = document.getElementById("tcchart");
ctx = cv.getContext("2d");
- if (NVRDataModel.getLogin().timelineModalGraphType == $translate.instant('kGraphAll')) {
+ if (NVRDataModel.getLogin().timelineModalGraphType == $translate.instant('kGraphAll'))
+ {
btype = 'line';
current_data = data;
- } else {
+ }
+ else
+ {
btype = 'bar';
current_data = onlyalarm_data;
}
- $timeout(function () {
- tcGraph = new Chart(ctx, {
+ $timeout(function()
+ {
+ tcGraph = new Chart(ctx,
+ {
type: btype,
data: current_data,
options: options
});
});
- cv.onclick = function (e) {
+ cv.onclick = function(e)
+ {
var b = tcGraph.getElementAtEvent(e);
- if (b.length > 0) {
+ if (b.length > 0)
+ {
tapOrHover(b[0]._index);
}
};
}
- function tapOrHover(ndx) {
-
- $timeout(function () {
+ function tapOrHover(ndx)
+ {
+ $timeout(function()
+ {
//console.log ("You tapped " + ndx);
$scope.alarm_images = [];
$scope.playbackURL = $scope.event.Event.baseURL;
var items = current_data.datasets[0].frames[ndx];
- $scope.alarm_images.push({
+ $scope.alarm_images.push(
+ {
relativePath: items.relativePath,
fid: items.fid,
id: items.id,
@@ -390,13 +407,12 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
}
-
-
//--------------------------------------------------------
// utility function
//--------------------------------------------------------
- function computeRelativePath(event) {
+ function computeRelativePath(event)
+ {
var relativePath = "";
var loginData = NVRDataModel.getLogin();
var str = event.Event.StartTime;
@@ -421,7 +437,8 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
// utility function
//--------------------------------------------------------
- function computeBasePath(event) {
+ function computeBasePath(event)
+ {
var basePath = "";
var loginData = NVRDataModel.getLogin();
var str = event.Event.StartTime;
@@ -443,32 +460,31 @@ angular.module('zmApp.controllers').controller('TimelineModalCtrl', ['$scope', '
return basePath;
}
-
function humanizeTime(str)
{
return moment.tz(str, NVRDataModel.getTimeZoneNow()).fromNow();
-
-
+
}
- function padToN(number, digits) {
+ function padToN(number, digits)
+ {
var i;
var stringMax = "";
var stringLeading = "";
- for (i = 1; i <= digits; i++) {
+ for (i = 1; i <= digits; i++)
+ {
stringMax = stringMax + "9";
if (i != digits) stringLeading = stringLeading + "0";
}
var numMax = parseInt(stringMax);
- if (number <= numMax) {
+ if (number <= numMax)
+ {
number = (stringLeading + number).slice(-digits);
}
//console.log ("PADTON: returning " + number);
return number;
}
-
-
-}]); \ No newline at end of file
+}]);