List sessions

This commit is contained in:
Guillem Borrell 2024-06-12 22:22:26 +02:00
parent 833a446899
commit 62c54dc3e6
3 changed files with 34 additions and 17 deletions

View file

@ -63,9 +63,8 @@
<label for="datasetLabel" class="form-label">Sesson name</label>
<input type="text" class="form-control" id="datasetLabel"
aria-describedby="labelHelp">
<div id="labelHelp" class="form-text">You'll be able to recover this file in the
future
with this name
<div id="labelHelp" class="form-text">
You'll be able to recover this file in the future with this name
</div>
</div>
<div class="modal-body">
@ -88,7 +87,7 @@
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop"
id="loadSessionsButton">
Browse sessions
Load a session
</button>
<!-- Modal -->
@ -97,15 +96,17 @@
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Current sessions</h5>
<h5 class="modal-title" id="staticBackdropLabel">Available sessions</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body" id="userSessions">
<p>Current sessions...</p>
<ul id="userSessions">
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"
id="sessionCloseButton">Close</button>
</div>
</div>
</div>

View file

@ -26,7 +26,6 @@ document.addEventListener("DOMContentLoaded", function () {
const textarea = document.getElementById('chatTextarea');
const sendButton = document.getElementById('sendButton');
const sessions = document.getElementById('userSessions');
const chatMessages = document.querySelector('.chat-messages');
// Auto resize textarea
@ -167,14 +166,24 @@ document.addEventListener("DOMContentLoaded", function () {
// Function to get the user sessions
document.addEventListener("DOMContentLoaded", function () {
const sessionsButton = document.getElementById('loadSessionsButton');
const sessions = document.getElementById('userSessions');
sessionsButton.addEventListener('click', async function fetchSessions() {
try {
const response = await fetch('/sessions');
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const data = await response.text();
sessions.innerHTML = data;
const data = JSON.parse(await response.text());
sessions.innerHTML = '';
data.forEach(item => {
const listItem = document.createElement('li');
const button = document.createElement('button');
button.textContent = item;
button.addEventListener("click", function () { alert(`You clicked on ${item}`); });
listItem.appendChild(button);
sessions.appendChild(listItem);
});
} catch (error) {
sessions.innerHTML = 'Error: ' + error.message;
}

View file

@ -91,16 +91,23 @@ class OwnershipDB(DDB):
return sid
def sessions(self, user_email: str) -> List[str]:
return (
self.db.sql(f"""
try:
return (
self.db.sql(f"""
SELECT
sid
FROM
'{self.path_prefix}/*.csv'
WHERE
email = '{user_email}'
email = '{user_email}
ORDER BY
timestamp ASC
LIMIT 10'
""")
.pl()
.to_series()
.to_list()
)
.pl()
.to_series()
.to_list()
)
# If the table does not exist
except duckdb.duckdb.IOException:
return []