Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -13091,8 +13091,130 @@ def page_ppm_activities():
|
|
| 13091 |
st.error("β οΈ Template name required")
|
| 13092 |
|
| 13093 |
with cb_tabs[1]:
|
| 13094 |
-
st.markdown("#### βοΈ Edit Template")
|
| 13095 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13096 |
|
| 13097 |
with cb_tabs[2]:
|
| 13098 |
st.markdown("#### βΉοΈ Schedule Configuration")
|
|
@@ -13599,23 +13721,35 @@ def page_cs():
|
|
| 13599 |
st.caption("Enroll multiple assets at once with the same template and schedule. Optionally stagger dates across assets.")
|
| 13600 |
|
| 13601 |
st.markdown("#### Step 1: Filter & Select Assets")
|
| 13602 |
-
c1, c2
|
| 13603 |
with c1:
|
| 13604 |
-
bulk_dept = st.selectbox("Department", ["
|
| 13605 |
with c2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13606 |
bulk_bldg = st.selectbox("Building", ["All"] + sorted(df["location_building"].dropna().unique().tolist()), key="bulk_bldg")
|
| 13607 |
-
with
|
| 13608 |
bulk_status = st.selectbox("Enrollment Status", ["All", "Enrolled", "Not Enrolled"], key="bulk_status")
|
| 13609 |
-
with
|
| 13610 |
-
bulk_search = st.text_input("π Search", key="bulk_search", placeholder="
|
| 13611 |
|
| 13612 |
filtered = df.copy()
|
| 13613 |
-
if bulk_dept != "
|
|
|
|
|
|
|
|
|
|
| 13614 |
if bulk_bldg != "All": filtered = filtered[filtered["location_building"] == bulk_bldg]
|
| 13615 |
if bulk_status == "Enrolled": filtered = filtered[filtered["checklist_clean"].notna()]
|
| 13616 |
elif bulk_status == "Not Enrolled": filtered = filtered[filtered["checklist_clean"].isna()]
|
| 13617 |
if bulk_search:
|
| 13618 |
-
filtered = filtered[filtered["name"].str.contains(bulk_search, case=False, na=False)
|
| 13619 |
|
| 13620 |
st.caption(f"π {len(filtered)} assets match filters")
|
| 13621 |
|
|
|
|
| 13091 |
st.error("β οΈ Template name required")
|
| 13092 |
|
| 13093 |
with cb_tabs[1]:
|
| 13094 |
+
st.markdown("#### βοΈ Edit Existing Template")
|
| 13095 |
+
|
| 13096 |
+
all_templates = safe_supabase_query(lambda: supabase.table("ppm_checklist_templates").select("*").order("created_at", desc=True).execute(), error_prefix="All templates")
|
| 13097 |
+
|
| 13098 |
+
if all_templates and all_templates.data and len(all_templates.data) > 0:
|
| 13099 |
+
template_names_list = [t.get("template_name","") for t in all_templates.data]
|
| 13100 |
+
edit_template_name = st.selectbox("Select Template to Edit", template_names_list, key="edit_template")
|
| 13101 |
+
|
| 13102 |
+
if edit_template_name:
|
| 13103 |
+
edit_template = next((t for t in all_templates.data if t.get("template_name") == edit_template_name), None)
|
| 13104 |
+
|
| 13105 |
+
if edit_template:
|
| 13106 |
+
st.markdown(f"**Editing:** {edit_template.get('template_name')} | **Standard:** {edit_template.get('international_standard','Custom')}")
|
| 13107 |
+
|
| 13108 |
+
c1, c2, c3 = st.columns(3)
|
| 13109 |
+
with c1:
|
| 13110 |
+
new_name = st.text_input("Template Name", value=edit_template.get("template_name",""), key="edit_tpl_name")
|
| 13111 |
+
with c2:
|
| 13112 |
+
desc_parts = edit_template.get("description","").split("|")
|
| 13113 |
+
period_val = desc_parts[0].replace("Period:","").strip() if len(desc_parts) > 0 else "Monthly"
|
| 13114 |
+
new_period = st.selectbox("Default Frequency", ["Daily","Weekly","Bi-Weekly","Monthly","Quarterly","Half-Yearly","Yearly"],
|
| 13115 |
+
index=["Daily","Weekly","Bi-Weekly","Monthly","Quarterly","Half-Yearly","Yearly"].index(period_val) if period_val in ["Daily","Weekly","Bi-Weekly","Monthly","Quarterly","Half-Yearly","Yearly"] else 3, key="edit_period")
|
| 13116 |
+
with c3:
|
| 13117 |
+
new_image = st.selectbox("Image Required", ["Yes","No"],
|
| 13118 |
+
index=0 if "Image: Yes" in edit_template.get("description","") else 1, key="edit_image")
|
| 13119 |
+
|
| 13120 |
+
c1, c2 = st.columns(2)
|
| 13121 |
+
with c1:
|
| 13122 |
+
time_val = desc_parts[1].replace("Time:","").replace("min","").strip() if len(desc_parts) > 1 else "30"
|
| 13123 |
+
new_time = st.number_input("Perform Time (min)", value=int(time_val) if time_val.isdigit() else 30, key="edit_time")
|
| 13124 |
+
with c2:
|
| 13125 |
+
buf_val = desc_parts[2].replace("Buffer:","").replace("days","").strip() if len(desc_parts) > 2 else "0"
|
| 13126 |
+
new_buffer = st.number_input("Buffer Days", value=int(buf_val) if buf_val.isdigit() else 0, key="edit_buffer")
|
| 13127 |
+
|
| 13128 |
+
new_standard = st.text_input("Standard Reference", value=edit_template.get("international_standard",""), key="edit_std")
|
| 13129 |
+
|
| 13130 |
+
st.info("π
Schedule dates are now configured during asset enrollment. Templates only define checklist items.")
|
| 13131 |
+
|
| 13132 |
+
st.markdown("---")
|
| 13133 |
+
st.markdown("### π Checklist Items")
|
| 13134 |
+
|
| 13135 |
+
existing_items = safe_supabase_query(lambda tid=edit_template["id"]: supabase.table("ppm_checklist_items").select("*").eq("template_id", tid).order("sort_order").execute(), error_prefix="Existing items")
|
| 13136 |
+
|
| 13137 |
+
if existing_items and existing_items.data:
|
| 13138 |
+
st.markdown("**Current Items (edit inline):**")
|
| 13139 |
+
for item in existing_items.data:
|
| 13140 |
+
c1, c2, c3, c4, c5 = st.columns([0.5, 3, 1.5, 1.5, 0.5])
|
| 13141 |
+
with c1:
|
| 13142 |
+
st.text_input("SNO", value=str(item.get("item_number","")), key=f"edit_sno_{item['id']}", label_visibility="collapsed")
|
| 13143 |
+
with c2:
|
| 13144 |
+
st.text_input("Description", value=item.get("description",""), key=f"edit_desc_{item['id']}", label_visibility="collapsed")
|
| 13145 |
+
with c3:
|
| 13146 |
+
st.selectbox("Type", ["yes_no","pass_fail","status","reading","text","section"],
|
| 13147 |
+
index=["yes_no","pass_fail","status","reading","text","section"].index(item.get("check_type","yes_no")) if item.get("check_type","yes_no") in ["yes_no","pass_fail","status","reading","text","section"] else 0,
|
| 13148 |
+
key=f"edit_type_{item['id']}", label_visibility="collapsed")
|
| 13149 |
+
with c4:
|
| 13150 |
+
st.text_input("Options", value=item.get("expected_value","") or "", key=f"edit_thresh_{item['id']}", label_visibility="collapsed")
|
| 13151 |
+
with c5:
|
| 13152 |
+
if st.button("ποΈ", key=f"del_item_{item['id']}", use_container_width=True):
|
| 13153 |
+
safe_supabase_query(lambda iid=item["id"]: supabase.table("ppm_checklist_items").delete().eq("id", iid).execute(), error_prefix="Delete item")
|
| 13154 |
+
st.rerun()
|
| 13155 |
+
|
| 13156 |
+
st.markdown("---")
|
| 13157 |
+
|
| 13158 |
+
st.markdown("**β Add New Item:**")
|
| 13159 |
+
c1, c2, c3, c4 = st.columns([1, 3, 2, 2])
|
| 13160 |
+
with c1:
|
| 13161 |
+
add_sno = st.number_input("SNO", min_value=1, value=len(existing_items.data)+1 if existing_items and existing_items.data else 1, key="edit_add_sno")
|
| 13162 |
+
with c2:
|
| 13163 |
+
add_desc = st.text_input("Description", key="edit_add_desc", placeholder="New checklist item...")
|
| 13164 |
+
with c3:
|
| 13165 |
+
add_type = st.selectbox("Type", ["yes_no","pass_fail","status","reading","text"], key="edit_add_type")
|
| 13166 |
+
with c4:
|
| 13167 |
+
add_thresh = st.text_input("Options", value="Yes/No", key="edit_add_thresh")
|
| 13168 |
+
|
| 13169 |
+
if st.button("β Add Item", key="edit_btn_add", use_container_width=True):
|
| 13170 |
+
if add_desc.strip():
|
| 13171 |
+
safe_supabase_query(lambda tid=edit_template["id"]: supabase.table("ppm_checklist_items").insert({
|
| 13172 |
+
"template_id": tid,
|
| 13173 |
+
"item_number": int(add_sno),
|
| 13174 |
+
"description": add_desc.strip(),
|
| 13175 |
+
"check_type": add_type,
|
| 13176 |
+
"expected_value": add_thresh,
|
| 13177 |
+
"sort_order": int(add_sno)
|
| 13178 |
+
}).execute(), error_prefix="Add item")
|
| 13179 |
+
st.success("β
Item added!")
|
| 13180 |
+
st.rerun()
|
| 13181 |
+
|
| 13182 |
+
st.markdown("---")
|
| 13183 |
+
|
| 13184 |
+
c1, c2, c3 = st.columns(3)
|
| 13185 |
+
with c1:
|
| 13186 |
+
if st.button("πΎ SAVE ALL CHANGES", use_container_width=True, type="primary"):
|
| 13187 |
+
# Update template
|
| 13188 |
+
safe_supabase_query(lambda tid=edit_template["id"]: supabase.table("ppm_checklist_templates").update({
|
| 13189 |
+
"template_name": new_name,
|
| 13190 |
+
"international_standard": new_standard,
|
| 13191 |
+
"description": f"Period: {new_period} | Time: {new_time}min | Buffer: {new_buffer}days | Image: {new_image}",
|
| 13192 |
+
"schedule_dates": None
|
| 13193 |
+
}).eq("id", tid).execute(), error_prefix="Update template")
|
| 13194 |
+
|
| 13195 |
+
# Update existing items
|
| 13196 |
+
for item in existing_items.data if existing_items and existing_items.data else []:
|
| 13197 |
+
safe_supabase_query(lambda iid=item["id"]: supabase.table("ppm_checklist_items").update({
|
| 13198 |
+
"item_number": int(st.session_state.get(f"edit_sno_{iid}", item.get("item_number",1)) or 1),
|
| 13199 |
+
"description": st.session_state.get(f"edit_desc_{iid}", item.get("description","")),
|
| 13200 |
+
"check_type": st.session_state.get(f"edit_type_{iid}", item.get("check_type","yes_no")),
|
| 13201 |
+
"expected_value": st.session_state.get(f"edit_thresh_{iid}", item.get("expected_value","") or "")
|
| 13202 |
+
}).eq("id", iid).execute(), error_prefix="Update items")
|
| 13203 |
+
|
| 13204 |
+
st.success("β
Template updated!")
|
| 13205 |
+
st.balloons()
|
| 13206 |
+
st.rerun()
|
| 13207 |
+
with c2:
|
| 13208 |
+
if st.button("οΏ½οΏ½οΏ½οΈ DELETE TEMPLATE", use_container_width=True):
|
| 13209 |
+
safe_supabase_query(lambda tid=edit_template["id"]: supabase.table("ppm_checklist_items").delete().eq("template_id", tid).execute(), error_prefix="Delete items")
|
| 13210 |
+
safe_supabase_query(lambda tid=edit_template["id"]: supabase.table("ppm_checklist_templates").delete().eq("id", tid).execute(), error_prefix="Delete template")
|
| 13211 |
+
st.warning("β
Template deleted!")
|
| 13212 |
+
st.rerun()
|
| 13213 |
+
with c3:
|
| 13214 |
+
if st.button("β CANCEL", use_container_width=True):
|
| 13215 |
+
st.rerun()
|
| 13216 |
+
else:
|
| 13217 |
+
st.info("No templates created yet. Create one in the 'Create Template' tab.")
|
| 13218 |
|
| 13219 |
with cb_tabs[2]:
|
| 13220 |
st.markdown("#### βΉοΈ Schedule Configuration")
|
|
|
|
| 13721 |
st.caption("Enroll multiple assets at once with the same template and schedule. Optionally stagger dates across assets.")
|
| 13722 |
|
| 13723 |
st.markdown("#### Step 1: Filter & Select Assets")
|
| 13724 |
+
c1, c2 = st.columns(2)
|
| 13725 |
with c1:
|
| 13726 |
+
bulk_dept = st.selectbox("Department*", ["Select Department..."] + sorted(df["dept_full"].dropna().unique().tolist()), key="bulk_dept")
|
| 13727 |
with c2:
|
| 13728 |
+
if bulk_dept != "Select Department...":
|
| 13729 |
+
dept_filtered = df[df["dept_full"] == bulk_dept]
|
| 13730 |
+
parent_assets = ["All"] + sorted(dept_filtered["parent_asset"].dropna().unique().tolist())
|
| 13731 |
+
else:
|
| 13732 |
+
parent_assets = ["All"]
|
| 13733 |
+
bulk_parent = st.selectbox("Parent Asset", parent_assets, key="bulk_parent")
|
| 13734 |
+
|
| 13735 |
+
c1, c2, c3 = st.columns(3)
|
| 13736 |
+
with c1:
|
| 13737 |
bulk_bldg = st.selectbox("Building", ["All"] + sorted(df["location_building"].dropna().unique().tolist()), key="bulk_bldg")
|
| 13738 |
+
with c2:
|
| 13739 |
bulk_status = st.selectbox("Enrollment Status", ["All", "Enrolled", "Not Enrolled"], key="bulk_status")
|
| 13740 |
+
with c3:
|
| 13741 |
+
bulk_search = st.text_input("π Search Sub-Asset", key="bulk_search", placeholder="Sub-asset name...")
|
| 13742 |
|
| 13743 |
filtered = df.copy()
|
| 13744 |
+
if bulk_dept != "Select Department...":
|
| 13745 |
+
filtered = filtered[filtered["dept_full"] == bulk_dept]
|
| 13746 |
+
if bulk_parent != "All" and bulk_parent != "Select Department...":
|
| 13747 |
+
filtered = filtered[filtered["parent_asset"] == bulk_parent]
|
| 13748 |
if bulk_bldg != "All": filtered = filtered[filtered["location_building"] == bulk_bldg]
|
| 13749 |
if bulk_status == "Enrolled": filtered = filtered[filtered["checklist_clean"].notna()]
|
| 13750 |
elif bulk_status == "Not Enrolled": filtered = filtered[filtered["checklist_clean"].isna()]
|
| 13751 |
if bulk_search:
|
| 13752 |
+
filtered = filtered[filtered["name"].str.contains(bulk_search, case=False, na=False)]
|
| 13753 |
|
| 13754 |
st.caption(f"π {len(filtered)} assets match filters")
|
| 13755 |
|