Added events system

This commit is contained in:
2025-05-29 14:27:15 +02:00
parent 3174f8fa5b
commit f00d569db3
24 changed files with 1186 additions and 114 deletions

View File

@@ -43,4 +43,93 @@
{% block extra_js %}
<script src="{{ url_for('static', filename='js/file-grid.js', v=config.CSS_VERSION) }}"></script>
<script src="{{ url_for('static', filename='js/starred.js', v=config.CSS_VERSION) }}"></script>
<script>
// Add event logging for starred actions
document.addEventListener('DOMContentLoaded', function() {
// Log when starred page is viewed
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({
event_type: 'starred_view',
details: {
user_id: '{{ current_user.id }}',
timestamp: new Date().toISOString()
}
})
});
// Log when view is toggled
const gridViewBtn = document.getElementById('gridViewBtn');
const listViewBtn = document.getElementById('listViewBtn');
if (gridViewBtn && listViewBtn) {
gridViewBtn.addEventListener('click', function() {
logViewChange('grid');
});
listViewBtn.addEventListener('click', function() {
logViewChange('list');
});
}
function logViewChange(viewType) {
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({
event_type: 'starred_view_change',
details: {
user_id: '{{ current_user.id }}',
view_type: viewType,
timestamp: new Date().toISOString()
}
})
});
}
// Log when search is performed
const searchInput = document.querySelector('.search-input');
if (searchInput) {
searchInput.addEventListener('input', debounce(function(e) {
if (e.target.value.length > 0) {
fetch('/api/events/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({
event_type: 'starred_search',
details: {
user_id: '{{ current_user.id }}',
search_term: e.target.value,
timestamp: new Date().toISOString()
}
})
});
}
}, 500));
}
// Debounce function to limit API calls
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
});
</script>
{% endblock %}