-
Notifications
You must be signed in to change notification settings - Fork 0
/
lots.html
138 lines (127 loc) · 6.02 KB
/
lots.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MaristParks - Parking Lots</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<nav>
<ul class="menu-bar">
<li><a href="./parking.html">Home</a></li>
<li><a href="./lots.html">Lots</a></li>
<li><a href="./map.html">Map</a></li>
<li><a href="./about.html">About</a></li>
</ul>
</nav>
</header>
<main>
<nav class="breadcrumbs">
<a href="index.html">Home</a> > <a href="lots.html">Parking Lots</a>
</nav>
<section class="content-container">
<div class="parking-lots">
<h2>Available Parking Lots</h2>
<input type="text" id="search-bar" placeholder="Search parking lots...">
<div id="parking-details"></div>
</div>
</section>
</main>
<script>
document.addEventListener("DOMContentLoaded", () => {
let parkingData = [];
const parkingDetails = document.getElementById('parking-details');
const searchBar = document.getElementById('search-bar');
fetch('./parking.json')
.then(response => response.json())
.then(data => {
parkingData = data.parkingLots;
displayParkingLots(parkingData);
const urlParams = new URLSearchParams(window.location.search);
const lotName = urlParams.get('name');
if (lotName) {
const matchingLot = parkingData.find(lot => lot.name === lotName);
if (matchingLot) {
scrollToAndExpandLot(matchingLot);
}
}
})
.catch(error => console.error('Error fetching parking lot details:', error));
searchBar.addEventListener('input', () => {
const searchQuery = searchBar.value.toLowerCase();
const filteredLots = parkingData.filter(lot =>
lot.name.toLowerCase().includes(searchQuery) ||
lot.comments.toLowerCase().includes(searchQuery) ||
lot.securityLevel.toLowerCase().includes(searchQuery)
);
displayParkingLots(filteredLots);
});
function displayParkingLots(lots) {
parkingDetails.innerHTML = '';
lots.forEach(lot => {
const lotContainer = document.createElement('div');
lotContainer.classList.add('lot-container');
const lotHeader = document.createElement('button');
lotHeader.textContent = lot.name;
lotHeader.classList.add('toggle-button');
lotHeader.addEventListener('click', () => {
const expanded = document.querySelector('.lot-container.expanded');
if (expanded && expanded !== lotContainer) {
expanded.classList.remove('expanded');
expanded.querySelector('.lot-details').style.display = 'none';
}
lotContainer.classList.toggle('expanded');
lotDetails.style.display = lotDetails.style.display === 'none' ? 'block' : 'none';
});
lotContainer.appendChild(lotHeader);
const lotDetails = document.createElement('div');
lotDetails.classList.add('lot-details');
lotDetails.innerHTML = `
<p>
<strong>Comments:</strong> ${lot.comments}<br>
<strong>Operational Hours:</strong> ${lot.operationalHours}<br>
<strong>Security Level:</strong> ${lot.securityLevel}<br>
<strong>Total Spaces:</strong> ${lot.totalSpaces}<br>
<strong>Empty Spots:</strong> ${lot.emptySpots}
</p>
`;
if (lot.parkingSpaces) {
const spaceList = document.createElement('ul');
spaceList.innerHTML = '<strong>Parking Spaces:</strong>';
lot.parkingSpaces.forEach(space => {
const spaceItem = document.createElement('li');
spaceItem.innerHTML = `
Space ID: ${space.spaceID} |
Type: ${space.type} |
Status: ${space.status} |
Reserved: ${space.reservedDateTime || 'N/A'} |
Filled: ${space.filledDateTime || 'N/A'}
`;
spaceList.appendChild(spaceItem);
});
lotDetails.appendChild(spaceList);
}
lotDetails.style.display = 'none';
lotContainer.appendChild(lotDetails);
parkingDetails.appendChild(lotContainer);
});
}
function scrollToAndExpandLot(lot) {
const lotContainer = [...document.querySelectorAll('.lot-container')]
.find(container => container.querySelector('.toggle-button').textContent === lot.name);
if (lotContainer) {
lotContainer.classList.add('expanded');
const lotDetails = lotContainer.querySelector('.lot-details');
lotDetails.style.display = 'block';
lotContainer.scrollIntoView({ behavior: 'smooth' });
}
}
});
</script>
<footer>
<p>© 2024 Ralph Wakim</p>
</footer>
</body>
</html>