-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.js
84 lines (78 loc) · 2.09 KB
/
services.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
'use strict';
angular.module('myApp').
factory('trackSimulationService', function($q, $http, $window) {
var serviceInstance = {
active: false,
reset: reset,
lap: lap,
getData: getData,
currentLap: currentLap,
data: undefined
}, lapStart, lapTime = 0;
function ajax(id, action) {
var deferred = $q.defer(),
url = '/simulation.php?transponderid=' + id;
if (action !== undefined) {
url += '&action=' + action;
}
$http.get(url).
success(function(data) {
deferred.resolve(data);
});
return deferred.promise;
}
function reset(id) {
var promise = ajax(id, 'reset');
serviceInstance.active = false;
return promise;
}
function currentLap() {
if (serviceInstance.active) {
lapTime = now() - lapStart;
}
return lapTime;
}
function lap(id) {
var promise = ajax(id,'lap');
serviceInstance.active = true;
lapStart = now();
return promise;
}
function getData(id) {
return ajax(id);
}
return serviceInstance;
}).
factory('pebbleService', function() {
var serviceInstance = {
viewNames: ['bestlap', 'laptime', 'numlaps', 'count'],
views: [],
vibe: ''
};
serviceInstance.viewNames.forEach(function(item) {
serviceInstance.views[item] = {
header: item.toUpperCase(),
body: ''
};
});
return serviceInstance;
}).
factory('configService', function($cookies) {
var year_ms = 365 * 24 * 3600 * 1000,
serviceInstance = {
data: {
transponderid: '',
trackid: ''
},
save: function() {
$cookies.putObject('myLapsConfig', serviceInstance.data, {
expire: new Date(Date.now + year_ms)
});
}
};
var data = $cookies.getObject('myLapsConfig');
if (data) {
serviceInstance.data = data;
}
return serviceInstance;
});