Commit Graph

3 Commits

Author SHA1 Message Date
1c5d8eb29f fix(luci-app-secubox-admin): fix WidgetRenderer constructor error
Fixed TypeError "WidgetRenderer is not a constructor" in dashboard.js
by removing the 'new' keyword. LuCI's baseclass.extend() creates callable
classes that should not be instantiated with 'new'.

Changes:
- dashboard.js: Changed from 'new WidgetRenderer({...})' to 'WidgetRenderer({...})'
- Added comprehensive try-catch error handling with fallback error display
- Incremented PKG_RELEASE: 5 → 6
- Updated DEPLOY_UPDATES.md with v1.0.0-6 details

This fix allows the widget system to initialize properly on the dashboard.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-04 14:59:10 +01:00
f2ee564b1a feat: Reactive Widget System for Dashboard (Phase 5)
Implement comprehensive widget rendering system allowing SecuBox apps to display
live metrics, status, and controls as responsive widgets on the dashboard.

## Widget Rendering Engine

**New**: `/secubox-admin/widget-renderer.js` (~450 lines)

Core widget system with:
- **WidgetRenderer Class**: Main rendering engine with plugin architecture
- **Template System**: Pluggable widget templates by category
- **Auto-refresh**: Configurable polling (default: 30s per widget)
- **Responsive Grid**: CSS Grid with auto, fixed-2, fixed-3, fixed-4 modes
- **Lifecycle Management**: Initialize, update, destroy with cleanup

### Built-in Templates

1. **Security Widget** (`template: 'security'`):
   - Status indicator (ok/warning/error)
   - Metric rows with labels/values
   - Last event timestamp
   - Color-coded border (red)

2. **Network Widget** (`template: 'network'`):
   - Active connections count
   - Bandwidth display (up/down) with auto-formatting
   - Custom metrics support
   - Color-coded border (blue)

3. **Monitoring Widget** (`template: 'monitoring'`):
   - Health status badge (healthy/degraded/down)
   - Metrics grid (responsive cards)
   - Uptime display with formatting
   - Color-coded border (green)

4. **Hosting Widget** (`template: 'hosting'`):
   - Services list with running/stopped status
   - Service status icons (✓/✗)
   - Metrics section
   - Color-coded border (orange)

5. **Compact Widget** (`template: 'compact'`):
   - Small icon + title
   - Large primary metric value
   - Label text
   - Minimal space usage

6. **Default Widget** (`template: 'default'`):
   - Fallback for apps without specific template
   - Icon + title + status
   - Simple display

### Features

- **Custom Templates**: `registerTemplate(name, {render: fn})` API
- **Metric Rendering**: `renderMetric()`, `renderMetricCard()` helpers
- **Data Formatting**: Bandwidth, uptime, timestamps (relative)
- **Error Handling**: Try-catch with error display
- **Loading States**: Spinner + message
- **Polling Management**: Automatic cleanup on destroy

## Widget Styles

**New**: `/secubox-admin/widgets.css` (~600 lines)

Comprehensive responsive styles:

### Grid System
- `.widget-grid-auto`: Auto-fill minmax(300px, 1fr)
- `.widget-grid-fixed-2/3/4`: Fixed column grids
- Responsive breakpoints: 1400px → 1024px → 768px
- Mobile: Single column layout

### Widget Components
- **Widget Item**: Card with shadow, hover effects, transform
- **Widget Header**: Icon + title + status indicator/badge
- **Metrics**: Row layout and grid layout variants
- **Status Colors**: Success (green), warning (orange), error (red), unknown (gray)
- **Loading State**: Animated spinner with message
- **Error State**: Icon + message + details

