🔍 Code Extractor

class CDocsApp

Maturity: 51

Panel-based web application class for the CDocs Controlled Document System that provides a complete UI with navigation, authentication, and document management features.

File:
/tf/active/vicechatdev/cdocs_panel_app.py
Lines:
57 - 132
Complexity:
moderate

Purpose

CDocsApp serves as the main application container for the CDocs Controlled Document System. It orchestrates the entire user interface including header, navigation sidebar, main content area, and footer. The class manages user authentication state, navigation between different views (documents, reviews, approvals), and provides a cohesive Panel-based web application for controlled document management. It integrates with AuthManager for user authentication and various view components for displaying document-related information.

Source Code

class CDocsApp:
    """
    Panel application for the CDocs Controlled Document System.
    
    This class provides a complete Panel application with navigation,
    user authentication, and all document management features.
    """
    
    def __init__(self):
        """Initialize the CDocs application."""
        # State variables
        self.current_view = None
        self.current_document_id = None
        self.auth_manager = AuthManager()
        self.user = None
        self.is_authenticated = False
        
        # Build the UI
        self._build_ui()
    
    def _build_ui(self):
        """Build the main UI components."""
        # Header
        self.header = pn.Row(
            pn.pane.Markdown("# Controlled Document System"),
            pn.layout.HSpacer(),
            self.auth_manager.get_auth_widget(),
            width=800
        )
        
        # Sidebar navigation
        self.nav_menu = pn.Column(
            pn.pane.Markdown("### Navigation"),
            pn.widgets.Button(name="Documents", button_type="primary"),
            pn.widgets.Button(name="My Reviews", button_type="default"),
            pn.widgets.Button(name="My Approvals", button_type="default"),
            width=200
        )
        
        # Main content area
        self.content_area = pn.Column(
            pn.pane.Markdown("## Welcome to the Controlled Document System"),
            pn.pane.Markdown("Please select an option from the navigation menu."),
            width=600
        )
        
        # Footer
        self.footer = pn.Row(
            pn.pane.Markdown(f"CDocs System v{self._get_version()} | © 2025"),
            pn.layout.HSpacer(),
            pn.pane.Markdown("Last updated: " + datetime.now().strftime("%Y-%m-%d %H:%M")),
            width=800
        )
        
        # Main layout
        self.layout = pn.Column(
            self.header,
            pn.Row(
                self.nav_menu,
                pn.layout.HSpacer(),
                self.content_area
            ),
            self.footer
        )
    
    def _get_version(self):
        """Get the current CDocs version."""
        try:
            from CDocs import __version__
            return __version__
        except ImportError:
            return "0.1.0"
    
    def get_app(self):
        """Get the Panel application."""
        return self.layout

Parameters

Name Type Default Kind
bases - -

Parameter Details

__init__: The constructor takes no parameters. It initializes all state variables (current_view, current_document_id, auth_manager, user, is_authenticated) and builds the complete UI by calling _build_ui().

Return Value

Instantiation returns a CDocsApp object with a fully constructed Panel layout. The get_app() method returns a Panel Column layout object that can be served as a web application. The _get_version() method returns a string representing the version number (either from CDocs.__version__ or '0.1.0' as fallback).

Class Interface

Methods

__init__(self) -> None

Purpose: Initialize the CDocs application with default state and build the complete UI

Returns: None - initializes the instance with state variables and UI components

_build_ui(self) -> None

Purpose: Build all main UI components including header, navigation menu, content area, footer, and main layout

Returns: None - creates and assigns UI components to instance attributes

_get_version(self) -> str

Purpose: Retrieve the current CDocs version number from the package or return default version

Returns: String representing version number (from CDocs.__version__ or '0.1.0' as fallback)

get_app(self) -> pn.Column

Purpose: Get the complete Panel application layout for serving or embedding

Returns: Panel Column object containing the entire application layout

Attributes

Name Type Description Scope
current_view Any | None Tracks the currently displayed view/page in the application (initially None) instance
current_document_id Any | None Stores the ID of the currently selected/viewed document (initially None) instance
auth_manager AuthManager Instance of AuthManager class that handles user authentication functionality instance
user Any | None Stores the currently authenticated user object or None if not authenticated instance
is_authenticated bool Boolean flag indicating whether a user is currently authenticated (initially False) instance
header pn.Row Panel Row containing the application header with title and authentication widget instance
nav_menu pn.Column Panel Column containing navigation buttons for Documents, My Reviews, and My Approvals instance
content_area pn.Column Panel Column serving as the main content display area for different views instance
footer pn.Row Panel Row containing version information and last updated timestamp instance
layout pn.Column Main Panel Column layout combining header, navigation, content area, and footer instance

Dependencies

  • panel
  • param
  • pandas
  • os
  • sys
  • logging
  • datetime
  • argparse
  • CDocs

Required Imports

import panel as pn
import param
import pandas as pd
import os
import sys
import logging
from datetime import datetime
import argparse
from CDocs.ui.components import DocumentListView
from CDocs.ui.components import DocumentDetailView
from CDocs.ui.components import ReviewListView
from CDocs.ui.components import ApprovalListView
from CDocs.ui.auth import AuthManager
from CDocs.initialize_system import initialize_system
from CDocs import __version__

Conditional/Optional Imports

These imports are only needed under specific conditions:

from CDocs import __version__

Condition: Used in _get_version() method to retrieve version number; falls back to '0.1.0' if import fails

Optional

Usage Example

import panel as pn
from CDocs.ui.app import CDocsApp

# Initialize the application
app = CDocsApp()

# Get the Panel layout for serving
layout = app.get_app()

# Serve the application
pn.serve(layout, port=5006, show=True)

# Or use in a notebook
layout.servable()

# Access application state
print(f"Authenticated: {app.is_authenticated}")
print(f"Current user: {app.user}")
print(f"Current view: {app.current_view}")

Best Practices

  • Instantiate CDocsApp only once per application session to avoid duplicate UI components
  • Use get_app() method to retrieve the Panel layout for serving or embedding
  • The class automatically builds UI on instantiation, so no additional setup is required after creating an instance
  • State variables (current_view, current_document_id, user, is_authenticated) track application state and should be updated when navigation or authentication changes occur
  • The auth_manager attribute provides access to authentication functionality through the AuthManager instance
  • Navigation buttons are created but event handlers need to be attached separately to make them functional
  • The layout uses fixed widths (800px for header/footer, 200px for nav, 600px for content) which may need adjustment for responsive design
  • The footer displays current timestamp at initialization; consider updating it dynamically if the app runs for extended periods
  • Error handling in _get_version() ensures graceful fallback if CDocs version cannot be imported

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ControlledDocApp 89.1% similar

    A standalone Panel web application class that provides a complete controlled document management system with user authentication, navigation, and document lifecycle management features.

    From: /tf/active/vicechatdev/panel_app.py
  • class ControlledDocumentApp 76.0% similar

    Main application class for the Controlled Document Management System. This class initializes all components and provides the main Panel interface for the application. It is designed to be served via `panel serve` command and integrates with the existing datacapture application.

    From: /tf/active/vicechatdev/CDocs/main.py
  • function main_v19 68.3% 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
  • class ControlledDocumentFlaskApp 61.6% similar

    Main Flask application class for Controlled Document Management System.

    From: /tf/active/vicechatdev/CDocs/main_flask.py
  • class DocumentAccessControls 61.6% similar

    A Panel-based UI component that manages document access controls, providing view and edit buttons with role-based permissions and status indicators.

    From: /tf/active/vicechatdev/CDocs/ui/components/document_access_controls.py
← Back to Browse