Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -842,11 +842,18 @@ def main():
|
|
| 842 |
except Exception as e:
|
| 843 |
st.error(f"Error creating document: {str(e)}")
|
| 844 |
|
|
|
|
| 845 |
elif selected_view == 'New Record':
|
| 846 |
-
# 🆕 New Record
|
| 847 |
st.markdown("#### Create a new document:")
|
|
|
|
| 848 |
if st.button("🤖 Insert Auto-Generated Record"):
|
| 849 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 850 |
if success:
|
| 851 |
st.success(message)
|
| 852 |
st.rerun()
|
|
@@ -854,16 +861,24 @@ def main():
|
|
| 854 |
st.error(message)
|
| 855 |
else:
|
| 856 |
new_id = st.text_input("ID", value=generate_unique_id(), key='new_id')
|
| 857 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 858 |
if st.button("➕ Create New Document"):
|
| 859 |
try:
|
| 860 |
new_doc = json.loads(new_doc_str)
|
| 861 |
-
new_doc['id'] = new_id #
|
| 862 |
success, message = insert_record(container, new_doc)
|
| 863 |
if success:
|
| 864 |
st.success(f"New document created with id: {new_doc['id']} 🎉")
|
| 865 |
st.session_state.selected_document_id = new_doc['id']
|
| 866 |
-
# Switch to 'Show as Edit and Save' mode
|
| 867 |
st.rerun()
|
| 868 |
else:
|
| 869 |
st.error(message)
|
|
|
|
| 842 |
except Exception as e:
|
| 843 |
st.error(f"Error creating document: {str(e)}")
|
| 844 |
|
| 845 |
+
#elif selected_view == 'New Record':
|
| 846 |
elif selected_view == 'New Record':
|
|
|
|
| 847 |
st.markdown("#### Create a new document:")
|
| 848 |
+
|
| 849 |
if st.button("🤖 Insert Auto-Generated Record"):
|
| 850 |
+
auto_doc = {
|
| 851 |
+
"id": generate_unique_id(),
|
| 852 |
+
"name": f"Auto-generated Record {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
|
| 853 |
+
"content": "This is an auto-generated record.",
|
| 854 |
+
"timestamp": datetime.now().isoformat()
|
| 855 |
+
}
|
| 856 |
+
success, message = save_or_clone_to_cosmos_db(container, document=auto_doc)
|
| 857 |
if success:
|
| 858 |
st.success(message)
|
| 859 |
st.rerun()
|
|
|
|
| 861 |
st.error(message)
|
| 862 |
else:
|
| 863 |
new_id = st.text_input("ID", value=generate_unique_id(), key='new_id')
|
| 864 |
+
default_doc = {
|
| 865 |
+
"id": new_id,
|
| 866 |
+
"name": "New Document",
|
| 867 |
+
"content": "",
|
| 868 |
+
"timestamp": datetime.now().isoformat()
|
| 869 |
+
}
|
| 870 |
+
new_doc_str = st.text_area("Document Content (in JSON format)",
|
| 871 |
+
value=json.dumps(default_doc, indent=2),
|
| 872 |
+
height=300)
|
| 873 |
+
|
| 874 |
if st.button("➕ Create New Document"):
|
| 875 |
try:
|
| 876 |
new_doc = json.loads(new_doc_str)
|
| 877 |
+
new_doc['id'] = new_id # Ensure ID matches input field
|
| 878 |
success, message = insert_record(container, new_doc)
|
| 879 |
if success:
|
| 880 |
st.success(f"New document created with id: {new_doc['id']} 🎉")
|
| 881 |
st.session_state.selected_document_id = new_doc['id']
|
|
|
|
| 882 |
st.rerun()
|
| 883 |
else:
|
| 884 |
st.error(message)
|