feat(dashboard): implement dashboard data structure (Task 1.3)
Add dashboard configuration to extensionSettings and create default layout system: State Management (state.js): - Added extensionSettings.dashboard with version 2 - gridConfig: columns (12), rowHeight (80px), gap (12px), snapToGrid, showGrid - tabs: Array of tab objects with widgets - defaultTab: ID of tab to show on load - Comprehensive inline documentation of structure Default Layout Generator (defaultLayout.js): - generateDefaultDashboard() - Creates 2-tab default layout - "Status" tab: userStats, infoBox, presentCharacters (3 widgets) - "Inventory" tab: inventory widget (1 widget) - migrateV1ToV2Dashboard() - Migrates v1.x settings to v2.0 - Respects user's visibility preferences (showUserStats, etc.) - Removes hidden widgets from migrated layout - Preserves user data during migration - validateDashboardConfig() - Validates dashboard structure - Utility functions: getWidgetCount(), findWidget() Persistence Layer (persistence.js): - Auto-migration on loadSettings() for existing users - Validates dashboard config on load - Regenerates default if config invalid or missing - Seamless backward compatibility Test Suite (defaultLayout.test.html): - 4 test scenarios with visual verification - Tests generation, validation, migration, utilities - Live dashboard JSON preview - Statistics panel (version, tabs, widgets, grid config) Features: - Automatic migration from v1.x hardcoded panel - Preserves user preferences during migration - Validates all dashboard configs on load - Generates sensible defaults for new users Acceptance Criteria Met: ✓ Dashboard config persists in extensionSettings ✓ Default layout generates on first load ✓ Existing users see migrated layout preserving their preferences ✓ All data structures validated Epic 1, Task 1.3 Complete (1-2 day estimate, <10 min actual)
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
} from './state.js';
|
||||
import { migrateInventory } from '../utils/migration.js';
|
||||
import { validateStoredInventory, cleanItemString } from '../utils/security.js';
|
||||
import { generateDefaultDashboard, migrateV1ToV2Dashboard, validateDashboardConfig } from '../systems/dashboard/defaultLayout.js';
|
||||
|
||||
const extensionName = 'third-party/rpg-companion-sillytavern';
|
||||
|
||||
@@ -95,6 +96,20 @@ export function loadSettings() {
|
||||
saveSettings(); // Persist migrated inventory
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate to v2.0 dashboard if not present
|
||||
if (!extensionSettings.dashboard || !extensionSettings.dashboard.tabs || extensionSettings.dashboard.tabs.length === 0) {
|
||||
console.log('[RPG Companion] Dashboard v2.0 not found, migrating from v1.x');
|
||||
extensionSettings.dashboard = migrateV1ToV2Dashboard(extensionSettings);
|
||||
saveSettings(); // Persist migrated dashboard
|
||||
} else {
|
||||
// Validate existing dashboard config
|
||||
if (!validateDashboardConfig(extensionSettings.dashboard)) {
|
||||
console.warn('[RPG Companion] Dashboard config invalid, regenerating default');
|
||||
extensionSettings.dashboard = generateDefaultDashboard();
|
||||
saveSettings();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[RPG Companion] Error loading settings:', error);
|
||||
console.error('[RPG Companion] Error details:', error.message, error.stack);
|
||||
|
||||
+35
-1
@@ -77,7 +77,41 @@ export let extensionSettings = {
|
||||
stored: 'list', // 'list' or 'grid' view mode for Stored section
|
||||
assets: 'list' // 'list' or 'grid' view mode for Assets section
|
||||
},
|
||||
debugMode: false // Enable debug logging visible in UI (for mobile debugging)
|
||||
debugMode: false, // Enable debug logging visible in UI (for mobile debugging)
|
||||
|
||||
// Dashboard v2.0 Configuration
|
||||
dashboard: {
|
||||
version: 2, // Dashboard config version
|
||||
|
||||
gridConfig: {
|
||||
columns: 12, // Grid columns
|
||||
rowHeight: 80, // Pixels per row
|
||||
gap: 12, // Gap between widgets (px)
|
||||
snapToGrid: true, // Auto-snap enabled
|
||||
showGrid: true // Show grid lines in edit mode
|
||||
},
|
||||
|
||||
tabs: [
|
||||
// Default tabs will be generated by generateDefaultDashboard()
|
||||
// Structure:
|
||||
// {
|
||||
// id: 'tab-status',
|
||||
// name: 'Status',
|
||||
// icon: '📊',
|
||||
// order: 0,
|
||||
// widgets: [
|
||||
// {
|
||||
// id: 'widget-1',
|
||||
// type: 'userStats',
|
||||
// x: 0, y: 0, w: 6, h: 3,
|
||||
// config: {}
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
],
|
||||
|
||||
defaultTab: 'tab-status' // Which tab to show on load
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user