arif670 commited on
Commit
ed75b35
Β·
verified Β·
1 Parent(s): 08ae0b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -20
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  from datetime import datetime
3
  import pandas as pd
4
  import plotly.express as px
 
 
5
 
6
  # Configure page first
7
  st.set_page_config(
@@ -11,19 +13,17 @@ st.set_page_config(
11
  menu_items={
12
  'Get Help': 'https://github.com',
13
  'Report a bug': "https://github.com",
14
- 'About': "# Task Management System v3.3"
15
  }
16
  )
17
 
18
  # Custom CSS for enhanced UI
19
  st.markdown("""
20
  <style>
21
- /* Modern UI Enhancements */
22
  .main .block-container {
23
  padding-top: 1.5rem;
24
  max-width: 1400px;
25
  }
26
-
27
  .header {
28
  background: linear-gradient(135deg, #2c3e50, #3498db);
29
  color: white;
@@ -32,7 +32,6 @@ st.markdown("""
32
  margin-bottom: 2rem;
33
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
34
  }
35
-
36
  .status-badge {
37
  padding: 6px 14px;
38
  border-radius: 20px;
@@ -41,27 +40,41 @@ st.markdown("""
41
  align-items: center;
42
  gap: 8px;
43
  }
44
-
45
  .pending { background: #fff3cd; color: #856404; }
46
  .in-progress { background: #cce5ff; color: #004085; }
47
  .completed { background: #d4edda; color: #155724; }
 
 
 
 
 
 
 
 
 
 
 
48
  </style>
49
  """, unsafe_allow_html=True)
50
 
51
  def initialize_firebase():
52
- import firebase_admin
53
- from firebase_admin import credentials, firestore, auth
54
-
55
  if not firebase_admin._apps:
56
  cred = credentials.Certificate("firebase_credentials.json")
57
  firebase_admin.initialize_app(cred)
58
  return firestore.client(), auth
59
 
60
- def create_default_admin(auth):
61
  try:
62
  admin_email = "admin@example.com"
63
  try:
64
- auth.get_user_by_email(admin_email)
 
 
 
 
 
 
 
65
  except auth.UserNotFoundError:
66
  admin_user = auth.create_user(
67
  email=admin_email,
@@ -69,14 +82,18 @@ def create_default_admin(auth):
69
  display_name="Admin"
70
  )
71
  auth.set_custom_user_claims(admin_user.uid, {'admin': True})
72
- return admin_user
 
 
 
 
73
  except Exception as e:
74
  st.error(f"Admin setup error: {str(e)}")
75
 
76
  def main():
77
  # Initialize Firebase
78
- db, auth = initialize_firebase()
79
- create_default_admin(auth)
80
 
81
  # Session State Management
82
  if "authenticated" not in st.session_state:
@@ -100,15 +117,18 @@ def main():
100
  password = st.text_input("πŸ”’ Password", type="password")
101
  if st.form_submit_button("πŸš€ Login"):
102
  try:
103
- user = auth.get_user_by_email(email)
104
  user_doc = db.collection("users").document(user.uid).get()
105
- custom_claims = user.custom_claims or {}
106
 
 
 
 
 
107
  st.session_state.update({
108
  "authenticated": True,
109
  "email": user.email,
110
  "user_uid": user.uid,
111
- "is_admin": custom_claims.get('admin', False) or user_doc.get('is_admin') or False
112
  })
113
  st.rerun()
114
  except Exception as e:
@@ -121,7 +141,7 @@ def main():
121
  new_password = st.text_input("πŸ” New Password", type="password")
122
  if st.form_submit_button("🌟 Register"):
123
  try:
124
- user = auth.create_user(email=new_email, password=new_password)
125
  db.collection("users").document(user.uid).set({
126
  "email": new_email,
127
  "is_admin": False,
@@ -132,7 +152,7 @@ def main():
132
  st.error(f"⚠️ Registration failed: {str(e)}")
133
  return
134
 
135
- # Main Application
136
  st.markdown(f"""
137
  <div class='header'>
138
  <h1>πŸ“‹ To-Do List Management System</h1>
@@ -185,7 +205,7 @@ def main():
185
  st.info("🌟 All tasks are up to date!")
186
  st.session_state.first_login = False
187
 
188
- # Navigation
189
  menu_items = ["🏠 Dashboard", "πŸ“₯ Task Entry", "πŸ‘€ Task Explorer", "✏️ Edit Tasks", "βš™οΈ Settings"]
190
  if st.session_state.is_admin:
191
  menu_items.insert(3, "πŸ—οΈ Project Management")
@@ -330,7 +350,7 @@ def main():
330
  else:
331
  st.info("πŸ“­ No tasks to edit")
332
 
333
- # Project Management
334
  elif menu == "πŸ—οΈ Project Management" and st.session_state.is_admin:
335
  st.subheader("πŸ—οΈ Project Management")
336
  projects = [p.id for p in db.collection("projects").stream()]
 
2
  from datetime import datetime
3
  import pandas as pd
4
  import plotly.express as px
5
+ import firebase_admin
6
+ from firebase_admin import credentials, firestore, auth, exceptions
7
 
8
  # Configure page first
9
  st.set_page_config(
 
13
  menu_items={
14
  'Get Help': 'https://github.com',
15
  'Report a bug': "https://github.com",
16
+ 'About': "# Task Management System v4.0"
17
  }
18
  )
19
 
20
  # Custom CSS for enhanced UI
21
  st.markdown("""
22
  <style>
 
23
  .main .block-container {
24
  padding-top: 1.5rem;
25
  max-width: 1400px;
26
  }
 
27
  .header {
28
  background: linear-gradient(135deg, #2c3e50, #3498db);
29
  color: white;
 
32
  margin-bottom: 2rem;
33
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
34
  }
 
35
  .status-badge {
36
  padding: 6px 14px;
37
  border-radius: 20px;
 
40
  align-items: center;
41
  gap: 8px;
42
  }
 
43
  .pending { background: #fff3cd; color: #856404; }
44
  .in-progress { background: #cce5ff; color: #004085; }
45
  .completed { background: #d4edda; color: #155724; }
46
+ .progress-container {
47
+ background: #f0f0f0;
48
+ border-radius: 10px;
49
+ height: 10px;
50
+ overflow: hidden;
51
+ }
52
+ .progress-bar {
53
+ height: 100%;
54
+ background: #3498db;
55
+ transition: width 0.3s ease;
56
+ }
57
  </style>
58
  """, unsafe_allow_html=True)
59
 
60
  def initialize_firebase():
 
 
 
61
  if not firebase_admin._apps:
62
  cred = credentials.Certificate("firebase_credentials.json")
63
  firebase_admin.initialize_app(cred)
64
  return firestore.client(), auth
65
 
66
+ def create_default_admin(auth, db):
67
  try:
68
  admin_email = "admin@example.com"
69
  try:
70
+ admin_user = auth.get_user_by_email(admin_email)
71
+ admin_ref = db.collection("users").document(admin_user.uid)
72
+ if not admin_ref.get().exists:
73
+ admin_ref.set({
74
+ "email": admin_email,
75
+ "is_admin": True,
76
+ "created_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
77
+ })
78
  except auth.UserNotFoundError:
79
  admin_user = auth.create_user(
80
  email=admin_email,
 
82
  display_name="Admin"
83
  )
84
  auth.set_custom_user_claims(admin_user.uid, {'admin': True})
85
+ db.collection("users").document(admin_user.uid).set({
86
+ "email": admin_email,
87
+ "is_admin": True,
88
+ "created_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
89
+ })
90
  except Exception as e:
91
  st.error(f"Admin setup error: {str(e)}")
92
 
93
  def main():
94
  # Initialize Firebase
95
+ db, firebase_auth = initialize_firebase()
96
+ create_default_admin(firebase_auth, db)
97
 
98
  # Session State Management
99
  if "authenticated" not in st.session_state:
 
117
  password = st.text_input("πŸ”’ Password", type="password")
118
  if st.form_submit_button("πŸš€ Login"):
119
  try:
120
+ user = firebase_auth.get_user_by_email(email)
121
  user_doc = db.collection("users").document(user.uid).get()
 
122
 
123
+ is_admin = user.custom_claims.get('admin', False) if user.custom_claims else False
124
+ if user_doc.exists:
125
+ is_admin = user_doc.to_dict().get('is_admin', is_admin)
126
+
127
  st.session_state.update({
128
  "authenticated": True,
129
  "email": user.email,
130
  "user_uid": user.uid,
131
+ "is_admin": is_admin
132
  })
133
  st.rerun()
134
  except Exception as e:
 
141
  new_password = st.text_input("πŸ” New Password", type="password")
142
  if st.form_submit_button("🌟 Register"):
143
  try:
144
+ user = firebase_auth.create_user(email=new_email, password=new_password)
145
  db.collection("users").document(user.uid).set({
146
  "email": new_email,
147
  "is_admin": False,
 
152
  st.error(f"⚠️ Registration failed: {str(e)}")
153
  return
154
 
155
+ # Main Application Interface
156
  st.markdown(f"""
157
  <div class='header'>
158
  <h1>πŸ“‹ To-Do List Management System</h1>
 
205
  st.info("🌟 All tasks are up to date!")
206
  st.session_state.first_login = False
207
 
208
+ # Navigation Menu
209
  menu_items = ["🏠 Dashboard", "πŸ“₯ Task Entry", "πŸ‘€ Task Explorer", "✏️ Edit Tasks", "βš™οΈ Settings"]
210
  if st.session_state.is_admin:
211
  menu_items.insert(3, "πŸ—οΈ Project Management")
 
350
  else:
351
  st.info("πŸ“­ No tasks to edit")
352
 
353
+ # Project Management (Admin Only)
354
  elif menu == "πŸ—οΈ Project Management" and st.session_state.is_admin:
355
  st.subheader("πŸ—οΈ Project Management")
356
  projects = [p.id for p in db.collection("projects").stream()]