-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
226 lines (215 loc) · 7.72 KB
/
index.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.11.8/semantic.min.css" />
<link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@800&family=Roboto+Slab:wght@300;900&family=Young+Serif&display=swap" rel="stylesheet">
<style>
#app {
padding-top: 20px;
padding-bottom: 20px;
padding-left: 2%;
padding-right: 2%;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
.stats {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 10px;
margin-top: 30px;
margin-bottom: 25px;
margin-left: 2%;
}
.saturated-background {
filter: saturate(150%);
/* Adjust the percentage value to control the saturation level */
}
</style>
</head>
<body>
<div id="app">
<div class="ui center aligned segment saturated-background"
:style="{ backgroundImage: 'url(' + weather.imageUrl + ')', backgroundSize: 'cover', backgroundPosition: 'center center'}">
<div
style="background-color: rgba(255, 255, 255, 0.7); padding: 5%; border-radius: 10px; box-shadow: 0 0 30px 5px #fff;">
<h2 class="ui center aligned icon header" style="font-family:Arial, Helvetica, sans-serif; font-weight:bold;">
<i class="blue cloud icon"></i>
Weather App
</h2>
<div class="ui icon input" style="margin-top: 10px">
<input type="text" v-model="cityName" placeholder="Enter a city name" v-on:keyup.enter="fetchWeather">
<i class="search icon"></i>
</div>
<button class="ui primary button" @click="fetchWeather" style="margin-left: 8px">Get Weather</button>
</div>
</div>
<div class="ui segment" v-if="isLoading" style="height:200px">
<div class="ui active inverted dimmer">
<div class="ui text loader">Loading</div>
</div>
<p></p>
</div>
<div v-if="weather.days" style="margin-top: 10px">
<div class="ui message">
<div class="content">
<div class="header"><i :class="['flag', weather.countryCode]" style="padding-right:5px"></i>Weather for
{{weather.city}}, {{weather.country}}</div>
<div class="stats">
<div :class="[weather.tempColor, 'ui', 'statistic']">
<div class="value">
{{weather.type}}
</div>
<div class="label">
Weather Type
</div>
</div>
<div class="ui statistic">
<div class="value">
{{weather.averageTemp}}°C
</div>
<div class="label">
Avg. Temperature
</div>
</div>
<div class="ui statistic">
<div class="value">
<i class="blue tint icon"></i>
{{weather.averageRainfall}}
</div>
<div class="label">
Avg. Daily Rainfall
</div>
</div>
<div class="ui statistic">
<div class="value">
<i class="purple mini angle double right icon"></i>
{{weather.averageWindSpeed}}
</div>
<div class="label">
Avg. Wind Speed
</div>
</div>
<div class="ui statistic">
<div class="value">
<i style="margin-bottom: 5px" class="green thumbs up icon" v-if="!weather.airPolutionWarning"></i>
<i style="margin-bottom: 5px" class="red thumbs down icon" v-if="weather.airPolutionWarning"></i>
{{weather.airQuality}}
</div>
<div class="label">
Air Quality (PM2.5)
</div>
</div>
</div>
</div>
<div class="ui negative icon message" v-if="weather.airPolutionWarning">
<i class="bullhorn icon"></i>
<div class="content">
<div class="header">Wear a mask for your health!</div>
<p>Bad Air Quality in {{weather.city}} this week.</p>
</div>
</div>
<div class="ui warning icon message" v-if="weather.umbrellaWarning">
<i class="umbrella icon"></i>
<div class="content">
<div class="header">Make sure to bring an Umbrella!</div>
<p>There will be rain on <b>{{weather.daysWithRain.join(', ')}}</b></p>
</div>
</div>
<div class="wrapper">
<div v-for="(details, day) in weather.days">
<div class="ui center aligned segment flex-segment" style="height: 100%">
<h2 class="header" style="margin-bottom: 2px;">{{day}}</h2>
<div class="ui statistic" style="margin-right: 5%">
<div class="value">
{{weather.summary[day].temp}}°C
</div>
<div class="label">
Temperature
</div>
</div>
<div class="ui statistic">
<div class="value">
{{weather.summary[day].rain}}
</div>
<div class="label">
Rainfall
</div>
</div>
<div :class="['ui', getClassForRating(weather.summary[day].outdoorRating), 'progress']"
style="margin-bottom: 0px; margin-top: 2px">
<div class="bar" :style="{ width: weather.summary[day].outdoorRating*10 + '%'}">
<div class="progress" style="font-size: 15px;">Outdoors: {{weather.summary[day].outdoorRating}}/10</div>
</div>
<div style="margin-top: 6px; margin-bottom: 1px; font-size: 12px;">Based on Humidity, Temperature and Rainfall</div>
</div>
<table class="ui celled table">
<thead>
<tr>
<th>Time</th>
<th>Description</th>
<th>Temp</th>
<th>Rainfall</th>
</tr>
</thead>
<tbody>
<tr v-for="(info, index) in details">
<td>{{info.time}}</td>
<td>{{info.description}}</td>
<td>{{info.temp}}°C</td>
<td>{{info.precipitation}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
const { createApp, ref } = Vue
createApp({
data() {
return {
locationList: null,
cityName: '',
weather: {
imageUrl: null,
},
isLoading: false
};
},
methods: {
getClassForRating(rating) {
if (rating >= 7) {
return 'green';
} else if (rating >= 4) {
return 'yellow';
} else {
return 'red';
}
},
fetchWeather() {
this.isLoading = true;
const url = `http://localhost:3000/weather/${this.cityName}`;
const xhttpr = new XMLHttpRequest();
xhttpr.open('GET', url, true);
xhttpr.send();
xhttpr.onload = () => {
if (xhttpr.status === 200) {
const response = xhttpr.response;
this.weather = JSON.parse(response);
this.isLoading = false;
} else {
console.log('Error getting data from server');
}
};
},
},
}).mount('#app');
</script>
</body>
</html>