Skip to content

Commit 615eed3

Browse files
committed
r4
changed gitignore
1 parent 69e1ee4 commit 615eed3

File tree

3 files changed

+210
-2
lines changed

3 files changed

+210
-2
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.vscode
22
www/data.json
33
www/settings.json
4-
www/index.html
54
www/locations.json

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
*.pyc
33
www/data.json
44
www/settings.json
5-
www/index.html
65
www/locations.json

www/index.html

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<html>
2+
3+
<head>
4+
<title>Google Traffic Screen</title>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7+
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
8+
<script type="text/javascript" src="angular-1.6.5.min.js"></script>
9+
<script type="text/javascript" src="moment-2.22.2.min.js"></script>
10+
11+
<script type="text/javascript">
12+
angular.module('traffic', [])
13+
.controller('trafficController', function () {
14+
var self = this;
15+
16+
self.locations = (localStorage.getItem('locations') != null) ? JSON.parse(localStorage.getItem(
17+
'locations')) : [];
18+
19+
self.settings = (localStorage.getItem('settings') != null) ? JSON.parse(localStorage.getItem(
20+
'settings')) : null;
21+
22+
self.lastUpdated = (localStorage.getItem('lastUpdated') != null) ? parseInt(localStorage.getItem(
23+
'lastUpdated')) : 0;
24+
25+
self.localTime = "";
26+
27+
self.setSettings = function (obj) {
28+
self.settings = obj;
29+
localStorage.setItem('settings', JSON.stringify(self.settings));
30+
}
31+
32+
self.setLocations = function (obj) {
33+
self.locations = obj;
34+
self.save();
35+
}
36+
37+
self.save = function () {
38+
self.lastUpdated = new Date().getTime();
39+
localStorage.setItem('locations', JSON.stringify(self.locations));
40+
localStorage.setItem('lastUpdated', self.lastUpdated);
41+
};
42+
43+
self.clear = function () {
44+
localStorage.removeItem('locations');
45+
localStorage.removeItem('lastUpdated');
46+
self.locations = [];
47+
self.settings = {};
48+
self.lastUpdated = 0;
49+
};
50+
51+
self.rowStyle = function (level) {
52+
return {
53+
backgroundColor: toColor(level)
54+
};
55+
}
56+
57+
self.etaText = function (eta) {
58+
return moment().add(eta, 'seconds').toNow(true);
59+
}
60+
});
61+
62+
63+
function toColor(level) {
64+
switch (parseInt(level)) {
65+
case 1:
66+
return "#c50d00"
67+
break;
68+
case 2:
69+
return "#f44336"
70+
break;
71+
case 3:
72+
return "#FFEB3B"
73+
break;
74+
case 4:
75+
return "#4CAF50"
76+
break;
77+
default:
78+
return "gray"
79+
}
80+
};
81+
82+
$(function () {
83+
setTimeout(loadSettings, 1000);
84+
});
85+
86+
var appscope = function () {
87+
return angular.element("body").scope().$$childHead
88+
};
89+
90+
function setLocalTime() {
91+
var scope = appscope();
92+
scope.ctrl.localTime = moment().format("LLLL");
93+
scope.$apply();
94+
setTimeout(setLocalTime, 1000);
95+
}
96+
97+
function loadSettings() {
98+
$.getJSON('settings.json?' + new Date().getTime()).done(function (ret) {
99+
var scope = appscope();
100+
scope.ctrl.setSettings(ret);
101+
scope.$apply();
102+
103+
moment.locale(ret.api_params.language);
104+
setTimeout(setLocalTime, 1000);
105+
updateValues();
106+
}).fail(function (e) {
107+
console.error(e);
108+
});
109+
}
110+
111+
function updateValues() {
112+
var scope = appscope();
113+
var lastUpdated = scope.ctrl.lastUpdated;
114+
var elapsed = (new Date().getTime() - lastUpdated) / 60000;
115+
if (elapsed < 3) {
116+
setTimeout(updateValues, 30000);
117+
return;
118+
} else if (elapsed > 60 && lastUpdated != 0) {
119+
scope.ctrl.clear();
120+
}
121+
122+
$.getJSON('data.json?' + new Date().getTime()).done(function (ret) {
123+
//sorting locations by name
124+
ret.sort(function (a, b) {
125+
return a.name.localeCompare(b.name, scope.ctrl.settings.api_params.language);
126+
});
127+
scope.ctrl.setLocations(ret);
128+
scope.$apply();
129+
}).fail(function (e) {
130+
console.error(e);
131+
}).always(function () {
132+
setTimeout(updateValues, 30000);
133+
});
134+
}
135+
</script>
136+
137+
<style>
138+
body {
139+
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
140+
font-size: 14pt;
141+
background-color: black;
142+
font-weight: bold;
143+
}
144+
145+
.name {
146+
width: 50%;
147+
text-align: left;
148+
display: inline-block;
149+
font-size: 120%;
150+
151+
}
152+
153+
.eta {
154+
width: 25%;
155+
text-align: right;
156+
display: inline-block;
157+
158+
}
159+
160+
.distance {
161+
font-size: 80%;
162+
height: 100%;
163+
width: 20%;
164+
165+
}
166+
167+
.row {
168+
display: inline-block;
169+
height: 60px;
170+
width: 455px;
171+
float: left;
172+
padding: 15px 5px 15px 5px;
173+
margin: 2px;
174+
}
175+
176+
.table {
177+
display: inline-block;
178+
}
179+
180+
.container {
181+
width: 100%;
182+
text-align: center;
183+
}
184+
185+
.title {
186+
width: 100%;
187+
display: table;
188+
color: whitesmoke;
189+
font-size: 200%;
190+
padding: 20px 0 20px 0;
191+
margin: 5px 0 5px 0;
192+
}
193+
</style>
194+
</head>
195+
196+
<body ng-app="traffic">
197+
<div class="container" ng-controller="trafficController as ctrl">
198+
<div class="title">{{ctrl.settings.origin.name}}</div>
199+
<div class="table" ng-repeat="obj in ctrl.locations">
200+
<div class="row" ng-style="ctrl.rowStyle(obj.level)">
201+
<span class="name">{{obj.name}}</span>
202+
<span class="eta">{{ctrl.etaText(obj.eta)}}</span>
203+
<span class="distance">/ {{obj.distance}}</span>
204+
</div>
205+
</div>
206+
<div class="title">{{ctrl.localTime}}</div>
207+
</div>
208+
</body>
209+
210+
</html>

0 commit comments

Comments
 (0)