-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (130 loc) · 6.41 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Assignment</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">
</head>
<body>
<section id="title">
<div class="container-fluid pt-5">
<div class="row d-flex justify-content-center ">
<div class="col-md-12 d-flex align-items-stretch ">
<!-- <div class="card d-flex align-items-stretch"> -->
<div class="container-fluid">
<div class="row height d-flex justify-content-center align-items-center">
<div class="col-lg-10">
<h1 style="font-size: larger; font-weight: bolder; padding-bottom: 20px;">Search
Parks by City Name:</h1>
<div id="detail"></div>
<div class="search"> <i class="fa fa-search"></i> <input type="text"
class="form-control" placeholder="Search here.." id="search"> <button
class="btn btn-primary" type="submit" id="getData">Search</button></div>
<div>
<br>
<div class="field">
<p class="help">
Try searching for <a class="query" href="#vital" onclick="$('#search').val('St. Vital')">St. Vital</a>
, or <a class="query" href="#garry" onclick="$('#search').val('Fort Garry')">Fort Garry</a>
, or <a class="query" href="#transcona" onclick="$('#search').val('Transcona')"> Transcona</a>
.
</p>
</div>
<br>
<h2 class="explanation subtitle" id="report"></h2>
<table class="table is-fullwidth is-hoverable parks">
<thead>
<tr>
<th>Park Name</th>
<th>Park Type</th>
<th>Location</th>
<th>District</th>
<th>City</th>
<th>Total Area in Hectares</th>
</tr>
</thead>
<tbody id="tableData"></tbody>
</table>
</div>
<!-- <div>
<a>Load More</a>
</div> -->
</div>
</div>
</div>
<!-- </div> -->
</div>
</div>
</section>
</body>
</html>
<script>
function addParkAsTableRow(table, park) {
const row = document.createElement('tr');
const parkNameTd = document.createElement('td');
const parkTypeTd = document.createElement('td');
const locationTd = document.createElement('td');
const districtTd = document.createElement('td');
const cityTd = document.createElement('td');
const areaTd = document.createElement('td');
parkNameTd.innerHTML = park.park_name;
parkTypeTd.innerHTML = park.park_category;
locationTd.innerHTML = park.location_description;
districtTd.innerHTML = park.district;
cityTd.innerHTML = park.cca;
areaTd.innerHTML = park.land_area_in_hectares;
row.appendChild(parkNameTd);
row.appendChild(parkTypeTd);
row.appendChild(locationTd);
row.appendChild(districtTd);
row.appendChild(cityTd);
row.appendChild(areaTd);
table.appendChild(row);
}
function addParksToTable(parkData) {
const parkTable = document.querySelector('tbody');;
parkTable.innerHTML = '';
for (let park of parkData) {
addParkAsTableRow(parkTable, park);
}
}
function requestJSON(url, callback) {
$.ajax({
url: url,
complete: function (xhr) {
callback.call(null, xhr.responseJSON);
}
});
}
$(function () {
$('#getData').on('click', function (e) {
e.preventDefault();
var searchItem = $('#search').val();
console.log("SI: ", searchItem);
if (searchItem != '') {
$('#detail').html('');
$('#tableData').html('<div class="spinner-border" role="status" style="alignSelf:center; justify:center;"><span class="sr-only"></span></div>');
var requri = `https://data.winnipeg.ca/resource/tx3d-pfxq.json?$where=lower(cca) LIKE lower('%25${searchItem}%25')&$order=land_area_in_hectares DESC &$limit=${20}`;
console.log("URL", requri);
requestJSON(requri, function (json) {
console.log(json);
if(json.length === 0){
console.log("yes");
$('#report').html('<div class="alert" role="alert">No Park found with this City Name</div>');
}
else{
addParksToTable(json);
$('#report').html('');
}
})
}
else {
$('#detail').html('<div class="alert alert-danger" role="alert">Enter City Name to search</div>');
}
})
})
</script>