Update web/templates/settings/home.html
This commit is contained in:
parent
6917a47604
commit
d3dcf1da44
@ -1,112 +1,60 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block body_class %}themed-bg{% endblock %}
|
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
|
{# Leave body_class empty so Classic gradient is controlled by base.html logic #}
|
||||||
|
{% block body_class %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="page-title">Settings</h1>
|
<h1 class="page-title">Settings</h1>
|
||||||
|
|
||||||
<!-- Blank Settings box -->
|
<!-- Intro / placeholder -->
|
||||||
<div class="card" style="padding:20px; margin-bottom:20px;">
|
<div class="card" style="padding:20px; margin-bottom:20px;">
|
||||||
<p class="muted small">Add your settings here when you’re ready.</p>
|
<p class="muted small">Add your settings here when you’re ready.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Privacy: Clear History -->
|
||||||
<div class="card" style="margin-top:18px; padding:20px;">
|
<div class="card" style="margin-top:18px; padding:20px;">
|
||||||
<h2 class="page-title">Privacy · Clear My History</h2>
|
<h2 class="page-title">Privacy · Clear My History</h2>
|
||||||
<p class="muted" style="margin:-6px 0 12px;">
|
<p class="muted" style="margin:-6px 0 12px;">
|
||||||
Remove your Recent Searches and Recently Viewed illustrations from the Search page.
|
Remove your Recent Searches and Recently Viewed illustrations from the Search page.
|
||||||
</p>
|
</p>
|
||||||
<button id="clear-history-btn" class="btn btn-danger">Clear History</button>
|
<button id="clear-history-btn" class="btn btn-danger">Clear History</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- toast -->
|
<!-- Theme chooser -->
|
||||||
<div id="toast-clear-history"
|
<div class="card" style="padding:20px; margin-top:18px;">
|
||||||
style="position:fixed; right:16px; bottom:16px; padding:10px 14px; border-radius:10px;
|
<h2 class="page-title">Appearance · Theme</h2>
|
||||||
background:#111827; color:#fff; box-shadow:0 6px 20px rgba(0,0,0,.25);
|
<form method="post" action="{% url 'set_theme' %}" style="margin-top:10px;">
|
||||||
opacity:0; pointer-events:none; transition:opacity .25s;">
|
|
||||||
History cleared.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
(function(){
|
|
||||||
function getCookie(name) {
|
|
||||||
var value = "; " + document.cookie;
|
|
||||||
var parts = value.split("; " + name + "=");
|
|
||||||
if (parts.length === 2) return parts.pop().split(";").shift();
|
|
||||||
}
|
|
||||||
var btn = document.getElementById("clear-history-btn");
|
|
||||||
var toast = document.getElementById("toast-clear-history");
|
|
||||||
if (!btn) return;
|
|
||||||
btn.addEventListener("click", function(){
|
|
||||||
fetch("{% url 'clear_history' %}", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "X-CSRFToken": getCookie("csrftoken") }
|
|
||||||
})
|
|
||||||
.then(function(r){ return r.ok ? r.json() : Promise.reject(); })
|
|
||||||
.then(function(data){
|
|
||||||
// Clear likely client-side copies too (harmless if not present)
|
|
||||||
var keys = ["recent_searches","recent_entries","recent_viewed","recently_viewed","recent_results","recentSearches","recentEntries"];
|
|
||||||
try {
|
|
||||||
keys.forEach(function(k){ localStorage.removeItem(k); sessionStorage.removeItem(k); });
|
|
||||||
} catch(e) {}
|
|
||||||
// Clear same-named cookies if any
|
|
||||||
try {
|
|
||||||
var expire = "expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
|
|
||||||
keys.forEach(function(k){ document.cookie = k + "=; " + expire; });
|
|
||||||
} catch(e) {}
|
|
||||||
// Toast
|
|
||||||
if (toast){
|
|
||||||
toast.textContent = "History cleared.";
|
|
||||||
toast.style.opacity = "1";
|
|
||||||
setTimeout(function(){ toast.style.opacity = "0"; }, 1500);
|
|
||||||
}
|
|
||||||
// Optional: log which server keys were removed
|
|
||||||
if (data && data.cleared) { console.log("Cleared server keys:", data.cleared); }
|
|
||||||
})
|
|
||||||
.catch(function(){ /* silent per spec */ });
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Your future settings content goes here -->
|
|
||||||
<div class="card" style="padding:20px; margin-bottom:20px;">
|
|
||||||
<form method="post" action="{% url 'set_theme' %}">
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<label for="theme">Theme</label>
|
<label for="theme" class="small muted" style="display:block; margin-bottom:6px;">Choose site theme</label>
|
||||||
<select id="theme" name="theme" class="form-control" style="max-width: 320px;">
|
<select id="theme" name="theme" class="form-control" style="max-width: 320px;">
|
||||||
{% for t in available_themes %}
|
{% for t in available_themes %}
|
||||||
<option value="{{ t }}" {% if request.session.theme|default:'midnight' == t %}selected{% endif %}>
|
<option value="{{ t }}" {% if request.session.theme|default:'classic' == t %}selected{% endif %}>
|
||||||
{{ t|capfirst }}
|
{{ t|capfirst }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<button class="btn btn-primary" style="margin-top:10px;">Save</button>
|
<button class="btn btn-primary" style="margin-top:10px;">Save</button>
|
||||||
<small class="text-muted" style="display:block;margin-top:6px;">Changes apply immediately across the site.</small>
|
<small class="text-muted" style="display:block;margin-top:6px;">Changes apply immediately across the site.</small>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<!-- Highlight search hits -->
|
||||||
/* Optional live preview without saving */
|
<div class="card" style="padding:20px; margin-top:18px;">
|
||||||
document.getElementById('theme').addEventListener('change', function(e){
|
<h2 class="page-title">Reading · Highlight Search Hits</h2>
|
||||||
const name = e.target.value;
|
<label style="display:flex;gap:10px;align-items:center; margin-top:8px;">
|
||||||
document.getElementById('theme-css').href = '{% static "themes/" %}' + name + '.css';
|
|
||||||
try { localStorage.setItem('theme', name); } catch(e){}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<div class="card" style="padding:20px; margin-bottom:20px;">
|
|
||||||
<label style="display:flex;gap:10px;align-items:center;">
|
|
||||||
<input id="highlightHitsToggle" type="checkbox">
|
<input id="highlightHitsToggle" type="checkbox">
|
||||||
<span>Highlight search hits on entry page</span>
|
<span>Highlight search hits on entry page</span>
|
||||||
</label>
|
</label>
|
||||||
<p class="small muted" style="margin-top:6px;">When on, your last search terms are lightly highlighted on result pages—but only in the fields you searched.</p>
|
<p class="small muted" style="margin-top:6px;">When on, your last search terms are lightly highlighted on result pages—but only in the fields you searched.</p>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if user.is_authenticated and user.is_superuser %}
|
{% if user.is_authenticated and user.is_superuser %}
|
||||||
<h1 class="page-title">Tools</h1>
|
<h1 class="page-title" style="margin-top:22px;">Tools</h1>
|
||||||
|
|
||||||
|
<!-- Release Announcement -->
|
||||||
|
<div class="card" style="margin-top:18px; padding:20px;">
|
||||||
{% if user.is_superuser %}
|
|
||||||
<div class="card" style="margin-top:18px; padding:20px;">
|
|
||||||
<h2 class="page-title">Release Announcement</h2>
|
<h2 class="page-title">Release Announcement</h2>
|
||||||
<p class="muted" style="margin:-6px 0 12px;">
|
<p class="muted" style="margin:-6px 0 12px;">
|
||||||
Publish a message to show once to each user on their next search page load.
|
Publish a message to show once to each user on their next search page load.
|
||||||
@ -117,16 +65,15 @@ document.getElementById('theme').addEventListener('change', function(e){
|
|||||||
{% if announcement_form %}
|
{% if announcement_form %}
|
||||||
{{ announcement_form.as_p }}
|
{{ announcement_form.as_p }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{# If this page isn't rendered via announcement_tools view, render a fresh form #}
|
<label class="small muted" style="display:block; margin-bottom:4px;">Title (optional)</label>
|
||||||
<label>Title (optional)</label>
|
|
||||||
<input type="text" name="title" class="tool-input">
|
<input type="text" name="title" class="tool-input">
|
||||||
|
|
||||||
<label>Message</label>
|
<label class="small muted" style="display:block; margin:10px 0 4px;">Message</label>
|
||||||
<textarea name="message" rows="6" class="tool-input" placeholder="What’s new in this release…"></textarea>
|
<textarea name="message" rows="6" class="tool-input" placeholder="What’s new in this release…"></textarea>
|
||||||
|
|
||||||
<label style="display:flex; gap:6px; align-items:center; margin-top:8px;">
|
<label style="display:flex; gap:6px; align-items:center; margin-top:8px;">
|
||||||
<input type="checkbox" name="is_active" checked> Active
|
<input type="checkbox" name="is_active" checked> Active
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<button class="btn btn-primary">Publish</button>
|
<button class="btn btn-primary">Publish</button>
|
||||||
@ -154,85 +101,114 @@ document.getElementById('theme').addEventListener('change', function(e){
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if user.is_superuser %}
|
<!-- Security tools -->
|
||||||
<div class="card" style="margin-top:18px; padding:20px;">
|
<div class="card" style="margin-top:18px; padding:20px;">
|
||||||
<h2 class="page-title">Security · Login Attempts (7 days)</h2>
|
<h2 class="page-title">Security · Login Attempts (7 days)</h2>
|
||||||
<p class="muted" style="margin:-6px 0 12px;">
|
<p class="muted" style="margin:-6px 0 12px;">
|
||||||
View successful and failed login attempts from the last week.
|
View successful and failed login attempts from the last week.
|
||||||
</p>
|
</p>
|
||||||
<a class="btn btn-secondary" href="{% url 'login_attempts' %}">Open Login Attempts</a>
|
<a class="btn btn-secondary" href="{% url 'login_attempts' %}">Open Login Attempts</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card" style="margin-top:18px; padding:20px;">
|
<div class="card" style="margin-top:18px; padding:20px;">
|
||||||
<h2 class="page-title">Security · Audit Log</h2>
|
<h2 class="page-title">Security · Audit Log</h2>
|
||||||
<p class="muted" style="margin:-6px 0 12px;">Track adds, edits (with per-field changes), and deletes. Newest first, latest 100 entries.</p>
|
<p class="muted" style="margin:-6px 0 12px;">Track adds, edits (with per-field changes), and deletes. Newest first, latest 100 entries.</p>
|
||||||
<a class="btn btn-secondary" href="{% url 'audit_log' %}">Open Audit Log</a>
|
<a class="btn btn-secondary" href="{% url 'audit_log' %}">Open Audit Log</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Toast for Clear History -->
|
||||||
|
<div id="toast-clear-history"
|
||||||
|
style="position:fixed; right:16px; bottom:16px; padding:10px 14px; border-radius:10px;
|
||||||
|
background:#111827; color:#fff; box-shadow:0 6px 20px rgba(0,0,0,.25);
|
||||||
|
opacity:0; pointer-events:none; transition:opacity .25s;">
|
||||||
|
History cleared.
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.tool-block { margin-bottom:16px; }
|
|
||||||
.tool-block h3 {
|
|
||||||
margin:0 0 6px;
|
|
||||||
font-size:18px;
|
|
||||||
color:#0f172a;
|
|
||||||
}
|
|
||||||
.tool-actions {
|
|
||||||
display:flex;
|
|
||||||
flex-wrap:wrap;
|
|
||||||
gap:10px;
|
|
||||||
margin-top:8px;
|
|
||||||
}
|
|
||||||
.tool-input {
|
.tool-input {
|
||||||
border:1px solid var(--border, #d1d5db);
|
border:1px solid var(--border, #d1d5db);
|
||||||
border-radius:8px;
|
border-radius:8px;
|
||||||
padding:6px 8px;
|
padding:6px 8px;
|
||||||
font-size:14px;
|
font-size:14px;
|
||||||
margin-right:6px;
|
width:100%;
|
||||||
}
|
max-width:640px;
|
||||||
.tool-sep {
|
|
||||||
border:none;
|
|
||||||
border-top:1px solid var(--border, #e5e7eb);
|
|
||||||
margin:18px 0;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
(function(){
|
||||||
const toggle = document.getElementById("darkToggle");
|
// Simple CSRF helper
|
||||||
if (!toggle) return;
|
function getCookie(name) {
|
||||||
|
var value = "; " + document.cookie;
|
||||||
toggle.addEventListener("click", () => {
|
var parts = value.split("; " + name + "=");
|
||||||
document.body.classList.toggle("dark-mode");
|
if (parts.length === 2) return parts.pop().split(";").shift();
|
||||||
localStorage.setItem("darkMode", document.body.classList.contains("dark-mode"));
|
return "";
|
||||||
});
|
|
||||||
|
|
||||||
// Restore preference on load
|
|
||||||
if (localStorage.getItem("darkMode") === "true") {
|
|
||||||
document.body.classList.add("dark-mode");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear history
|
||||||
|
var btn = document.getElementById("clear-history-btn");
|
||||||
|
var toast = document.getElementById("toast-clear-history");
|
||||||
|
if (btn) {
|
||||||
|
btn.addEventListener("click", function(){
|
||||||
|
fetch("{% url 'clear_history' %}", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "X-CSRFToken": getCookie("csrftoken") }
|
||||||
|
})
|
||||||
|
.then(function(r){ return r.ok ? r.json() : Promise.reject(); })
|
||||||
|
.then(function(data){
|
||||||
|
// Clear likely client-side copies too (harmless if not present)
|
||||||
|
var keys = ["recent_searches","recent_entries","recent_viewed","recently_viewed","recent_results","recentSearches","recentEntries"];
|
||||||
|
try {
|
||||||
|
keys.forEach(function(k){
|
||||||
|
localStorage.removeItem(k);
|
||||||
|
sessionStorage.removeItem(k);
|
||||||
|
document.cookie = k + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
|
||||||
});
|
});
|
||||||
</script>
|
} catch(e) {}
|
||||||
<script>
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
if (toast){
|
||||||
|
toast.textContent = "History cleared.";
|
||||||
|
toast.style.opacity = "1";
|
||||||
|
setTimeout(function(){ toast.style.opacity = "0"; }, 1500);
|
||||||
|
}
|
||||||
|
if (data && data.cleared) { console.log("Cleared server keys:", data.cleared); }
|
||||||
|
})
|
||||||
|
.catch(function(){ /* silent */ });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theme live preview (without saving)
|
||||||
|
var themeSel = document.getElementById('theme');
|
||||||
|
if (themeSel) {
|
||||||
|
themeSel.addEventListener('change', function(e){
|
||||||
|
var name = e.target.value;
|
||||||
|
var link = document.getElementById('theme-css');
|
||||||
|
if (link) link.href = '{% static "themes/" %}' + name + '.css';
|
||||||
|
try {
|
||||||
|
localStorage.setItem('theme', name);
|
||||||
|
// Toggle the classic gradient body class in case user previews Classic
|
||||||
|
if (name === 'classic') {
|
||||||
|
document.body.classList.add('themed-bg');
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('themed-bg');
|
||||||
|
}
|
||||||
|
document.documentElement.setAttribute('data-theme', name);
|
||||||
|
} catch(e){}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Highlight search hits toggle
|
||||||
|
(async function(){
|
||||||
const toggle = document.getElementById("highlightHitsToggle");
|
const toggle = document.getElementById("highlightHitsToggle");
|
||||||
if (!toggle) return;
|
if (!toggle) return;
|
||||||
|
|
||||||
// Load current prefs
|
// Load current prefs
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/get-prefs/");
|
const res = await fetch("{% url 'api_get_prefs' %}");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data && typeof data.highlight_search_hits !== "undefined") {
|
if (data && typeof data.highlight_search_hits !== "undefined") {
|
||||||
toggle.checked = !!data.highlight_search_hits;
|
toggle.checked = !!data.highlight_search_hits;
|
||||||
@ -244,18 +220,16 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append("enabled", toggle.checked ? "true" : "false");
|
form.append("enabled", toggle.checked ? "true" : "false");
|
||||||
try {
|
try {
|
||||||
await fetch("/api/set-highlight-hits/", { method: "POST", body: form, headers: { "X-CSRFToken": getCookie("csrftoken") }});
|
await fetch("{% url 'api_set_highlight_hits' %}", {
|
||||||
|
method: "POST",
|
||||||
|
body: form,
|
||||||
|
headers: { "X-CSRFToken": getCookie("csrftoken") }
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert("Could not save the setting. Please try again.");
|
alert("Could not save the setting. Please try again.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
// Standard Django CSRF helper
|
})();
|
||||||
function getCookie(name) {
|
|
||||||
const m = document.cookie.match("(^|;)\\s*" + name + "\\s*=\\s*([^;]+)");
|
|
||||||
return m ? m.pop() : "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue
Block a user