arif670 commited on
Commit
497ec38
Β·
verified Β·
1 Parent(s): 91d3ac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -112
app.py CHANGED
@@ -516,123 +516,125 @@ def main():
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
- if task['attachments']:
561
- for att in task['attachments']:
562
- col1, col2 = st.columns([4,1])
563
- with col1:
564
- st.markdown(f"""
565
- <div style="margin:0.5rem 0; padding:0.5rem; border-radius:5px; background:#f0f2f6;">
566
- <div style="display:flex; align-items:center; gap:1rem;">
567
- <span style="flex:1;">πŸ“„ {att['name']}</span>
568
- <a href="{att['url']}" target="_blank" style="text-decoration:none;">
569
- πŸ”— View
570
- </a>
571
- </div>
572
- <small style="color:#666;">{att['type']} | {att['size'] // 1024} KB</small>
573
- </div>
574
- """, unsafe_allow_html=True)
575
- with col2:
576
- if st.button("πŸ—‘οΈ", key=f"del_att_{att['name']}"):
577
- # Remove attachment from task
578
- updated_attachments = [a for a in task['attachments'] if a['name'] != att['name']]
579
- db.collection("tasks").document(task['id']).update({
580
- "attachments": updated_attachments
581
- })
582
- st.rerun()
583
-
584
- # New Attachments
585
- new_attachments = st.file_uploader(
586
- "Add New Attachments",
587
- type=["pdf", "docx", "xlsx", "png", "jpg", "jpeg"],
588
- accept_multiple_files=True,
589
- help="Upload new files (max 10MB each)"
590
  )
 
 
591
 
592
- # Submit Button
593
- if st.form_submit_button("πŸ’Ύ Save Changes"):
594
- try:
595
- # Process new attachments
596
- attachments = task.get('attachments', [])
597
- if new_attachments:
598
- for file in new_attachments:
599
- if file.size > 10 * 1024 * 1024: # 10MB limit
600
- st.error(f"❌ File {file.name} exceeds 10MB limit")
601
- st.stop()
602
-
603
- result = cloudinary.uploader.upload(
604
- file,
605
- folder=f"attachments/{st.session_state.user_uid}/",
606
- resource_type="auto"
607
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
 
609
- attachments.append({
610
- "name": file.name,
611
- "url": result['secure_url'],
612
- "type": file.type,
613
- "size": file.size
614
- })
615
-
616
- # Update task
617
- db.collection("tasks").document(task['id']).update({
618
- "task": new_task,
619
- "type": new_type,
620
- "project": new_project,
621
- "status": new_status,
622
- "date": str(new_date),
623
- "attachments": attachments,
624
- "updated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
625
- })
626
-
627
- st.success("βœ… Task updated successfully!")
628
- st.rerun()
629
 
630
- except cloudinary.exceptions.Error as e:
631
- st.error(f"❌ Cloudinary upload failed: {str(e)}")
632
- except Exception as e:
633
- st.error(f"❌ Update failed: {str(e)}")
634
- else:
635
- st.info("πŸ“­ No tasks to edit")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
 
637
  # Project Management (Admin Only)
638
  elif menu == "πŸ—οΈ Project Management" and st.session_state.is_admin:
 
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
  # Project Management (Admin Only)
640
  elif menu == "πŸ—οΈ Project Management" and st.session_state.is_admin: