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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
// This is the controller for Event view. StateParams is if I recall the monitor ID.
// This was before I got access to the new APIs. FIXME: Revisit this code to see what I am doing with it
// and whether the new API has a better mechanism
angular.module('zmApp.controllers').controller('zmApp.EventCtrl', function ($ionicPlatform, $scope, $stateParams, message, ZMDataModel, $ionicSideMenuDelegate, $ionicModal, $ionicLoading, $http, $state, $window) {
console.log("I got STATE PARAM " + $stateParams.id);
$scope.id = parseInt($stateParams.id, 10);
$scope.connKey = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111;
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
}
$scope.reloadView = function () {
console.log("*** Refreshing Modal view ***");
//$state.go($state.current, {}, {reload: true});
$scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111;
$ionicLoading.show({
template: "refreshed view",
noBackdrop: true,
duration: 3000
});
}
$scope.$on('$ionicView.loaded', function () {
console.log("**VIEW ** Events Ctrl Loaded");
});
$scope.$on('$ionicView.enter', function () {
console.log("**VIEW ** Events Ctrl Entered");
});
$scope.$on('$ionicView.leave', function () {
console.log("**VIEW ** Events Ctrl Left");
});
$scope.$on('$ionicView.unloaded', function () {
console.log("**VIEW ** Events Ctrl Unloaded");
console.log("*** MODAL ** Destroying modal too");
$scope.modal.remove();
});
// This is a modal to show the event footage
$ionicModal.fromTemplateUrl('templates/events-modal.html', {
scope: $scope,
animation: 'slide-in-up'
})
.then(function (modal) {
$scope.modal = modal;
});
var eventCommands = {
next: "13",
previous: "12",
zoomin: "8",
zoomout: "9",
stop: "3",
pause: "1",
play: "2"
}
$scope.eventCommands = eventCommands;
// this routine handles skipping through events
// in different event views
$scope.controlEventStream = function (cmd) {
console.log("Command value " + cmd);
if (ZMDataModel.isSimulated()) {
var str = "simulation mode. no action taken";
$ionicLoading.show({
template: str,
noBackdrop: true,
duration: 3000
});
return;
}
var loginData = ZMDataModel.getLogin();
var toast_blurb = "";
switch (cmd) {
case "13":
toast_blurb = "moving to ";
break;
case "12":
toast_blurb = "moving to ";
break;
case "8":
toast_blurb = "zoomed into ";
break;
case "9":
toast_blurb = "zoomed out of ";
break;
case "3":
toast_blurb = "stopping playback for ";
break;
case "2":
toast_blurb = "resuming playback for ";
break;
case "1":
toast_blurb = "pausing playback for ";
break;
};
var req = $http({
method: 'POST',
url: loginData.url + 'zm/index.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
console.log("****RETURNING " + foo);
return foo;
},
data: {
view: "request",
request: "stream",
connkey: $scope.connKey,
command: cmd,
user: loginData.username,
pass: loginData.password
}
});
req.success(function (resp) {
console.log("SUCCESS: " + JSON.stringify(resp));
var str = toast_blurb + "event:" + resp.status.event;
console.log(str);
$ionicLoading.show({
template: str,
noBackdrop: true,
duration: 3000
});
});
req.error(function (resp) {
console.log("ERROR: " + JSON.stringify(resp));
});
}
$scope.openModal = function (eid, ename, edur) {
console.log("Open Modal");
$scope.eventName = ename;
$scope.eventId = eid;
$scope.eventDur = Math.round(edur);
$scope.loginData = ZMDataModel.getLogin();
$scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111;
$scope.modal.show();
};
$scope.closeModal = function () {
console.log("Close Modal");
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function () {
console.log("Destroy Modal");
$scope.modal.remove();
});
console.log("***CALLING EVENTS FACTORY");
var lData = ZMDataModel.getLogin();
console.log("ZM Service Username = " + lData.username);
$scope.monitors = message;
$scope.events = ZMDataModel.getEvents($scope.id)
.then(function (data) {
console.log("EventCtrl Got events");
//var events = [];
var myevents = data;
for (var i = 0; i < myevents.length; i++) {
myevents[i].Event.MonitorName = ZMDataModel.getMonitorName(myevents[i].Event.MonitorId);
}
$scope.events = myevents;
});
$scope.isSimulated = function () {
return ZMDataModel.isSimulated();
};
$scope.doRefresh = function () {
console.log("***Pull to Refresh");
$scope.events = [];
$scope.events = ZMDataModel.getEvents($scope.id)
.then(function (data) {
console.log("EventCtrl Got events");
//var events = [];
var myevents = data;
for (var i = 0; i < myevents.length; i++) {
myevents[i].Event.MonitorName = ZMDataModel.getMonitorName(myevents[i].Event.MonitorId);
}
$scope.events = myevents;
$scope.$broadcast('scroll.refreshComplete');
});
}; //dorefresh
});
|