Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (63 loc) · 2.99 KB
/
Copy pathscript.js
File metadata and controls
73 lines (63 loc) · 2.99 KB
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
document.addEventListener("DOMContentLoaded", function() {
const itemsList = document.getElementById("items-list");
const clearSearchBtn = document.getElementById("clear-search");
// Fetch items and display on page load
fetchItems();
function fetchItems() {
fetch("https://9ookpuq4tk.execute-api.us-east-1.amazonaws.com/prod/items")
.then(response => response.json())
.then(data => displayItems(data))
.catch(error => console.error("Error fetching items:", error));
}
function displayItems(items) {
itemsList.innerHTML = ""; // Clear previous items
items.forEach(item => {
const li = document.createElement("li");
li.innerHTML = `
<strong>ID:</strong> ${item.mainID}<br>
<strong>Name:</strong> ${item.mainDescription}<br>
<strong>Description:</strong> ${item.scope}<br>
<strong>Domain:</strong> ${item.domain}
`;
itemsList.appendChild(li);
});
}
// Add event listener for clear search button
clearSearchBtn.addEventListener("click", clearSearch);
// Function to clear search and display all items
function clearSearch() {
// Clear input fields
document.getElementById("id-search").value = "";
document.getElementById("name-search").value = "";
document.getElementById("description-search").value = "";
document.getElementById("domain-search").value = "";
// Fetch all items again
fetchItems();
}
// Add event listeners for search inputs
const searchInputs = document.querySelectorAll("#search-form input");
searchInputs.forEach(input => {
input.addEventListener("input", function() {
performSearch();
});
});
// Function to perform search based on input fields
function performSearch() {
const idSearchTerm = document.getElementById("id-search").value.toLowerCase();
const nameSearchTerm = document.getElementById("name-search").value.toLowerCase();
const descriptionSearchTerm = document.getElementById("description-search").value.toLowerCase();
const domainSearchTerm = document.getElementById("domain-search").value.toLowerCase();
fetch("https://9ookpuq4tk.execute-api.us-east-1.amazonaws.com/prod/items")
.then(response => response.json())
.then(data => {
const filteredItems = data.filter(item =>
new RegExp(idSearchTerm, 'i').test(item.mainID.toLowerCase()) &&
new RegExp(nameSearchTerm, 'i').test(item.mainDescription.toLowerCase()) &&
new RegExp(descriptionSearchTerm, 'i').test(item.scope.toLowerCase()) &&
new RegExp(domainSearchTerm, 'i').test(item.domain.toLowerCase())
);
displayItems(filteredItems);
})
.catch(error => console.error("Error fetching items:", error));
}
});