removed persistant data

This commit is contained in:
pika 2025-04-14 22:37:25 +02:00
parent 345a801c40
commit 627f805377
10 changed files with 412 additions and 29 deletions

View file

@ -178,17 +178,7 @@
<div>
<label for="doc-category" class="block text-sm font-medium text-gray-400 mb-1">Category</label>
<select id="doc-category" class="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-md text-white focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary">
{% for category in categories %}
{% if category.is_root %}
<option value="{{ category.id }}" {% if (document and document.category_id == category.id) or (not document and (not preselected_category_id or preselected_category_id|int == category.id|int)) %}selected{% endif %}>
{{ category.name }} (Home)
</option>
{% else %}
<option value="{{ category.id }}" {% if (document and document.category_id == category.id) or (not document and preselected_category_id and preselected_category_id|int == category.id|int) %}selected{% endif %}>
{{ category.name }}
</option>
{% endif %}
{% endfor %}
<!-- Categories will be populated via JavaScript -->
</select>
</div>
@ -315,9 +305,60 @@
// Initialize
document.addEventListener('DOMContentLoaded', function() {
// Populate categories dropdown with hierarchical structure
populateCategoriesDropdown();
// Initial preview
updatePreview();
// Function to create hierarchical category dropdown
function populateCategoriesDropdown() {
const categorySelect = document.getElementById('doc-category');
const categories = {{ categories|tojson|safe }};
const preselectedId = {% if document and document.category_id %}{{ document.category_id }}{% elif preselected_category_id %}{{ preselected_category_id }}{% else %}null{% endif %};
// Find the root category
const rootCategory = categories.find(c => c.is_root);
let rootCategoryId = null;
if (rootCategory) {
rootCategoryId = rootCategory.id;
}
function addCategoryOptions(categoryList, depth = 0) {
categoryList.forEach(category => {
const option = document.createElement('option');
option.value = category.id;
// Create indentation for hierarchy
const indent = '\u00A0\u00A0\u00A0\u00A0'.repeat(depth);
let prefix = '';
if (depth > 0) {
prefix = '└─ ';
}
option.textContent = indent + prefix + category.name;
// Select this option if it matches the preselected ID
// Or if this is the root category and no preselection was made
option.selected = (category.id == preselectedId) ||
(category.is_root && !preselectedId);
categorySelect.appendChild(option);
// Add children recursively if any
if (category.children && category.children.length > 0) {
addCategoryOptions(category.children, depth + 1);
}
});
}
// Get root categories and their children
const rootCategories = categories.filter(c => c.parent_id === null);
addCategoryOptions(rootCategories);
console.log("Preselected category ID:", preselectedId || (rootCategoryId + " (root by default)"));
}
// Add debounce function for efficiency
function debounce(func, wait) {
let timeout;