1 |
01189277
|
kohlicekjan
|
angular.module('pvpk', ['ngResource']);
|
2 |
b88dd6bb
|
Jan Kohlíček
|
angular.module('pvpk')
|
3 |
|
|
.constant('config', {
|
4 |
|
|
APP_NAME: 'PVPK',
|
5 |
01189277
|
kohlicekjan
|
APP_VERSION: '1.3.3',
|
6 |
b88dd6bb
|
Jan Kohlíček
|
API_URL: API_URL,
|
7 |
|
|
API_TOKEN: API_TOKEN,
|
8 |
|
|
DEFAULT_POSITION: {lat: 49.53, lng: 13.3},
|
9 |
|
|
DEFAULT_ZOOM: 10,
|
10 |
|
|
DEFAULT_ZOOM_MIN: 7,
|
11 |
|
|
DEFAULT_RANGE_DATE_DAY: {from: -30, to: -1},
|
12 |
|
|
DEFAULT_RANGE_TIME_HOUR: {from: 7, to: 16}
|
13 |
49df590a
|
Jan Kohlíček
|
});
|
14 |
b88dd6bb
|
Jan Kohlíček
|
angular.module('pvpk')
|
15 |
01189277
|
kohlicekjan
|
.factory('Device', ['$resource', 'config', function ($resource, config) {
|
16 |
|
|
return $resource(config.API_URL + '/devices/:id', {id: '@id', period: '@period'}, {
|
17 |
|
|
'get': {
|
18 |
|
|
url: config.API_URL + '/devices/:id/:period',
|
19 |
|
|
method: 'GET',
|
20 |
|
|
headers: {
|
21 |
|
|
'Content-Type': 'application/json',
|
22 |
|
|
'Accept': 'application/json',
|
23 |
|
|
'jwt': config.API_TOKEN
|
24 |
|
|
}
|
25 |
|
|
},
|
26 |
|
|
'query': {
|
27 |
|
|
url: config.API_URL + '/devices',
|
28 |
|
|
method: 'GET',
|
29 |
|
|
isArray: true,
|
30 |
|
|
headers: {
|
31 |
|
|
'Content-Type': 'application/json',
|
32 |
|
|
'Accept': 'application/json',
|
33 |
|
|
'jwt': config.API_TOKEN
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
});
|
37 |
|
|
}]);
|
38 |
|
|
angular.module('pvpk')
|
39 |
|
|
.factory('Range', ['$resource', 'config', function ($resource, config) {
|
40 |
|
|
return $resource(config.API_URL + '/range', null, {
|
41 |
|
|
'get': {
|
42 |
|
|
url: config.API_URL + '/range',
|
43 |
|
|
method: 'GET',
|
44 |
|
|
headers: {
|
45 |
|
|
'Content-Type': 'application/json',
|
46 |
|
|
'Accept': 'application/json',
|
47 |
|
|
'jwt': config.API_TOKEN
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
});
|
51 |
|
|
}]);
|
52 |
|
|
angular.module('pvpk')
|
53 |
|
|
.factory('Vehicle', ['$resource', 'config', function ($resource, config) {
|
54 |
|
|
return $resource(config.API_URL + '/vehicles', null, {
|
55 |
|
|
'query': {
|
56 |
|
|
url: config.API_URL + '/vehicles',
|
57 |
|
|
method: 'GET',
|
58 |
|
|
isArray: true,
|
59 |
|
|
headers: {
|
60 |
|
|
'Content-Type': 'application/json',
|
61 |
|
|
'Accept': 'application/json',
|
62 |
|
|
'jwt': config.API_TOKEN
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
});
|
66 |
|
|
}]);
|
67 |
|
|
angular.module('pvpk')
|
68 |
|
|
.controller('infoController', ['$rootScope', '$scope', '$location', 'config', 'Device', 'Vehicle', 'Range', function ($rootScope, $scope, $location, config, Device, Vehicle, Range) {
|
69 |
49df590a
|
Jan Kohlíček
|
|
70 |
b88dd6bb
|
Jan Kohlíček
|
this.$onInit = function () {
|
71 |
|
|
$rootScope.selectDevice = null;
|
72 |
|
|
$scope.showInfoLoading = false;
|
73 |
|
|
$scope.vehicles = [];
|
74 |
|
|
$scope.urlExportCsv = null;
|
75 |
01189277
|
kohlicekjan
|
$scope.directions = [
|
76 |
|
|
{id: undefined, name: 'po směru i proti směru'},
|
77 |
|
|
{id: 1, name: 'po směru'},
|
78 |
|
|
{id: 2, name: 'proti směru'}];
|
79 |
|
|
$scope.isLoadRange = false;
|
80 |
b88dd6bb
|
Jan Kohlíček
|
|
81 |
|
|
Vehicle.query(null, function (data) {
|
82 |
|
|
$scope.vehicles = data;
|
83 |
|
|
}, function (response) {
|
84 |
|
|
$rootScope.graphShow = false;
|
85 |
|
|
console.log('Error api all Vehicles');
|
86 |
|
|
$rootScope.handleErrorResponse(response);
|
87 |
|
|
});
|
88 |
d68f7bbd
|
Jan Kohlíček
|
|
89 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$emit('setRangeFromUrl', null);
|
90 |
|
|
};
|
91 |
0b27c108
|
Jan Kohlíček
|
|
92 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$on('setRangeFromUrl', function (event, args) {
|
93 |
|
|
var params = $location.search();
|
94 |
01189277
|
kohlicekjan
|
|
95 |
b88dd6bb
|
Jan Kohlíček
|
$scope.range = {
|
96 |
|
|
fromDate: moment(params.fromDate, 'YYYY-MM-DD').isValid() ? moment(params.fromDate).toDate() : moment().add(config.DEFAULT_RANGE_DATE_DAY.from, 'd').toDate(),
|
97 |
|
|
toDate: moment(params.toDate, 'YYYY-MM-DD').isValid() ? moment(params.toDate).toDate() : moment().add(config.DEFAULT_RANGE_DATE_DAY.to, 'd').toDate(),
|
98 |
|
|
fromTime: moment(params.fromTime, 'HH:mm').isValid() ? moment(params.fromTime, 'HH:mm').toDate() : moment({hour: config.DEFAULT_RANGE_TIME_HOUR.from}).toDate(),
|
99 |
|
|
toTime: moment(params.toTime, 'HH:mm').isValid() ? moment(params.toTime, 'HH:mm').toDate() : moment({hour: config.DEFAULT_RANGE_TIME_HOUR.to}).toDate(),
|
100 |
01189277
|
kohlicekjan
|
isTime: params.isTime == 0 ? false : true,
|
101 |
|
|
maxDate: $scope.range == null ? null : $scope.range.maxDate,
|
102 |
|
|
minDate: $scope.range == null ? null : $scope.range.minDate
|
103 |
b88dd6bb
|
Jan Kohlíček
|
};
|
104 |
01189277
|
kohlicekjan
|
|
105 |
|
|
if (!$scope.isLoadRange) {
|
106 |
|
|
Range.get(null, function (data) {
|
107 |
|
|
$scope.range.fromDate = moment.max(moment(data.last_date).add(config.DEFAULT_RANGE_DATE_DAY.from, 'd'), moment(data.first_date)).toDate();
|
108 |
|
|
$scope.range.toDate = moment.min(moment($scope.range.toDate), moment(data.last_date)).toDate();
|
109 |
|
|
$scope.range.maxDate = moment(data.last_date).toDate();
|
110 |
|
|
$scope.range.minDate = moment(data.first_date).toDate();
|
111 |
|
|
$scope.isLoadRange = true;
|
112 |
|
|
}, function (response) {
|
113 |
|
|
console.log('Error api get Range');
|
114 |
|
|
$rootScope.handleErrorResponse(response);
|
115 |
|
|
});
|
116 |
|
|
}
|
117 |
0b27c108
|
Jan Kohlíček
|
});
|
118 |
|
|
|
119 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$on('infoLocation', function (event, args) {
|
120 |
|
|
$scope.showInfoLoading = true;
|
121 |
49df590a
|
Jan Kohlíček
|
|
122 |
b88dd6bb
|
Jan Kohlíček
|
var params = $location.search();
|
123 |
|
|
params.deviceId = args.id;
|
124 |
|
|
params.direction = args.direction;
|
125 |
|
|
$location.search(params);
|
126 |
d68f7bbd
|
Jan Kohlíček
|
|
127 |
b88dd6bb
|
Jan Kohlíček
|
var range = $scope.getRange();
|
128 |
d68f7bbd
|
Jan Kohlíček
|
|
129 |
b88dd6bb
|
Jan Kohlíček
|
var query = {
|
130 |
|
|
period: range.isTime ? 'time-period' : 'day-period',
|
131 |
|
|
id: args.id,
|
132 |
|
|
direction: args.direction,
|
133 |
|
|
dateFrom: range.fromDate.format('YYYY-MM-DD'),
|
134 |
|
|
dateTo: range.toDate.format('YYYY-MM-DD'),
|
135 |
|
|
timeFrom: range.isTime ? range.fromTime.format('HH:mm') : null,
|
136 |
|
|
timeTo: range.isTime ? range.toTime.format('HH:mm') : null
|
137 |
|
|
};
|
138 |
d68f7bbd
|
Jan Kohlíček
|
|
139 |
b88dd6bb
|
Jan Kohlíček
|
Device.get(query, function (data) {
|
140 |
|
|
$rootScope.selectDevice = data;
|
141 |
|
|
$scope.renderGraph();
|
142 |
|
|
$scope.urlExportCsv = $scope.generateUrlExportCsv(query);
|
143 |
d68f7bbd
|
Jan Kohlíček
|
|
144 |
b88dd6bb
|
Jan Kohlíček
|
$scope.showInfoLoading = false;
|
145 |
|
|
}, function (response) {
|
146 |
|
|
$rootScope.selectDevice = null;
|
147 |
|
|
$scope.showInfoLoading = false;
|
148 |
|
|
console.log('Error api get Devices');
|
149 |
|
|
$rootScope.handleErrorResponse(response);
|
150 |
|
|
});
|
151 |
d68f7bbd
|
Jan Kohlíček
|
|
152 |
|
|
});
|
153 |
49df590a
|
Jan Kohlíček
|
|
154 |
b88dd6bb
|
Jan Kohlíček
|
$scope.generateUrlExportCsv = function (query) {
|
155 |
|
|
var relativeUrl = '/devices/:id/:period/csv?'.replace(':id', query.id).replace(':period', query.period);
|
156 |
|
|
delete query.id;
|
157 |
|
|
delete query.period;
|
158 |
49df590a
|
Jan Kohlíček
|
|
159 |
b88dd6bb
|
Jan Kohlíček
|
var paramsUrl = jQuery.param(query);
|
160 |
|
|
return config.API_URL + relativeUrl + paramsUrl;
|
161 |
49df590a
|
Jan Kohlíček
|
};
|
162 |
|
|
|
163 |
b88dd6bb
|
Jan Kohlíček
|
$scope.changeRange = function () {
|
164 |
|
|
if ($scope.range.fromDate >= $scope.range.toDate || ($scope.range.isTime && $scope.range.fromTime >= $scope.range.toTime)) {
|
165 |
|
|
$rootScope.selectDevice.traffics = [];
|
166 |
|
|
return;
|
167 |
|
|
}
|
168 |
49df590a
|
Jan Kohlíček
|
|
169 |
b88dd6bb
|
Jan Kohlíček
|
var range = $scope.getRange();
|
170 |
|
|
|
171 |
|
|
var params = $location.search();
|
172 |
|
|
params.fromDate = range.fromDate.format('YYYY-MM-DD');
|
173 |
|
|
params.toDate = range.toDate.format('YYYY-MM-DD');
|
174 |
|
|
params.fromTime = range.isTime ? range.fromTime.format('HH:mm') : null;
|
175 |
|
|
params.toTime = range.isTime ? range.toTime.format('HH:mm') : null;
|
176 |
|
|
params.isTime = range.isTime ? null : 0;
|
177 |
|
|
$location.search(params);
|
178 |
|
|
|
179 |
|
|
if ($rootScope.selectDevice)
|
180 |
|
|
$rootScope.$emit('infoLocation', {
|
181 |
|
|
id: $rootScope.selectDevice.id,
|
182 |
|
|
direction: $rootScope.selectDevice.direction
|
183 |
|
|
});
|
184 |
274760e7
|
Jan Kohlíček
|
};
|
185 |
|
|
|
186 |
01189277
|
kohlicekjan
|
$scope.changeDirection = function () {
|
187 |
|
|
|
188 |
|
|
$rootScope.$emit('infoLocation', {
|
189 |
|
|
id: $rootScope.selectDevice.id,
|
190 |
|
|
direction: $rootScope.selectDevice.direction
|
191 |
|
|
});
|
192 |
|
|
};
|
193 |
|
|
|
194 |
b88dd6bb
|
Jan Kohlíček
|
$scope.getRange = function () {
|
195 |
|
|
return {
|
196 |
|
|
fromDate: moment($scope.range.fromDate).isValid() ? moment($scope.range.fromDate) : moment().add(config.DEFAULT_RANGE_DATE_DAY.from, 'd'),
|
197 |
|
|
toDate: moment($scope.range.toDate).isValid() ? moment($scope.range.toDate) : moment().add(config.DEFAULT_RANGE_DATE_DAY.to, 'd'),
|
198 |
|
|
fromTime: moment($scope.range.fromTime).isValid() ? moment($scope.range.fromTime) : moment({hour: config.DEFAULT_RANGE_TIME_HOUR.from}),
|
199 |
|
|
toTime: moment($scope.range.toTime).isValid() ? moment($scope.range.toTime) : moment({hour: config.DEFAULT_RANGE_TIME_HOUR.to}),
|
200 |
|
|
isTime: $scope.range.isTime ? true : false
|
201 |
|
|
};
|
202 |
|
|
};
|
203 |
49df590a
|
Jan Kohlíček
|
|
204 |
b88dd6bb
|
Jan Kohlíček
|
$scope.renderGraph = function () {
|
205 |
|
|
var color = ['rgba(158, 158, 158, #alpha)', 'rgba(213, 0, 0, #alpha)', 'rgba(0, 123, 255, #alpha)', 'rgba(170, 0, 255, #alpha)',
|
206 |
|
|
'rgba(0, 200, 83, #alpha)', 'rgba(255, 214, 0, #alpha)', 'rgba(255, 109, 0, #alpha)',
|
207 |
|
|
'rgba(174, 234, 0, #alpha)', 'rgba(98, 0, 234, #alpha)', 'rgba(255, 171, 0, #alpha)', 'rgba(100, 221, 23, #alpha)', 'rgba(0, 184, 212, #alpha)'];
|
208 |
49df590a
|
Jan Kohlíček
|
|
209 |
b88dd6bb
|
Jan Kohlíček
|
var labels = jQuery.unique($rootScope.selectDevice.traffics.map(function (d) {
|
210 |
|
|
return $scope.range.isTime ? d.timeFrom : moment(d.date, 'YYYY-MM-DD').format('D.M.YYYY');
|
211 |
|
|
}));
|
212 |
274760e7
|
Jan Kohlíček
|
|
213 |
b88dd6bb
|
Jan Kohlíček
|
var useVehiclesIds = jQuery.unique($rootScope.selectDevice.traffics.map(function (d) {
|
214 |
|
|
return d.typeVehicleId;
|
215 |
|
|
}));
|
216 |
0b27c108
|
Jan Kohlíček
|
|
217 |
b88dd6bb
|
Jan Kohlíček
|
var filterVehicles = jQuery.grep($scope.vehicles, function (n) {
|
218 |
|
|
return useVehiclesIds.indexOf(n.id) >= 0;
|
219 |
|
|
});
|
220 |
d68f7bbd
|
Jan Kohlíček
|
|
221 |
b88dd6bb
|
Jan Kohlíček
|
var datasetsNumberVehicles = [];
|
222 |
|
|
var datasetsAverageSpeed = [];
|
223 |
274760e7
|
Jan Kohlíček
|
|
224 |
b88dd6bb
|
Jan Kohlíček
|
for (var i = 0, vehicle; vehicle = filterVehicles[i]; i++) {
|
225 |
|
|
var datasetNumberVehicles = {
|
226 |
|
|
label: vehicle.name,
|
227 |
|
|
backgroundColor: color[vehicle.id].replace("#alpha", "0.3"),
|
228 |
|
|
borderColor: color[vehicle.id].replace("#alpha", "1"),
|
229 |
|
|
borderWidth: 2,
|
230 |
|
|
data: []
|
231 |
|
|
};
|
232 |
fb12df6d
|
Jan Kohlíček
|
|
233 |
b88dd6bb
|
Jan Kohlíček
|
var datasetAverageSpeed = {
|
234 |
|
|
data: [],
|
235 |
|
|
borderWidth: 2,
|
236 |
|
|
label: vehicle.name,
|
237 |
|
|
fill: false,
|
238 |
|
|
backgroundColor: color[vehicle.id].replace("#alpha", "0.3"),
|
239 |
|
|
borderColor: color[vehicle.id].replace("#alpha", "1"),
|
240 |
|
|
cubicInterpolationMode: 'monotone',
|
241 |
|
|
pointRadius: 0
|
242 |
|
|
};
|
243 |
49df590a
|
Jan Kohlíček
|
|
244 |
b88dd6bb
|
Jan Kohlíček
|
var l = 0;
|
245 |
|
|
for (var j = 0, traffic; traffic = $rootScope.selectDevice.traffics[j]; j++) {
|
246 |
|
|
if (($scope.range.isTime && labels[l] !== traffic.timeFrom) || (!$scope.range.isTime && labels[l] !== moment(traffic.date, 'YYYY-MM-DD').format('D.M.YYYY'))) {
|
247 |
|
|
l++;
|
248 |
|
|
if (datasetNumberVehicles.data.length < l) {
|
249 |
|
|
datasetNumberVehicles.data.push(0);
|
250 |
01189277
|
kohlicekjan
|
datasetAverageSpeed.data.push(0);
|
251 |
b88dd6bb
|
Jan Kohlíček
|
}
|
252 |
|
|
}
|
253 |
|
|
if (traffic.typeVehicleId === vehicle.id) {
|
254 |
|
|
datasetNumberVehicles.data.push($scope.range.isTime ? traffic.numberVehicleAverage : traffic.numberVehicle);
|
255 |
01189277
|
kohlicekjan
|
datasetAverageSpeed.data.push(traffic.speedAverage <= 0 ? 0 : traffic.speedAverage);
|
256 |
b88dd6bb
|
Jan Kohlíček
|
}
|
257 |
|
|
}
|
258 |
|
|
datasetsNumberVehicles.push(datasetNumberVehicles);
|
259 |
|
|
datasetsAverageSpeed.push(datasetAverageSpeed);
|
260 |
|
|
}
|
261 |
49df590a
|
Jan Kohlíček
|
|
262 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$emit('renderGraphNumberVehicles', {
|
263 |
|
|
data: {
|
264 |
|
|
labels: labels,
|
265 |
|
|
datasets: datasetsNumberVehicles
|
266 |
|
|
}
|
267 |
|
|
});
|
268 |
49df590a
|
Jan Kohlíček
|
|
269 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$emit('renderGraphAverageSpeed', {
|
270 |
|
|
data: {
|
271 |
|
|
labels: labels,
|
272 |
|
|
datasets: datasetsAverageSpeed
|
273 |
|
|
}
|
274 |
49df590a
|
Jan Kohlíček
|
});
|
275 |
b88dd6bb
|
Jan Kohlíček
|
};
|
276 |
49df590a
|
Jan Kohlíček
|
|
277 |
b88dd6bb
|
Jan Kohlíček
|
$scope.infoClose = function () {
|
278 |
|
|
$rootScope.selectDevice = null;
|
279 |
49df590a
|
Jan Kohlíček
|
|
280 |
b88dd6bb
|
Jan Kohlíček
|
var params = $location.search();
|
281 |
|
|
params.deviceId = null;
|
282 |
|
|
params.direction = null;
|
283 |
|
|
$location.search(params);
|
284 |
|
|
|
285 |
|
|
$rootScope.$emit('setDefaultMap', null);
|
286 |
49df590a
|
Jan Kohlíček
|
};
|
287 |
b88dd6bb
|
Jan Kohlíček
|
}]);
|
288 |
49df590a
|
Jan Kohlíček
|
|
289 |
b88dd6bb
|
Jan Kohlíček
|
angular.module('pvpk')
|
290 |
|
|
.controller('mainController', ['$rootScope', '$scope', '$location', '$window', function ($rootScope, $scope, $location, $window) {
|
291 |
49df590a
|
Jan Kohlíček
|
|
292 |
b88dd6bb
|
Jan Kohlíček
|
this.$onInit = function () {
|
293 |
|
|
$scope.showLoadingScreen = true;
|
294 |
|
|
};
|
295 |
49df590a
|
Jan Kohlíček
|
|
296 |
b88dd6bb
|
Jan Kohlíček
|
$window.onload = function () {
|
297 |
|
|
var params = $location.search();
|
298 |
|
|
if (params.deviceId) {
|
299 |
|
|
$rootScope.$emit('activeMarker', {id: params.deviceId});
|
300 |
49df590a
|
Jan Kohlíček
|
}
|
301 |
|
|
|
302 |
b88dd6bb
|
Jan Kohlíček
|
$scope.$apply(function () {
|
303 |
|
|
$scope.showLoadingScreen = false;
|
304 |
|
|
});
|
305 |
|
|
};
|
306 |
|
|
|
307 |
|
|
$rootScope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
|
308 |
|
|
var params = $location.search();
|
309 |
49df590a
|
Jan Kohlíček
|
|
310 |
b88dd6bb
|
Jan Kohlíček
|
if (newUrl !== oldUrl && $scope.historyUrl) {
|
311 |
|
|
if ($scope.historyUrl.q !== $scope.historyUrl.q || $scope.historyUrl.isDirection != params.isDirection) {
|
312 |
|
|
$rootScope.$emit('setSearchFromUrl', null);
|
313 |
|
|
}
|
314 |
49df590a
|
Jan Kohlíček
|
|
315 |
b88dd6bb
|
Jan Kohlíček
|
if ($scope.historyUrl.fromDate !== params.fromDate || $scope.historyUrl.toDate !== params.toDate ||
|
316 |
|
|
$scope.historyUrl.fromTime !== params.fromTime || $scope.historyUrl.toTime !== params.toTime) {
|
317 |
|
|
$rootScope.$emit('setRangeFromUrl', null);
|
318 |
|
|
if (params.deviceId) {
|
319 |
|
|
$rootScope.$emit('infoLocation', {id: params.deviceId, direction: params.direction});
|
320 |
49df590a
|
Jan Kohlíček
|
}
|
321 |
b88dd6bb
|
Jan Kohlíček
|
} else if (params.deviceId && ($scope.historyUrl.deviceId !== params.deviceId || $scope.historyUrl.direction !== params.direction)) {
|
322 |
|
|
$rootScope.$emit('infoLocation', {id: params.deviceId, direction: params.direction});
|
323 |
|
|
$rootScope.$emit('activeMarker', {id: params.deviceId});
|
324 |
|
|
} else if (!params.deviceId && $scope.historyUrl.deviceId) {
|
325 |
|
|
$rootScope.selectDevice = null;
|
326 |
|
|
$rootScope.$emit('setDefaultMap', null);
|
327 |
49df590a
|
Jan Kohlíček
|
}
|
328 |
b88dd6bb
|
Jan Kohlíček
|
} else if (params.deviceId) {
|
329 |
|
|
$rootScope.$emit('infoLocation', {id: params.deviceId, direction: params.direction});
|
330 |
49df590a
|
Jan Kohlíček
|
}
|
331 |
|
|
|
332 |
b88dd6bb
|
Jan Kohlíček
|
$scope.historyUrl = $location.search();
|
333 |
49df590a
|
Jan Kohlíček
|
});
|
334 |
|
|
|
335 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.handleErrorResponse = function (response) {
|
336 |
|
|
|
337 |
|
|
var modalError = jQuery('#modalError');
|
338 |
|
|
switch (response.status) {
|
339 |
|
|
case 400:
|
340 |
|
|
console.log('API ERROR 400');
|
341 |
|
|
$scope.modalError = {
|
342 |
|
|
title: 'Neplatný požadavek',
|
343 |
|
|
body: 'Požadavek nemůže být vyřízen, poněvadž byl syntakticky nesprávně zapsán.',
|
344 |
|
|
button: 'OK'
|
345 |
|
|
};
|
346 |
|
|
modalError.modal('show');
|
347 |
|
|
break;
|
348 |
|
|
case 401:
|
349 |
|
|
$scope.modalError = {
|
350 |
|
|
title: 'Platnost webové aplikace vypršela',
|
351 |
01189277
|
kohlicekjan
|
body: 'Pro obnovení platnosti stačí stisknout tlačítko Obnovit.',
|
352 |
b88dd6bb
|
Jan Kohlíček
|
button: 'Obnovit',
|
353 |
|
|
clickButton: $scope.reloadApp
|
354 |
|
|
};
|
355 |
|
|
modalError.modal({backdrop: 'static', keyboard: false});
|
356 |
|
|
break;
|
357 |
|
|
case 404:
|
358 |
|
|
console.log('API ERROR 404');
|
359 |
|
|
$scope.modalError = {title: 'Nenalezen', body: 'Záznam nebyl nalezen.', button: 'OK'};
|
360 |
|
|
modalError.modal('show');
|
361 |
|
|
break;
|
362 |
|
|
case 500:
|
363 |
|
|
console.log('API ERROR 500');
|
364 |
|
|
$scope.modalError = {title: 'Chyba', body: 'Chyba serveru. Zopakujte akci později.', button: 'OK'};
|
365 |
|
|
modalError.modal('show');
|
366 |
|
|
break;
|
367 |
|
|
case -1:
|
368 |
|
|
console.log('API NOT CONNECTED');
|
369 |
|
|
$scope.modalError = {
|
370 |
|
|
title: 'Připojení k internetu',
|
371 |
|
|
body: 'Nejste připojeni k internetu. Zkontrolujte připojení.',
|
372 |
|
|
button: 'OK'
|
373 |
|
|
};
|
374 |
|
|
modalError.modal('show');
|
375 |
|
|
break;
|
376 |
|
|
default:
|
377 |
|
|
console.log('API UNKNOWN ERROR');
|
378 |
|
|
$scope.modalError = {title: 'Neočekávaná chyba', body: 'Nastala neočekávaná chyba.', button: 'OK'};
|
379 |
|
|
modalError.modal('show');
|
380 |
|
|
break;
|
381 |
49df590a
|
Jan Kohlíček
|
}
|
382 |
b88dd6bb
|
Jan Kohlíček
|
};
|
383 |
|
|
|
384 |
|
|
$scope.reloadApp = function () {
|
385 |
|
|
$window.location.reload();
|
386 |
49df590a
|
Jan Kohlíček
|
}
|
387 |
b88dd6bb
|
Jan Kohlíček
|
}]);
|
388 |
|
|
angular.module('pvpk')
|
389 |
|
|
.controller('mapController', ['$rootScope', '$scope', 'config', 'Device', function ($rootScope, $scope, config, Device) {
|
390 |
|
|
|
391 |
|
|
this.$onInit = function () {
|
392 |
|
|
$scope.markers = [];
|
393 |
|
|
|
394 |
|
|
$scope.map = new google.maps.Map(document.getElementById('map'), {
|
395 |
|
|
center: config.DEFAULT_POSITION,
|
396 |
|
|
zoom: config.DEFAULT_ZOOM,
|
397 |
|
|
minZoom: config.DEFAULT_ZOOM_MIN,
|
398 |
|
|
zoomControl: true,
|
399 |
|
|
mapTypeControl: false,
|
400 |
|
|
scaleControl: false,
|
401 |
|
|
streetViewControl: false,
|
402 |
|
|
rotateControl: false,
|
403 |
|
|
fullscreenControl: false,
|
404 |
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
405 |
|
|
});
|
406 |
49df590a
|
Jan Kohlíček
|
|
407 |
b88dd6bb
|
Jan Kohlíček
|
Device.query({showDirection: 0}, function (data) {
|
408 |
|
|
for (var i = 0, lctn; lctn = data[i]; i++) {
|
409 |
|
|
$scope.createMarker(lctn);
|
410 |
|
|
}
|
411 |
|
|
}, function (response) {
|
412 |
|
|
console.log('Error api all Devices');
|
413 |
|
|
$rootScope.handleErrorResponse(response);
|
414 |
|
|
});
|
415 |
|
|
};
|
416 |
49df590a
|
Jan Kohlíček
|
|
417 |
b88dd6bb
|
Jan Kohlíček
|
$scope.createMarker = function (lctn) {
|
418 |
|
|
if (lctn.lat && lctn.lng) {
|
419 |
|
|
var marker = new google.maps.Marker({
|
420 |
|
|
map: $scope.map,
|
421 |
|
|
position: {lat: lctn.lat, lng: lctn.lng},
|
422 |
|
|
title: lctn.name,
|
423 |
|
|
infoWindow: new google.maps.InfoWindow({
|
424 |
|
|
content: '<h6 class="mb-1">' + lctn.name + '</h6>'
|
425 |
|
|
+ '<address>' + lctn.street + ', ' + lctn.town + '</address>'
|
426 |
|
|
}),
|
427 |
|
|
id: lctn.id
|
428 |
|
|
});
|
429 |
|
|
|
430 |
|
|
marker.addListener('click', function () {
|
431 |
|
|
$scope.closeInfoWindows();
|
432 |
|
|
marker.infoWindow.open($scope.map, marker);
|
433 |
|
|
$rootScope.$emit('infoLocation', {id: lctn.id});
|
434 |
|
|
});
|
435 |
|
|
|
436 |
|
|
$scope.markers.push(marker);
|
437 |
|
|
}
|
438 |
|
|
};
|
439 |
49df590a
|
Jan Kohlíček
|
|
440 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$on('activeMarker', function (event, args) {
|
441 |
|
|
for (var i = 0, marker; marker = $scope.markers[i]; i++) {
|
442 |
|
|
if (marker.id && marker.id === args.id && marker.infoWindow) {
|
443 |
|
|
$scope.map.setCenter(marker.getPosition());
|
444 |
|
|
$scope.map.setZoom(12);
|
445 |
|
|
marker.infoWindow.open($scope.map, marker);
|
446 |
|
|
} else {
|
447 |
|
|
marker.infoWindow.close();
|
448 |
49df590a
|
Jan Kohlíček
|
}
|
449 |
|
|
}
|
450 |
|
|
});
|
451 |
|
|
|
452 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$on('setDefaultMap', function (event, args) {
|
453 |
|
|
$scope.map.setCenter(config.DEFAULT_POSITION);
|
454 |
|
|
$scope.map.setZoom(config.DEFAULT_ZOOM);
|
455 |
|
|
$scope.closeInfoWindows();
|
456 |
|
|
});
|
457 |
|
|
|
458 |
|
|
$scope.closeInfoWindows = function () {
|
459 |
|
|
for (var i = 0, marker; marker = $scope.markers[i]; i++) {
|
460 |
|
|
marker.infoWindow.close();
|
461 |
|
|
}
|
462 |
|
|
};
|
463 |
|
|
}]);
|
464 |
|
|
angular.module('pvpk')
|
465 |
|
|
.controller('searchController', ['$rootScope', '$scope', '$location', 'config', 'Device', function ($rootScope, $scope, $location, config, Device) {
|
466 |
d68f7bbd
|
Jan Kohlíček
|
|
467 |
b88dd6bb
|
Jan Kohlíček
|
this.$onInit = function () {
|
468 |
|
|
$scope.config = config;
|
469 |
|
|
$scope.locations = [];
|
470 |
|
|
$scope.showSearchLoading = false;
|
471 |
49df590a
|
Jan Kohlíček
|
|
472 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$emit('setSearchFromUrl', null);
|
473 |
|
|
};
|
474 |
0b27c108
|
Jan Kohlíček
|
|
475 |
b88dd6bb
|
Jan Kohlíček
|
$scope.searchLocations = function () {
|
476 |
|
|
var params = $location.search();
|
477 |
|
|
params.q = $scope.search.q;
|
478 |
|
|
params.isDirection = $scope.search.isDirection ? 1 : null;
|
479 |
|
|
$location.search(params);
|
480 |
0b27c108
|
Jan Kohlíček
|
|
481 |
b88dd6bb
|
Jan Kohlíček
|
if (!$scope.search.q || $scope.search.q.length <= 1) {
|
482 |
|
|
$scope.locations = [];
|
483 |
|
|
return;
|
484 |
|
|
}
|
485 |
0b27c108
|
Jan Kohlíček
|
|
486 |
b88dd6bb
|
Jan Kohlíček
|
$scope.showSearchLoading = true;
|
487 |
|
|
|
488 |
|
|
Device.query({
|
489 |
|
|
address: $scope.search.q,
|
490 |
|
|
showDirection: $scope.search.isDirection ? 1 : 0
|
491 |
|
|
}, function (data) {
|
492 |
|
|
$scope.locations = data;
|
493 |
|
|
$scope.showSearchLoading = false;
|
494 |
|
|
}, function (response) {
|
495 |
|
|
$scope.showSearchLoading = false;
|
496 |
|
|
console.log('Error api all Devices');
|
497 |
|
|
$rootScope.handleErrorResponse(response);
|
498 |
|
|
});
|
499 |
|
|
};
|
500 |
0b27c108
|
Jan Kohlíček
|
|
501 |
b88dd6bb
|
Jan Kohlíček
|
$rootScope.$on('setSearchFromUrl', function (event, args) {
|
502 |
|
|
var params = $location.search();
|
503 |
|
|
$scope.search = {
|
504 |
|
|
q: params.q,
|
505 |
|
|
isDirection: params.isDirection ? !!+params.isDirection : false
|
506 |
|
|
};
|
507 |
|
|
$scope.searchLocations();
|
508 |
d68f7bbd
|
Jan Kohlíček
|
});
|
509 |
0b27c108
|
Jan Kohlíček
|
|
510 |
b88dd6bb
|
Jan Kohlíček
|
$scope.selectDevice = function (id, direction) {
|
511 |
|
|
$rootScope.$emit('activeMarker', {id: id});
|
512 |
|
|
$rootScope.$emit('infoLocation', {id: id, direction: direction});
|
513 |
|
|
};
|
514 |
|
|
|
515 |
|
|
}]);
|
516 |
|
|
angular.module('pvpk')
|
517 |
|
|
.component('graphAverageSpeed', {
|
518 |
01189277
|
kohlicekjan
|
template: '<div><canvas id="graphAverageSpeed" class="graph-size mb-5"></canvas></div>',
|
519 |
b88dd6bb
|
Jan Kohlíček
|
controller: ['$rootScope', '$scope', function ($rootScope, $scope) {
|
520 |
|
|
|
521 |
|
|
$rootScope.$on('renderGraphAverageSpeed', function (event, args) {
|
522 |
|
|
var canvas = document.getElementById('graphAverageSpeed').getContext('2d');
|
523 |
|
|
|
524 |
|
|
if ($scope.graphLine)
|
525 |
|
|
$scope.graphLine.destroy();
|
526 |
|
|
|
527 |
|
|
$scope.graphLine = new Chart(canvas, {
|
528 |
|
|
type: 'line',
|
529 |
|
|
data: args.data,
|
530 |
|
|
options: {
|
531 |
|
|
responsive: true,
|
532 |
|
|
pointDot: false,
|
533 |
|
|
legend: {
|
534 |
|
|
position: 'bottom'
|
535 |
|
|
},
|
536 |
|
|
scales: {
|
537 |
|
|
xAxes: [{
|
538 |
|
|
ticks: {
|
539 |
|
|
autoSkip: true,
|
540 |
|
|
maxTicksLimit: 15
|
541 |
|
|
}
|
542 |
|
|
}],
|
543 |
|
|
yAxes: [{
|
544 |
|
|
scaleLabel: {
|
545 |
|
|
display: true,
|
546 |
|
|
labelString: 'km/h'
|
547 |
|
|
},
|
548 |
|
|
ticks: {
|
549 |
|
|
beginAtZero: true,
|
550 |
|
|
suggestedMax: 70
|
551 |
|
|
}
|
552 |
|
|
}]
|
553 |
|
|
},
|
554 |
|
|
tooltips: {
|
555 |
|
|
mode: 'index',
|
556 |
|
|
intersect: false,
|
557 |
|
|
callbacks: {
|
558 |
|
|
label: function (tooltipItems) {
|
559 |
|
|
return tooltipItems.yLabel + ' km/h';
|
560 |
|
|
}
|
561 |
|
|
}
|
562 |
|
|
}
|
563 |
|
|
}
|
564 |
|
|
});
|
565 |
fb12df6d
|
Jan Kohlíček
|
|
566 |
|
|
});
|
567 |
|
|
|
568 |
b88dd6bb
|
Jan Kohlíček
|
}]
|
569 |
d68f7bbd
|
Jan Kohlíček
|
});
|
570 |
b88dd6bb
|
Jan Kohlíček
|
angular.module('pvpk')
|
571 |
|
|
.component('graphNumberVehicles', {
|
572 |
01189277
|
kohlicekjan
|
template: '<div><canvas id="graphNumberVehicles" class="graph-size mb-5"></canvas></div>',
|
573 |
b88dd6bb
|
Jan Kohlíček
|
controller: ['$rootScope', '$scope', function ($rootScope, $scope) {
|
574 |
|
|
|
575 |
|
|
$rootScope.$on('renderGraphNumberVehicles', function (event, args) {
|
576 |
|
|
var canvasGraphNumberVehicles = document.getElementById('graphNumberVehicles').getContext('2d');
|
577 |
|
|
|
578 |
|
|
if ($scope.graphNumberVehicles)
|
579 |
|
|
$scope.graphNumberVehicles.destroy();
|
580 |
|
|
|
581 |
|
|
$scope.graphNumberVehicles = new Chart(canvasGraphNumberVehicles, {
|
582 |
|
|
type: 'bar',
|
583 |
|
|
data: args.data,
|
584 |
|
|
options: {
|
585 |
|
|
responsive: true,
|
586 |
|
|
onResize: function (chart, size) {
|
587 |
|
|
chart.options.legend.display = size.height > 240;
|
588 |
|
|
chart.update();
|
589 |
|
|
},
|
590 |
|
|
legend: {
|
591 |
|
|
position: 'bottom'
|
592 |
|
|
},
|
593 |
|
|
scales: {
|
594 |
|
|
xAxes: [{
|
595 |
|
|
stacked: true,
|
596 |
|
|
ticks: {
|
597 |
|
|
autoSkip: true,
|
598 |
|
|
maxTicksLimit: 15
|
599 |
|
|
}
|
600 |
|
|
}],
|
601 |
|
|
yAxes: [{
|
602 |
|
|
scaleLabel: {
|
603 |
|
|
display: true,
|
604 |
|
|
labelString: "počet vozidel"
|
605 |
|
|
},
|
606 |
|
|
stacked: true
|
607 |
|
|
}]
|
608 |
|
|
},
|
609 |
|
|
tooltips: {
|
610 |
|
|
mode: 'index',
|
611 |
|
|
intersect: false
|
612 |
|
|
}
|
613 |
|
|
}
|
614 |
|
|
});
|
615 |
0b27c108
|
Jan Kohlíček
|
|
616 |
b88dd6bb
|
Jan Kohlíček
|
});
|
617 |
fb12df6d
|
Jan Kohlíček
|
|
618 |
b88dd6bb
|
Jan Kohlíček
|
}]
|
619 |
01189277
|
kohlicekjan
|
});
|