File size: 7,572 Bytes
6ea020b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{% extends "base.html" %}

{% block title %}Activity Logs - NexLab{% endblock %}

{% block content %}
<div class="max-w-7xl mx-auto pb-10">
    <div class="mb-8">
        <h1 class="text-3xl font-bold text-slate-900 tracking-tight">System Activity Logs</h1>
        <p class="text-sm text-slate-500 mt-2">Monitor recent operational events and user actions across the system. (Top 500)</p>
    </div>

    <!-- Error/Success Messages -->
    {% if message_success %}
    <div class="mb-4 bg-emerald-50 border-l-4 border-emerald-500 p-4 rounded-r shadow-sm">
        <div class="flex items-center">
            <svg class="h-5 w-5 text-emerald-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
            <p class="text-sm font-medium text-emerald-800">{{ message_success }}</p>
        </div>
    </div>
    {% endif %}
    {% if message_error %}
    <div class="mb-4 bg-red-50 border-l-4 border-red-500 p-4 rounded-r shadow-sm">
        <div class="flex items-center">
            <svg class="h-5 w-5 text-red-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
            <p class="text-sm font-medium text-red-800">{{ message_error }}</p>
        </div>
    </div>
    {% endif %}

    <!-- Filter Bar -->
    <form method="GET" action="/activity-logs" class="bg-white rounded-xl shadow-sm border border-slate-200 p-4 mb-4">
        <div class="flex flex-wrap items-end gap-4">
            <div class="flex-1 min-w-[180px]">
                <label class="block text-xs font-medium text-slate-500 mb-1">User</label>
                <select name="user" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    <option value="">All Users</option>
                    {% for u in all_users %}
                    <option value="{{ u }}" {% if filter_user == u %}selected{% endif %}>{{ u }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="flex-1 min-w-[180px]">
                <label class="block text-xs font-medium text-slate-500 mb-1">Action Type</label>
                <select name="action" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                    <option value="">All Actions</option>
                    {% for a in all_actions %}
                    <option value="{{ a }}" {% if filter_action == a %}selected{% endif %}>{{ a }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="flex gap-2">
                <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-5 py-2 rounded-lg text-sm font-medium transition-colors shadow-sm">
                    <svg class="w-4 h-4 inline mr-1 -mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"></path></svg>
                    Filter
                </button>
                <a href="/activity-logs" class="bg-slate-100 hover:bg-slate-200 text-slate-600 px-4 py-2 rounded-lg text-sm font-medium transition-colors">Clear</a>
            </div>
        </div>
    </form>

    <div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left border-collapse">
                <thead>
                    <tr class="bg-slate-50 text-slate-500 text-xs uppercase tracking-wider border-b border-slate-200">
                        <th class="py-3 px-4">Timestamp</th>
                        <th class="py-3 px-4">User</th>
                        <th class="py-3 px-4">Action Type</th>
                        <th class="py-3 px-4">Description</th>
                        <th class="py-3 px-4">Target Details</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    {% for log in activities %}
                    <tr class="hover:bg-slate-50 transition-colors">
                        <td class="py-3 px-4 text-sm text-slate-500 whitespace-nowrap">{{ log.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        <td class="py-3 px-4 text-sm font-medium text-slate-700 whitespace-nowrap">{{ log.username }}</td>
                        <td class="py-3 px-4">
                            {% if "LOGIN" in log.action_type %}
                            <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium {% if 'FAILED' in log.action_type %}bg-red-100 text-red-800{% else %}bg-emerald-100 text-emerald-800{% endif %}">
                                {{ log.action_type }}
                            </span>
                            {% elif "LOGOUT" in log.action_type %}
                            <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-slate-100 text-slate-800">
                                {{ log.action_type }}
                            </span>
                            {% elif "PRINT" in log.action_type %}
                            <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-indigo-100 text-indigo-800">
                                {{ log.action_type }}
                            </span>
                            {% else %}
                            <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-800">
                                {{ log.action_type }}
                            </span>
                            {% endif %}
                        </td>
                        <td class="py-3 px-4 text-sm text-slate-600">{{ log.description }}</td>
                        <td class="py-3 px-4 text-sm text-slate-500 whitespace-nowrap">
                            {% if log.target_type %}
                            <span class="capitalize text-slate-600 font-medium">{{ log.target_type }}</span>
                            {% if log.target_id %}<span class="text-slate-400">#{{ log.target_id }}</span>{% endif %}
                            {% else %}-{% endif %}
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="5" class="py-8 text-center text-slate-500">
                            <div class="flex flex-col items-center justify-center">
                                <svg class="w-12 h-12 text-slate-300 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                                <span>No activity logs found.</span>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}