Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

237 config name not persisted #249

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def save_settings(raw_source, form_data):
# Log raw form data
print(f"[DEBUG] Raw form data received: {form_data}")

# grab new config name if they entered one:
if "config_name" in form_data:
session["config_name"] = form_data["config_name"]
print(f"[DEBUG] Received config name in form: {session['config_name']}")

# Handle asset_directory specifically
if "asset_directory" in form_data:
# Use getlist to retrieve all values for asset_directory
Expand Down
14 changes: 10 additions & 4 deletions quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@ def clear_session():

if config_name != session["config_name"]:
session["config_name"] = config_name
except:
config_name = session["config_name"]
except KeyError: # Handle missing `name` key safely
config_name = session.get("config_name")

flush_session_storage(config_name)
flash("Session storage cleared successfully.", "success")
return redirect(url_for("start"))

# Send message to toast
return jsonify(
{
"status": "success",
"message": f"Session storage cleared for '{config_name}'.",
}
)


@app.route("/clear_data/<name>/<section>")
Expand Down
47 changes: 41 additions & 6 deletions static/local-js/001-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ document.addEventListener('DOMContentLoaded', function () {
const clearSessionButton = document.getElementById('clearSessionButton')
const configNameInput = document.getElementById('config_name')

// Get references to modal and elements
// Get references to modal and its elements
const modal = new bootstrap.Modal(document.getElementById('confirmationModal'))
const modalBody = document.getElementById('confirmationModalBody')
const modalConfirmButton = document.getElementById('confirmClearSession')

// Get references to toast elements
const successToastElement = document.getElementById('successToast')
const errorToastElement = document.getElementById('errorToast')

if (clearSessionButton) {
clearSessionButton.addEventListener('click', function (event) {
event.preventDefault()
Expand All @@ -21,14 +25,45 @@ document.addEventListener('DOMContentLoaded', function () {

// Add confirm action to the modal button
modalConfirmButton.onclick = function () {
$.post('/clear_session', { name: configName }, function (data) {
// Handle success or failure (if necessary)
console.log('Config cleared for:', configName)
const configName = configNameInput.value.trim()

if (!configName) {
// Show error toast for missing config name
const errorToastBody = errorToastElement.querySelector('.toast-body')
errorToastBody.textContent = 'Config name is required.'
const errorToast = new bootstrap.Toast(errorToastElement)
errorToast.show()
return // Exit if no config name is provided
}

// Send AJAX POST request to clear the session
$.post('/clear_session', { name: configName }, function (response) {
if (response.status === 'success') {
// Show success toast
const successToastBody = successToastElement.querySelector('.toast-body')
successToastBody.textContent = response.message
const successToast = new bootstrap.Toast(successToastElement)
successToast.show()

// Hide the modal
modal.hide()
} else {
// Show error toast for an unexpected server response
const errorToastBody = errorToastElement.querySelector('.toast-body')
errorToastBody.textContent = response.message || 'An unexpected error occurred.'
const errorToast = new bootstrap.Toast(errorToastElement)
errorToast.show()
}
}).fail(function (error) {
console.error('Error clearing config:', error)
// Show error toast for failed request
const errorMessage = error.responseJSON?.message || 'An unknown error occurred.'
const errorToastBody = errorToastElement.querySelector('.toast-body')
errorToastBody.textContent = errorMessage
const errorToast = new bootstrap.Toast(errorToastElement)
errorToast.show()
})

// Hide modal after submission
// Hide modal after the action (optional, could move to success block)
modal.hide()
}
})
Expand Down
25 changes: 24 additions & 1 deletion templates/001-start.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,30 @@ <h2>{{ page_info['title'] }}</h2>
</div>
</form>
</form>
<!-- Modal for confirmation -->
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div class="toast-container position-fixed top-0 start-50 translate-middle-x p-3">
<!-- Success Toast -->
<div id="successToast" class="toast align-items-center text-bg-success border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<!-- Success message will be inserted dynamically -->
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>

<!-- Error Toast -->
<div id="errorToast" class="toast align-items-center text-bg-danger border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<!-- Error message will be inserted dynamically -->
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>

<!-- Modal for confirmation -->
<div class="modal fade" id="confirmationModal" tabindex="-1" aria-labelledby="confirmationModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down