Skip to content

Commit 8731fdc

Browse files
committed
add files for dashboard project
1 parent 227ebb7 commit 8731fdc

File tree

4 files changed

+106
-17
lines changed

4 files changed

+106
-17
lines changed

dashboard/app.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function loadDate() {
2+
var currentDate = new Date();
3+
var dateString = currentDate.toString()
4+
.split(" ")
5+
.splice(0, 4)
6+
.join(" ");
7+
8+
$("#date").text(dateString);
9+
}
10+
11+
function loadWeather() {
12+
var weather = $("#weather");
13+
var url = "https://api.forecast.io/forecast/";
14+
var apiKey = "8c3b1be59891dcd2d60a0a88e1b0c0fb";
15+
16+
function success(position) {
17+
var latitude = position.coords.latitude;
18+
var longitude = position.coords.longitude;
19+
20+
$.getJSON(url + apiKey + "/" + latitude + "," + longitude + "?callback=?", function(data) {
21+
weather.text("Based on your current location, it is " + data.currently.temperature + "° F right now");
22+
});
23+
}
24+
25+
function error() {
26+
alert("Unable to retrieve your location for weather");
27+
}
28+
29+
navigator.geolocation.getCurrentPosition(success, error);
30+
31+
weather.text("fetching weather...");
32+
}
33+
34+
function loadNews() {
35+
var news = $("#news");
36+
var url = "https://newsapi.org/v1/articles?source=google-news&sortBy=top&apiKey=";
37+
var apiKey = "c3384798975942aa9b84fac44cbe2c9c";
38+
39+
$.getJSON(url + apiKey, function(data) {
40+
var titles = data.articles.map(function(articles) {
41+
return "<a href='" + articles.url + "'>" + articles.title + "</a>";
42+
});
43+
44+
news.html(titles.join("<br><br>"));
45+
});
46+
47+
news.text("fetching news...");
48+
}
49+
50+
loadDate();
51+
loadWeather();
52+
loadNews();

dashboard/index.html

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<link rel="stylesheet" href="styles.css"/>
5-
</head>
6-
<body>
7-
<img src="https://github.com/hackclub/dinosaurs/raw/master/smart_dinosaur_docs.png"/>
8-
<h1>Prophet Orpheus</h1>
9-
<p>Coder Dino</p>
10-
<p>Will code for food</p>
11-
</body>
3+
<head>
4+
<title>My Dashboard</title>
5+
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta charset="utf-8">
8+
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
10+
<link rel="stylesheet" href="style.css">
11+
</head>
12+
13+
<body>
14+
15+
<h1>Hello! Today is <span id="date"></span></h1>
16+
<hr>
17+
18+
<h2><span id="weather"></span></h2>
19+
<hr>
20+
21+
<h2>Latest news:</h2>
22+
<div id="news">
23+
</div>
24+
<p>Powered by <a href="https://newsapi.org/">NewsAPI</a> and <a href="https://darksky.net/poweredby/">Dark Sky</a></p>
25+
26+
<script
27+
src="https://code.jquery.com/jquery-3.1.1.min.js"
28+
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
29+
crossorigin="anonymous"></script>
30+
<script type="text/javascript" src="app.js"></script>
31+
</body>
1232
</html>

dashboard/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
html {
2+
max-width: 50em;
3+
margin: 0 auto;
4+
padding: 10px;
5+
font-family: Avenir Next, Helvetica, sans-serif;
6+
}
7+
8+
h1, h2, #news {
9+
font-weight: 300;
10+
}
11+
12+
#news {
13+
font-size: 1.5em;
14+
line-height: 1.5em;
15+
}
16+
17+
a {
18+
text-decoration: none;
19+
color: #000;
20+
border-bottom: 2px solid #e42d40;
21+
}
22+
23+
a:hover {
24+
font-style: italic;
25+
}

dashboard/styles.css

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

0 commit comments

Comments
 (0)