### Category Styling
- Left border color coding by category
- Security: Red (#f44336)
- Network: Blue (#2196f3)
- Monitoring: Green (#4caf50)
- Hosting: Orange (#ff9800)
- Productivity: Purple (#9c27b0)

### Dark Mode Support
- Media query for `prefers-color-scheme: dark`
- Adjusted backgrounds, borders, text colors
- Maintains readability and contrast

### Print Styles
- Break-inside: avoid for widgets
- Border styles for print
- Block layout (no grid)

## Dashboard Integration

**Modified**: `view/secubox-admin/dashboard.js`

Enhanced with widget support:

### Changes
1. Import `widget-renderer` module
2. Add widget renderer instance: `widgetRenderer: null`
3. Load widgets.css stylesheet
4. New section: `renderWidgetsSection(apps)`
   - Filters apps with `widget.enabled === true`
   - Shows widget count
   - Creates container `#dashboard-widgets-container`

5. New method: `initializeWidgets(apps)`
   - Creates WidgetRenderer instance
   - Config: 30s refresh, auto grid mode
   - Renders all enabled widgets

6. Lifecycle: `addFooter()`
   - Cleanup widget renderer on page leave
   - Removes all poll handles

### Widget Section UI
- Card layout matching other dashboard sections
- Header with "App Widgets" title + count
- Container for widget grid
- Initialized via `requestAnimationFrame` (DOM ready)

## Widget Configuration Schema

Apps in catalog.json can include:

```json
{
  "id": "app-id",
  "widget": {
    "enabled": true,
    "template": "security|network|monitoring|hosting|compact|default",
    "refresh_interval": 30,
    "metrics": [
      {
        "id": "active_sessions",
        "label": "Active Sessions",
        "type": "counter",
        "source": "ubus",
        "method": "app.get_sessions"
      }
    ]
  }
}
```

## Data Flow

```
Dashboard Init
  ↓
WidgetRenderer.render()
  ↓
For each app with widget.enabled:
  ├── Create widget container (DOM)
  ├── Show loading spinner
  ├── API.getWidgetData(app_id)
  ↓
RPCD: luci.secubox.get_widget_data(app_id)
  ↓
Return widget data (metrics, status, etc.)
  ↓
Template.render(container, app, data)
  ↓
Display widget with live data
  ↓
Poll every N seconds (refresh_interval)
```

## Widget Renderer API

```javascript
// Create renderer
var renderer = new WidgetRenderer({
  containerId: 'widget-container',
  apps: appsWithWidgets,
  defaultRefreshInterval: 30,
  gridMode: 'auto'  // 'auto', 'fixed-2', 'fixed-3', 'fixed-4'
});

// Render all widgets
renderer.render();

// Register custom template
renderer.registerTemplate('mytemplate', {
  render: function(container, app, data) {
    container.innerHTML = '<div>...</div>';
  }
});

// Cleanup
renderer.destroy();
```

## Key Features Delivered

 **Pluggable template system** for different app categories
 **Responsive grid layout** with breakpoints
 **Auto-refresh** with configurable intervals per widget
 **Error handling** with graceful degradation
 **Loading states** with spinners
 **Dark mode** support via media queries
 **Category styling** with color-coded borders
 **Lifecycle management** with cleanup
 **Formatting utilities** for bandwidth, uptime, timestamps
 **Print-friendly** styles

## Files Changed/Created

**Created (2)**:
- `luci-app-secubox-admin/htdocs/luci-static/resources/secubox-admin/widget-renderer.js`
- `luci-app-secubox-admin/htdocs/luci-static/resources/secubox-admin/widgets.css`

**Modified (1)**:
- `luci-app-secubox-admin/htdocs/luci-static/resources/view/secubox-admin/dashboard.js`

**Total**: ~1,100 lines added

## Next Steps

To enable widgets for apps:
1. Add `widget` section to app entries in catalog.json
2. Implement `get_widget_data()` in app's RPCD handler
3. Return metrics, status, and relevant data
4. Widget will auto-refresh and display on dashboard

Example apps ready for widgets:
- Auth Guardian (security template)
- Bandwidth Manager (network template)
- System monitors (monitoring template)
- Hosting services (hosting template)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-04 14:07:59 +01:00
e7c9411d79 feat: Release v0.8.2 - Admin Control Center, Documentation Mirror & Docker Automation
This release adds major new features for SecuBox management and deployment:

## New Features

### 1. LuCI Admin Control Center (luci-app-secubox-admin)
- Unified admin dashboard for managing all SecuBox appstore plugins
- **Control Panel**: Real-time stats, system health, alerts, quick actions
- **Apps Manager**: Browse catalog, install/remove apps with search & filtering
- **App Settings**: Per-app configuration, start/stop controls
- **System Health**: Live monitoring (CPU, RAM, disk) with auto-refresh
- **System Logs**: Centralized log viewer with download capability
- Fully integrated with existing RPCD backend (luci.secubox)
- Mobile-responsive design with polished UI components

### 2. Documentation Mirror in SecuBox Bonus
- Integrated complete development documentation into luci-app-secubox-bonus
- 64+ documentation files now available offline at /luci-static/secubox/docs/
- Beautiful landing page (index-main.html) with 4 sections:
  - Development guides & references
  - Live module demos
  - Tutorials & blog posts
  - Marketing campaign pages
- Accessible locally on router without internet connection

### 3. Automated Docker Plugin Installation
- Enhanced secubox-appstore CLI with full Docker automation
- One-click installation from web UI now fully automated:
  - Auto-detects Docker runtime from catalog
  - Discovers and executes control scripts (*ctl install)
  - Pulls Docker images automatically
  - Creates directories and configures UCI
  - Enables init services
- No manual CLI steps required for Docker apps
- Works for all Docker apps: AdGuard Home, Mail-in-a-Box, Nextcloud, etc.

### 4. Mail-in-a-Box Plugin
- New Docker-based email server plugin (secubox-app-mailinabox)
- Complete package with:
  - UCI configuration (8 port mappings, feature flags)
  - Control script (mailinaboxctl) with install/check/update/status/logs
  - Procd init script with auto-restart
  - Catalog manifest (category: hosting, maturity: beta)
- Network mode: host (required for mail server)
- Persistent storage: mail, SSL, data, DNS volumes

## Improvements

### Build System
- Updated local-build.sh to include luci-app-* packages from package/secubox/
- Now automatically discovers and builds luci-app-secubox-admin and similar packages
- Fixed Makefile include paths for feed structure

### Package Releases
- Incremented PKG_RELEASE for all 31 SecuBox packages
- Ensures clean upgrade path from previous versions

### Catalog Updates
- Mail-in-a-Box entry moved from "productivity" to "hosting" category
- Status changed to "beta" reflecting community Docker image maturity
- Storage requirement increased: 1024MB → 2048MB
- Added port 25 accessibility note

## Files Changed

### New Packages (2)
- package/secubox/luci-app-secubox-admin/ (12 files)
- package/secubox/secubox-app-mailinabox/ (4 files)

### Enhanced Packages (1)
- package/secubox/luci-app-secubox-bonus/ (65 new docs files)

### Modified Core (3)
- package/secubox/secubox-core/root/usr/sbin/secubox-appstore
- package/secubox/secubox-core/root/usr/share/secubox/catalog.json
- secubox-tools/local-build.sh

### All Makefiles (31 packages)
- Incremented PKG_RELEASE for clean upgrade path

## Technical Details

**Admin Control Center Architecture:**
- Frontend: 5 views (dashboard, apps, settings, health, logs)
- API: Wrapper around luci.secubox RPCD methods
- Components: Reusable UI library (cards, badges, alerts, loaders)
- Styling: Common + admin-specific CSS with responsive design
- Auto-refresh: Polling for live updates (5-30s intervals)

**Docker Automation Flow:**
```
Web UI → RPCD → secubox-appstore CLI → opkg install → *ctl install →
docker pull → directories → UCI config → init enable → ✓ Ready
```

**Access Points:**
- Admin Control: http://router/cgi-bin/luci/admin/secubox/admin/
- Documentation: http://router/luci-static/secubox/index-main.html
- Demos: http://router/luci-static/secubox/demo-*.html

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-04 08:29:31 +01:00