🔍 Code Extractor

function main_page

Maturity: 49

Renders the main navigation page for the FileCloud Data Processor application, providing authenticated users with access to various modules including document audit, controlled documents, settings, and reports.

File:
/tf/active/vicechatdev/datacapture_integrated.py
Lines:
4128 - 4213
Complexity:
moderate

Purpose

This function serves as the primary landing page and navigation hub for the FileCloud Data Processing Tool. It handles user authentication checks, displays user information in the sidebar, and presents a grid-based navigation interface with four main modules. The function manages session state for user context and module navigation, and provides logout functionality. It's designed to be used within a Streamlit application framework.

Source Code

def main_page():
    """Render the main application page with navigation options."""
    st.title("FileCloud Data Processor")
    
    # Application header and welcome message
    st.write("Welcome to the FileCloud Data Processing Tool.")
    
    # Check if user is authenticated
    if not st.session_state.get("authenticated", False):
        st.warning("Please log in to access the system.")
        return
    
    # Set user context for document system
    if 'user_info' in st.session_state:
        set_user_context(st.session_state['user_info'])
    
    # Display user information
    if 'user_info' in st.session_state:
        st.sidebar.write(f"Logged in as: {st.session_state['user_info'].get('username', 'Unknown User')}")
        st.sidebar.write(f"Role: {st.session_state['user_info'].get('role', 'Standard User')}")
        
        if st.sidebar.button("Logout"):
            st.session_state.clear()
            st.experimental_rerun()
    
    # Main navigation - using columns for a cleaner layout
    st.markdown("### Select a module to continue:")
    
    # Create a 2x2 grid of navigation options
    col1, col2 = st.columns(2)
    
    with col1:
        # Original document audit functionality
        doc_audit_card = """
        <div style="padding: 20px; border-radius: 10px; border: 1px solid #ddd; margin: 10px 0;">
            <h3 style="color: #2c3e50;">Document Audit</h3>
            <p>Perform document auditing tasks, manage processing jobs, and view audit results.</p>
        </div>
        """
        st.markdown(doc_audit_card, unsafe_allow_html=True)
        if st.button("Open Document Audit", key="btn_doc_audit"):
            st.session_state['current_module'] = 'document_audit'
            st.experimental_rerun()
    
    with col2:
        # Controlled document system
        if config.get('CONTROLLED_DOCS_ENABLED', False):
            controlled_doc_card = """
            <div style="padding: 20px; border-radius: 10px; border: 1px solid #ddd; margin: 10px 0;">
                <h3 style="color: #2c3e50;">Controlled Documents</h3>
                <p>Create, manage, and review controlled documents with full workflow support.</p>
            </div>
            """
            st.markdown(controlled_doc_card, unsafe_allow_html=True)
            if st.button("Open Controlled Documents", key="btn_controlled_docs"):
                st.session_state['current_module'] = 'controlled_docs'
                st.experimental_rerun()
    
    # Second row
    col3, col4 = st.columns(2)
    
    with col3:
        # Configuration settings
        settings_card = """
        <div style="padding: 20px; border-radius: 10px; border: 1px solid #ddd; margin: 10px 0;">
            <h3 style="color: #2c3e50;">Settings</h3>
            <p>Configure application settings, connections, and user preferences.</p>
        </div>
        """
        st.markdown(settings_card, unsafe_allow_html=True)
        if st.button("Open Settings", key="btn_settings"):
            st.session_state['current_module'] = 'settings'
            st.experimental_rerun()
    
    with col4:
        # Reports and analytics
        reports_card = """
        <div style="padding: 20px; border-radius: 10px; border: 1px solid #ddd; margin: 10px 0;">
            <h3 style="color: #2c3e50;">Reports & Analytics</h3>
            <p>Generate reports, view analytics, and export data.</p>
        </div>
        """
        st.markdown(reports_card, unsafe_allow_html=True)
        if st.button("Open Reports", key="btn_reports"):
            st.session_state['current_module'] = 'reports'
            st.experimental_rerun()

Return Value

This function returns None. It performs side effects by rendering UI components through Streamlit (st) and managing session state. If the user is not authenticated, it displays a warning and returns early without rendering the navigation options.

Dependencies

  • streamlit
  • config
  • controlled_doc_system.utils.context
  • controlled_doc_system.core.document_manager
  • neo4j
  • panel
  • holoviews
  • pandas
  • rdkit
  • numpy
  • langchain_community
  • langchain_openai
  • langchain
  • sentence_transformers
  • langchain_core

Required Imports

import streamlit as st
import config
from controlled_doc_system.utils.context import set_user_context

Conditional/Optional Imports

These imports are only needed under specific conditions:

from controlled_doc_system.ui.document_dashboard import render_document_dashboard

Condition: only if navigating to controlled documents module

Optional
from controlled_doc_system.ui.review_dashboard import render_review_dashboard

Condition: only if navigating to review dashboard within controlled documents

Optional
from controlled_doc_system.ui.document_form import render_document_form

Condition: only if creating/editing documents in controlled documents module

Optional
from controlled_doc_system.core.document_manager import initialize_document_system

Condition: only if controlled documents system needs initialization

Optional

Usage Example

import streamlit as st
import config
from controlled_doc_system.utils.context import set_user_context

# Initialize session state
if 'authenticated' not in st.session_state:
    st.session_state['authenticated'] = False

# Simulate user login
if st.session_state.get('authenticated'):
    st.session_state['user_info'] = {
        'username': 'john.doe',
        'role': 'Administrator'
    }

# Render the main page
main_page()

# Handle module navigation
if st.session_state.get('current_module') == 'document_audit':
    # Render document audit module
    pass
elif st.session_state.get('current_module') == 'controlled_docs':
    # Render controlled documents module
    pass
elif st.session_state.get('current_module') == 'settings':
    # Render settings module
    pass
elif st.session_state.get('current_module') == 'reports':
    # Render reports module
    pass

Best Practices

  • Always ensure st.session_state['authenticated'] is set before calling this function to control access
  • Initialize user_info in session state with 'username' and 'role' keys after successful authentication
  • Set config.CONTROLLED_DOCS_ENABLED to True/False to enable/disable the controlled documents module
  • Handle the 'current_module' session state value in the main application to route to appropriate module pages
  • The function uses st.experimental_rerun() which may be deprecated in newer Streamlit versions - consider using st.rerun() instead
  • Ensure proper cleanup of session state on logout to prevent data leakage between user sessions
  • The HTML cards use inline styles - consider moving to external CSS for better maintainability
  • User context should be set via set_user_context() before accessing controlled document features
  • Module navigation relies on session state persistence - ensure Streamlit session state is properly configured

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v7 80.5% similar

    Main entry point for a Streamlit-based FileCloud Data Processor application that handles authentication, session state management, and navigation between multiple modules including document audit, controlled documents, settings, and reports.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • function controlled_docs_navigation 67.0% similar

    Navigation controller for a Streamlit-based controlled documents module that manages document and review dashboards with URL parameter-based routing.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • function index 61.5% similar

    Flask route handler that renders the main landing page containing a form for the meeting minutes application.

    From: /tf/active/vicechatdev/leexi/app.py
  • function main_v10 56.6% similar

    Entry point function that initializes and serves the CDocs Panel web application with configurable port and debug mode options.

    From: /tf/active/vicechatdev/cdocs_panel_app.py
  • function main_v8 54.4% similar

    Main test function that validates SharePoint Graph API integration, tests the Graph client connection, and verifies FileCloud sync functionality.

    From: /tf/active/vicechatdev/SPFCsync/test_graph_client.py
← Back to Browse