askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/dbbasic_unified_ui.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
dbbasic_unified_ui.py · 15.5 KB · 456 lines
1#!/usr/bin/env python3
2"""
3DBBasic Unified UI System
4Master layout and navigation for all services
5"""
6
7from typing import Dict, List, Any, Optional
8from presentation_layer import PresentationLayer
9from bootstrap_components import ExtendedBootstrapRenderer
10
11# Initialize presentation layer
12PresentationLayer.add_renderer('bootstrap', ExtendedBootstrapRenderer())
13
14# Service registry with ports and status
15SERVICES = {
16 'monitor': {
17 'name': 'Monitor',
18 'port': 8004,
19 'icon': 'bi-activity',
20 'description': 'Real-time service monitoring',
21 'status': 'running'
22 },
23 'data': {
24 'name': 'Data',
25 'port': 8005,
26 'icon': 'bi-database',
27 'description': 'CRUD Engine - 402M rows/sec',
28 'status': 'running'
29 },
30 'ai_services': {
31 'name': 'AI Services',
32 'port': 8003,
33 'icon': 'bi-robot',
34 'description': 'AI-powered service builder',
35 'status': 'running'
36 },
37 'event_store': {
38 'name': 'Event Store',
39 'port': 8007,
40 'icon': 'bi-journal-text',
41 'description': 'Event sourcing & audit trails',
42 'status': 'running'
43 },
44 'test_runner': {
45 'name': 'Test Runner',
46 'port': 8006,
47 'icon': 'bi-speedometer2',
48 'description': 'Testing at 402M rows/sec',
49 'status': 'running'
50 },
51 'templates': {
52 'name': 'Templates',
53 'port': 8005,
54 'path': '/templates',
55 'icon': 'bi-shop',
56 'description': 'Template marketplace',
57 'status': 'running'
58 }
59}
60
61def get_unified_navigation(active_service: str = None) -> Dict:
62 """Generate unified navigation bar"""
63 links = []
64 for key, service in SERVICES.items():
65 url = f"http://localhost:{service['port']}"
66 if 'path' in service:
67 url += service['path']
68
69 links.append({
70 'text': service['name'],
71 'url': url,
72 'active': key == active_service,
73 'icon': service.get('icon', '')
74 })
75
76 return {
77 'type': 'navbar',
78 'brand': 'DBBasic',
79 'variant': 'dark',
80 'links': links,
81 'extras': [
82 {'type': 'badge', 'text': '⚡ 402M rows/sec', 'variant': 'success'}
83 ]
84 }
85
86def get_master_layout(
87 title: str,
88 service_name: str,
89 content: List[Dict],
90 scripts: Optional[List[Dict]] = None,
91 styles: Optional[List[Dict]] = None
92) -> Dict:
93 """Generate master layout for any DBBasic service"""
94
95 # Build the page structure
96 page = {
97 'type': 'page',
98 'title': f'{title} - DBBasic',
99 'components': [
100 # Unified navigation
101 get_unified_navigation(service_name),
102
103 # Service header (optional)
104 {
105 'type': 'container',
106 'fluid': True,
107 'class': 'bg-light py-3 mb-4',
108 'children': [
109 {
110 'type': 'container',
111 'children': [
112 {
113 'type': 'breadcrumb',
114 'items': [
115 {'text': 'DBBasic', 'url': '/'},
116 {'text': SERVICES.get(service_name, {}).get('name', service_name), 'active': True}
117 ]
118 }
119 ]
120 }
121 ]
122 },
123
124 # Main content area
125 {
126 'type': 'container',
127 'fluid': True,
128 'children': content
129 },
130
131 # Footer
132 get_footer()
133 ]
134 }
135
136 # Add scripts if provided
137 if scripts:
138 page['components'].extend(scripts)
139
140 # Add styles if provided
141 if styles:
142 # Insert styles after navbar
143 page['components'].insert(1, styles)
144
145 return page
146
147def get_footer() -> Dict:
148 """Generate professional unified footer"""
149 # Build service links
150 service_links = []
151 for key, service in SERVICES.items():
152 url = f"http://localhost:{service['port']}"
153 if 'path' in service:
154 url += service['path']
155 icon = service.get('icon', 'bi-circle')
156 service_links.append(
157 f'<li class="mb-2"><a href="{url}" class="text-decoration-none text-light opacity-75">'
158 f'<i class="{icon} me-2"></i>{service["name"]}</a></li>'
159 )
160
161 return {
162 'type': 'raw',
163 'content': f'''
164 <footer class="mt-auto" style="background: linear-gradient(135deg, #1a1a2e 0%, #0f172a 100%); margin-top: 5rem !important;">
165 <div class="container-fluid py-5">
166 <div class="row g-4 px-4">
167 <!-- Brand Section -->
168 <div class="col-lg-4">
169 <div class="d-flex align-items-center mb-3">
170 <div class="bg-primary rounded-circle p-2 me-2">
171 <i class="bi bi-cpu-fill text-white fs-5"></i>
172 </div>
173 <h4 class="text-white mb-0">DBBasic</h4>
174 <span class="badge bg-success ms-2">v1.0</span>
175 </div>
176 <p class="text-light opacity-75">
177 Revolutionary config-driven platform. Build production apps with YAML & AI.
178 </p>
179 <div class="d-flex gap-2 mt-3">
180 <a href="#" class="btn btn-outline-light btn-sm">
181 <i class="bi bi-github"></i> GitHub
182 </a>
183 <a href="#" class="btn btn-outline-light btn-sm">
184 <i class="bi bi-book"></i> Docs
185 </a>
186 </div>
187 </div>
188
189 <!-- Services -->
190 <div class="col-lg-2 col-md-6">
191 <h6 class="text-white mb-3">Services</h6>
192 <ul class="list-unstyled">
193 {''.join(service_links)}
194 </ul>
195 </div>
196
197 <!-- Resources -->
198 <div class="col-lg-3 col-md-6">
199 <h6 class="text-white mb-3">Resources</h6>
200 <ul class="list-unstyled">
201 <li class="mb-2">
202 <a href="#" class="text-decoration-none text-light opacity-75">
203 <i class="bi bi-file-text me-2"></i>Documentation
204 </a>
205 </li>
206 <li class="mb-2">
207 <a href="#" class="text-decoration-none text-light opacity-75">
208 <i class="bi bi-code-square me-2"></i>API Reference
209 </a>
210 </li>
211 <li class="mb-2">
212 <a href="#" class="text-decoration-none text-light opacity-75">
213 <i class="bi bi-play-circle me-2"></i>Tutorials
214 </a>
215 </li>
216 </ul>
217 </div>
218
219 <!-- Stats -->
220 <div class="col-lg-3">
221 <h6 class="text-white mb-3">Performance</h6>
222 <div class="d-flex flex-column gap-2">
223 <div class="d-flex align-items-center">
224 <i class="bi bi-lightning-fill text-warning me-2"></i>
225 <span class="text-light opacity-75">402M rows/sec</span>
226 </div>
227 <div class="d-flex align-items-center">
228 <i class="bi bi-hdd-stack text-info me-2"></i>
229 <span class="text-light opacity-75">DuckDB Engine</span>
230 </div>
231 <div class="d-flex align-items-center">
232 <i class="bi bi-gear-fill text-success me-2"></i>
233 <span class="text-light opacity-75">90% Token Reduction</span>
234 </div>
235 <div class="d-flex align-items-center">
236 <i class="bi bi-magic text-primary me-2"></i>
237 <span class="text-light opacity-75">AI-Powered</span>
238 </div>
239 </div>
240 </div>
241 </div>
242 </div>
243
244 <!-- Bottom Bar -->
245 <div class="border-top border-dark bg-black bg-opacity-25">
246 <div class="container-fluid py-3">
247 <div class="text-center">
248 <p class="text-light opacity-50 mb-0 small">
249 © 2024 DBBasic - Post-Code Era Platform • Built with <i class="bi bi-heart-fill text-danger"></i> for developers
250 </p>
251 </div>
252 </div>
253 </div>
254 </footer>
255 '''
256 }
257
258def get_service_dashboard() -> Dict:
259 """Generate main service dashboard"""
260 return get_master_layout(
261 title='Services Dashboard',
262 service_name='dashboard',
263 content=[
264 # Hero section
265 {
266 'type': 'hero',
267 'title': 'DBBasic Platform',
268 'subtitle': 'All services running at peak performance'
269 },
270
271 # Service cards grid
272 {
273 'type': 'grid',
274 'columns': 3,
275 'items': [
276 {
277 'type': 'card',
278 'id': f'{key}-card',
279 'title': service['name'],
280 'category': f'Port {service["port"]}',
281 'description': service['description'],
282 'footer': [
283 {
284 'type': 'badge',
285 'text': 'Running' if service['status'] == 'running' else 'Stopped',
286 'variant': 'success' if service['status'] == 'running' else 'danger'
287 },
288 {
289 'type': 'button',
290 'text': 'Open',
291 'variant': 'primary',
292 'onclick': f"window.open('http://localhost:{service['port']}')"
293 }
294 ]
295 }
296 for key, service in SERVICES.items()
297 ]
298 }
299 ]
300 )
301
302# Service-specific layouts
303def get_crud_engine_layout(content: List[Dict]) -> Dict:
304 """Layout for CRUD Engine pages"""
305 return get_master_layout(
306 title='Data Service',
307 service_name='data',
308 content=content,
309 scripts=[{
310 'type': 'script',
311 'content': '''
312 // CRUD Engine specific scripts
313 console.log("CRUD Engine initialized");
314 '''
315 }]
316 )
317
318def get_ai_service_layout(content: List[Dict]) -> Dict:
319 """Layout for AI Service Builder pages"""
320 return get_master_layout(
321 title='AI Service Builder',
322 service_name='ai_services',
323 content=content,
324 scripts=[{
325 'type': 'script',
326 'content': '''
327 // AI Service specific scripts
328 console.log("AI Service Builder initialized");
329 '''
330 }]
331 )
332
333def get_monitor_layout(content: List[Dict]) -> Dict:
334 """Layout for Real-time Monitor"""
335 return get_master_layout(
336 title='Real-time Monitor',
337 service_name='monitor',
338 content=content,
339 scripts=[{
340 'type': 'script',
341 'content': '''
342 // WebSocket connection for real-time updates
343 let ws = new WebSocket('ws://localhost:8004/ws');
344 ws.onmessage = (event) => {
345 const data = JSON.parse(event.data);
346 updateMetrics(data);
347 };
348 '''
349 }]
350 )
351
352def get_event_store_layout(content: List[Dict]) -> Dict:
353 """Layout for Event Store"""
354 return get_master_layout(
355 title='Event Store',
356 service_name='event_store',
357 content=content
358 )
359
360# Convert all views to unified layout
361def convert_crud_engine_views():
362 """Convert all CRUD Engine views to use unified layout"""
363
364 # Main CRUD dashboard
365 crud_dashboard = get_crud_engine_layout([
366 {
367 'type': 'hero',
368 'title': 'Data Service',
369 'subtitle': 'Config-driven CRUD at 402M rows/sec'
370 },
371 {
372 'type': 'grid',
373 'columns': 2,
374 'items': [
375 {
376 'type': 'card',
377 'title': 'Resources',
378 'description': 'Manage your data resources',
379 'actions': [
380 {'type': 'button', 'text': 'View Resources', 'onclick': "location.href='/resources'"}
381 ]
382 },
383 {
384 'type': 'card',
385 'title': 'Templates',
386 'description': 'Browse and deploy templates',
387 'actions': [
388 {'type': 'button', 'text': 'Template Marketplace', 'onclick': "location.href='/templates'"}
389 ]
390 }
391 ]
392 }
393 ])
394
395 # Template marketplace
396 template_marketplace = get_crud_engine_layout([
397 {
398 'type': 'hero',
399 'title': '🛍️ Template Marketplace',
400 'subtitle': 'Deploy production-ready applications instantly'
401 },
402 {
403 'type': 'grid',
404 'columns': 3,
405 'items': [] # Templates loaded dynamically
406 }
407 ])
408
409 return {
410 'dashboard': crud_dashboard,
411 'templates': template_marketplace
412 }
413
414# Example: Convert a static mockup
415def convert_static_mockup(mockup_name: str) -> Dict:
416 """Convert static HTML mockups to data structures"""
417
418 if mockup_name == 'dashboard':
419 return get_master_layout(
420 title='Dashboard Mockup',
421 service_name='dashboard',
422 content=[
423 {
424 'type': 'alert',
425 'message': 'This is a converted mockup using the presentation layer',
426 'variant': 'info'
427 },
428 # Add mockup content here
429 ]
430 )
431
432 # Convert other mockups...
433 return {}
434
435# Generate all layouts
436if __name__ == "__main__":
437 # Generate service dashboard
438 dashboard_html = PresentationLayer.render(get_service_dashboard(), 'bootstrap')
439 with open('dbbasic_dashboard.html', 'w') as f:
440 f.write(dashboard_html)
441
442 # Generate CRUD views
443 crud_views = convert_crud_engine_views()
444 for name, view in crud_views.items():
445 html = PresentationLayer.render(view, 'bootstrap')
446 with open(f'crud_{name}.html', 'w') as f:
447 f.write(html)
448
449 print("✅ Generated unified DBBasic UI")
450 print("\nUnified features:")
451 print("- Consistent navigation across all services")
452 print("- Master layout template")
453 print("- Service-specific layouts")
454 print("- Unified footer")
455 print("- Clean data structures for everything")
456 print("\nAll services now share the same UI system!")