2014-11-16 07:50:46 +08:00
|
|
|
var ZoneMinder = angular.module('ZoneMinderControllers', []);
|
2014-11-16 03:34:00 +08:00
|
|
|
|
2014-11-16 07:50:46 +08:00
|
|
|
ZoneMinder.controller('HeaderController', function($scope, Header) {
|
2014-11-16 03:34:00 +08:00
|
|
|
Header.getLogState(function(results) {
|
|
|
|
});
|
2014-11-16 08:35:10 +08:00
|
|
|
|
|
|
|
Header.getDaemonStatus(function(results) {
|
|
|
|
if (results.result == 1) {
|
|
|
|
$scope.isRunning = true;
|
|
|
|
}
|
|
|
|
});
|
2014-11-16 03:34:00 +08:00
|
|
|
});
|
2014-11-16 07:50:46 +08:00
|
|
|
|
2014-11-22 04:06:59 +08:00
|
|
|
ZoneMinder.controller('FooterController', function($scope, Footer) {
|
2014-11-24 08:56:20 +08:00
|
|
|
Footer.getVersion(function(version) {
|
|
|
|
$scope.version = version.version;
|
|
|
|
});
|
2014-11-22 04:06:59 +08:00
|
|
|
});
|
|
|
|
|
2014-12-02 00:15:42 +08:00
|
|
|
ZoneMinder.controller('LogController', function($scope, Log) {
|
|
|
|
Log.getLogs(function(results) {
|
|
|
|
$scope.logs = results.logs;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-16 07:50:46 +08:00
|
|
|
ZoneMinder.controller('EventController', function($scope, $location, Event) {
|
|
|
|
|
|
|
|
var eventId = $location.search().eid;
|
|
|
|
|
|
|
|
Event.getEvent(eventId).then(function(results) {
|
|
|
|
$scope.eventId = eventId;
|
|
|
|
$scope.name = results.data.event.Event.Name;
|
|
|
|
$scope.cause = results.data.event.Event.Cause;
|
|
|
|
$scope.startTime = results.data.event.Event.StartTime;
|
|
|
|
$scope.endTime = results.data.event.Event.EndTime;
|
|
|
|
$scope.width = results.data.event.Event.Width;
|
|
|
|
$scope.length = results.data.event.Event.Length;
|
|
|
|
$scope.frames = results.data.event.Event.Frames;
|
|
|
|
$scope.alarmFrames = results.data.event.Event.AlarmFrames;
|
|
|
|
$scope.totScore = results.data.event.Event.TotScore;
|
|
|
|
$scope.avgScore = results.data.event.Event.AvgScore;
|
|
|
|
$scope.maxScore = results.data.event.Event.MaxScore;
|
|
|
|
$scope.notes = results.data.event.Event.Notes;
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2014-11-19 23:53:07 +08:00
|
|
|
|
2014-12-18 05:08:35 +08:00
|
|
|
ZoneMinder.controller('MonitorController', function($scope, $http) {
|
|
|
|
$scope.monitor = {};
|
2014-12-19 23:13:52 +08:00
|
|
|
$scope.monitor.Type = 'Remote';
|
2014-12-18 05:08:35 +08:00
|
|
|
$scope.monitor.RefBlendPerc = 6;
|
|
|
|
$scope.monitor.AlarmRefBlendPerc = 6;
|
|
|
|
$scope.monitor.Function = 'Monitor';
|
|
|
|
$scope.monitor.ImageBufferCount = 100;
|
|
|
|
$scope.monitor.WarmupCount = 25;
|
|
|
|
$scope.monitor.PreEventCount = 50;
|
|
|
|
$scope.monitor.PostEventCount = 50;
|
|
|
|
$scope.monitor.StreamReplayBuffer = 1000;
|
|
|
|
$scope.monitor.AlarmFrameCount = 1;
|
|
|
|
$scope.monitor.LabelFormat = '%N - %d/%m/%y %H:%M:%S';
|
|
|
|
$scope.monitor.LabelX = 0;
|
|
|
|
$scope.monitor.LabelY = 0;
|
|
|
|
$scope.monitor.Colours = 3;
|
|
|
|
$scope.monitor.Orientation = 0;
|
|
|
|
$scope.monitor.Enabled = true;
|
|
|
|
$scope.monitor.Protocol = 'http';
|
|
|
|
$scope.monitor.SectionLength = 600;
|
|
|
|
$scope.monitor.EventPrefix = 'Event-';
|
|
|
|
$scope.monitor.FrameSkip = 0;
|
|
|
|
$scope.monitor.MotionFrameSkip = 0;
|
|
|
|
$scope.monitor.FPSReportInterval = 1000;
|
|
|
|
$scope.monitor.DefaultView = 'Events';
|
|
|
|
$scope.monitor.DefaultRate = 100;
|
|
|
|
$scope.monitor.DefaultScale = 100;
|
|
|
|
$scope.monitor.SignalCheckColour = '#0000c0';
|
2014-12-19 23:17:25 +08:00
|
|
|
$scope.monitor.Method = 'simple';
|
2014-12-18 05:08:35 +08:00
|
|
|
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
|
|
|
|
$scope.monitor.WebColour = color;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.submitMonitor = function() {
|
|
|
|
$http({
|
|
|
|
method : 'POST',
|
|
|
|
url : '/api/monitors.json',
|
|
|
|
data : $.param($scope.monitor),
|
|
|
|
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
|
|
|
|
})
|
|
|
|
.success(function(data) {
|
|
|
|
console.log(data);
|
|
|
|
window.location = "/index.php?view=console";
|
|
|
|
});
|
|
|
|
};
|
2014-12-17 06:11:28 +08:00
|
|
|
});
|
|
|
|
|
2014-11-19 23:53:07 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2014-11-28 08:25:15 +08:00
|
|
|
|
|
|
|
Console.getMonitors().then(function(results) {
|
|
|
|
var monitors = new Array();
|
|
|
|
var daemons = ['zmc', 'zma']; // Daemons to check for each monitor
|
|
|
|
|
|
|
|
// For each monitor
|
|
|
|
angular.forEach(results['data']['monitors'], function(value, key) {
|
|
|
|
var id = value.Monitor.Id;
|
|
|
|
var alerts = value.Monitor.alerts = new Array();
|
|
|
|
|
|
|
|
// Check if the above daemons are running for it
|
|
|
|
angular.forEach(daemons, function(daemon) {
|
|
|
|
// Ask the API for the daemonStatus of the id
|
|
|
|
Console.daemonStatus(id, daemon).then(function(results) {
|
|
|
|
value.Monitor.alerts[daemon] = results.data.status;
|
|
|
|
|
|
|
|
// If there is a failed daemon, set a generic error
|
|
|
|
if (daemon) {
|
|
|
|
value.Monitor.alert = 'zma or zmc is not running';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
monitors.push(value.Monitor);
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.monitors = monitors;
|
|
|
|
});
|
2014-11-19 23:53:07 +08:00
|
|
|
});
|
2014-11-20 12:10:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
ZoneMinder.controller('ConfigController', function($scope, $http, Config) {
|
|
|
|
|
|
|
|
Config.setConfigModel().then(function(results) {
|
|
|
|
$scope.myModel = {configData: results.data.keyValues};
|
|
|
|
});
|
|
|
|
|
2014-11-20 12:11:33 +08:00
|
|
|
Config.getCategories().then(function(results) {
|
|
|
|
// List of category names for the tabs
|
|
|
|
$scope.categories = results.data.categories;
|
|
|
|
|
|
|
|
// For each category, add all config options belonging to it to the categories array
|
|
|
|
angular.forEach(results['data']['categories'], function(value, key) {
|
|
|
|
var cat = results.data.categories[key].Config.Category;
|
|
|
|
catman(cat);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
function catman(category) {
|
|
|
|
Config.getCategory(category).then(function(results) {
|
|
|
|
$scope[category] = results.data.config;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.updateConfig = function(configId, configName) {
|
|
|
|
var newValue = $scope.myModel.configData[configName];
|
|
|
|
var i = document.getElementById(configName).parentNode.parentNode;
|
|
|
|
var s = i.getElementsByTagName("span");
|
|
|
|
s = s[0];
|
|
|
|
|
|
|
|
Config.updateOption(configId, newValue).then(function(results) {
|
|
|
|
if (results.statusText == 'OK') {
|
|
|
|
i.className = i.className + " has-success has-feedback";
|
|
|
|
s.className = s.className + " glyphicon glyphicon-ok";
|
|
|
|
} else {
|
|
|
|
i.className = i.className + " has-failure has-feedback";
|
|
|
|
s.className = s.className + " glyphicon glyphicon-ok";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-20 12:10:01 +08:00
|
|
|
});
|
2014-11-25 23:21:30 +08:00
|
|
|
|
2014-11-26 00:30:27 +08:00
|
|
|
ZoneMinder.controller('HostController', function($scope, Host) {
|
|
|
|
Host.getDiskPercent(function(diskPercent) {
|
2014-11-26 00:27:38 +08:00
|
|
|
var array = [];
|
|
|
|
angular.forEach(diskPercent.usage, function(value, key) {
|
|
|
|
var a = {
|
|
|
|
'value' : Math.floor(value),
|
|
|
|
'label' : key,
|
|
|
|
'color' : '#F7464A',
|
|
|
|
'highlight' : '#FFC870',
|
|
|
|
};
|
|
|
|
array.push(a);
|
|
|
|
});
|
|
|
|
$scope.ddata = array;
|
|
|
|
});
|
2014-11-26 00:25:10 +08:00
|
|
|
|
|
|
|
Host.getLoad(function(load) {
|
|
|
|
$scope.loadData = {
|
|
|
|
labels: ['1 min', '5 min', '15 min'],
|
|
|
|
datasets: [{
|
|
|
|
label: 'CPU Load',
|
|
|
|
fillColor: 'rgba(220,220,220,0.2)',
|
|
|
|
strokeColor: 'rgba(220,220,220,1)',
|
|
|
|
pointColor: 'rgba(220,220,220,1)',
|
|
|
|
pointStrokeColor: '#fff',
|
|
|
|
pointHighlightFill: '#fff',
|
|
|
|
pointHighlightStroke: 'rgba(220,220,220,1)',
|
|
|
|
data: [ load.load[0], load.load[1], load.load[2] ]
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
2014-11-25 23:21:30 +08:00
|
|
|
|
2014-11-26 00:25:10 +08:00
|
|
|
$scope.doptions = {
|
|
|
|
responsive: false,
|
|
|
|
segmentShowStroke : true,
|
|
|
|
segmentStrokeColor : '#fff',
|
|
|
|
segmentStrokeWidth : 2,
|
|
|
|
percentageInnerCutout : 50, // This is 0 for Pie charts
|
|
|
|
animationSteps : 1,
|
|
|
|
animationEasing : 'easeOutBounce',
|
|
|
|
animateRotate : false,
|
|
|
|
animateScale : false,
|
|
|
|
legendTemplate : '<ul class="tc-chart-js-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'
|
|
|
|
};
|
2014-11-25 23:21:30 +08:00
|
|
|
});
|