-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_components.py
More file actions
287 lines (242 loc) · 10.6 KB
/
ui_components.py
File metadata and controls
287 lines (242 loc) · 10.6 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# ui_components.py
"""User interface components for Streamlit application"""
import streamlit as st
import pandas as pd
from pathlib import Path
from datetime import datetime
from auth import (
get_all_users, delete_user, register_user_admin,
log_activity, get_admin_statistics
)
from config import ACTIVITY_CSV
def show_login_page():
"""Display enhanced professional login page"""
# # Main header with gradient background
# st.markdown(
# """
# <div style='text-align:center; padding:3rem 2rem; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius:20px; margin-bottom:3rem; box-shadow: 0 10px 40px rgba(0,0,0,0.1)'>
# <h1 style='color:white; margin:0; font-size:2.8rem; font-weight:700'>📚 Ethicallogix</h1>
# <h2 style='color:#f0f0f0; margin:0.5rem 0; font-size:1.8rem; font-weight:400'>Assignment Maker</h2>
# <p style='color:#e0e0e0; font-size:1.1rem; margin:1rem 0 0 0'>AI-Powered Academic Assignment Generator</p>
# </div>
# """,
# unsafe_allow_html=True
# )
# Login form in a centered card
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.markdown(
"""
<div style='background:white; padding:1rem; border-radius:15px; box-shadow: 0 4px 5px rgba(0,0,0,0.08)'>
<h3 style='text-align:center; color:#1a2384; margin-bottom:1.5rem'>🔐 User Login</h3>
</div>
""",
unsafe_allow_html=True
)
with st.form("login_form", clear_on_submit=False):
st.markdown("<br>", unsafe_allow_html=True)
# Username field with icon
login_username = st.text_input(
"👤 Username",
key="login_username",
placeholder="Enter your username",
help="Use your registered username"
)
# Password field with icon
login_password = st.text_input(
"🔒 Password",
type="password",
key="login_password",
placeholder="Enter your password",
help="Enter your account password"
)
st.markdown("<br>", unsafe_allow_html=True)
# Login button
login_submit = st.form_submit_button(
"Login ",
use_container_width=True,
type="primary"
)
st.markdown("<br>", unsafe_allow_html=True)
# Information boxes
st.info("📧 **New User?** Contact administrator for account creation\n\n✉️ **Email:** hasiraza511@gmail.com")
return login_submit, login_username, login_password
def show_admin_portal():
"""Display admin dashboard"""
st.markdown(
"""
<div style='text-align:center; padding:2rem; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius:15px; margin-bottom:2rem'>
<h1 style='color:white; margin:0'>🔐 Admin Portal</h1>
<p style='color:#f0f0f0; font-size:1.1rem; margin:0.5rem 0 0 0'>System Management Dashboard</p>
</div>
""",
unsafe_allow_html=True
)
# Get statistics
stats = get_admin_statistics()
# Display statistics cards
st.markdown("### 📊 System Overview")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.markdown(
f"""
<div style='background:#e8f5e9; padding:1.5rem; border-radius:10px; text-align:center'>
<h2 style='color:#2e7d32; margin:0'>{stats['total_users']}</h2>
<p style='color:#66bb6a; margin:0.5rem 0 0 0'>Total Users</p>
</div>
""",
unsafe_allow_html=True
)
with col2:
st.markdown(
f"""
<div style='background:#e3f2fd; padding:1.5rem; border-radius:10px; text-align:center'>
<h2 style='color:#1565c0; margin:0'>{stats['active_users']}</h2>
<p style='color:#42a5f5; margin:0.5rem 0 0 0'>Active Users</p>
</div>
""",
unsafe_allow_html=True
)
with col3:
st.markdown(
f"""
<div style='background:#fff3e0; padding:1.5rem; border-radius:10px; text-align:center'>
<h2 style='color:#ef6c00; margin:0'>{stats['total_assignments']}</h2>
<p style='color:#ff9800; margin:0.5rem 0 0 0'>Assignments Generated</p>
</div>
""",
unsafe_allow_html=True
)
with col4:
st.markdown(
f"""
<div style='background:#f3e5f5; padding:1.5rem; border-radius:10px; text-align:center'>
<h2 style='color:#7b1fa2; margin:0'>{stats['total_activities']}</h2>
<p style='color:#ab47bc; margin:0.5rem 0 0 0'>Total Activities</p>
</div>
""",
unsafe_allow_html=True
)
st.markdown("---")
# Tabs for different admin functions
tab1, tab2, tab3 = st.tabs(["👥 User Management", "➕ Register New User", "📈 Activity Logs"])
# Tab 1: User Management
with tab1:
st.markdown("### 👥 Registered Users")
users_df = get_all_users()
if not users_df.empty:
st.dataframe(users_df, use_container_width=True, hide_index=True)
st.markdown("### 🗑️ Delete User")
col1, col2 = st.columns([3, 1])
with col1:
user_to_delete = st.selectbox(
"Select user to delete",
options=users_df['username'].tolist(),
key="delete_user_select"
)
with col2:
st.markdown("<br>", unsafe_allow_html=True)
if st.button("🗑️ Delete User", type="secondary", use_container_width=True):
success, message = delete_user(user_to_delete)
if success:
st.success(message)
st.rerun()
else:
st.error(message)
else:
st.info("📭 No users registered yet.")
# Tab 2: Register New User
with tab2:
st.markdown("### ➕ Register New User")
with st.form("admin_register_form"):
col1, col2 = st.columns(2)
with col1:
new_full_name = st.text_input("Full Name *", key="admin_reg_full_name")
new_username = st.text_input("Username * (min 4 characters)", key="admin_reg_username")
with col2:
new_email = st.text_input("Email Address *", key="admin_reg_email")
new_password = st.text_input("Password * (min 6 characters)", type="password", key="admin_reg_password")
register_submit = st.form_submit_button("✅ Register User", use_container_width=True, type="primary")
if register_submit:
errors = []
if not new_full_name or len(new_full_name.strip()) < 2:
errors.append("Full name must be at least 2 characters")
if not new_username or len(new_username.strip()) < 4:
errors.append("Username must be at least 4 characters")
if not new_email or '@' not in new_email:
errors.append("Valid email address required")
if not new_password or len(new_password) < 6:
errors.append("Password must be at least 6 characters")
if errors:
for error in errors:
st.error(f"❌ {error}")
else:
success, message = register_user_admin(new_username, new_email, new_password, new_full_name)
if success:
st.success(f"✅ {message}")
st.balloons()
else:
st.error(f"❌ {message}")
# Tab 3: Activity Logs
with tab3:
st.markdown("### 📈 Recent Activity Logs")
if Path(ACTIVITY_CSV).exists():
activity_df = pd.read_csv(ACTIVITY_CSV)
# Show last 50 activities
recent_activities = activity_df.tail(50).sort_values('timestamp', ascending=False)
st.dataframe(recent_activities, use_container_width=True, hide_index=True)
# Download activity logs
csv_data = activity_df.to_csv(index=False)
st.download_button(
"📥 Download All Activity Logs",
data=csv_data,
file_name=f"activity_logs_{datetime.now().strftime('%Y%m%d')}.csv",
mime="text/csv",
use_container_width=True
)
else:
st.info("📭 No activity logs available.")
st.markdown("---")
# Logout button
col1, col2, col3 = st.columns([1, 1, 1])
with col2:
if st.button("🚪 Logout", use_container_width=True, type="secondary"):
log_activity('admin', "ADMIN_LOGOUT", "Administrator logged out")
return True
return False
def show_tips_section():
"""Display tips for best results"""
st.markdown("---")
st.markdown("### 💡 Tips for Best Results")
tips_col1, tips_col2 = st.columns(2)
with tips_col1:
st.markdown("""
**Topic Guidelines:**
- Be specific and clear about requirements
- Include context and scope
- Mention any specific concepts to cover
- Specify format preferences (if any)
- Upload documents for context (NEW!)
""")
with tips_col2:
st.markdown("""
**Quality Tips:**
- Choose appropriate difficulty level
- Enable examples for better understanding
- Include references for academic credibility
- Adjust word count based on depth needed
- Upload university logo for professional branding
""")
def show_footer():
"""Display application footer"""
st.markdown("---")
st.markdown(
"""
<div style='text-align:center; color:#6b7280; padding:20px; background-color:#f9fafb; border-radius:10px; margin-top:2rem'>
<strong style='font-size:1.1rem'>📚 Ethicallogix Assignment Maker</strong><br>
<p style='margin:0.5rem 0'>Developed by <strong>Muhammad Haseeb</strong></p>
<small>Version 4.0 | Enhanced with Document Upload Support</small>
</div>
""",
unsafe_allow_html=True,
)