-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
96 lines (85 loc) · 2.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var app = angular.module('surveillance', [
'ngResource',
'ngSanitize',
'ui.bootstrap',
'ui.bootstrap.pagination'
]);
app.controller('MainCtrl', function($scope, $resource) {
$scope.currentPage = 1;
$scope.itemsPerPage = 8;
var Cameras = $resource('rest/camera/:camera');
var Dates = $resource('rest/camera/:camera/date');
var Items = $resource('rest/camera/:camera/date/:date');
var Images = $resource('rest/camera/:camera/date/:date/images');
var Videos = $resource('rest/camera/:camera/date/:date/videos');
Cameras.get().$promise.then(function(success) {
$scope.cameras = success.cameras;
});
var fetchDates = function() {
if ($scope.selectedCamera) {
Dates.get({
"camera": $scope.selectedCamera
}).$promise.then(function(success) {
$scope.dates = success.dates;
});
} else {
$scope.dates = null;
}
if ($scope.selected) {
fetchdata($scope.selected, $scope.page);
} else {
$scope.pager = null;
}
};
var pageChanged = function() {
if ($scope.allItems) {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.items = $scope.allItems.slice(begin, end);
}
};
var fetchItems = function() {
$scope.allItems = null;
$scope.items = null;
if ($scope.selectedCamera && $scope.selectedDate) {
Items.get({
"camera": $scope.selectedCamera,
"date": $scope.selectedDate
}).$promise.then(function(success) {
$scope.allItems = success.items;
$scope.totalItems = $scope.allItems.length;
$scope.currentPage = 1;
pageChanged();
});
}
};
$scope.$watch('selectedCamera', function(newvalue, oldvalue) {
fetchDates();
fetchItems();
});
$scope.$watch('selectedDate', function(newvalue, oldvalue) {
fetchItems();
});
$scope.$watch('currentPage', function(newvalue, oldvalue) {
if (newvalue) {
pageChanged();
}
});
});
app.directive('videoPlayer', function() {
return {
restrict: 'E',
templateUrl: 'videoplayer.tpl.html',
scope: {
'video': '='
},
controller: function($scope, $sce) {
var showPlayer = function() {
$scope.player = true;
};
$scope.enablePlayer = function() {
showPlayer();
};
}
};
});