Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
dashboard_example.py · 13.6 KB · 308 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | DBBasic Dashboard Example - Shows all presentation layer components |
| 4 | This demonstrates how to build a complete dashboard using data structures |
| 5 | """ |
| 6 | |
| 7 | from presentation_layer import PresentationLayer |
| 8 | from bootstrap_components import ExtendedBootstrapRenderer |
| 9 | |
| 10 | # Initialize with extended components |
| 11 | PresentationLayer.add_renderer('bootstrap', ExtendedBootstrapRenderer()) |
| 12 | |
| 13 | # Define a complete dashboard as data |
| 14 | dashboard = { |
| 15 | 'type': 'page', |
| 16 | 'title': 'DBBasic Dashboard', |
| 17 | 'components': [ |
| 18 | # Navigation |
| 19 | { |
| 20 | 'type': 'navbar', |
| 21 | 'brand': 'DBBasic', |
| 22 | 'links': [ |
| 23 | {'text': 'Dashboard', 'url': '/'}, |
| 24 | {'text': 'Data', 'url': '/data'}, |
| 25 | {'text': 'Templates', 'url': '/templates'}, |
| 26 | {'text': 'Settings', 'url': '/settings'} |
| 27 | ] |
| 28 | }, |
| 29 | |
| 30 | # Main container |
| 31 | { |
| 32 | 'type': 'container', |
| 33 | 'children': [ |
| 34 | # Breadcrumb |
| 35 | { |
| 36 | 'type': 'breadcrumb', |
| 37 | 'items': [ |
| 38 | {'text': 'Home', 'url': '/'}, |
| 39 | {'text': 'Dashboard', 'active': True} |
| 40 | ] |
| 41 | }, |
| 42 | |
| 43 | # Welcome alert |
| 44 | { |
| 45 | 'type': 'alert', |
| 46 | 'message': 'Welcome to DBBasic Dashboard - Everything is data!', |
| 47 | 'variant': 'primary', |
| 48 | 'dismissible': True |
| 49 | }, |
| 50 | |
| 51 | # Stats cards row |
| 52 | { |
| 53 | 'type': 'grid', |
| 54 | 'columns': 4, |
| 55 | 'items': [ |
| 56 | { |
| 57 | 'type': 'card', |
| 58 | 'title': 'Total Users', |
| 59 | 'description': '1,234', |
| 60 | 'category': 'Active' |
| 61 | }, |
| 62 | { |
| 63 | 'type': 'card', |
| 64 | 'title': 'Templates', |
| 65 | 'description': '42', |
| 66 | 'category': 'Available' |
| 67 | }, |
| 68 | { |
| 69 | 'type': 'card', |
| 70 | 'title': 'API Calls', |
| 71 | 'description': '98,765', |
| 72 | 'category': 'Today' |
| 73 | }, |
| 74 | { |
| 75 | 'type': 'card', |
| 76 | 'title': 'Performance', |
| 77 | 'description': '402M rows/sec', |
| 78 | 'category': 'DuckDB' |
| 79 | } |
| 80 | ] |
| 81 | }, |
| 82 | |
| 83 | # Main content tabs |
| 84 | { |
| 85 | 'type': 'tabs', |
| 86 | 'items': [ |
| 87 | { |
| 88 | 'id': 'overview-tab', |
| 89 | 'label': 'Overview', |
| 90 | 'active': True, |
| 91 | 'content': { |
| 92 | 'type': 'container', |
| 93 | 'children': [ |
| 94 | # Progress indicators |
| 95 | '<h5 class="mt-3">System Status</h5>', |
| 96 | { |
| 97 | 'type': 'list_group', |
| 98 | 'items': [ |
| 99 | { |
| 100 | 'text': 'CPU Usage: 45%', |
| 101 | 'badge': 'Normal', |
| 102 | 'variant': 'success' |
| 103 | }, |
| 104 | { |
| 105 | 'text': 'Memory: 2.3GB / 8GB', |
| 106 | 'badge': 'OK' |
| 107 | }, |
| 108 | { |
| 109 | 'text': 'Disk: 120GB / 500GB', |
| 110 | 'badge': 'Good' |
| 111 | } |
| 112 | ] |
| 113 | }, |
| 114 | |
| 115 | '<h5 class="mt-4">Service Health</h5>', |
| 116 | { |
| 117 | 'type': 'progress', |
| 118 | 'value': 85, |
| 119 | 'label': 'System Health: 85%', |
| 120 | 'variant': 'success', |
| 121 | 'striped': True |
| 122 | } |
| 123 | ] |
| 124 | } |
| 125 | }, |
| 126 | { |
| 127 | 'id': 'data-tab', |
| 128 | 'label': 'Data Tables', |
| 129 | 'content': { |
| 130 | 'type': 'table', |
| 131 | 'striped': True, |
| 132 | 'hover': True, |
| 133 | 'headers': ['Service', 'Status', 'Port', 'Uptime', 'Actions'], |
| 134 | 'rows': [ |
| 135 | [ |
| 136 | 'CRUD Engine', |
| 137 | {'type': 'badge', 'text': 'Running', 'variant': 'success'}, |
| 138 | '8005', |
| 139 | '2 days', |
| 140 | {'type': 'button', 'text': 'Restart', 'variant': 'sm'} |
| 141 | ], |
| 142 | [ |
| 143 | 'AI Service', |
| 144 | {'type': 'badge', 'text': 'Running', 'variant': 'success'}, |
| 145 | '8003', |
| 146 | '2 days', |
| 147 | {'type': 'button', 'text': 'Restart', 'variant': 'sm'} |
| 148 | ], |
| 149 | [ |
| 150 | 'Monitor', |
| 151 | {'type': 'badge', 'text': 'Running', 'variant': 'success'}, |
| 152 | '8004', |
| 153 | '2 days', |
| 154 | {'type': 'button', 'text': 'Restart', 'variant': 'sm'} |
| 155 | ], |
| 156 | [ |
| 157 | 'Event Store', |
| 158 | {'type': 'badge', 'text': 'Stopped', 'variant': 'danger'}, |
| 159 | '8006', |
| 160 | 'N/A', |
| 161 | {'type': 'button', 'text': 'Start', 'variant': 'primary'} |
| 162 | ] |
| 163 | ] |
| 164 | } |
| 165 | }, |
| 166 | { |
| 167 | 'id': 'templates-tab', |
| 168 | 'label': 'Templates', |
| 169 | 'content': { |
| 170 | 'type': 'grid', |
| 171 | 'columns': 3, |
| 172 | 'items': [ |
| 173 | { |
| 174 | 'type': 'card', |
| 175 | 'title': 'Blog Platform', |
| 176 | 'category': 'CMS', |
| 177 | 'description': 'Full-featured blog with posts, categories, and SEO', |
| 178 | 'actions': ['deploy', 'preview'] |
| 179 | }, |
| 180 | { |
| 181 | 'type': 'card', |
| 182 | 'title': 'E-Commerce', |
| 183 | 'category': 'Shop', |
| 184 | 'description': 'Complete online store with products and orders', |
| 185 | 'actions': ['deploy', 'preview'] |
| 186 | }, |
| 187 | { |
| 188 | 'type': 'card', |
| 189 | 'title': 'CRM System', |
| 190 | 'category': 'Business', |
| 191 | 'description': 'Customer relationship management', |
| 192 | 'actions': ['deploy', 'preview'] |
| 193 | } |
| 194 | ] |
| 195 | } |
| 196 | }, |
| 197 | { |
| 198 | 'id': 'config-tab', |
| 199 | 'label': 'Configuration', |
| 200 | 'content': { |
| 201 | 'type': 'form', |
| 202 | 'fields': [ |
| 203 | { |
| 204 | 'type': 'input', |
| 205 | 'name': 'app_name', |
| 206 | 'label': 'Application Name', |
| 207 | 'value': 'My DBBasic App' |
| 208 | }, |
| 209 | { |
| 210 | 'type': 'select', |
| 211 | 'name': 'theme', |
| 212 | 'label': 'UI Framework', |
| 213 | 'options': [ |
| 214 | {'value': 'bootstrap', 'text': 'Bootstrap 5.3', 'selected': True}, |
| 215 | {'value': 'tailwind', 'text': 'Tailwind CSS'}, |
| 216 | {'value': 'material', 'text': 'Material UI (Coming Soon)'} |
| 217 | ] |
| 218 | }, |
| 219 | { |
| 220 | 'type': 'select', |
| 221 | 'name': 'database', |
| 222 | 'label': 'Database', |
| 223 | 'options': [ |
| 224 | {'value': 'duckdb', 'text': 'DuckDB (402M rows/sec)', 'selected': True}, |
| 225 | {'value': 'sqlite', 'text': 'SQLite'}, |
| 226 | {'value': 'postgres', 'text': 'PostgreSQL'} |
| 227 | ] |
| 228 | }, |
| 229 | { |
| 230 | 'type': 'checkbox', |
| 231 | 'name': 'websockets', |
| 232 | 'label': 'Enable WebSocket real-time updates', |
| 233 | 'checked': True |
| 234 | }, |
| 235 | { |
| 236 | 'type': 'checkbox', |
| 237 | 'name': 'ai_hooks', |
| 238 | 'label': 'Enable AI-powered business logic hooks', |
| 239 | 'checked': True |
| 240 | }, |
| 241 | { |
| 242 | 'type': 'textarea', |
| 243 | 'name': 'notes', |
| 244 | 'label': 'Configuration Notes', |
| 245 | 'rows': 3, |
| 246 | 'placeholder': 'Any additional configuration notes...' |
| 247 | } |
| 248 | ], |
| 249 | 'buttons': [ |
| 250 | {'type': 'submit', 'text': 'Save Configuration', 'variant': 'primary'}, |
| 251 | {'type': 'reset', 'text': 'Reset', 'variant': 'secondary'} |
| 252 | ] |
| 253 | } |
| 254 | } |
| 255 | ] |
| 256 | }, |
| 257 | |
| 258 | # Activity feed |
| 259 | '<h4 class="mt-5">Recent Activity</h4>', |
| 260 | { |
| 261 | 'type': 'accordion', |
| 262 | 'id': 'activity-accordion', |
| 263 | 'items': [ |
| 264 | { |
| 265 | 'header': 'Template Deployed - Blog Platform', |
| 266 | 'body': 'User deployed the Blog Platform template at 10:45 AM', |
| 267 | 'expanded': True |
| 268 | }, |
| 269 | { |
| 270 | 'header': 'Configuration Updated', |
| 271 | 'body': 'Database settings were updated to use DuckDB' |
| 272 | }, |
| 273 | { |
| 274 | 'header': 'AI Service Generated', |
| 275 | 'body': 'New shipping calculation service was generated' |
| 276 | } |
| 277 | ] |
| 278 | }, |
| 279 | |
| 280 | # Pagination |
| 281 | '<div class="mt-4 d-flex justify-content-center">', |
| 282 | { |
| 283 | 'type': 'pagination', |
| 284 | 'current': 1, |
| 285 | 'total': 5 |
| 286 | }, |
| 287 | '</div>' |
| 288 | ] |
| 289 | } |
| 290 | ] |
| 291 | } |
| 292 | |
| 293 | # Generate the dashboard |
| 294 | html = PresentationLayer.render(dashboard, 'bootstrap') |
| 295 | |
| 296 | # Save to file |
| 297 | with open('dashboard.html', 'w') as f: |
| 298 | f.write(html) |
| 299 | |
| 300 | print("✅ Generated dashboard.html - Complete DBBasic Dashboard") |
| 301 | print("\nThis dashboard demonstrates:") |
| 302 | print("- Navigation (navbar, breadcrumb)") |
| 303 | print("- Content (cards, alerts, badges)") |
| 304 | print("- Forms (all input types)") |
| 305 | print("- Tables (with embedded components)") |
| 306 | print("- Tabs, Accordion, Progress bars") |
| 307 | print("- Grid layouts and responsive design") |
| 308 | print("\nEverything defined as pure data structures!") |