From 582cb3cb4c4a9fe5837354fdf5e54bb354de753c Mon Sep 17 00:00:00 2001 From: Edd Date: Fri, 23 Jan 2026 21:21:43 +0000 Subject: [PATCH] user history --- app/pages/admin/users/index.vue | 100 ++++++++++++-------------------- 1 file changed, 37 insertions(+), 63 deletions(-) diff --git a/app/pages/admin/users/index.vue b/app/pages/admin/users/index.vue index 4715795..5456bc8 100644 --- a/app/pages/admin/users/index.vue +++ b/app/pages/admin/users/index.vue @@ -441,27 +441,30 @@ class="relative bg-slate-50 dark:bg-slate-800/50 rounded-xl p-5 border border-slate-200 dark:border-slate-800">
- {{ new - Date(item.timestamp).toLocaleDateString('en-US', { - month: 'short', - day: 'numeric' - }) }} - {{ new - Date(item.timestamp).toLocaleTimeString([], { - hour: '2-digit', - minute: '2-digit' - }) }} + + {{ new Date(item.timestamp).toLocaleDateString('en-US', { + month: + 'short', day: 'numeric' }) }} + + + {{ new Date(item.timestamp).toLocaleTimeString([], { + hour: + '2-digit', minute: '2-digit' }) }} +
{{ - item.action.replace('_', ' ') }} - {{ item.target_type - }} #{{ item.target_id }} + class="px-2.5 py-1 rounded-md text-xs font-bold uppercase tracking-wide bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300"> + {{ item.actionType.replace('_', ' ') }} + + + {{ item.targetType }} #{{ item.targetId }} +
-

{{ - item.details }}

+

+ {{ item.description }} +

@@ -504,51 +507,6 @@ const searchQuery = ref(''); const selectedUser = ref(null); const userHistory = ref([]); -const generateMockHistory = () => { - const actions = ['UPLOADED_PUBLICATION', 'ADDED_COMMENT', 'CORRECTED_PUBLICATION', 'RATED_PUBLICATION', 'TAGGED_PUBLICATION']; - const targetTypes = ['Publication', 'Comment', 'Review']; - const details = [ - 'Fez upload da publicação "A New Technique for Data Science"', - 'Comentou na publicação "Reference Paper Y"', - 'Corrigiu informação da publicação "Machine Learning Advances"', - 'Atribuiu 5 estrelas à publicação "Deep Learning Research"', - 'Adicionou tag "AI" à publicação "Neural Networks Study"', - 'Fez upload da publicação "Quantum Computing Overview"', - 'Comentou na publicação "Data Analysis Methods"', - 'Corrigiu informação da publicação "Statistical Models in Research"', - 'Atribuiu 4 estrelas à publicação "Big Data Trends"', - 'Adicionou tag "Data Science" à publicação "Data Visualization Techniques"' - ]; - - const history = []; - const numEvents = Math.floor(Math.random() * 20) + 8; - - for (let i = 0; i < numEvents; i++) { - const randomAction = actions[Math.floor(Math.random() * actions.length)]; - const randomTargetType = targetTypes[Math.floor(Math.random() * targetTypes.length)]; - const randomDetails = details[Math.floor(Math.random() * details.length)]; - const daysAgo = Math.floor(Math.random() * 30); - const hoursAgo = Math.floor(Math.random() * 24); - const minutesAgo = Math.floor(Math.random() * 60); - - const timestamp = new Date(); - timestamp.setDate(timestamp.getDate() - daysAgo); - timestamp.setHours(timestamp.getHours() - hoursAgo); - timestamp.setMinutes(timestamp.getMinutes() - minutesAgo); - - history.push({ - id: 1000 + i, - action: randomAction, - target_type: randomTargetType, - target_id: 200 + Math.floor(Math.random() * 50), - details: randomDetails, - timestamp: timestamp.toISOString() - }); - } - - return history.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); -}; - const formData = reactive({ id: 0, name: '', @@ -654,10 +612,26 @@ const confirmDelete = async (user) => { } }; -const openUserDetails = (user) => { +const openUserDetails = async (user) => { selectedUser.value = user; - userHistory.value = generateMockHistory(user.id); showDetailsModal.value = true; + + try { + const data = await $fetch(`${api}/users/${user.id}/history`, { + method: 'GET', + headers: { Authorization: `Bearer ${token.value}` } + }); + + if (data && typeof data === 'object') { + userHistory.value = Object.values(data).sort((a, b) => b.timestamp - a.timestamp); + } else { + userHistory.value = []; + } + } catch (error) { + console.error("Error fetching user history", error); + notifications.error("Failed to load activity history"); + userHistory.value = []; + } }; const closeDetailsModal = () => {