arif670 commited on
Commit
ca3cafc
Β·
verified Β·
1 Parent(s): 6949d80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -39
app.py CHANGED
@@ -95,42 +95,50 @@ st.sidebar.title(f"Welcome, {st.session_state['email']}")
95
  menu = st.sidebar.radio("Go to", ["Dashboard View", "Task Entry", "View Tasks by Status"])
96
  email = st.session_state['email']
97
 
98
- if menu == "View Tasks by Status":
99
- st.subheader("πŸ“‚ View Tasks by Status")
100
- statuses = ["Pending", "In Progress", "Completed"]
101
- for status in statuses:
102
- st.subheader(f"πŸ“Œ {status} Tasks")
103
- tasks_ref = db.collection("tasks").where(filter=firestore.FieldFilter("user", "==", email)).where(filter=firestore.FieldFilter("status", "==", status))
104
- tasks = [task.to_dict() for task in tasks_ref.stream()]
105
- if tasks:
106
- df = pd.DataFrame(tasks)
107
- st.dataframe(df[['task', 'type', 'project', 'status', 'date']].rename(columns={
108
- 'task': 'Task', 'type': 'Type', 'project': 'Project', 'status': 'Status', 'date': 'Date'
109
- }))
110
-
111
- # Add task editing feature with unique keys
112
- for index, row in df.iterrows():
113
- with st.expander(f"Edit Task: {row['task']}"):
114
- new_status = st.selectbox("Update Status", ["Pending", "In Progress", "Completed"],
115
- index=["Pending", "In Progress", "Completed"].index(row['status']),
116
- key=f"status_{index}")
117
- new_task_desc = st.text_input("Update Task Description", row['task'], key=f"task_{index}")
118
- new_type = st.selectbox("Update Type", ["Design", "Procurement", "Construction", "Testing", "Other"],
119
- index=["Design", "Procurement", "Construction", "Testing", "Other"].index(row['type']),
120
- key=f"type_{index}")
121
- new_project = st.text_input("Update Project", row['project'], key=f"project_{index}")
122
- if st.button("Save Changes", key=f"update_{index}"):
123
- db.collection("tasks").document(row['task']).update({
124
- "task": new_task_desc,
125
- "type": new_type,
126
- "project": new_project,
127
- "status": new_status
128
- })
129
- st.success("Task Updated Successfully!")
130
- st.rerun()
131
-
132
- # Button to download PDF
133
- pdf_data = generate_pdf(df)
134
- st.download_button(label="Download Report", data=pdf_data, file_name="task_report.pdf", mime="application/pdf")
135
- else:
136
- st.info("No tasks found.")
 
 
 
 
 
 
 
 
 
95
  menu = st.sidebar.radio("Go to", ["Dashboard View", "Task Entry", "View Tasks by Status"])
96
  email = st.session_state['email']
97
 
98
+ if menu == "Dashboard View":
99
+ st.title("πŸ“Š Dashboard Overview")
100
+ tasks_ref = db.collection("tasks").where(filter=firestore.FieldFilter("user", "==", email))
101
+ tasks = [task.to_dict() for task in tasks_ref.stream()]
102
+ df = pd.DataFrame(tasks) if tasks else pd.DataFrame()
103
+
104
+ if not df.empty and "status" in df.columns:
105
+ col1, col2 = st.columns(2)
106
+ col1.metric("Total Tasks", len(df))
107
+ col1.metric("Pending Tasks", len(df[df['status'] == "Pending"]))
108
+ col2.metric("In Progress Tasks", len(df[df['status'] == "In Progress"]))
109
+ col2.metric("Completed Tasks", len(df[df['status'] == "Completed"]))
110
+
111
+ fig = px.pie(df, names='status', title='Task Status Distribution')
112
+ st.plotly_chart(fig)
113
+ else:
114
+ st.warning("No tasks found for the user.")
115
+
116
+ elif menu == "Task Entry":
117
+ st.title("πŸ“ Add New Task")
118
+ projects_ref = db.collection("projects")
119
+ projects = [proj.id for proj in projects_ref.stream()]
120
+ projects.append("Add New Project")
121
+
122
+ with st.form("task_form"):
123
+ task = st.text_input("Task Description:")
124
+ task_type = st.selectbox("Task Type:", ["Design", "Procurement", "Construction", "Testing", "Other"])
125
+ selected_project = st.selectbox("Project Name:", projects)
126
+ if selected_project == "Add New Project":
127
+ new_project = st.text_input("Enter New Project Name:")
128
+ if new_project:
129
+ db.collection("projects").document(new_project).set({"created_by": email})
130
+ selected_project = new_project
131
+ status = st.selectbox("Status:", ["Pending", "In Progress", "Completed"])
132
+ date = st.date_input("Task Date:")
133
+ submit = st.form_submit_button("Add Task")
134
+ if submit and task:
135
+ db.collection("tasks").add({
136
+ "user": email,
137
+ "task": task,
138
+ "type": task_type,
139
+ "project": selected_project,
140
+ "status": status,
141
+ "date": str(date)
142
+ })
143
+ st.success("Task Added Successfully!")
144
+ st.rerun()