List sessions
This commit is contained in:
parent
833a446899
commit
62c54dc3e6
|
@ -63,9 +63,8 @@
|
||||||
<label for="datasetLabel" class="form-label">Sesson name</label>
|
<label for="datasetLabel" class="form-label">Sesson name</label>
|
||||||
<input type="text" class="form-control" id="datasetLabel"
|
<input type="text" class="form-control" id="datasetLabel"
|
||||||
aria-describedby="labelHelp">
|
aria-describedby="labelHelp">
|
||||||
<div id="labelHelp" class="form-text">You'll be able to recover this file in the
|
<div id="labelHelp" class="form-text">
|
||||||
future
|
You'll be able to recover this file in the future with this name
|
||||||
with this name
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
@ -88,7 +87,7 @@
|
||||||
<!-- Button trigger modal -->
|
<!-- Button trigger modal -->
|
||||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop"
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop"
|
||||||
id="loadSessionsButton">
|
id="loadSessionsButton">
|
||||||
Browse sessions
|
Load a session
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
|
@ -97,15 +96,17 @@
|
||||||
<div class="modal-dialog modal-dialog-scrollable">
|
<div class="modal-dialog modal-dialog-scrollable">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<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"
|
<button type="button" class="btn-close" data-bs-dismiss="modal"
|
||||||
aria-label="Close"></button>
|
aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" id="userSessions">
|
<div class="modal-body" id="userSessions">
|
||||||
<p>Current sessions...</p>
|
<ul id="userSessions">
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,7 +26,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
|
||||||
const textarea = document.getElementById('chatTextarea');
|
const textarea = document.getElementById('chatTextarea');
|
||||||
const sendButton = document.getElementById('sendButton');
|
const sendButton = document.getElementById('sendButton');
|
||||||
const sessions = document.getElementById('userSessions');
|
|
||||||
const chatMessages = document.querySelector('.chat-messages');
|
const chatMessages = document.querySelector('.chat-messages');
|
||||||
|
|
||||||
// Auto resize textarea
|
// Auto resize textarea
|
||||||
|
@ -167,14 +166,24 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
// Function to get the user sessions
|
// Function to get the user sessions
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
const sessionsButton = document.getElementById('loadSessionsButton');
|
const sessionsButton = document.getElementById('loadSessionsButton');
|
||||||
|
const sessions = document.getElementById('userSessions');
|
||||||
|
|
||||||
sessionsButton.addEventListener('click', async function fetchSessions() {
|
sessionsButton.addEventListener('click', async function fetchSessions() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/sessions');
|
const response = await fetch('/sessions');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Network response was not ok ' + response.statusText);
|
throw new Error('Network response was not ok ' + response.statusText);
|
||||||
}
|
}
|
||||||
const data = await response.text();
|
const data = JSON.parse(await response.text());
|
||||||
sessions.innerHTML = data;
|
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) {
|
} catch (error) {
|
||||||
sessions.innerHTML = 'Error: ' + error.message;
|
sessions.innerHTML = 'Error: ' + error.message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ class OwnershipDB(DDB):
|
||||||
return sid
|
return sid
|
||||||
|
|
||||||
def sessions(self, user_email: str) -> List[str]:
|
def sessions(self, user_email: str) -> List[str]:
|
||||||
|
try:
|
||||||
return (
|
return (
|
||||||
self.db.sql(f"""
|
self.db.sql(f"""
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -98,9 +99,15 @@ class OwnershipDB(DDB):
|
||||||
FROM
|
FROM
|
||||||
'{self.path_prefix}/*.csv'
|
'{self.path_prefix}/*.csv'
|
||||||
WHERE
|
WHERE
|
||||||
email = '{user_email}'
|
email = '{user_email}
|
||||||
|
ORDER BY
|
||||||
|
timestamp ASC
|
||||||
|
LIMIT 10'
|
||||||
""")
|
""")
|
||||||
.pl()
|
.pl()
|
||||||
.to_series()
|
.to_series()
|
||||||
.to_list()
|
.to_list()
|
||||||
)
|
)
|
||||||
|
# If the table does not exist
|
||||||
|
except duckdb.duckdb.IOException:
|
||||||
|
return []
|
||||||
|
|
Loading…
Reference in a new issue