cryogenic22 commited on
Commit
1cb9bbc
·
verified ·
1 Parent(s): 16d7537

Update components/collection_manager.py

Browse files
Files changed (1) hide show
  1. components/collection_manager.py +72 -0
components/collection_manager.py CHANGED
@@ -1,5 +1,77 @@
1
  # components/collection_manager.py
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def display_enhanced_collections():
4
  """Enhanced collections management interface."""
5
  col1, col2 = st.columns([1, 2])
 
1
  # components/collection_manager.py
2
 
3
+
4
+ def show_collection_creation_dialog():
5
+ """Show dialog for creating a new collection."""
6
+ with st.form("create_collection"):
7
+ st.subheader("Create New Collection")
8
+ name = st.text_input("Collection Name", key="new_col_name")
9
+ description = st.text_area("Description", key="new_col_desc")
10
+
11
+ # Document selection
12
+ existing_docs = get_all_documents(st.session_state.db_conn)
13
+ if existing_docs:
14
+ st.subheader("Add Existing Documents")
15
+ selected_docs = st.multiselect(
16
+ "Select documents to add",
17
+ options=[doc['id'] for doc in existing_docs],
18
+ format_func=lambda x: next(doc['name'] for doc in existing_docs if doc['id'] == x)
19
+ )
20
+
21
+ submitted = st.form_submit_button("Create Collection")
22
+
23
+ if submitted and name:
24
+ collection_id = create_collection(st.session_state.db_conn, name, description)
25
+ if collection_id and selected_docs:
26
+ for doc_id in selected_docs:
27
+ add_document_to_collection(st.session_state.db_conn, doc_id, collection_id)
28
+ st.success(f"Collection '{name}' created!")
29
+ st.rerun()
30
+
31
+ def show_collection_details(collection):
32
+ """Show collection details and management interface."""
33
+ st.markdown(f"### 📁 {collection['name']}")
34
+
35
+ # Collection Analytics
36
+ col1, col2 = st.columns(2)
37
+ with col1:
38
+ st.metric("Total Documents", collection['doc_count'])
39
+ with col2:
40
+ st.metric("Last Updated", collection['last_updated'])
41
+
42
+ # Document List
43
+ documents = get_collection_documents(st.session_state.db_conn, collection['id'])
44
+ if documents:
45
+ with st.expander("Manage Documents", expanded=True):
46
+ selected_docs = []
47
+ for doc in documents:
48
+ col1, col2, col3 = st.columns([0.1, 0.7, 0.2])
49
+ with col1:
50
+ selected = st.checkbox("", key=f"select_{doc['id']}")
51
+ if selected:
52
+ selected_docs.append(doc['id'])
53
+ with col2:
54
+ st.write(f"📄 {doc['name']}")
55
+ with col3:
56
+ if st.button("Preview", key=f"preview_{doc['id']}"):
57
+ show_document_preview(doc)
58
+
59
+ if selected_docs:
60
+ if st.button("Remove Selected", key="remove_selected"):
61
+ for doc_id in selected_docs:
62
+ remove_from_collection(st.session_state.db_conn, doc_id, collection['id'])
63
+ st.rerun()
64
+
65
+ def show_document_preview(document):
66
+ """Show document preview in a modal."""
67
+ with st.expander(f"Preview: {document['name']}", expanded=True):
68
+ st.text_area(
69
+ "Content",
70
+ value=document['content'][:1000] + "..." if len(document['content']) > 1000 else document['content'],
71
+ height=300,
72
+ disabled=True
73
+ )
74
+
75
  def display_enhanced_collections():
76
  """Enhanced collections management interface."""
77
  col1, col2 = st.columns([1, 2])