🔍 Code Extractor

function main_page

Maturity: 47

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 to the Streamlit application and modifying st.session_state for navigation and user context management.

Dependencies

  • streamlit
  • config

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.utils.context import set_user_context

Condition: Required when user_info exists in session_state to set document system context

Required (conditional)

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['authenticated']:
    st.session_state['user_info'] = {
        'username': 'john.doe',
        'role': 'Administrator'
    }

# Set configuration
config.CONTROLLED_DOCS_ENABLED = True

# Render the main page
main_page()

# Handle module navigation
if 'current_module' in st.session_state:
    if st.session_state['current_module'] == 'document_audit':
        # Load document audit module
        pass
    elif st.session_state['current_module'] == 'controlled_docs':
        # Load controlled documents module
        pass
    elif st.session_state['current_module'] == 'settings':
        # Load settings module
        pass
    elif st.session_state['current_module'] == 'reports':
        # Load reports module
        pass

Best Practices

  • Ensure st.session_state['authenticated'] is set to True before calling this function to allow access to modules
  • Always populate st.session_state['user_info'] with 'username' and 'role' keys after successful authentication
  • Set config.CONTROLLED_DOCS_ENABLED appropriately based on your application's feature requirements
  • Handle the 'current_module' session state value in your main application logic 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
  • Implement proper logout cleanup logic as the function clears all session state on logout
  • The HTML cards use inline styles - consider extracting to CSS for better maintainability
  • Ensure set_user_context() is properly implemented in your controlled document system before enabling that module

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v13 81.2% 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 index_v1 70.2% similar

    Flask route handler that renders the main application page with user session management, authentication checks, and document collection statistics.

    From: /tf/active/vicechatdev/docchat/app.py
  • function controlled_docs_navigation 67.7% 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 67.4% similar

    Flask route handler that serves as the main landing page for authenticated users, displaying their documents and text sections in a workspace interface.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function index_v6 61.7% 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
← Back to Browse