Skip to content

Commit 57d7744

Browse files
author
xss
committed
Add flight doc updater
1 parent 5ba9b4d commit 57d7744

File tree

6 files changed

+104
-64
lines changed

6 files changed

+104
-64
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations -
2626
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge app.js >> mobile.js
2727
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge colour-map.js >> mobile.js
2828
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge format.js >> mobile.js
29-
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge auth.js >> mobile.js
29+
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge flight_doc.js >> mobile.js
3030

3131
#compile plot lib and config
3232
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge _jquery.flot.js >> init_plot.js

css/habitat-font.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
.icon-daylight:before { content: "\f008"; }
7878
.icon-settings:before { content: "\f010"; }
7979
.icon-user:before {
80-
content: "🔒";
80+
content: "🎈";
8181
color: transparent;
8282
text-shadow: 0 0 0 white;
8383
line-height: 1;

css/main.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,13 @@ header .search form input[type='submit'] {
969969
}
970970
}
971971

972+
/* login button */
973+
#login_url {
974+
display: block;
975+
background-color: #33b5e5;
976+
color: white;
977+
text-decoration: none;
978+
font-weight: bold;
979+
text-align: center;
980+
padding: 10px;
981+
}

index.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,24 @@ <h2><i class="icon-car rfloat"></i>Chase Mode</h2>
268268
</div>
269269
<div id="userbox" style="display: none" class="flatpage">
270270
<div class="slimContainer">
271-
<h2><i class="icon-user rfloat"></i>User</h2>
271+
<h2><i class="icon-user rfloat"></i>Prediction Settings</h2>
272+
Only use this tab if your the operator of a balloon launch.
272273
<hr>
273-
<p id="login-prompt">
274-
<a href="" id="login_url">Click here to login.</a>
275-
</p>
276-
<p>
277-
<a onclick="do_a_thing()">Click here to do a thing</a>
278-
</p>
274+
<div id="update-flightdocs" style="display: none">
275+
<form action="javascript:;">
276+
Callsign (case sensitive):<br /> <input id="flight_doc_payload_callsign" type="text"><br />
277+
Peak altitude:<br /> <input id="flight_doc_peak_altitude" type="text"><br />
278+
Descent rate:<br /> <input id="flight_doc_descent_rate" type="text"><br />
279+
Ascent rate:<br /> <input id="flight_doc_ascent_rate" type="text"><br />
280+
Float expected:<br /> <input id="flight_doc_float_expected" type="checkbox"><br />
281+
<input type="submit" onclick="update_flight_doc()">
282+
</form>
283+
</div>
279284
<p id="payload-update-results">
280285
</p>
286+
<p id="login-prompt">
287+
<a href="" id="login_url">Login</a>
288+
</p>
281289

282290

283291
</div>

js/auth.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

js/flight_doc.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
// populate login url
3+
document.getElementById("login_url").href= "https://auth.v2.sondehub.org/oauth2/authorize?client_id=21dpr4kth8lonk2rq803loh5oa&response_type=token&scope=email+openid+phone&redirect_uri=" + window.location.protocol + "//" + window.location.host
4+
5+
// manage AWS cognito auth
6+
if (window.location.hash.indexOf("id_token") != -1){
7+
console.log("Detected login")
8+
var args = window.location.hash.slice(1)
9+
var parms = new URLSearchParams(args)
10+
var id_token = parms.get("id_token")
11+
sessionStorage.setItem("id_token", id_token)
12+
}
13+
14+
// do AWS login
15+
AWS.config.region = 'us-east-1';
16+
17+
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
18+
IdentityPoolId: 'us-east-1:55e43eac-9626-43e1-a7d2-bbc57f5f5aa9',
19+
Logins: {
20+
"cognito-idp.us-east-1.amazonaws.com/us-east-1_G4H7NMniM": sessionStorage.getItem("id_token")
21+
}
22+
});
23+
24+
AWS.config.credentials.get(function(){
25+
// if this passes we update the login page to say logged in
26+
if (AWS.config.credentials.accessKeyId != undefined){
27+
document.getElementById("login_url").innerText = "Logout"
28+
document.getElementById("login_url").href="javascript:logout()"
29+
document.getElementById("update-flightdocs").style.display = "block"
30+
}
31+
});
32+
33+
function logout(){
34+
logout_url = "https://auth.v2.sondehub.org/logout?client_id=21dpr4kth8lonk2rq803loh5oa&response_type=token&logout_uri=" + window.location.protocol + "//" + window.location.host
35+
sessionStorage.removeItem("id_token")
36+
window.location = logout_url
37+
}
38+
39+
function update_flight_doc(){
40+
41+
var body = JSON.stringify(
42+
{
43+
"payload_callsign": document.getElementById("flight_doc_payload_callsign").value,
44+
"float_expected": document.getElementById("flight_doc_float_expected").value == "on",
45+
"peak_altitude": parseFloat(document.getElementById("flight_doc_peak_altitude").value),
46+
"descent_rate": parseFloat(document.getElementById("flight_doc_descent_rate").value),
47+
"ascent_rate": parseFloat(document.getElementById("flight_doc_ascent_rate").value),
48+
}
49+
)
50+
51+
52+
var httpRequest = new AWS.HttpRequest("https://api-raw.v2.sondehub.org/amateur/flightdoc" , "us-east-1");
53+
var v4signer = new AWS.Signers.V4(httpRequest, "execute-api", true);
54+
httpRequest.method = "PUT";
55+
httpRequest.headers['Host'] = 'api-raw.v2.sondehub.org';
56+
httpRequest.headers['Content-Type'] = 'application/json';
57+
httpRequest.headers['Content-Length'] = body.length;
58+
httpRequest.headers['X-Amz-Content-Sha256'] = v4signer.hexEncodedHash(body)
59+
httpRequest.body = body
60+
61+
62+
63+
v4signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate());
64+
document.getElementById("payload-update-results").textContent = "Updating..."
65+
fetch(httpRequest.endpoint.href , {
66+
method: httpRequest.method,
67+
headers: httpRequest.headers,
68+
body: httpRequest.body,
69+
}).then(function (response) {
70+
if (!response.ok) {
71+
response.text().then(function(x) {document.getElementById("payload-update-results").textContent =x })
72+
return;
73+
}
74+
response.text().then(function(x) {document.getElementById("payload-update-results").textContent =x })
75+
});
76+
77+
}

0 commit comments

Comments
 (0)