Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
dbbasic_design_system.py · 12.3 KB · 332 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | DBBasic Unified Design System - Bootstrap 5.3 |
| 4 | Shared HTML templates and styling for all DBBasic services |
| 5 | """ |
| 6 | |
| 7 | # Bootstrap 5.3.3 CDN links (latest stable version) |
| 8 | BOOTSTRAP_CSS = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" |
| 9 | BOOTSTRAP_JS = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" |
| 10 | |
| 11 | # DBBasic Brand Colors |
| 12 | BRAND_COLORS = { |
| 13 | "primary": "#0d6efd", # Bootstrap primary blue |
| 14 | "secondary": "#6c757d", # Bootstrap secondary gray |
| 15 | "success": "#198754", # Bootstrap success green |
| 16 | "info": "#0dcaf0", # Bootstrap info cyan |
| 17 | "warning": "#ffc107", # Bootstrap warning yellow |
| 18 | "danger": "#dc3545", # Bootstrap danger red |
| 19 | "light": "#f8f9fa", # Bootstrap light gray |
| 20 | "dark": "#212529", # Bootstrap dark gray |
| 21 | "dbbasic": "#667eea", # Custom DBBasic gradient start |
| 22 | "dbbasic_end": "#764ba2" # Custom DBBasic gradient end |
| 23 | } |
| 24 | |
| 25 | def get_base_html_template(title: str, service_name: str, port: int, active_nav: str = "") -> str: |
| 26 | """ |
| 27 | Generate the base HTML template with Bootstrap 5.3 and unified navigation |
| 28 | |
| 29 | Args: |
| 30 | title: Page title |
| 31 | service_name: Name of the current service (Data, AI Services, Monitor, etc.) |
| 32 | port: Port number of current service |
| 33 | active_nav: Which nav item should be marked as active |
| 34 | """ |
| 35 | return f"""<!DOCTYPE html> |
| 36 | <html lang="en"> |
| 37 | <head> |
| 38 | <meta charset="UTF-8"> |
| 39 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 40 | <title>{title}</title> |
| 41 | |
| 42 | <!-- Bootstrap 5.3.3 CSS --> |
| 43 | <link href="{BOOTSTRAP_CSS}" rel="stylesheet" |
| 44 | integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" |
| 45 | crossorigin="anonymous"> |
| 46 | |
| 47 | <!-- Bootstrap Icons --> |
| 48 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css"> |
| 49 | |
| 50 | <!-- Custom DBBasic Styles --> |
| 51 | <style> |
| 52 | :root {{ |
| 53 | --dbbasic-primary: {BRAND_COLORS["dbbasic"]}; |
| 54 | --dbbasic-secondary: {BRAND_COLORS["dbbasic_end"]}; |
| 55 | --dbbasic-gradient: linear-gradient(135deg, var(--dbbasic-primary) 0%, var(--dbbasic-secondary) 100%); |
| 56 | }} |
| 57 | |
| 58 | .dbbasic-gradient {{ |
| 59 | background: var(--dbbasic-gradient); |
| 60 | }} |
| 61 | |
| 62 | .dbbasic-navbar {{ |
| 63 | background: var(--dbbasic-gradient) !important; |
| 64 | box-shadow: 0 2px 4px rgba(0,0,0,0.1); |
| 65 | }} |
| 66 | |
| 67 | .dbbasic-card {{ |
| 68 | border: none; |
| 69 | box-shadow: 0 4px 6px rgba(0,0,0,0.1); |
| 70 | transition: transform 0.2s, box-shadow 0.2s; |
| 71 | }} |
| 72 | |
| 73 | .dbbasic-card:hover {{ |
| 74 | transform: translateY(-2px); |
| 75 | box-shadow: 0 8px 15px rgba(0,0,0,0.15); |
| 76 | }} |
| 77 | |
| 78 | .service-badge {{ |
| 79 | font-size: 0.75rem; |
| 80 | padding: 0.25rem 0.5rem; |
| 81 | }} |
| 82 | |
| 83 | .performance-badge {{ |
| 84 | background: var(--dbbasic-gradient); |
| 85 | color: white; |
| 86 | border: none; |
| 87 | }} |
| 88 | |
| 89 | .navbar-brand {{ |
| 90 | font-weight: bold; |
| 91 | font-size: 1.5rem; |
| 92 | }} |
| 93 | |
| 94 | .nav-link {{ |
| 95 | font-weight: 500; |
| 96 | transition: all 0.2s; |
| 97 | }} |
| 98 | |
| 99 | .nav-link:hover {{ |
| 100 | background-color: rgba(255,255,255,0.1); |
| 101 | border-radius: 0.375rem; |
| 102 | }} |
| 103 | |
| 104 | .btn-dbbasic {{ |
| 105 | background: var(--dbbasic-gradient); |
| 106 | border: none; |
| 107 | color: white; |
| 108 | font-weight: 500; |
| 109 | }} |
| 110 | |
| 111 | .btn-dbbasic:hover {{ |
| 112 | background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%); |
| 113 | color: white; |
| 114 | }} |
| 115 | |
| 116 | .table-dbbasic thead {{ |
| 117 | background: var(--dbbasic-gradient); |
| 118 | color: white; |
| 119 | }} |
| 120 | |
| 121 | .footer {{ |
| 122 | background-color: var(--bs-gray-100); |
| 123 | margin-top: auto; |
| 124 | }} |
| 125 | </style> |
| 126 | </head> |
| 127 | <body class="d-flex flex-column min-vh-100"> |
| 128 | |
| 129 | <!-- Navigation Bar --> |
| 130 | <nav class="navbar navbar-expand-lg dbbasic-navbar"> |
| 131 | <div class="container-fluid"> |
| 132 | <a class="navbar-brand text-white" href="http://localhost:{port}"> |
| 133 | <i class="bi bi-database-fill me-2"></i>DBBasic |
| 134 | </a> |
| 135 | |
| 136 | <button class="navbar-toggler" type="button" data-bs-toggle="collapse" |
| 137 | data-bs-target="#navbarNav" aria-controls="navbarNav" |
| 138 | aria-expanded="false" aria-label="Toggle navigation"> |
| 139 | <span class="navbar-toggler-icon"></span> |
| 140 | </button> |
| 141 | |
| 142 | <div class="collapse navbar-collapse" id="navbarNav"> |
| 143 | <ul class="navbar-nav me-auto"> |
| 144 | <li class="nav-item"> |
| 145 | <a class="nav-link text-white{'active' if active_nav == 'monitor' else ''}" |
| 146 | href="http://localhost:8004"> |
| 147 | <i class="bi bi-speedometer2 me-1"></i>Monitor |
| 148 | </a> |
| 149 | </li> |
| 150 | <li class="nav-item"> |
| 151 | <a class="nav-link text-white{'active' if active_nav == 'data' else ''}" |
| 152 | href="http://localhost:8005"> |
| 153 | <i class="bi bi-table me-1"></i>Data |
| 154 | </a> |
| 155 | </li> |
| 156 | <li class="nav-item"> |
| 157 | <a class="nav-link text-white{'active' if active_nav == 'ai' else ''}" |
| 158 | href="http://localhost:8003"> |
| 159 | <i class="bi bi-robot me-1"></i>AI Services |
| 160 | </a> |
| 161 | </li> |
| 162 | <li class="nav-item"> |
| 163 | <a class="nav-link text-white{'active' if active_nav == 'events' else ''}" |
| 164 | href="http://localhost:8006"> |
| 165 | <i class="bi bi-journal-code me-1"></i>Events |
| 166 | </a> |
| 167 | </li> |
| 168 | <li class="nav-item"> |
| 169 | <a class="nav-link text-white{'active' if active_nav == 'templates' else ''}" |
| 170 | href="http://localhost:8005/templates"> |
| 171 | <i class="bi bi-collection me-1"></i>Templates |
| 172 | </a> |
| 173 | </li> |
| 174 | </ul> |
| 175 | |
| 176 | <div class="d-flex align-items-center"> |
| 177 | <span class="badge performance-badge me-3"> |
| 178 | <i class="bi bi-lightning-fill me-1"></i>402M rows/sec |
| 179 | </span> |
| 180 | <span class="badge service-badge bg-light text-dark"> |
| 181 | {service_name} |
| 182 | </span> |
| 183 | </div> |
| 184 | </div> |
| 185 | </div> |
| 186 | </nav> |
| 187 | |
| 188 | <!-- Main Content Area --> |
| 189 | <main class="flex-grow-1"> |
| 190 | """ |
| 191 | |
| 192 | def get_footer_template() -> str: |
| 193 | """Generate the unified footer template""" |
| 194 | return """ |
| 195 | </main> |
| 196 | |
| 197 | <!-- Footer --> |
| 198 | <footer class="footer py-3 mt-4"> |
| 199 | <div class="container"> |
| 200 | <div class="row"> |
| 201 | <div class="col-md-6"> |
| 202 | <small class="text-muted"> |
| 203 | <i class="bi bi-database-fill me-1"></i> |
| 204 | DBBasic - Configuration-Driven Application Framework |
| 205 | </small> |
| 206 | </div> |
| 207 | <div class="col-md-6 text-md-end"> |
| 208 | <small class="text-muted"> |
| 209 | <i class="bi bi-github me-1"></i> |
| 210 | <a href="https://github.com/askrobots/dbbasic" class="text-decoration-none"> |
| 211 | Open Source |
| 212 | </a> |
| 213 | </small> |
| 214 | </div> |
| 215 | </div> |
| 216 | </div> |
| 217 | </footer> |
| 218 | |
| 219 | <!-- Bootstrap 5.3.3 JS --> |
| 220 | <script src="{BOOTSTRAP_JS}" |
| 221 | integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" |
| 222 | crossorigin="anonymous"></script> |
| 223 | |
| 224 | <!-- Custom DBBasic JS --> |
| 225 | <script> |
| 226 | // Initialize all Bootstrap tooltips |
| 227 | const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); |
| 228 | const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl)); |
| 229 | |
| 230 | // Initialize all Bootstrap popovers |
| 231 | const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]'); |
| 232 | const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl)); |
| 233 | </script> |
| 234 | </body> |
| 235 | </html> |
| 236 | """ |
| 237 | |
| 238 | def get_service_card(title: str, description: str, url: str, icon: str = "bi-gear", |
| 239 | status: str = "active", stats: str = "") -> str: |
| 240 | """Generate a Bootstrap service card component""" |
| 241 | status_class = "success" if status == "active" else "secondary" |
| 242 | return f""" |
| 243 | <div class="col"> |
| 244 | <div class="card dbbasic-card h-100"> |
| 245 | <div class="card-body"> |
| 246 | <div class="d-flex justify-content-between align-items-start mb-3"> |
| 247 | <h5 class="card-title"> |
| 248 | <i class="{icon} me-2"></i>{title} |
| 249 | </h5> |
| 250 | <span class="badge bg-{status_class}">{status}</span> |
| 251 | </div> |
| 252 | <p class="card-text">{description}</p> |
| 253 | {f'<small class="text-muted">{stats}</small>' if stats else ''} |
| 254 | </div> |
| 255 | <div class="card-footer bg-transparent"> |
| 256 | <a href="{url}" class="btn btn-dbbasic"> |
| 257 | <i class="bi bi-arrow-right me-1"></i>Access |
| 258 | </a> |
| 259 | </div> |
| 260 | </div> |
| 261 | </div> |
| 262 | """ |
| 263 | |
| 264 | def get_template_card(title: str, description: str, category: str, |
| 265 | deploy_action: str = "", preview_action: str = "") -> str: |
| 266 | """Generate a Bootstrap template card for the marketplace""" |
| 267 | return f""" |
| 268 | <div class="col"> |
| 269 | <div class="card dbbasic-card h-100"> |
| 270 | <div class="card-body"> |
| 271 | <div class="d-flex justify-content-between align-items-start mb-3"> |
| 272 | <h5 class="card-title">{title}</h5> |
| 273 | <span class="badge bg-primary">{category}</span> |
| 274 | </div> |
| 275 | <p class="card-text">{description}</p> |
| 276 | </div> |
| 277 | <div class="card-footer bg-transparent"> |
| 278 | <div class="d-grid gap-2 d-md-flex justify-content-md-end"> |
| 279 | {f'<button class="btn btn-outline-secondary btn-sm" {preview_action}><i class="bi bi-eye me-1"></i>Preview</button>' if preview_action else ''} |
| 280 | <button class="btn btn-dbbasic btn-sm" {deploy_action}> |
| 281 | <i class="bi bi-rocket-takeoff me-1"></i>Deploy |
| 282 | </button> |
| 283 | </div> |
| 284 | </div> |
| 285 | </div> |
| 286 | </div> |
| 287 | """ |
| 288 | |
| 289 | def get_alert(message: str, alert_type: str = "info", dismissible: bool = True) -> str: |
| 290 | """Generate a Bootstrap alert component""" |
| 291 | icons = { |
| 292 | "success": "bi-check-circle-fill", |
| 293 | "danger": "bi-exclamation-triangle-fill", |
| 294 | "warning": "bi-exclamation-triangle-fill", |
| 295 | "info": "bi-info-circle-fill" |
| 296 | } |
| 297 | icon = icons.get(alert_type, "bi-info-circle-fill") |
| 298 | dismissible_class = "alert-dismissible" if dismissible else "" |
| 299 | dismiss_button = """ |
| 300 | <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
| 301 | """ if dismissible else "" |
| 302 | |
| 303 | return f""" |
| 304 | <div class="alert alert-{alert_type} {dismissible_class}" role="alert"> |
| 305 | <i class="{icon} me-2"></i>{message} |
| 306 | {dismiss_button} |
| 307 | </div> |
| 308 | """ |
| 309 | |
| 310 | def get_breadcrumb(items: list) -> str: |
| 311 | """Generate a Bootstrap breadcrumb component""" |
| 312 | breadcrumb_items = [] |
| 313 | for i, item in enumerate(items): |
| 314 | if i == len(items) - 1: # Last item (current page) |
| 315 | breadcrumb_items.append(f'<li class="breadcrumb-item active" aria-current="page">{item["text"]}</li>') |
| 316 | else: |
| 317 | breadcrumb_items.append(f'<li class="breadcrumb-item"><a href="{item["url"]}">{item["text"]}</a></li>') |
| 318 | |
| 319 | return f""" |
| 320 | <nav aria-label="breadcrumb"> |
| 321 | <ol class="breadcrumb"> |
| 322 | {"".join(breadcrumb_items)} |
| 323 | </ol> |
| 324 | </nav> |
| 325 | """ |
| 326 | |
| 327 | # Export commonly used components and templates |
| 328 | __all__ = [ |
| 329 | 'BOOTSTRAP_CSS', 'BOOTSTRAP_JS', 'BRAND_COLORS', |
| 330 | 'get_base_html_template', 'get_footer_template', |
| 331 | 'get_service_card', 'get_template_card', 'get_alert', 'get_breadcrumb' |
| 332 | ] |