currentData.js 11.5 KB
Newer Older
Weiser's avatar
Weiser committed
1
2
import React from "react";

Weiser's avatar
fusion    
Weiser committed
3
import "./currentData.css";
Weiser's avatar
Weiser committed
4

Weiser's avatar
fusion    
Weiser committed
5
const Currentdata = (props) => {
EnesKarakas's avatar
dw    
EnesKarakas committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  return (
    <div className="home-container">
      <div>
        <div className="thq-grid-5">
          <div class="filter">
            <label for="location">Location:</label>
            <input type="text" id="location" placeholder="Location" />
            <br />
            <label for="region">Region:</label>
            <input type="text" id="region" placeholder="Region" />
            <br />
            <label>Country:</label>
            <input type="text" id="country" placeholder="Country" />
            <br />
            <label>Latitude:</label>
            <input type="text" id="latitude" placeholder="Latitude" />
            <label>Longitude:</label>
            <input type="text" id="longitude" placeholder="Longitude" />
            <br />
          </div>
Weiser's avatar
Weiser committed
26
          <div>
EnesKarakas's avatar
dw    
EnesKarakas committed
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
            <input type="checkbox" id="name" className="checkBoxFilter" />
            <label> City Name</label>
            <br />
            <input type="checkbox" id="region" className="checkBoxFilter" />
            <label> Region</label>
            <br />
            <input type="checkbox" id="country" className="checkBoxFilter" />
            <label> Country</label>
            <br />
            <input type="checkbox" id="lon" className="checkBoxFilter" />
            <label> Longitude</label>
            <br />
            <input type="checkbox" id="lat" className="checkBoxFilter" />
            <label> Latitude</label>
            <br />
            <input type="checkbox" id="tz_id" className="checkBoxFilter" />
            <label> Timezone Id</label>
            <br />
            <input
              type="checkbox"
              id="localtime_epoch"
              className="checkBoxFilter"
            />
            <label> Localtime Epoch</label>
            <br />
            <input type="checkbox" id="localtime" className="checkBoxFilter" />
            <label> Localtime</label>
            <br />
            <input
              type="checkbox"
              id="last_updated_epoch"
              className="checkBoxFilter"
            />
            <label> Last Updated Epoch</label>
            <br />
            <input
              type="checkbox"
              id="last_updated"
              className="checkBoxFilter"
            />
            <label> Last Updated</label>
            <br />
            <input type="checkbox" id="temp_c" className="checkBoxFilter" />
            <label for="temp_c">Temp C</label>
            <br />
            <input type="checkbox" id="temp_f" className="checkBoxFilter" />
            <label for="temp_f">Temp F</label>
            <br />
            <input type="checkbox" id="id_day" className="checkBoxFilter" />
            <label for="id_day">ID Day</label>
            <br />
            <input
              type="checkbox"
              id="condition_text"
              className="checkBoxFilter"
            />
            <label for="condition_text">Condition Text</label>
            <br />
            <input
              type="checkbox"
              id="condition_icon"
              className="checkBoxFilter"
            />
            <label for="condition_icon">Condition Icon</label>
            <br />
            <input
              type="checkbox"
              id="condition_code"
              className="checkBoxFilter"
            />
            <label for="condition_code">Condition Code</label>
            <input type="checkbox" id="wind" className="checkBoxFilter" />
            <label for="wind">Wind </label>
            <br />
            <input
              type="checkbox"
              id="wind_degree"
              className="checkBoxFilter"
            />
            <label for="wind_degree">Wind Degree</label>
            <br />
            <input type="checkbox" id="wind_dir" className="checkBoxFilter" />
            <label for="wind_dir">Wind Direction</label>
            <br />
            <input type="checkbox" id="pressure" className="checkBoxFilter" />
            <label for="pressure">Pressure</label>
            <br />
            <input type="checkbox" id="precip" className="checkBoxFilter" />
            <label for="precip">Precip</label>
            <br />
            <input type="checkbox" id="humidity" className="checkBoxFilter" />
            <label for="humidity">Humidity</label>
            <br />
            <input type="checkbox" id="cloud" className="checkBoxFilter" />
            <label for="cloud">Cloud</label>
            <br />
            <input type="checkbox" id="feelslike" className="checkBoxFilter" />
            <label for="feelslike">Feelslike</label>
            <br />
            <input type="checkbox" id="windchill" className="checkBoxFilter" />
            <label for="windchill">Windchill</label>
            <br />
            <input type="checkbox" id="heatindex" className="checkBoxFilter" />
            <label for="heatindex">Heatindex</label>
            <br />
            <input type="checkbox" id="dewpoint" className="checkBoxFilter" />
            <label for="dewpoint">Dewpoint</label>
            <br />
            <input type="checkbox" id="vis" className="checkBoxFilter" />
            <label for="vis">Visibility </label>
            <br />
            <input type="checkbox" id="uv" className="checkBoxFilter" />
            <label for="uv">UV Index</label>
            <br />
            <input type="checkbox" id="gust" className="checkBoxFilter" />
            <label for="gust">Gust </label>
            <br />
            <input
              type="checkbox"
              id="air_quality_co"
              className="checkBoxFilter"
            />
            <label for="air_quality_co">Air Quality CO</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_no2"
              className="checkBoxFilter"
            />
            <label for="air_quality_no2">Air Quality NO2</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_o3"
              className="checkBoxFilter"
            />
            <label for="air_quality_o3">Air Quality O3</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_so2"
              className="checkBoxFilter"
            />
            <label for="air_quality_so2">Air Quality SO2</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_pm2_5"
              className="checkBoxFilter"
            />
            <label for="air_quality_pm2_5">Air Quality PM2.5</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_pm10"
              className="checkBoxFilter"
            />
            <label for="air_quality_pm10">Air Quality PM10</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_us_epa_index"
              className="checkBoxFilter"
            />
            <label for="air_quality_us_epa_index">US EPA Index</label>
            <br />
            <input
              type="checkbox"
              id="air_quality_gb_defra_index"
              className="checkBoxFilter"
            />
            <label for="air_quality_gb_defra_index">GB DEFRA Index</label>
            <br />
            <br />
            <br />
            <br />
Weiser's avatar
Weiser committed
203
204
          </div>
        </div>
EnesKarakas's avatar
dw    
EnesKarakas committed
205
206
207
      </div>
    </div>
  );
Weiser's avatar
Weiser committed
208
209

  function getData() {
EnesKarakas's avatar
dw    
EnesKarakas committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
    const city_text = document.getElementById("city_text").value;
    const region_text = document.getElementById("region_text").value;
    const country_text = document.getElementById("country_text").value;
    const latitude_text = document.getElementById("latitude_text").value;
    const longitude_text = document.getElementById("longitude_text").value;

    //Checkboxes
    //location
    const name = document.getElementById("name").checked;
    const region = document.getElementById("region").checked;
    const country = document.getElementById("country").checked;
    const lon = document.getElementById("lon").checked;
    const lat = document.getElementById("lat").checked;
    const tz_id = document.getElementById("tz_id").checked;
    const localtime_epoch = document.getElementById("localtime_epoch").checked;
    const localtime = document.getElementById("localtime").checked;
    //current
Weiser's avatar
Weiser committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
    const temperature = document.getElementById("temperature").checked;
    const isDay = document.getElementById("isDay").checked;
    const condition = document.getElementById("condition").checked;
    const pressure = document.getElementById("pressure").checked;
    const precipitation = document.getElementById("precipitation").checked;
    const humidity = document.getElementById("humidity").checked;
    const cloud = document.getElementById("cloud").checked;
    const feelslikeTemp = document.getElementById("feelslikeTemp").checked;
    const visibility = document.getElementById("visibility").checked;
    const uv = document.getElementById("uv").checked;
    const gust = document.getElementById("gust").checked;
    const airquality = boolToWord(
      document.getElementById("airquality").checked
    );
    const unitTemperature = document.getElementById("unitTemperature").value;
    const unitWindSpeed = document.getElementById("unitWindSpeed").value;
    const unitPressure = document.getElementById("unitPressure").value;
    const unitPrecipitation =
      document.getElementById("unitPrecipitation").value;
    const output = document.getElementById("output").value;
    const format = document.getElementById("format").value;

EnesKarakas's avatar
dw    
EnesKarakas committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    let filterArray = [];

    if (name) {
      filterArray.push("name");
    }
    if (region) {
      filterArray.push("region");
    }
    if (country) {
      filterArray.push("country");
    }
    if (lon) {
      filterArray.push("lon");
    }
    if (lat) {
      filterArray.push("lat");
    }
    if (tz_id) {
      filterArray.push("tz_id");
    }
    if (localtime_epoch) {
      filterArray.push("localtime_epoch");
    }
    if (localtime) {
      filterArray.push("localtime");
    }
    let filterString = filterArray.join(",");

    console.log(filterString);

    const apiUrl = `localhost:8080/currentwaether?q=${city_text}&filter=${filterString}`;
Weiser's avatar
Weiser committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }
        return response.json();
      })
      .then((data) => {
        // Wetterdaten anzeigen
        document.getElementById("weatherData").innerText = JSON.stringify(
          data,
          null,
          2
        );
        document.getElementById("apiUrloutput").value = apiUrl;
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }
  function searchAPI() {
    const cityInput = document.getElementById("city").value;

    const apiKey = "1244099aeaee4b179e6111803241304";
    const apiUrl = `https://api.weatherapi.com/v1/search.json?key=${apiKey}&q=${cityInput}`;

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }

        return response.json();
      })
      .then((data) => {
        // Wetterdaten anzeigen
        document.getElementById("weatherData").innerText = JSON.stringify(
          data,
          null,
          2
        );
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }

  function boolToWord(bool) {
    return bool ? "yes" : "no";
  }
};

EnesKarakas's avatar
dw    
EnesKarakas committed
333
export default Currentdata;