Update app.py
Browse files
app.py
CHANGED
|
@@ -514,127 +514,127 @@ def main():
|
|
| 514 |
else:
|
| 515 |
st.info("π No tasks found. Start by adding new tasks!")
|
| 516 |
|
| 517 |
-
# Edit Tasks
|
| 518 |
-
elif menu == "βοΈ Edit Tasks":
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
with st.form(key="edit_form"):
|
| 526 |
-
col1, col2 = st.columns(2)
|
| 527 |
-
|
| 528 |
-
# Left Column
|
| 529 |
-
with col1:
|
| 530 |
-
new_task = st.text_area("Description", value=task['task'], height=100)
|
| 531 |
-
new_type = st.selectbox(
|
| 532 |
-
"Type",
|
| 533 |
-
["Design", "Procurement", "Construction", "Testing", "Other"],
|
| 534 |
-
index=["Design", "Procurement", "Construction", "Testing", "Other"].index(task['type'])
|
| 535 |
-
)
|
| 536 |
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
projects = [p.id for p in db.collection("projects").stream()] + ["Add New Project"]
|
| 540 |
-
new_project = st.selectbox(
|
| 541 |
-
"Project",
|
| 542 |
-
projects,
|
| 543 |
-
index=projects.index(task['project']) if task['project'] in projects else 0
|
| 544 |
-
)
|
| 545 |
-
if new_project == "Add New Project":
|
| 546 |
-
new_project = st.text_input("New Project Name")
|
| 547 |
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
</div>
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
"
|
| 624 |
-
|
| 625 |
-
"attachments": attachments,
|
| 626 |
-
"updated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 627 |
-
})
|
| 628 |
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
st.error(f"β Update failed: {str(e)}")
|
| 636 |
-
else:
|
| 637 |
-
st.info("π No tasks to edit")
|
| 638 |
|
| 639 |
|
| 640 |
# Project Management (Admin Only)
|
|
|
|
| 514 |
else:
|
| 515 |
st.info("π No tasks found. Start by adding new tasks!")
|
| 516 |
|
| 517 |
+
# Edit Tasks
|
| 518 |
+
elif menu == "βοΈ Edit Tasks":
|
| 519 |
+
tasks = get_tasks()
|
| 520 |
+
if tasks:
|
| 521 |
+
task_options = [f"{t['task']} ({t['project']})" for t in tasks]
|
| 522 |
+
selected = st.selectbox("Select Task", task_options)
|
| 523 |
+
task = next(t for t in tasks if f"{t['task']} ({t['project']})" == selected)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
|
| 525 |
+
with st.form(key="edit_form"):
|
| 526 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
|
| 528 |
+
# Left Column
|
| 529 |
+
with col1:
|
| 530 |
+
new_task = st.text_area("Description", value=task['task'], height=100)
|
| 531 |
+
new_type = st.selectbox(
|
| 532 |
+
"Type",
|
| 533 |
+
["Design", "Procurement", "Construction", "Testing", "Other"],
|
| 534 |
+
index=["Design", "Procurement", "Construction", "Testing", "Other"].index(task['type'])
|
| 535 |
+
)
|
| 536 |
+
|
| 537 |
+
# Right Column
|
| 538 |
+
with col2:
|
| 539 |
+
projects = [p.id for p in db.collection("projects").stream()] + ["Add New Project"]
|
| 540 |
+
new_project = st.selectbox(
|
| 541 |
+
"Project",
|
| 542 |
+
projects,
|
| 543 |
+
index=projects.index(task['project']) if task['project'] in projects else 0
|
| 544 |
+
)
|
| 545 |
+
if new_project == "Add New Project":
|
| 546 |
+
new_project = st.text_input("New Project Name")
|
| 547 |
+
|
| 548 |
+
new_status = st.selectbox(
|
| 549 |
+
"Status",
|
| 550 |
+
["Pending", "In Progress", "Completed"],
|
| 551 |
+
index=["Pending", "In Progress", "Completed"].index(task['status'])
|
| 552 |
+
)
|
| 553 |
+
new_date = st.date_input(
|
| 554 |
+
"Due Date",
|
| 555 |
+
value=datetime.strptime(task['date'], "%Y-%m-%d").date()
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
# Attachment Management
|
| 559 |
+
st.subheader("π Attachments")
|
| 560 |
+
attachments = task.get('attachments', []) # Safely get attachments
|
| 561 |
+
if attachments:
|
| 562 |
+
for att in attachments:
|
| 563 |
+
col1, col2 = st.columns([4,1])
|
| 564 |
+
with col1:
|
| 565 |
+
st.markdown(f"""
|
| 566 |
+
<div style="margin:0.5rem 0; padding:0.5rem; border-radius:5px; background:#f0f2f6;">
|
| 567 |
+
<div style="display:flex; align-items:center; gap:1rem;">
|
| 568 |
+
<span style="flex:1;">π {att['name']}</span>
|
| 569 |
+
<a href="{att['url']}" target="_blank" style="text-decoration:none;">
|
| 570 |
+
π View
|
| 571 |
+
</a>
|
| 572 |
+
</div>
|
| 573 |
+
<small style="color:#666;">{att['type']} | {att['size'] // 1024} KB</small>
|
| 574 |
</div>
|
| 575 |
+
""", unsafe_allow_html=True)
|
| 576 |
+
with col2:
|
| 577 |
+
if st.button("ποΈ", key=f"del_att_{att['name']}"):
|
| 578 |
+
# Remove attachment from task
|
| 579 |
+
updated_attachments = [a for a in attachments if a['name'] != att['name']]
|
| 580 |
+
db.collection("tasks").document(task['id']).update({
|
| 581 |
+
"attachments": updated_attachments
|
| 582 |
+
})
|
| 583 |
+
st.rerun()
|
| 584 |
+
|
| 585 |
+
# New Attachments
|
| 586 |
+
new_attachments = st.file_uploader(
|
| 587 |
+
"Add New Attachments",
|
| 588 |
+
type=["pdf", "docx", "xlsx", "png", "jpg", "jpeg"],
|
| 589 |
+
accept_multiple_files=True,
|
| 590 |
+
help="Upload new files (max 10MB each)"
|
| 591 |
+
)
|
| 592 |
+
|
| 593 |
+
# Submit Button
|
| 594 |
+
submitted = st.form_submit_button("πΎ Save Changes")
|
| 595 |
+
|
| 596 |
+
if submitted:
|
| 597 |
+
try:
|
| 598 |
+
# Process new attachments
|
| 599 |
+
if new_attachments:
|
| 600 |
+
for file in new_attachments:
|
| 601 |
+
if file.size > 10 * 1024 * 1024: # 10MB limit
|
| 602 |
+
st.error(f"β File {file.name} exceeds 10MB limit")
|
| 603 |
+
st.stop()
|
| 604 |
+
|
| 605 |
+
result = cloudinary.uploader.upload(
|
| 606 |
+
file,
|
| 607 |
+
folder=f"attachments/{st.session_state.user_uid}/",
|
| 608 |
+
resource_type="auto"
|
| 609 |
+
)
|
| 610 |
|
| 611 |
+
attachments.append({
|
| 612 |
+
"name": file.name,
|
| 613 |
+
"url": result['secure_url'],
|
| 614 |
+
"type": file.type,
|
| 615 |
+
"size": file.size
|
| 616 |
+
})
|
| 617 |
+
|
| 618 |
+
# Update task
|
| 619 |
+
db.collection("tasks").document(task['id']).update({
|
| 620 |
+
"task": new_task,
|
| 621 |
+
"type": new_type,
|
| 622 |
+
"project": new_project,
|
| 623 |
+
"status": new_status,
|
| 624 |
+
"date": str(new_date),
|
| 625 |
+
"attachments": attachments,
|
| 626 |
+
"updated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 627 |
+
})
|
| 628 |
+
|
| 629 |
+
st.success("β
Task updated successfully!")
|
| 630 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
| 631 |
|
| 632 |
+
except cloudinary.exceptions.Error as e:
|
| 633 |
+
st.error(f"β Cloudinary upload failed: {str(e)}")
|
| 634 |
+
except Exception as e:
|
| 635 |
+
st.error(f"β Update failed: {str(e)}")
|
| 636 |
+
else:
|
| 637 |
+
st.info("π No tasks to edit")
|
|
|
|
|
|
|
|
|
|
| 638 |
|
| 639 |
|
| 640 |
# Project Management (Admin Only)
|