-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu-storage-example.js
More file actions
79 lines (69 loc) · 2.19 KB
/
menu-storage-example.js
File metadata and controls
79 lines (69 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
/**
* Simple example demonstrating MenuStorageService usage.
*
* This example shows how to:
* - Store a menu structure
* - Retrieve the menu
* - Get storage statistics
*/
import MenuStorageService from '../src/services/menu-storage-service.js';
async function main() {
const menuStorage = new MenuStorageService();
console.log('=== MenuStorageService Example ===\n');
try {
// Define a simple menu structure
const menu = [
{
label: 'Dashboard',
icon: 'pi pi-home',
to: '/dashboard',
items: [
{ label: 'Analytics', icon: 'pi pi-chart-bar', to: '/dashboard/analytics' },
{ label: 'Reports', icon: 'pi pi-file', to: '/dashboard/reports' }
]
},
{
label: 'Settings',
icon: 'pi pi-cog',
to: '/settings',
items: [
{ label: 'Profile', icon: 'pi pi-user', to: '/settings/profile' },
{ label: 'Security', icon: 'pi pi-shield', to: '/settings/security' }
]
}
];
// Store the menu structure
console.log('1. Storing menu structure...');
const itemIds = await menuStorage.storeMenuStructure(menu, 0);
console.log(` Stored ${itemIds.length} root menu items`);
console.log();
// Retrieve the menu
console.log('2. Retrieving menu structure...');
const retrievedMenu = await menuStorage.getMenuStructure(0);
console.log(` Retrieved ${retrievedMenu.length} root items`);
console.log(' Menu structure:');
retrievedMenu.forEach(item => {
console.log(` - ${item.label} (${item.items ? item.items.length : 0} subitems)`);
if (item.items) {
item.items.forEach(subitem => {
console.log(` - ${subitem.label}`);
});
}
});
console.log();
// Get statistics
console.log('3. Getting storage statistics...');
const stats = await menuStorage.getStatistics();
console.log(' Statistics:', {
totalLinks: stats.totalLinks,
totalFiles: stats.totalFiles,
rootItems: stats.rootItems
});
console.log('\nExample completed successfully!');
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
main();