-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from octodemo/search_improvements
chore: Add styles for table and search functionality
- Loading branch information
Showing
4 changed files
with
112 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
document.getElementById('searchForm').addEventListener('submit', function(e) { | ||
e.preventDefault(); | ||
|
||
var input = document.getElementById('search').value; | ||
var resultsDiv = document.getElementById('searchResults'); | ||
resultsDiv.innerHTML = 'Loading...'; | ||
|
||
fetch('/search?q=' + encodeURIComponent(input)) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
resultsDiv.innerHTML = ''; | ||
for (var i = 0; i < data.length; i++) { | ||
var item = data[i]; | ||
var highlightedItem = item.replace(new RegExp(input, 'gi'), function(match) { | ||
return '<strong>' + match + '</strong>'; | ||
}); | ||
resultsDiv.innerHTML += '<p>' + highlightedItem + '</p>'; | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
resultsDiv.innerHTML = 'An error occurred while performing the search.'; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
document.getElementById('csvFile').addEventListener('change', function() { | ||
if (this.value) { | ||
document.getElementById('uploadForm').style.display = 'block'; | ||
} else { | ||
document.getElementById('uploadForm').style.display = 'none'; | ||
} | ||
}); | ||
|
||
document.getElementById('uploadForm').addEventListener('submit', function(e) { | ||
e.preventDefault(); | ||
|
||
var formData = new FormData(); | ||
formData.append('file', document.getElementById('csvFile').files[0]); | ||
|
||
fetch('/import', { | ||
method: 'POST', | ||
body: formData | ||
}).then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.text(); | ||
}).then(data => { | ||
console.log('File uploaded successfully: ' + data); | ||
// clear the file input and hide the form | ||
document.getElementById('csvFile').value = ''; | ||
document.getElementById('uploadForm').style.display = 'none'; | ||
|
||
// Wait for 1 second before reloading the page | ||
setTimeout(function() { | ||
location.reload(); | ||
}, 1000); | ||
}).catch(error => { | ||
console.error('There has been a problem with your fetch operation: ', error); | ||
document.getElementById('errorMessage').textContent = 'Error: ' + error.message; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters