@nodestackapp/server 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +36 -0
- package/README.md +182 -3
- package/bin/nodebase.js +4 -0
- package/bin/nodestack.js +21 -0
- package/dist/NodeBase.d.ts +2 -0
- package/dist/NodeBase.d.ts.map +1 -0
- package/dist/NodeBase.js +8 -0
- package/dist/NodeBase.js.map +1 -0
- package/dist/NodeStack.d.ts +111 -0
- package/dist/NodeStack.d.ts.map +1 -0
- package/dist/NodeStack.js +316 -0
- package/dist/NodeStack.js.map +1 -0
- package/dist/admin/AdminUIBundler.d.ts +8 -0
- package/dist/admin/AdminUIBundler.d.ts.map +1 -0
- package/dist/admin/AdminUIBundler.js +104 -0
- package/dist/admin/AdminUIBundler.js.map +1 -0
- package/dist/admin/AdminUIService.d.ts +30 -0
- package/dist/admin/AdminUIService.d.ts.map +1 -0
- package/dist/admin/AdminUIService.js +210 -0
- package/dist/admin/AdminUIService.js.map +1 -0
- package/dist/admin/DocsService.d.ts +29 -0
- package/dist/admin/DocsService.d.ts.map +1 -0
- package/dist/admin/DocsService.js +564 -0
- package/dist/admin/DocsService.js.map +1 -0
- package/dist/admin/ui/css/analytics.css +382 -0
- package/dist/admin/ui/css/main.css +2189 -0
- package/dist/admin/ui/css/rules.css +292 -0
- package/dist/admin/ui/css/webhooks.css +360 -0
- package/dist/admin/ui/favicon.svg +17 -0
- package/dist/admin/ui/icon.svg +17 -0
- package/dist/admin/ui/index.html +15168 -0
- package/dist/admin/ui/js/analytics.js +673 -0
- package/dist/admin/ui/js/api.js +369 -0
- package/dist/admin/ui/js/app.js +254 -0
- package/dist/admin/ui/js/apps.js +454 -0
- package/dist/admin/ui/js/collections.js +435 -0
- package/dist/admin/ui/js/command-palette.js +631 -0
- package/dist/admin/ui/js/demo.js +661 -0
- package/dist/admin/ui/js/modals.js +2379 -0
- package/dist/admin/ui/js/plugin-tester.js +559 -0
- package/dist/admin/ui/js/plugins.js +778 -0
- package/dist/admin/ui/js/records.js +1270 -0
- package/dist/admin/ui/js/rules.js +775 -0
- package/dist/admin/ui/js/schema.js +290 -0
- package/dist/admin/ui/js/state.js +140 -0
- package/dist/admin/ui/js/theme.js +120 -0
- package/dist/admin/ui/js/views.js +632 -0
- package/dist/admin/ui/js/webhooks.js +1104 -0
- package/dist/analytics/AnalyticsService.d.ts +62 -0
- package/dist/analytics/AnalyticsService.d.ts.map +1 -0
- package/dist/analytics/AnalyticsService.js +196 -0
- package/dist/analytics/AnalyticsService.js.map +1 -0
- package/dist/apps/AppManager.d.ts +28 -0
- package/dist/apps/AppManager.d.ts.map +1 -0
- package/dist/apps/AppManager.js +211 -0
- package/dist/apps/AppManager.js.map +1 -0
- package/dist/apps/AppRegistry.d.ts +27 -0
- package/dist/apps/AppRegistry.d.ts.map +1 -0
- package/dist/apps/AppRegistry.js +220 -0
- package/dist/apps/AppRegistry.js.map +1 -0
- package/dist/apps/AppScope.d.ts +57 -0
- package/dist/apps/AppScope.d.ts.map +1 -0
- package/dist/apps/AppScope.js +299 -0
- package/dist/apps/AppScope.js.map +1 -0
- package/dist/apps/index.d.ts +5 -0
- package/dist/apps/index.d.ts.map +1 -0
- package/dist/apps/index.js +21 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/models/App.d.ts +29 -0
- package/dist/apps/models/App.d.ts.map +1 -0
- package/dist/apps/models/App.js +3 -0
- package/dist/apps/models/App.js.map +1 -0
- package/dist/audit/AuditLogService.d.ts +68 -0
- package/dist/audit/AuditLogService.d.ts.map +1 -0
- package/dist/audit/AuditLogService.js +243 -0
- package/dist/audit/AuditLogService.js.map +1 -0
- package/dist/auth/AuthService.d.ts +35 -0
- package/dist/auth/AuthService.d.ts.map +1 -0
- package/dist/auth/AuthService.js +303 -0
- package/dist/auth/AuthService.js.map +1 -0
- package/dist/cli/cli.d.ts +3 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +541 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/core/config/ConfigService.d.ts +42 -0
- package/dist/core/config/ConfigService.d.ts.map +1 -0
- package/dist/core/config/ConfigService.js +142 -0
- package/dist/core/config/ConfigService.js.map +1 -0
- package/dist/core/config/EnvLoader.d.ts +7 -0
- package/dist/core/config/EnvLoader.d.ts.map +1 -0
- package/dist/core/config/EnvLoader.js +84 -0
- package/dist/core/config/EnvLoader.js.map +1 -0
- package/dist/core/container/Container.d.ts +34 -0
- package/dist/core/container/Container.d.ts.map +1 -0
- package/dist/core/container/Container.js +98 -0
- package/dist/core/container/Container.js.map +1 -0
- package/dist/core/container/Tokens.d.ts +42 -0
- package/dist/core/container/Tokens.d.ts.map +1 -0
- package/dist/core/container/Tokens.js +42 -0
- package/dist/core/container/Tokens.js.map +1 -0
- package/dist/core/errors/AppError.d.ts +24 -0
- package/dist/core/errors/AppError.d.ts.map +1 -0
- package/dist/core/errors/AppError.js +52 -0
- package/dist/core/errors/AppError.js.map +1 -0
- package/dist/core/events/EventBus.d.ts +45 -0
- package/dist/core/events/EventBus.d.ts.map +1 -0
- package/dist/core/events/EventBus.js +360 -0
- package/dist/core/events/EventBus.js.map +1 -0
- package/dist/core/events/types.d.ts +35 -0
- package/dist/core/events/types.d.ts.map +1 -0
- package/dist/core/events/types.js +3 -0
- package/dist/core/events/types.js.map +1 -0
- package/dist/core/maintenance/MaintenanceGate.d.ts +65 -0
- package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -0
- package/dist/core/maintenance/MaintenanceGate.js +162 -0
- package/dist/core/maintenance/MaintenanceGate.js.map +1 -0
- package/dist/core/plugins/PluginManager.d.ts +150 -0
- package/dist/core/plugins/PluginManager.d.ts.map +1 -0
- package/dist/core/plugins/PluginManager.js +1592 -0
- package/dist/core/plugins/PluginManager.js.map +1 -0
- package/dist/core/plugins/types.d.ts +170 -0
- package/dist/core/plugins/types.d.ts.map +1 -0
- package/dist/core/plugins/types.js +3 -0
- package/dist/core/plugins/types.js.map +1 -0
- package/dist/database/DatabaseService.d.ts +27 -0
- package/dist/database/DatabaseService.d.ts.map +1 -0
- package/dist/database/DatabaseService.js +97 -0
- package/dist/database/DatabaseService.js.map +1 -0
- package/dist/database/drivers/IDatabaseDriver.d.ts +17 -0
- package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -0
- package/dist/database/drivers/IDatabaseDriver.js +3 -0
- package/dist/database/drivers/IDatabaseDriver.js.map +1 -0
- package/dist/database/drivers/NodeSqliteDriver.d.ts +16 -0
- package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -0
- package/dist/database/drivers/NodeSqliteDriver.js +115 -0
- package/dist/database/drivers/NodeSqliteDriver.js.map +1 -0
- package/dist/database/migrations/SystemMigrations.d.ts +5 -0
- package/dist/database/migrations/SystemMigrations.d.ts.map +1 -0
- package/dist/database/migrations/SystemMigrations.js +164 -0
- package/dist/database/migrations/SystemMigrations.js.map +1 -0
- package/dist/demo/DemoService.d.ts +27 -0
- package/dist/demo/DemoService.d.ts.map +1 -0
- package/dist/demo/DemoService.js +22 -0
- package/dist/demo/DemoService.js.map +1 -0
- package/dist/files/FileStorageService.d.ts +35 -0
- package/dist/files/FileStorageService.d.ts.map +1 -0
- package/dist/files/FileStorageService.js +126 -0
- package/dist/files/FileStorageService.js.map +1 -0
- package/dist/http/HttpServer.d.ts +63 -0
- package/dist/http/HttpServer.d.ts.map +1 -0
- package/dist/http/HttpServer.js +513 -0
- package/dist/http/HttpServer.js.map +1 -0
- package/dist/http/controllers/AnalyticsController.d.ts +9 -0
- package/dist/http/controllers/AnalyticsController.d.ts.map +1 -0
- package/dist/http/controllers/AnalyticsController.js +18 -0
- package/dist/http/controllers/AnalyticsController.js.map +1 -0
- package/dist/http/controllers/AppController.d.ts +29 -0
- package/dist/http/controllers/AppController.d.ts.map +1 -0
- package/dist/http/controllers/AppController.js +36 -0
- package/dist/http/controllers/AppController.js.map +1 -0
- package/dist/http/controllers/AuditLogController.d.ts +26 -0
- package/dist/http/controllers/AuditLogController.d.ts.map +1 -0
- package/dist/http/controllers/AuditLogController.js +32 -0
- package/dist/http/controllers/AuditLogController.js.map +1 -0
- package/dist/http/controllers/AuthController.d.ts +18 -0
- package/dist/http/controllers/AuthController.d.ts.map +1 -0
- package/dist/http/controllers/AuthController.js +84 -0
- package/dist/http/controllers/AuthController.js.map +1 -0
- package/dist/http/controllers/BaseController.d.ts +7 -0
- package/dist/http/controllers/BaseController.d.ts.map +1 -0
- package/dist/http/controllers/BaseController.js +20 -0
- package/dist/http/controllers/BaseController.js.map +1 -0
- package/dist/http/controllers/CollectionController.d.ts +44 -0
- package/dist/http/controllers/CollectionController.d.ts.map +1 -0
- package/dist/http/controllers/CollectionController.js +89 -0
- package/dist/http/controllers/CollectionController.js.map +1 -0
- package/dist/http/controllers/DemoController.d.ts +34 -0
- package/dist/http/controllers/DemoController.d.ts.map +1 -0
- package/dist/http/controllers/DemoController.js +56 -0
- package/dist/http/controllers/DemoController.js.map +1 -0
- package/dist/http/controllers/FileController.d.ts +29 -0
- package/dist/http/controllers/FileController.d.ts.map +1 -0
- package/dist/http/controllers/FileController.js +172 -0
- package/dist/http/controllers/FileController.js.map +1 -0
- package/dist/http/controllers/HealthController.d.ts +10 -0
- package/dist/http/controllers/HealthController.d.ts.map +1 -0
- package/dist/http/controllers/HealthController.js +28 -0
- package/dist/http/controllers/HealthController.js.map +1 -0
- package/dist/http/controllers/LogController.d.ts +15 -0
- package/dist/http/controllers/LogController.d.ts.map +1 -0
- package/dist/http/controllers/LogController.js +25 -0
- package/dist/http/controllers/LogController.js.map +1 -0
- package/dist/http/controllers/RealtimeController.d.ts +13 -0
- package/dist/http/controllers/RealtimeController.d.ts.map +1 -0
- package/dist/http/controllers/RealtimeController.js +54 -0
- package/dist/http/controllers/RealtimeController.js.map +1 -0
- package/dist/http/controllers/RecordController.d.ts +74 -0
- package/dist/http/controllers/RecordController.d.ts.map +1 -0
- package/dist/http/controllers/RecordController.js +202 -0
- package/dist/http/controllers/RecordController.js.map +1 -0
- package/dist/http/controllers/SnapshotController.d.ts +58 -0
- package/dist/http/controllers/SnapshotController.d.ts.map +1 -0
- package/dist/http/controllers/SnapshotController.js +79 -0
- package/dist/http/controllers/SnapshotController.js.map +1 -0
- package/dist/http/controllers/TemplateController.d.ts +29 -0
- package/dist/http/controllers/TemplateController.d.ts.map +1 -0
- package/dist/http/controllers/TemplateController.js +63 -0
- package/dist/http/controllers/TemplateController.js.map +1 -0
- package/dist/http/controllers/WebhookController.d.ts +78 -0
- package/dist/http/controllers/WebhookController.d.ts.map +1 -0
- package/dist/http/controllers/WebhookController.js +113 -0
- package/dist/http/controllers/WebhookController.js.map +1 -0
- package/dist/http/middleware/AppResolutionMiddleware.d.ts +8 -0
- package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -0
- package/dist/http/middleware/AppResolutionMiddleware.js +98 -0
- package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -0
- package/dist/http/middleware/AuthMiddleware.d.ts +17 -0
- package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -0
- package/dist/http/middleware/AuthMiddleware.js +97 -0
- package/dist/http/middleware/AuthMiddleware.js.map +1 -0
- package/dist/http/middleware/ChaosMiddleware.d.ts +130 -0
- package/dist/http/middleware/ChaosMiddleware.d.ts.map +1 -0
- package/dist/http/middleware/ChaosMiddleware.js +434 -0
- package/dist/http/middleware/ChaosMiddleware.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/LogService.d.ts +31 -0
- package/dist/logger/LogService.d.ts.map +1 -0
- package/dist/logger/LogService.js +104 -0
- package/dist/logger/LogService.js.map +1 -0
- package/dist/plugins/algolia.d.ts +76 -0
- package/dist/plugins/algolia.d.ts.map +1 -0
- package/dist/plugins/algolia.js +532 -0
- package/dist/plugins/algolia.js.map +1 -0
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +22 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/resend.d.ts +42 -0
- package/dist/plugins/resend.d.ts.map +1 -0
- package/dist/plugins/resend.js +335 -0
- package/dist/plugins/resend.js.map +1 -0
- package/dist/plugins/s3.d.ts +35 -0
- package/dist/plugins/s3.d.ts.map +1 -0
- package/dist/plugins/s3.js +425 -0
- package/dist/plugins/s3.js.map +1 -0
- package/dist/plugins/stripe.d.ts +45 -0
- package/dist/plugins/stripe.d.ts.map +1 -0
- package/dist/plugins/stripe.js +470 -0
- package/dist/plugins/stripe.js.map +1 -0
- package/dist/plugins/webhooks.d.ts +35 -0
- package/dist/plugins/webhooks.d.ts.map +1 -0
- package/dist/plugins/webhooks.js +415 -0
- package/dist/plugins/webhooks.js.map +1 -0
- package/dist/realtime/RealtimeService.d.ts +26 -0
- package/dist/realtime/RealtimeService.d.ts.map +1 -0
- package/dist/realtime/RealtimeService.js +165 -0
- package/dist/realtime/RealtimeService.js.map +1 -0
- package/dist/records/CsvHelper.d.ts +27 -0
- package/dist/records/CsvHelper.d.ts.map +1 -0
- package/dist/records/CsvHelper.js +195 -0
- package/dist/records/CsvHelper.js.map +1 -0
- package/dist/records/FakerEngine.d.ts +73 -0
- package/dist/records/FakerEngine.d.ts.map +1 -0
- package/dist/records/FakerEngine.js +644 -0
- package/dist/records/FakerEngine.js.map +1 -0
- package/dist/records/FilterCodec.d.ts +22 -0
- package/dist/records/FilterCodec.d.ts.map +1 -0
- package/dist/records/FilterCodec.js +57 -0
- package/dist/records/FilterCodec.js.map +1 -0
- package/dist/records/FtsService.d.ts +63 -0
- package/dist/records/FtsService.d.ts.map +1 -0
- package/dist/records/FtsService.js +310 -0
- package/dist/records/FtsService.js.map +1 -0
- package/dist/records/MockDataService.d.ts +31 -0
- package/dist/records/MockDataService.d.ts.map +1 -0
- package/dist/records/MockDataService.js +222 -0
- package/dist/records/MockDataService.js.map +1 -0
- package/dist/records/QueryFilterParser.d.ts +35 -0
- package/dist/records/QueryFilterParser.d.ts.map +1 -0
- package/dist/records/QueryFilterParser.js +263 -0
- package/dist/records/QueryFilterParser.js.map +1 -0
- package/dist/records/RecordService.d.ts +77 -0
- package/dist/records/RecordService.d.ts.map +1 -0
- package/dist/records/RecordService.js +704 -0
- package/dist/records/RecordService.js.map +1 -0
- package/dist/rules/RuleBuilder.d.ts +72 -0
- package/dist/rules/RuleBuilder.d.ts.map +1 -0
- package/dist/rules/RuleBuilder.js +383 -0
- package/dist/rules/RuleBuilder.js.map +1 -0
- package/dist/rules/RuleEngine.d.ts +42 -0
- package/dist/rules/RuleEngine.d.ts.map +1 -0
- package/dist/rules/RuleEngine.js +347 -0
- package/dist/rules/RuleEngine.js.map +1 -0
- package/dist/schema/OpenApiGenerator.d.ts +32 -0
- package/dist/schema/OpenApiGenerator.d.ts.map +1 -0
- package/dist/schema/OpenApiGenerator.js +1836 -0
- package/dist/schema/OpenApiGenerator.js.map +1 -0
- package/dist/schema/SchemaInferenceService.d.ts +82 -0
- package/dist/schema/SchemaInferenceService.d.ts.map +1 -0
- package/dist/schema/SchemaInferenceService.js +622 -0
- package/dist/schema/SchemaInferenceService.js.map +1 -0
- package/dist/schema/SchemaService.d.ts +33 -0
- package/dist/schema/SchemaService.d.ts.map +1 -0
- package/dist/schema/SchemaService.js +338 -0
- package/dist/schema/SchemaService.js.map +1 -0
- package/dist/schema/TypeGenerator.d.ts +19 -0
- package/dist/schema/TypeGenerator.d.ts.map +1 -0
- package/dist/schema/TypeGenerator.js +173 -0
- package/dist/schema/TypeGenerator.js.map +1 -0
- package/dist/schema/models/Collection.d.ts +44 -0
- package/dist/schema/models/Collection.d.ts.map +1 -0
- package/dist/schema/models/Collection.js +3 -0
- package/dist/schema/models/Collection.js.map +1 -0
- package/dist/schema/models/Field.d.ts +25 -0
- package/dist/schema/models/Field.d.ts.map +1 -0
- package/dist/schema/models/Field.js +3 -0
- package/dist/schema/models/Field.js.map +1 -0
- package/dist/snapshots/SnapshotService.d.ts +75 -0
- package/dist/snapshots/SnapshotService.d.ts.map +1 -0
- package/dist/snapshots/SnapshotService.js +775 -0
- package/dist/snapshots/SnapshotService.js.map +1 -0
- package/dist/snapshots/types.d.ts +63 -0
- package/dist/snapshots/types.d.ts.map +1 -0
- package/dist/snapshots/types.js +5 -0
- package/dist/snapshots/types.js.map +1 -0
- package/dist/templates/TemplateImageGenerator.d.ts +43 -0
- package/dist/templates/TemplateImageGenerator.d.ts.map +1 -0
- package/dist/templates/TemplateImageGenerator.js +350 -0
- package/dist/templates/TemplateImageGenerator.js.map +1 -0
- package/dist/templates/TemplateService.d.ts +31 -0
- package/dist/templates/TemplateService.d.ts.map +1 -0
- package/dist/templates/TemplateService.js +209 -0
- package/dist/templates/TemplateService.js.map +1 -0
- package/dist/templates/definitions/blog.d.ts +3 -0
- package/dist/templates/definitions/blog.d.ts.map +1 -0
- package/dist/templates/definitions/blog.js +386 -0
- package/dist/templates/definitions/blog.js.map +1 -0
- package/dist/templates/definitions/crm.d.ts +3 -0
- package/dist/templates/definitions/crm.d.ts.map +1 -0
- package/dist/templates/definitions/crm.js +456 -0
- package/dist/templates/definitions/crm.js.map +1 -0
- package/dist/templates/definitions/ecommerce.d.ts +3 -0
- package/dist/templates/definitions/ecommerce.d.ts.map +1 -0
- package/dist/templates/definitions/ecommerce.js +781 -0
- package/dist/templates/definitions/ecommerce.js.map +1 -0
- package/dist/templates/definitions/index.d.ts +7 -0
- package/dist/templates/definitions/index.d.ts.map +1 -0
- package/dist/templates/definitions/index.js +15 -0
- package/dist/templates/definitions/index.js.map +1 -0
- package/dist/templates/types.d.ts +65 -0
- package/dist/templates/types.d.ts.map +1 -0
- package/dist/templates/types.js +3 -0
- package/dist/templates/types.js.map +1 -0
- package/dist/webhooks/WebhookService.d.ts +149 -0
- package/dist/webhooks/WebhookService.d.ts.map +1 -0
- package/dist/webhooks/WebhookService.js +781 -0
- package/dist/webhooks/WebhookService.js.map +1 -0
- package/package.json +88 -6
|
@@ -0,0 +1,1270 @@
|
|
|
1
|
+
// Records Data Grid & Export
|
|
2
|
+
function getSearchableFields(col) {
|
|
3
|
+
if (!col) return [];
|
|
4
|
+
const fields = [];
|
|
5
|
+
if (col.type === 'auth') {
|
|
6
|
+
fields.push({ name: 'email', type: 'email' });
|
|
7
|
+
}
|
|
8
|
+
for (const f of col.schema) {
|
|
9
|
+
if (['text', 'email', 'url', 'select'].includes(f.type)) {
|
|
10
|
+
if (!fields.some(existing => existing.name === f.name)) {
|
|
11
|
+
fields.push(f);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return fields;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function buildSearchFilter(term, field, col) {
|
|
19
|
+
if (!term || !term.trim()) return '';
|
|
20
|
+
const trimmed = term.trim();
|
|
21
|
+
const encoded = encodeFilterString(trimmed);
|
|
22
|
+
const searchable = getSearchableFields(col);
|
|
23
|
+
|
|
24
|
+
if (field && field !== '_all') {
|
|
25
|
+
return `${field} ~ ${encoded}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (searchable.length === 0) {
|
|
29
|
+
return `id ~ ${encoded}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// By default, search across all text/email/url fields using an || condition
|
|
33
|
+
return searchable.map(f => `${f.name} ~ ${encoded}`).join(' || ');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let searchDebounceTimer = null;
|
|
37
|
+
|
|
38
|
+
function handleSearch(val) {
|
|
39
|
+
state.recordsSearchTerm = val;
|
|
40
|
+
updateSearchActiveIndicator();
|
|
41
|
+
if (searchDebounceTimer) clearTimeout(searchDebounceTimer);
|
|
42
|
+
searchDebounceTimer = setTimeout(() => {
|
|
43
|
+
executeSearch();
|
|
44
|
+
}, 250);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleSearchFieldChange(field) {
|
|
48
|
+
state.recordsSearchField = field;
|
|
49
|
+
executeSearch();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function executeSearch() {
|
|
53
|
+
state.recordsPage = 1;
|
|
54
|
+
state.recordsFilter = buildSearchFilter(state.recordsSearchTerm, state.recordsSearchField, state.activeCollection);
|
|
55
|
+
loadRecords();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function clearSearch() {
|
|
59
|
+
state.recordsSearchTerm = '';
|
|
60
|
+
const searchInput = document.getElementById('records-search');
|
|
61
|
+
if (searchInput) {
|
|
62
|
+
searchInput.value = '';
|
|
63
|
+
searchInput.focus();
|
|
64
|
+
}
|
|
65
|
+
executeSearch();
|
|
66
|
+
updateSearchActiveIndicator();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function updateSearchActiveIndicator() {
|
|
70
|
+
const compBox = document.getElementById('search-composite-box');
|
|
71
|
+
const clearBtn = document.getElementById('search-clear-btn');
|
|
72
|
+
const indicator = document.getElementById('search-active-indicator');
|
|
73
|
+
const term = (state.recordsSearchTerm || '').trim();
|
|
74
|
+
const isSearching = term.length > 0;
|
|
75
|
+
|
|
76
|
+
if (compBox) {
|
|
77
|
+
if (isSearching) compBox.classList.add('is-active');
|
|
78
|
+
else compBox.classList.remove('is-active');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (clearBtn) {
|
|
82
|
+
clearBtn.style.display = isSearching ? 'block' : 'none';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (indicator) {
|
|
86
|
+
if (isSearching) {
|
|
87
|
+
let fieldLabel = 'All text fields';
|
|
88
|
+
if (state.recordsSearchField !== '_all') {
|
|
89
|
+
fieldLabel = state.recordsSearchField;
|
|
90
|
+
}
|
|
91
|
+
indicator.innerHTML = `
|
|
92
|
+
<span class="search-active-dot"></span>
|
|
93
|
+
<span>Filtering by <strong>${escapeHtml(fieldLabel)}</strong>: "${escapeHtml(term.length > 20 ? term.slice(0, 20) + '...' : term)}"</span>
|
|
94
|
+
<button class="search-clear-badge-btn" onclick="clearSearch()" title="Clear filter">✕</button>
|
|
95
|
+
`;
|
|
96
|
+
indicator.style.display = 'inline-flex';
|
|
97
|
+
} else {
|
|
98
|
+
indicator.style.display = 'none';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getCurrentSort() {
|
|
104
|
+
const s = state.recordsSort || '-created';
|
|
105
|
+
if (s.startsWith('-')) {
|
|
106
|
+
return { field: s.substring(1), dir: 'desc' };
|
|
107
|
+
}
|
|
108
|
+
if (s.startsWith('+')) {
|
|
109
|
+
return { field: s.substring(1), dir: 'asc' };
|
|
110
|
+
}
|
|
111
|
+
return { field: s, dir: 'asc' };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toggleSort(field) {
|
|
115
|
+
const current = getCurrentSort();
|
|
116
|
+
let newDir = 'asc';
|
|
117
|
+
if (current.field === field) {
|
|
118
|
+
newDir = current.dir === 'asc' ? 'desc' : 'asc';
|
|
119
|
+
} else {
|
|
120
|
+
newDir = field === 'created' ? 'desc' : 'asc';
|
|
121
|
+
}
|
|
122
|
+
state.recordsSort = (newDir === 'desc' ? '-' : '') + field;
|
|
123
|
+
state.recordsPage = 1;
|
|
124
|
+
loadRecords();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function changeRecordsPage(newPage) {
|
|
128
|
+
const totalPages = Math.max(1, Math.ceil(state.recordsTotal / state.recordsPerPage));
|
|
129
|
+
if (newPage < 1 || newPage > totalPages || newPage === state.recordsPage) return;
|
|
130
|
+
state.recordsPage = newPage;
|
|
131
|
+
loadRecords();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function goToRecordsPage(val) {
|
|
135
|
+
const totalPages = Math.max(1, Math.ceil(state.recordsTotal / state.recordsPerPage));
|
|
136
|
+
let num = parseInt(val, 10);
|
|
137
|
+
if (isNaN(num)) {
|
|
138
|
+
const input = document.getElementById('page-jump-input');
|
|
139
|
+
if (input) input.value = state.recordsPage;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (num < 1) num = 1;
|
|
143
|
+
if (num > totalPages) num = totalPages;
|
|
144
|
+
if (num !== state.recordsPage) {
|
|
145
|
+
state.recordsPage = num;
|
|
146
|
+
loadRecords();
|
|
147
|
+
} else {
|
|
148
|
+
const input = document.getElementById('page-jump-input');
|
|
149
|
+
if (input) input.value = state.recordsPage;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function changeRecordsPerPage(val) {
|
|
154
|
+
const num = parseInt(val, 10);
|
|
155
|
+
if (num && num !== state.recordsPerPage) {
|
|
156
|
+
state.recordsPerPage = num;
|
|
157
|
+
state.recordsPage = 1;
|
|
158
|
+
loadRecords();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function renderRecordsView() {
|
|
163
|
+
const topActions = document.getElementById('view-actions');
|
|
164
|
+
if (topActions) topActions.innerHTML = '';
|
|
165
|
+
const actions = document.getElementById('collection-actions') || topActions;
|
|
166
|
+
actions.innerHTML = `
|
|
167
|
+
<div style="display:flex; align-items:center; gap:0.5rem;">
|
|
168
|
+
<div class="dropdown-wrapper">
|
|
169
|
+
<button class="btn btn-secondary btn-sm" onclick="toggleExportMenu(event)" title="Export collection records">
|
|
170
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
|
|
171
|
+
<span>Export</span>
|
|
172
|
+
<span style="font-size:10px; margin-left:1px; opacity:0.7;">▾</span>
|
|
173
|
+
</button>
|
|
174
|
+
<div id="export-dropdown-menu" style="display:none; position:absolute; right:0; top:calc(100% + 4px); background:var(--bg-card); border:1px solid var(--border-subtle); border-radius:6px; box-shadow:var(--shadow-dropdown); min-width:150px; z-index:100; padding:4px 0;">
|
|
175
|
+
<button class="dropdown-menu-item" onclick="exportData('csv')">
|
|
176
|
+
<span style="color:#60a5fa; font-weight:bold;">CSV</span> Export as CSV
|
|
177
|
+
</button>
|
|
178
|
+
<button class="dropdown-menu-item" onclick="exportData('json')">
|
|
179
|
+
<span style="color:#34d399; font-weight:bold;">{ }</span> Export as JSON
|
|
180
|
+
</button>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<button class="btn btn-secondary btn-sm" onclick="openImportModal()" title="Drag & drop CSV import with visual column mapping">
|
|
185
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
|
|
186
|
+
<span>Import CSV</span>
|
|
187
|
+
</button>
|
|
188
|
+
|
|
189
|
+
<button class="btn btn-secondary btn-sm" onclick="openMockDataModal()" title="1-Click Generate Mock Data (Built-in Faker Engine)" style="border-color: rgba(96, 165, 250, 0.4); color: var(--accent-primary);">
|
|
190
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>
|
|
191
|
+
<span>Generate Mock Data</span>
|
|
192
|
+
</button>
|
|
193
|
+
|
|
194
|
+
<button class="btn btn-primary btn-sm" onclick="openNewRecordModal()">
|
|
195
|
+
<span>+ New Record</span>
|
|
196
|
+
</button>
|
|
197
|
+
</div>
|
|
198
|
+
`;
|
|
199
|
+
|
|
200
|
+
if (typeof showPageView === 'function') {
|
|
201
|
+
showPageView('collections');
|
|
202
|
+
}
|
|
203
|
+
const col = state.activeCollection;
|
|
204
|
+
const searchableFields = getSearchableFields(col);
|
|
205
|
+
|
|
206
|
+
const main = document.getElementById('collections-detail-pane') || document.getElementById('main-body');
|
|
207
|
+
main.innerHTML = `
|
|
208
|
+
<div class="controls-bar">
|
|
209
|
+
<div style="display:flex; align-items:center; gap:0.75rem; flex:1; max-width:640px;">
|
|
210
|
+
<div class="search-bar-composite" id="search-composite-box">
|
|
211
|
+
<select id="records-search-field" class="search-field-select" onchange="handleSearchFieldChange(this.value)" title="Choose column to search">
|
|
212
|
+
<option value="_all" ${state.recordsSearchField === '_all' ? 'selected' : ''}>All Text Fields (${searchableFields.length}) ▾</option>
|
|
213
|
+
${searchableFields.map(f => {
|
|
214
|
+
const safeName = escapeHtml(f.name);
|
|
215
|
+
const safeType = escapeHtml(f.type);
|
|
216
|
+
return `<option value="${safeName}" ${state.recordsSearchField === f.name ? 'selected' : ''}>${safeName} (${safeType})</option>`;
|
|
217
|
+
}).join('')}
|
|
218
|
+
<option value="id" ${state.recordsSearchField === 'id' ? 'selected' : ''}>id (system)</option>
|
|
219
|
+
</select>
|
|
220
|
+
<div class="search-input-wrapper">
|
|
221
|
+
<span class="search-icon">🔍</span>
|
|
222
|
+
<input type="text" class="search-input" placeholder="Search records..." id="records-search" value="${escapeHtml(state.recordsSearchTerm)}" oninput="handleSearch(this.value)">
|
|
223
|
+
<button id="search-clear-btn" class="search-clear-btn" onclick="clearSearch()" style="display:${state.recordsSearchTerm ? 'block' : 'none'};" title="Clear search">✕</button>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
<div id="search-active-indicator" class="search-active-badge" style="display:none;"></div>
|
|
227
|
+
</div>
|
|
228
|
+
<div style="font-size:12px; color:var(--text-muted);" id="pagination-label">Loading records...</div>
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
<div class="table-container">
|
|
232
|
+
<table id="records-table">
|
|
233
|
+
<thead><tr id="table-head"></tr></thead>
|
|
234
|
+
<tbody id="table-body"><tr><td colspan="10" style="text-align:center;padding:2rem;">Loading...</td></tr></tbody>
|
|
235
|
+
</table>
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<div class="pagination-footer" id="records-pagination">
|
|
239
|
+
<!-- Injected by updatePaginationControls() -->
|
|
240
|
+
</div>
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function loadRecords() {
|
|
245
|
+
if (!state.activeCollection) return;
|
|
246
|
+
try {
|
|
247
|
+
const queryParams = new URLSearchParams({
|
|
248
|
+
page: state.recordsPage.toString(),
|
|
249
|
+
perPage: state.recordsPerPage.toString(),
|
|
250
|
+
});
|
|
251
|
+
if (state.recordsFilter) {
|
|
252
|
+
queryParams.set('filter', state.recordsFilter);
|
|
253
|
+
}
|
|
254
|
+
if (state.recordsSort) {
|
|
255
|
+
queryParams.set('sort', state.recordsSort);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const res = await api(`/api/collections/${state.activeCollection.name}/records?${queryParams}`);
|
|
259
|
+
const totalItems = res.totalItems || 0;
|
|
260
|
+
const totalPages = Math.max(1, res.totalPages || Math.ceil(totalItems / state.recordsPerPage));
|
|
261
|
+
|
|
262
|
+
// If deleting the final item on the last page reduces totalPages, the API returns
|
|
263
|
+
// an empty out-of-range page but recordsPage remains unchanged. Clamp and reload when
|
|
264
|
+
// the response shows that the current page no longer exists.
|
|
265
|
+
if (state.recordsPage > totalPages) {
|
|
266
|
+
state.recordsPage = totalPages;
|
|
267
|
+
return loadRecords();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
state.records = res.items || [];
|
|
271
|
+
state.recordsTotal = totalItems;
|
|
272
|
+
state.recordsTotalPages = totalPages;
|
|
273
|
+
|
|
274
|
+
renderRecordsTable();
|
|
275
|
+
updatePaginationControls();
|
|
276
|
+
updateSearchActiveIndicator();
|
|
277
|
+
|
|
278
|
+
// If drawer is currently open, refresh its data if record exists
|
|
279
|
+
if (state.selectedRecordId) {
|
|
280
|
+
const updatedRec = state.records.find(r => r.id === state.selectedRecordId);
|
|
281
|
+
if (updatedRec) {
|
|
282
|
+
renderDrawerContent(updatedRec);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
toast(e.message, 'error');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function getRecordFileUrl(colName, recId, filename) {
|
|
291
|
+
const encCol = encodeURIComponent(colName || '');
|
|
292
|
+
const encId = encodeURIComponent(recId || '');
|
|
293
|
+
const encFile = encodeURIComponent(filename || '').replace(/'/g, '%27');
|
|
294
|
+
const encToken = encodeURIComponent(state.token || '');
|
|
295
|
+
return `/api/files/${encCol}/${encId}/${encFile}?token=${encToken}`;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function isImageFile(filename) {
|
|
299
|
+
return /\.(jpe?g|png|gif|webp|svg)$/i.test(filename);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function handleHeaderSort(el) {
|
|
303
|
+
if (!el) return;
|
|
304
|
+
const col = el.getAttribute('data-column') || el.closest('[data-column]')?.getAttribute('data-column');
|
|
305
|
+
if (col) {
|
|
306
|
+
toggleSort(col);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function renderSortableTh(columnName, displayName) {
|
|
311
|
+
const current = getCurrentSort();
|
|
312
|
+
const isActive = current.field === columnName;
|
|
313
|
+
const arrow = isActive ? (current.dir === 'asc' ? '↑' : '↓') : '<span class="sort-icon-ghost">↕</span>';
|
|
314
|
+
const activeClass = isActive ? `sort-active sort-${escapeHtml(current.dir)}` : '';
|
|
315
|
+
const safeCol = escapeHtml(columnName);
|
|
316
|
+
const safeDisplay = escapeHtml(displayName);
|
|
317
|
+
const nextOrder = isActive ? (current.dir === 'asc' ? 'Descending next' : 'Ascending next') : 'Ascending';
|
|
318
|
+
const safeTitle = escapeHtml(`Sort by ${displayName} (${nextOrder})`);
|
|
319
|
+
const ariaSort = isActive ? (current.dir === 'asc' ? 'ascending' : 'descending') : 'none';
|
|
320
|
+
|
|
321
|
+
return `
|
|
322
|
+
<th scope="col" class="th-sortable ${activeClass}" data-column="${safeCol}" aria-sort="${ariaSort}">
|
|
323
|
+
<button type="button" class="th-sort-btn" data-column="${safeCol}" onclick="handleHeaderSort(this)" title="${safeTitle}" aria-label="${safeTitle}">
|
|
324
|
+
<span>${safeDisplay}</span>
|
|
325
|
+
<span class="sort-icon" aria-hidden="true">${arrow}</span>
|
|
326
|
+
</button>
|
|
327
|
+
</th>
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function renderRecordsTable() {
|
|
332
|
+
const col = state.activeCollection;
|
|
333
|
+
const thContainer = document.getElementById('table-head');
|
|
334
|
+
const tbContainer = document.getElementById('table-body');
|
|
335
|
+
|
|
336
|
+
if (!thContainer || !tbContainer) return;
|
|
337
|
+
|
|
338
|
+
// Columns to display
|
|
339
|
+
const displayFields = [];
|
|
340
|
+
if (col.type === 'auth' && !col.schema.some(f => f.name === 'email')) {
|
|
341
|
+
displayFields.push('email');
|
|
342
|
+
}
|
|
343
|
+
displayFields.push(...col.schema.map(f => f.name));
|
|
344
|
+
|
|
345
|
+
thContainer.innerHTML = `
|
|
346
|
+
${renderSortableTh('id', 'ID')}
|
|
347
|
+
${displayFields.map(f => renderSortableTh(f, f)).join('')}
|
|
348
|
+
${renderSortableTh('created', 'Created')}
|
|
349
|
+
<th style="cursor:default;">Actions</th>
|
|
350
|
+
`;
|
|
351
|
+
|
|
352
|
+
if (state.records.length === 0) {
|
|
353
|
+
if (state.recordsFilter) {
|
|
354
|
+
tbContainer.innerHTML = `
|
|
355
|
+
<tr>
|
|
356
|
+
<td colspan="${displayFields.length + 3}" style="text-align:center;padding:3.5rem 1rem;">
|
|
357
|
+
<div style="display:flex; flex-direction:column; align-items:center; gap:0.75rem;">
|
|
358
|
+
<div style="width:44px; height:44px; border-radius:50%; background:rgba(59,130,246,0.12); color:#60a5fa; display:flex; align-items:center; justify-content:center; font-size:20px;">
|
|
359
|
+
🔍
|
|
360
|
+
</div>
|
|
361
|
+
<div style="font-weight:600; font-size:15px; color:var(--text-main);">No matching records found</div>
|
|
362
|
+
<div style="font-size:13px; color:var(--text-muted); max-width:380px; line-height:1.4;">
|
|
363
|
+
No records match the current search filter in '${col.name}'. Try a different term or search across all text fields.
|
|
364
|
+
</div>
|
|
365
|
+
<div style="margin-top:0.5rem;">
|
|
366
|
+
<button class="btn btn-secondary btn-sm" onclick="clearSearch()">
|
|
367
|
+
<span>Clear Search Filter</span>
|
|
368
|
+
</button>
|
|
369
|
+
</div>
|
|
370
|
+
</div>
|
|
371
|
+
</td>
|
|
372
|
+
</tr>
|
|
373
|
+
`;
|
|
374
|
+
} else {
|
|
375
|
+
tbContainer.innerHTML = `
|
|
376
|
+
<tr>
|
|
377
|
+
<td colspan="${displayFields.length + 3}" style="text-align:center;padding:3.5rem 1rem;">
|
|
378
|
+
<div style="display:flex; flex-direction:column; align-items:center; gap:0.75rem;">
|
|
379
|
+
<div style="width:44px; height:44px; border-radius:50%; background:rgba(59,130,246,0.12); color:#60a5fa; display:flex; align-items:center; justify-content:center; font-size:20px;">
|
|
380
|
+
✨
|
|
381
|
+
</div>
|
|
382
|
+
<div style="font-weight:600; font-size:15px; color:var(--text-main);">No records in '${col.name}' yet</div>
|
|
383
|
+
<div style="font-size:13px; color:var(--text-muted); max-width:380px; line-height:1.4;">
|
|
384
|
+
Populate your collection in seconds with realistic human names, emails, prices, avatars, and linked relations.
|
|
385
|
+
</div>
|
|
386
|
+
<div style="display:flex; gap:0.5rem; margin-top:0.5rem;">
|
|
387
|
+
<button class="btn btn-primary btn-sm" onclick="openMockDataModal()">
|
|
388
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>
|
|
389
|
+
<span>Generate Mock Data</span>
|
|
390
|
+
</button>
|
|
391
|
+
<button class="btn btn-secondary btn-sm" onclick="openNewRecordModal()">
|
|
392
|
+
<span>+ New Record</span>
|
|
393
|
+
</button>
|
|
394
|
+
</div>
|
|
395
|
+
</div>
|
|
396
|
+
</td>
|
|
397
|
+
</tr>
|
|
398
|
+
`;
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
tbContainer.innerHTML = state.records.map(rec => {
|
|
404
|
+
const safeRecId = escapeHtml(rec.id);
|
|
405
|
+
return `
|
|
406
|
+
<tr class="record-row ${state.selectedRecordId === rec.id ? 'row-selected' : ''}" data-id="${safeRecId}" tabindex="0" role="button" aria-label="Record ${safeRecId}, press Enter to view details" onclick="handleRecordRowClick(this)" onkeydown="handleRecordRowKeyDown(event, this)">
|
|
407
|
+
<td><span class="id-pill">${safeRecId}</span></td>
|
|
408
|
+
${displayFields.map(f => {
|
|
409
|
+
const schemaField = col.schema.find(sf => sf.name === f);
|
|
410
|
+
const val = rec[f];
|
|
411
|
+
if (val === null || val === undefined || val === '') return '<td style="color:#6b7280; font-style:italic;">NULL</td>';
|
|
412
|
+
if (schemaField && schemaField.type === 'file') {
|
|
413
|
+
const filename = String(val);
|
|
414
|
+
const fileUrl = getRecordFileUrl(col.name, rec.id, filename);
|
|
415
|
+
const safeUrl = escapeHtml(fileUrl);
|
|
416
|
+
const isImg = isImageFile(filename);
|
|
417
|
+
if (isImg) {
|
|
418
|
+
return `<td><a href="${safeUrl}" target="_blank" onclick="event.stopPropagation()" style="display:inline-flex; align-items:center; gap:6px; color:#60a5fa; text-decoration:none;"><img src="${safeUrl}" style="width:24px; height:24px; object-fit:cover; border-radius:4px; border:1px solid var(--border-subtle);"/> <span style="font-family:var(--font-mono); font-size:12px;">${escapeHtml(filename)}</span></a></td>`;
|
|
419
|
+
}
|
|
420
|
+
return `<td><a href="${safeUrl}" target="_blank" onclick="event.stopPropagation()" style="color:#60a5fa; text-decoration:underline; font-family:var(--font-mono); font-size:12px;">📎 ${escapeHtml(filename)}</a></td>`;
|
|
421
|
+
}
|
|
422
|
+
if (typeof val === 'boolean') return `<td><span class="badge ${val ? 'badge-get' : 'badge-delete'}">${val ? 'TRUE' : 'FALSE'}</span></td>`;
|
|
423
|
+
if (typeof val === 'object') return `<td><code>${escapeHtml(JSON.stringify(val).slice(0, 30))}...</code></td>`;
|
|
424
|
+
return `<td>${escapeHtml(String(val))}</td>`;
|
|
425
|
+
}).join('')}
|
|
426
|
+
<td style="color:var(--text-muted);font-size:12px;">${new Date(rec.created).toLocaleString()}</td>
|
|
427
|
+
<td>
|
|
428
|
+
<div style="display:flex; align-items:center; gap:4px;">
|
|
429
|
+
<button class="btn btn-secondary btn-sm" data-id="${safeRecId}" onclick="handleTableEditRecord(event, this)" title="Edit record">Edit</button>
|
|
430
|
+
<button class="btn btn-danger btn-sm" data-id="${safeRecId}" onclick="handleTableDeleteRecord(event, this)" title="Delete record">Delete</button>
|
|
431
|
+
</div>
|
|
432
|
+
</td>
|
|
433
|
+
</tr>
|
|
434
|
+
`;
|
|
435
|
+
}).join('');
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function updatePaginationControls() {
|
|
439
|
+
const paginationLabel = document.getElementById('pagination-label');
|
|
440
|
+
const footer = document.getElementById('records-pagination');
|
|
441
|
+
if (!footer) return;
|
|
442
|
+
|
|
443
|
+
const total = state.recordsTotal;
|
|
444
|
+
const perPage = state.recordsPerPage;
|
|
445
|
+
const page = state.recordsPage;
|
|
446
|
+
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
|
447
|
+
|
|
448
|
+
const start = total === 0 ? 0 : Math.min((page - 1) * perPage + 1, total);
|
|
449
|
+
const end = Math.min(page * perPage, total);
|
|
450
|
+
|
|
451
|
+
if (paginationLabel) {
|
|
452
|
+
paginationLabel.textContent = total === 0 ? 'Showing 0 records' : `Showing ${start}–${end} of ${total} records`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
footer.innerHTML = `
|
|
456
|
+
<div class="pagination-left">
|
|
457
|
+
<span class="pagination-label-text">
|
|
458
|
+
${total === 0 ? '0 records' : `Showing <strong>${start}–${end}</strong> of <strong>${total}</strong> records`}
|
|
459
|
+
</span>
|
|
460
|
+
<div class="per-page-selector">
|
|
461
|
+
<span>Rows per page:</span>
|
|
462
|
+
<select id="records-per-page" class="per-page-select" onchange="changeRecordsPerPage(this.value)" title="Number of rows per page">
|
|
463
|
+
<option value="25" ${perPage === 25 ? 'selected' : ''}>25</option>
|
|
464
|
+
<option value="50" ${perPage === 50 ? 'selected' : ''}>50</option>
|
|
465
|
+
<option value="100" ${perPage === 100 ? 'selected' : ''}>100</option>
|
|
466
|
+
</select>
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
<div class="pagination-nav">
|
|
470
|
+
<button class="btn btn-secondary btn-sm" id="btn-page-prev" onclick="changeRecordsPage(${page - 1})" ${page <= 1 ? 'disabled' : ''} title="Previous page">
|
|
471
|
+
« Prev
|
|
472
|
+
</button>
|
|
473
|
+
<div class="page-counter-box">
|
|
474
|
+
<span>Page</span>
|
|
475
|
+
<input type="number" id="page-jump-input" min="1" max="${totalPages}" value="${page}" class="page-jump-input" onchange="goToRecordsPage(this.value)" onkeydown="if(event.key==='Enter'){event.preventDefault(); goToRecordsPage(this.value);}" title="Jump to page">
|
|
476
|
+
<span>of <span id="page-total-count">${totalPages}</span></span>
|
|
477
|
+
</div>
|
|
478
|
+
<button class="btn btn-secondary btn-sm" id="btn-page-next" onclick="changeRecordsPage(${page + 1})" ${page >= totalPages ? 'disabled' : ''} title="Next page">
|
|
479
|
+
Next »
|
|
480
|
+
</button>
|
|
481
|
+
</div>
|
|
482
|
+
`;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// ==========================================
|
|
486
|
+
// Slide-Over Record Detail Drawer
|
|
487
|
+
// ==========================================
|
|
488
|
+
|
|
489
|
+
let drawerTriggerElement = null;
|
|
490
|
+
|
|
491
|
+
function handleRecordRowClick(trEl) {
|
|
492
|
+
if (!trEl) return;
|
|
493
|
+
const id = trEl.getAttribute('data-id');
|
|
494
|
+
if (id) {
|
|
495
|
+
openRecordDrawer(id, trEl);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function handleRecordRowKeyDown(e, trEl) {
|
|
500
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
501
|
+
if (e.target && e.target.closest && e.target.closest('button, a, input, select, textarea')) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
e.preventDefault();
|
|
505
|
+
handleRecordRowClick(trEl);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function openRecordDrawer(id, triggerEl) {
|
|
510
|
+
const rec = state.records.find(r => r.id === id);
|
|
511
|
+
if (!rec) return;
|
|
512
|
+
|
|
513
|
+
state.selectedRecordId = id;
|
|
514
|
+
|
|
515
|
+
// Store trigger element for focus restoration upon closing
|
|
516
|
+
if (triggerEl && typeof triggerEl.focus === 'function') {
|
|
517
|
+
drawerTriggerElement = triggerEl;
|
|
518
|
+
} else if (document.activeElement && typeof document.activeElement.focus === 'function' && document.activeElement !== document.body) {
|
|
519
|
+
drawerTriggerElement = document.activeElement;
|
|
520
|
+
} else {
|
|
521
|
+
drawerTriggerElement = document.querySelector(`#records-table tr.record-row[data-id="${id}"]`);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Update row selection style
|
|
525
|
+
document.querySelectorAll('#records-table tr.record-row').forEach(tr => {
|
|
526
|
+
tr.classList.remove('row-selected');
|
|
527
|
+
});
|
|
528
|
+
const activeTr = document.querySelector(`#records-table tr.record-row[data-id="${id}"]`);
|
|
529
|
+
if (activeTr) activeTr.classList.add('row-selected');
|
|
530
|
+
|
|
531
|
+
renderDrawer(rec);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function renderDrawer(rec) {
|
|
535
|
+
let root = document.getElementById('drawer-root');
|
|
536
|
+
if (!root) {
|
|
537
|
+
root = document.createElement('div');
|
|
538
|
+
root.id = 'drawer-root';
|
|
539
|
+
document.body.appendChild(root);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
root.innerHTML = `
|
|
543
|
+
<div id="record-drawer-backdrop" class="drawer-backdrop" onclick="closeRecordDrawer()" aria-hidden="true"></div>
|
|
544
|
+
<aside id="record-drawer-panel" class="record-drawer" role="dialog" aria-modal="true" aria-labelledby="record-drawer-title" tabindex="-1">
|
|
545
|
+
<!-- Dynamic Content -->
|
|
546
|
+
</aside>
|
|
547
|
+
`;
|
|
548
|
+
|
|
549
|
+
renderDrawerContent(rec);
|
|
550
|
+
|
|
551
|
+
// Trigger slide-over animation smoothly and move focus into drawer
|
|
552
|
+
const triggerDrawerOpen = () => {
|
|
553
|
+
const backdrop = document.getElementById('record-drawer-backdrop');
|
|
554
|
+
const panel = document.getElementById('record-drawer-panel');
|
|
555
|
+
if (backdrop) backdrop.classList.add('open');
|
|
556
|
+
if (panel) {
|
|
557
|
+
panel.classList.add('open');
|
|
558
|
+
focusDrawerOnOpen();
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
562
|
+
requestAnimationFrame(triggerDrawerOpen);
|
|
563
|
+
} else {
|
|
564
|
+
triggerDrawerOpen();
|
|
565
|
+
}
|
|
566
|
+
setTimeout(() => {
|
|
567
|
+
focusDrawerOnOpen();
|
|
568
|
+
}, 50);
|
|
569
|
+
|
|
570
|
+
// Escape key and Tab focus trap listener
|
|
571
|
+
window.removeEventListener('keydown', handleDrawerKeyDown);
|
|
572
|
+
window.addEventListener('keydown', handleDrawerKeyDown);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function focusDrawerOnOpen() {
|
|
576
|
+
const panel = document.getElementById('record-drawer-panel');
|
|
577
|
+
if (!panel) return;
|
|
578
|
+
const closeBtn = document.getElementById('drawer-close-btn');
|
|
579
|
+
if (closeBtn && typeof closeBtn.focus === 'function') {
|
|
580
|
+
closeBtn.focus();
|
|
581
|
+
} else if (typeof panel.focus === 'function') {
|
|
582
|
+
panel.focus();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function handleDrawerKeyDown(e) {
|
|
587
|
+
if (e.key === 'Escape') {
|
|
588
|
+
e.preventDefault();
|
|
589
|
+
closeRecordDrawer();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (e.key === 'Tab') {
|
|
594
|
+
const panel = document.getElementById('record-drawer-panel');
|
|
595
|
+
if (!panel) return;
|
|
596
|
+
|
|
597
|
+
const focusableElements = panel.querySelectorAll(
|
|
598
|
+
'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
599
|
+
);
|
|
600
|
+
const focusable = Array.from(focusableElements).filter(el => {
|
|
601
|
+
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0 || el.style.display !== 'none';
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
if (focusable.length === 0) {
|
|
605
|
+
e.preventDefault();
|
|
606
|
+
if (typeof panel.focus === 'function') panel.focus();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const firstElement = focusable[0];
|
|
611
|
+
const lastElement = focusable[focusable.length - 1];
|
|
612
|
+
|
|
613
|
+
if (e.shiftKey) {
|
|
614
|
+
if (document.activeElement === firstElement || !panel.contains(document.activeElement)) {
|
|
615
|
+
e.preventDefault();
|
|
616
|
+
lastElement.focus();
|
|
617
|
+
}
|
|
618
|
+
} else {
|
|
619
|
+
if (document.activeElement === lastElement || !panel.contains(document.activeElement)) {
|
|
620
|
+
e.preventDefault();
|
|
621
|
+
firstElement.focus();
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function closeRecordDrawer() {
|
|
628
|
+
drawerHistoryState = {
|
|
629
|
+
colName: '',
|
|
630
|
+
recId: '',
|
|
631
|
+
page: 1,
|
|
632
|
+
perPage: 25,
|
|
633
|
+
items: [],
|
|
634
|
+
totalItems: 0,
|
|
635
|
+
totalPages: 1,
|
|
636
|
+
isLoading: false,
|
|
637
|
+
};
|
|
638
|
+
state.selectedRecordId = null;
|
|
639
|
+
document.querySelectorAll('#records-table tr.record-row').forEach(tr => {
|
|
640
|
+
tr.classList.remove('row-selected');
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const backdrop = document.getElementById('record-drawer-backdrop');
|
|
644
|
+
const panel = document.getElementById('record-drawer-panel');
|
|
645
|
+
if (backdrop) backdrop.classList.remove('open');
|
|
646
|
+
if (panel) panel.classList.remove('open');
|
|
647
|
+
|
|
648
|
+
window.removeEventListener('keydown', handleDrawerKeyDown);
|
|
649
|
+
|
|
650
|
+
// Restore focus to the trigger element that opened the drawer
|
|
651
|
+
if (drawerTriggerElement && typeof drawerTriggerElement.focus === 'function' && document.body.contains(drawerTriggerElement)) {
|
|
652
|
+
try {
|
|
653
|
+
drawerTriggerElement.focus();
|
|
654
|
+
} catch (_) {}
|
|
655
|
+
}
|
|
656
|
+
drawerTriggerElement = null;
|
|
657
|
+
|
|
658
|
+
setTimeout(() => {
|
|
659
|
+
const root = document.getElementById('drawer-root');
|
|
660
|
+
if (root && !state.selectedRecordId) {
|
|
661
|
+
root.innerHTML = '';
|
|
662
|
+
}
|
|
663
|
+
}, 300);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function renderDrawerContent(rec) {
|
|
667
|
+
const panel = document.getElementById('record-drawer-panel');
|
|
668
|
+
if (!panel) return;
|
|
669
|
+
|
|
670
|
+
const col = state.activeCollection;
|
|
671
|
+
if (!col) return;
|
|
672
|
+
|
|
673
|
+
const safeRecId = escapeHtml(rec.id);
|
|
674
|
+
|
|
675
|
+
panel.innerHTML = `
|
|
676
|
+
<!-- Drawer Header -->
|
|
677
|
+
<div class="drawer-header">
|
|
678
|
+
<div class="drawer-title-area">
|
|
679
|
+
<span style="font-size:18px;" aria-hidden="true">📄</span>
|
|
680
|
+
<h2 id="record-drawer-title" class="drawer-title" style="margin:0; font-size:1.05rem;">Record Details</h2>
|
|
681
|
+
<span class="badge badge-post">${escapeHtml(col.name)}</span>
|
|
682
|
+
<span class="id-pill" title="Record ID">${safeRecId}</span>
|
|
683
|
+
</div>
|
|
684
|
+
<button class="btn btn-secondary btn-sm" id="drawer-close-btn" onclick="closeRecordDrawer()" title="Close drawer (Esc)" aria-label="Close drawer">✕</button>
|
|
685
|
+
</div>
|
|
686
|
+
|
|
687
|
+
<!-- Quick Actions Bar -->
|
|
688
|
+
<div class="drawer-quick-actions">
|
|
689
|
+
<button class="btn btn-secondary btn-sm" data-id="${safeRecId}" onclick="handleDrawerCopyId(this)" title="Copy Record ID to clipboard">
|
|
690
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
|
|
691
|
+
<span>Copy ID</span>
|
|
692
|
+
</button>
|
|
693
|
+
<button class="btn btn-primary btn-sm" data-id="${safeRecId}" onclick="handleDrawerEditRecord(this)" title="Edit this record">
|
|
694
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"></path><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
|
|
695
|
+
<span>Edit Record</span>
|
|
696
|
+
</button>
|
|
697
|
+
<button class="btn btn-secondary btn-sm" data-id="${safeRecId}" onclick="handleDrawerCopyJson(this)" title="Copy full record JSON">
|
|
698
|
+
<span style="color:#34d399; font-weight:bold; font-size:11px;">{ }</span>
|
|
699
|
+
<span>Copy JSON</span>
|
|
700
|
+
</button>
|
|
701
|
+
<button class="btn btn-secondary btn-sm" id="btn-drawer-history" data-id="${safeRecId}" onclick="handleToggleDrawerHistory(this)" title="View audit history">
|
|
702
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
|
|
703
|
+
<span id="drawer-history-btn-text">History</span>
|
|
704
|
+
</button>
|
|
705
|
+
<button class="btn btn-danger btn-sm" data-id="${safeRecId}" onclick="handleDrawerDeleteRecord(this)" title="Delete record" style="margin-left:auto;">
|
|
706
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
|
|
707
|
+
<span>Delete</span>
|
|
708
|
+
</button>
|
|
709
|
+
</div>
|
|
710
|
+
|
|
711
|
+
<!-- Drawer Body -->
|
|
712
|
+
<div class="drawer-body">
|
|
713
|
+
<div id="drawer-history-container" style="display:none;"></div>
|
|
714
|
+
<div id="drawer-details-content">
|
|
715
|
+
<!-- System Metadata Section -->
|
|
716
|
+
<div>
|
|
717
|
+
<div class="drawer-section-title">System Metadata</div>
|
|
718
|
+
<div class="drawer-card">
|
|
719
|
+
<div class="drawer-field-item">
|
|
720
|
+
<div class="drawer-field-header">
|
|
721
|
+
<span class="drawer-field-name">id</span>
|
|
722
|
+
<span class="badge" style="background:var(--bg-hover-subtle); color:var(--text-muted);">system</span>
|
|
723
|
+
</div>
|
|
724
|
+
<div class="drawer-field-value" style="display:flex; align-items:center; justify-content:space-between;">
|
|
725
|
+
<span class="id-pill">${safeRecId}</span>
|
|
726
|
+
<button class="btn btn-secondary btn-sm" style="padding:2px 6px; font-size:11px;" data-id="${safeRecId}" onclick="handleDrawerCopyId(this)">Copy</button>
|
|
727
|
+
</div>
|
|
728
|
+
</div>
|
|
729
|
+
|
|
730
|
+
<div class="drawer-field-item">
|
|
731
|
+
<div class="drawer-field-header">
|
|
732
|
+
<span class="drawer-field-name">created</span>
|
|
733
|
+
<span class="badge" style="background:var(--bg-hover-subtle); color:var(--text-muted);">datetime</span>
|
|
734
|
+
</div>
|
|
735
|
+
<div class="drawer-field-value" style="font-size:12px; color:var(--text-muted);">
|
|
736
|
+
${new Date(rec.created).toLocaleString()} <span style="font-family:var(--font-mono); opacity:0.7;">(${escapeHtml(rec.created)})</span>
|
|
737
|
+
</div>
|
|
738
|
+
</div>
|
|
739
|
+
|
|
740
|
+
${rec.updated ? `
|
|
741
|
+
<div class="drawer-field-item">
|
|
742
|
+
<div class="drawer-field-header">
|
|
743
|
+
<span class="drawer-field-name">updated</span>
|
|
744
|
+
<span class="badge" style="background:var(--bg-hover-subtle); color:var(--text-muted);">datetime</span>
|
|
745
|
+
</div>
|
|
746
|
+
<div class="drawer-field-value" style="font-size:12px; color:var(--text-muted);">
|
|
747
|
+
${new Date(rec.updated).toLocaleString()} <span style="font-family:var(--font-mono); opacity:0.7;">(${escapeHtml(rec.updated)})</span>
|
|
748
|
+
</div>
|
|
749
|
+
</div>
|
|
750
|
+
` : ''}
|
|
751
|
+
|
|
752
|
+
${col.type === 'auth' ? `
|
|
753
|
+
<div class="drawer-field-item">
|
|
754
|
+
<div class="drawer-field-header">
|
|
755
|
+
<span class="drawer-field-name">email</span>
|
|
756
|
+
<span class="badge badge-get">auth</span>
|
|
757
|
+
</div>
|
|
758
|
+
<div class="drawer-field-value" style="display:flex; align-items:center; justify-content:space-between;">
|
|
759
|
+
<span style="font-family:var(--font-mono); color: var(--accent-primary);">${escapeHtml(rec.email || '—')}</span>
|
|
760
|
+
<button class="btn btn-secondary btn-sm" style="padding:2px 6px; font-size:11px;" data-email="${escapeHtml(rec.email || '')}" onclick="handleDrawerCopyEmail(this)">Copy</button>
|
|
761
|
+
</div>
|
|
762
|
+
</div>
|
|
763
|
+
<div class="drawer-field-item">
|
|
764
|
+
<div class="drawer-field-header">
|
|
765
|
+
<span class="drawer-field-name">verified</span>
|
|
766
|
+
<span class="badge" style="background:var(--bg-hover-subtle); color:var(--text-muted);">auth</span>
|
|
767
|
+
</div>
|
|
768
|
+
<div class="drawer-field-value">
|
|
769
|
+
<span class="badge ${rec.verified ? 'badge-get' : 'badge-delete'}">${rec.verified ? 'Verified' : 'Unverified'}</span>
|
|
770
|
+
</div>
|
|
771
|
+
</div>
|
|
772
|
+
<div class="drawer-field-item">
|
|
773
|
+
<div class="drawer-field-header">
|
|
774
|
+
<span class="drawer-field-name">emailVisibility</span>
|
|
775
|
+
<span class="badge" style="background:var(--bg-hover-subtle); color:var(--text-muted);">auth</span>
|
|
776
|
+
</div>
|
|
777
|
+
<div class="drawer-field-value">
|
|
778
|
+
<span class="badge ${rec.emailVisibility ? 'badge-get' : 'badge-delete'}">${rec.emailVisibility ? 'Public' : 'Hidden'}</span>
|
|
779
|
+
</div>
|
|
780
|
+
</div>
|
|
781
|
+
` : ''}
|
|
782
|
+
</div>
|
|
783
|
+
</div>
|
|
784
|
+
|
|
785
|
+
<!-- Collection Fields Section -->
|
|
786
|
+
<div>
|
|
787
|
+
<div class="drawer-section-title">Schema Fields (${col.schema.length})</div>
|
|
788
|
+
<div class="drawer-card">
|
|
789
|
+
${col.schema.length === 0 ? `
|
|
790
|
+
<div style="color:var(--text-muted); font-size:13px; text-align:center; padding:1rem;">No custom schema fields defined.</div>
|
|
791
|
+
` : col.schema.map(f => {
|
|
792
|
+
const val = rec[f.name];
|
|
793
|
+
return `
|
|
794
|
+
<div class="drawer-field-item">
|
|
795
|
+
<div class="drawer-field-header">
|
|
796
|
+
<span class="drawer-field-name">${escapeHtml(f.name)}</span>
|
|
797
|
+
<span class="badge badge-post">${escapeHtml(f.type)}</span>
|
|
798
|
+
</div>
|
|
799
|
+
<div class="drawer-field-value">
|
|
800
|
+
${renderDrawerFieldValue(col, rec, f, val)}
|
|
801
|
+
</div>
|
|
802
|
+
</div>
|
|
803
|
+
`;
|
|
804
|
+
}).join('')}
|
|
805
|
+
</div>
|
|
806
|
+
</div>
|
|
807
|
+
</div>
|
|
808
|
+
</div>
|
|
809
|
+
`;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function renderDrawerFieldValue(col, rec, field, val) {
|
|
813
|
+
if (val === null || val === undefined || val === '') {
|
|
814
|
+
return '<span style="color:#6b7280; font-style:italic;">NULL</span>';
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (field.type === 'file') {
|
|
818
|
+
const filename = String(val);
|
|
819
|
+
const fileUrl = getRecordFileUrl(col.name, rec.id, filename);
|
|
820
|
+
const safeUrl = escapeHtml(fileUrl);
|
|
821
|
+
const isImg = isImageFile(filename);
|
|
822
|
+
if (isImg) {
|
|
823
|
+
return `
|
|
824
|
+
<div class="drawer-media-box">
|
|
825
|
+
<a href="${safeUrl}" target="_blank" title="Click to view full image">
|
|
826
|
+
<img src="${safeUrl}" class="drawer-media-img" alt="${escapeHtml(filename)}" />
|
|
827
|
+
</a>
|
|
828
|
+
<div style="display:flex; flex-direction:column; gap:4px; overflow:hidden;">
|
|
829
|
+
<a href="${safeUrl}" target="_blank" style="color:#60a5fa; font-family:var(--font-mono); font-size:12px; text-decoration:none; font-weight:600; text-overflow:ellipsis; overflow:hidden; white-space:nowrap;">
|
|
830
|
+
📎 ${escapeHtml(filename)}
|
|
831
|
+
</a>
|
|
832
|
+
<span style="font-size:11px; color:var(--text-muted);">Media Image • Click thumbnail to inspect</span>
|
|
833
|
+
</div>
|
|
834
|
+
</div>
|
|
835
|
+
`;
|
|
836
|
+
}
|
|
837
|
+
return `
|
|
838
|
+
<div class="drawer-media-box">
|
|
839
|
+
<span style="font-size:24px;">📄</span>
|
|
840
|
+
<div style="display:flex; flex-direction:column; gap:4px; overflow:hidden;">
|
|
841
|
+
<a href="${safeUrl}" target="_blank" style="color:#60a5fa; font-family:var(--font-mono); font-size:12px; text-decoration:none; font-weight:600; text-overflow:ellipsis; overflow:hidden; white-space:nowrap;">
|
|
842
|
+
📎 ${escapeHtml(filename)}
|
|
843
|
+
</a>
|
|
844
|
+
<span style="font-size:11px; color:var(--text-muted);">File Attachment • Click to download</span>
|
|
845
|
+
</div>
|
|
846
|
+
</div>
|
|
847
|
+
`;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
if (field.type === 'json' || (typeof val === 'object' && val !== null)) {
|
|
851
|
+
const jsonFormatted = JSON.stringify(val, null, 2);
|
|
852
|
+
const keysCount = typeof val === 'object' && val !== null ? Object.keys(val).length : 0;
|
|
853
|
+
const safeRecId = escapeHtml(rec.id);
|
|
854
|
+
const safeFieldName = escapeHtml(field.name);
|
|
855
|
+
return `
|
|
856
|
+
<div class="drawer-json-container">
|
|
857
|
+
<div class="drawer-json-bar">
|
|
858
|
+
<span>JSON Object (${keysCount} ${keysCount === 1 ? 'key' : 'keys'})</span>
|
|
859
|
+
<button class="btn btn-secondary btn-sm" style="padding:2px 7px; font-size:11px;" data-id="${safeRecId}" data-field="${safeFieldName}" onclick="handleDrawerCopyJsonField(this)">Copy JSON</button>
|
|
860
|
+
</div>
|
|
861
|
+
<pre class="drawer-json-pre"><code>${escapeHtml(jsonFormatted)}</code></pre>
|
|
862
|
+
</div>
|
|
863
|
+
`;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (typeof val === 'boolean' || field.type === 'bool') {
|
|
867
|
+
return `<span class="badge ${val ? 'badge-get' : 'badge-delete'}">${val ? 'TRUE' : 'FALSE'}</span>`;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if (typeof val === 'number' || field.type === 'number') {
|
|
871
|
+
return `<span style="font-family:var(--font-mono); font-weight:600; color: var(--accent-primary);">${val}</span>`;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Plain text or long text: display full inspection with copy button
|
|
875
|
+
const safeRecId = escapeHtml(rec.id);
|
|
876
|
+
const safeFieldName = escapeHtml(field.name);
|
|
877
|
+
return `
|
|
878
|
+
<div style="display:flex; justify-content:space-between; align-items:flex-start; gap:8px;">
|
|
879
|
+
<div style="white-space:pre-wrap; word-break:break-word; font-size:13px; color:var(--text-main); flex:1; line-height:1.5;">${escapeHtml(String(val))}</div>
|
|
880
|
+
<button class="btn btn-secondary btn-sm" style="padding:2px 6px; font-size:11px; flex-shrink:0;" data-id="${safeRecId}" data-field="${safeFieldName}" onclick="handleDrawerCopyFieldValue(this)" title="Copy text value">Copy</button>
|
|
881
|
+
</div>
|
|
882
|
+
`;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function drawerDeleteRecord(id) {
|
|
886
|
+
deleteRecord(id);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function handleTableEditRecord(e, btnEl) {
|
|
890
|
+
if (e) e.stopPropagation();
|
|
891
|
+
if (!btnEl) return;
|
|
892
|
+
const id = btnEl.getAttribute('data-id');
|
|
893
|
+
if (id) {
|
|
894
|
+
if (typeof closeRecordDrawer === 'function') {
|
|
895
|
+
closeRecordDrawer();
|
|
896
|
+
}
|
|
897
|
+
editRecord(id);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function handleTableDeleteRecord(e, btnEl) {
|
|
902
|
+
if (e) e.stopPropagation();
|
|
903
|
+
if (!btnEl) return;
|
|
904
|
+
const id = btnEl.getAttribute('data-id');
|
|
905
|
+
if (id) deleteRecord(id);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
function handleDrawerCopyId(btnEl) {
|
|
909
|
+
if (!btnEl) return;
|
|
910
|
+
const id = btnEl.getAttribute('data-id');
|
|
911
|
+
if (id) copyToClipboard(id, btnEl, 'Copied ID!');
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function handleDrawerEditRecord(btnEl) {
|
|
915
|
+
if (!btnEl) return;
|
|
916
|
+
const id = btnEl.getAttribute('data-id');
|
|
917
|
+
if (id) {
|
|
918
|
+
if (typeof closeRecordDrawer === 'function') {
|
|
919
|
+
closeRecordDrawer();
|
|
920
|
+
}
|
|
921
|
+
editRecord(id);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function handleDrawerCopyJson(btnEl) {
|
|
926
|
+
if (!btnEl) return;
|
|
927
|
+
const id = btnEl.getAttribute('data-id');
|
|
928
|
+
if (id) copyRecordJson(id, btnEl);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function handleDrawerDeleteRecord(btnEl) {
|
|
932
|
+
if (!btnEl) return;
|
|
933
|
+
const id = btnEl.getAttribute('data-id');
|
|
934
|
+
if (id) {
|
|
935
|
+
if (typeof closeRecordDrawer === 'function') {
|
|
936
|
+
closeRecordDrawer();
|
|
937
|
+
}
|
|
938
|
+
drawerDeleteRecord(id);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function handleDrawerCopyEmail(btnEl) {
|
|
943
|
+
if (!btnEl) return;
|
|
944
|
+
const email = btnEl.getAttribute('data-email');
|
|
945
|
+
copyToClipboard(email || '', btnEl, 'Copied email!');
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
let drawerHistoryState = {
|
|
949
|
+
colName: '',
|
|
950
|
+
recId: '',
|
|
951
|
+
page: 1,
|
|
952
|
+
perPage: 25,
|
|
953
|
+
items: [],
|
|
954
|
+
totalItems: 0,
|
|
955
|
+
totalPages: 1,
|
|
956
|
+
isLoading: false,
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
async function handleToggleDrawerHistory(btnEl) {
|
|
960
|
+
const historyContainer = document.getElementById('drawer-history-container');
|
|
961
|
+
const detailsContent = document.getElementById('drawer-details-content');
|
|
962
|
+
const btnText = document.getElementById('drawer-history-btn-text');
|
|
963
|
+
if (!historyContainer || !detailsContent) return;
|
|
964
|
+
|
|
965
|
+
const isShowing = historyContainer.style.display !== 'none';
|
|
966
|
+
if (isShowing) {
|
|
967
|
+
historyContainer.style.display = 'none';
|
|
968
|
+
detailsContent.style.display = 'block';
|
|
969
|
+
if (btnText) btnText.textContent = 'History';
|
|
970
|
+
btnEl.classList.remove('btn-primary');
|
|
971
|
+
btnEl.classList.add('btn-secondary');
|
|
972
|
+
} else {
|
|
973
|
+
historyContainer.style.display = 'block';
|
|
974
|
+
detailsContent.style.display = 'none';
|
|
975
|
+
if (btnText) btnText.textContent = '← Back';
|
|
976
|
+
btnEl.classList.remove('btn-secondary');
|
|
977
|
+
btnEl.classList.add('btn-primary');
|
|
978
|
+
|
|
979
|
+
const col = state.activeCollection;
|
|
980
|
+
const recId = btnEl.getAttribute('data-id');
|
|
981
|
+
if (col && recId) {
|
|
982
|
+
drawerHistoryState = {
|
|
983
|
+
colName: col.name,
|
|
984
|
+
recId: recId,
|
|
985
|
+
page: 1,
|
|
986
|
+
perPage: 25,
|
|
987
|
+
items: [],
|
|
988
|
+
totalItems: 0,
|
|
989
|
+
totalPages: 1,
|
|
990
|
+
isLoading: true,
|
|
991
|
+
};
|
|
992
|
+
historyContainer.innerHTML = '<div style="text-align:center; padding:2rem; color:var(--text-muted);">Loading audit history...</div>';
|
|
993
|
+
try {
|
|
994
|
+
const res = await api('/api/collections/' + encodeURIComponent(col.name) + '/records/' + encodeURIComponent(recId) + '/history?page=1&perPage=25');
|
|
995
|
+
drawerHistoryState.items = res.items || [];
|
|
996
|
+
drawerHistoryState.totalItems = res.totalItems ?? (res.items || []).length;
|
|
997
|
+
drawerHistoryState.totalPages = res.totalPages ?? 1;
|
|
998
|
+
drawerHistoryState.page = res.page ?? 1;
|
|
999
|
+
drawerHistoryState.isLoading = false;
|
|
1000
|
+
renderDrawerHistoryTimeline(
|
|
1001
|
+
historyContainer,
|
|
1002
|
+
drawerHistoryState.items,
|
|
1003
|
+
drawerHistoryState.totalItems,
|
|
1004
|
+
drawerHistoryState.page < drawerHistoryState.totalPages
|
|
1005
|
+
);
|
|
1006
|
+
} catch (err) {
|
|
1007
|
+
drawerHistoryState.isLoading = false;
|
|
1008
|
+
historyContainer.innerHTML = '<div class="audit-card" style="color:#fca5a5; padding:1rem;">Failed to load history: ' + escapeHtml(err.message) + '</div>';
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
async function handleDrawerHistoryLoadMore() {
|
|
1015
|
+
if (drawerHistoryState.isLoading) return;
|
|
1016
|
+
if (drawerHistoryState.page >= drawerHistoryState.totalPages) return;
|
|
1017
|
+
|
|
1018
|
+
const loadMoreBtn = document.getElementById('btn-drawer-history-load-more');
|
|
1019
|
+
if (loadMoreBtn) {
|
|
1020
|
+
loadMoreBtn.disabled = true;
|
|
1021
|
+
loadMoreBtn.innerHTML = '<span style="display:inline-block; animation:spin 1s linear infinite; margin-right:6px;">⏳</span> Loading more changes...';
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
drawerHistoryState.isLoading = true;
|
|
1025
|
+
const nextPage = drawerHistoryState.page + 1;
|
|
1026
|
+
|
|
1027
|
+
try {
|
|
1028
|
+
const res = await api('/api/collections/' + encodeURIComponent(drawerHistoryState.colName) + '/records/' + encodeURIComponent(drawerHistoryState.recId) + '/history?page=' + nextPage + '&perPage=' + drawerHistoryState.perPage);
|
|
1029
|
+
const newItems = res.items || [];
|
|
1030
|
+
drawerHistoryState.items = drawerHistoryState.items.concat(newItems);
|
|
1031
|
+
drawerHistoryState.page = res.page ?? nextPage;
|
|
1032
|
+
drawerHistoryState.totalItems = res.totalItems ?? drawerHistoryState.totalItems;
|
|
1033
|
+
drawerHistoryState.totalPages = res.totalPages ?? drawerHistoryState.totalPages;
|
|
1034
|
+
drawerHistoryState.isLoading = false;
|
|
1035
|
+
|
|
1036
|
+
const historyContainer = document.getElementById('drawer-history-container');
|
|
1037
|
+
if (historyContainer) {
|
|
1038
|
+
renderDrawerHistoryTimeline(
|
|
1039
|
+
historyContainer,
|
|
1040
|
+
drawerHistoryState.items,
|
|
1041
|
+
drawerHistoryState.totalItems,
|
|
1042
|
+
drawerHistoryState.page < drawerHistoryState.totalPages
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
} catch (err) {
|
|
1046
|
+
drawerHistoryState.isLoading = false;
|
|
1047
|
+
if (loadMoreBtn) {
|
|
1048
|
+
loadMoreBtn.disabled = false;
|
|
1049
|
+
loadMoreBtn.textContent = 'Retry Loading More';
|
|
1050
|
+
}
|
|
1051
|
+
if (typeof toast === 'function') {
|
|
1052
|
+
toast('Failed to load more audit history: ' + err.message, 'error');
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof window !== 'undefined') {
|
|
1057
|
+
window.handleDrawerHistoryLoadMore = handleDrawerHistoryLoadMore;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function formatAuditValue(val) {
|
|
1061
|
+
if (val === null || val === undefined) return '<em style="color:#64748b;">null</em>';
|
|
1062
|
+
if (typeof val === 'object') return escapeHtml(JSON.stringify(val));
|
|
1063
|
+
return escapeHtml(String(val));
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
function renderDrawerHistoryTimeline(container, items, totalItems, hasMore) {
|
|
1067
|
+
if (!items || items.length === 0) {
|
|
1068
|
+
container.innerHTML = `
|
|
1069
|
+
<div class="audit-card" style="text-align:center; padding:2rem; color:var(--text-muted);">
|
|
1070
|
+
<div style="font-size:1.5rem; margin-bottom:0.5rem;">🕒</div>
|
|
1071
|
+
<div style="font-weight:600; color:#fff; margin-bottom:0.25rem;">No History Logged</div>
|
|
1072
|
+
<div style="font-size:12px;">No recorded field modifications found for this record.</div>
|
|
1073
|
+
</div>
|
|
1074
|
+
`;
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
const total = typeof totalItems === 'number' ? totalItems : items.length;
|
|
1079
|
+
const countLabel = total > items.length ? `${items.length} of ${total}` : `${items.length}`;
|
|
1080
|
+
|
|
1081
|
+
container.innerHTML = `
|
|
1082
|
+
<div style="margin-bottom:1rem; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px;">
|
|
1083
|
+
<h3 style="margin:0; font-size:13px; font-weight:700; color:#fff; text-transform:uppercase; letter-spacing:0.05em;">
|
|
1084
|
+
Audit History (${countLabel})
|
|
1085
|
+
</h3>
|
|
1086
|
+
<span style="font-size:11px; color:var(--text-muted);">Immutable Append-Only Log</span>
|
|
1087
|
+
</div>
|
|
1088
|
+
<div class="audit-timeline">
|
|
1089
|
+
${items.map(item => {
|
|
1090
|
+
const action = (item.action || '').toLowerCase();
|
|
1091
|
+
const dotClass = action === 'create' ? 'dot-create' : action === 'delete' ? 'dot-delete' : 'dot-update';
|
|
1092
|
+
const actionBadgeClass = action === 'create' ? 'badge-get' : action === 'delete' ? 'badge-delete' : 'badge-post';
|
|
1093
|
+
const actorLabel = item.authEmail || (item.authId ? 'User: ' + item.authId : 'System');
|
|
1094
|
+
const diffKeys = Object.keys(item.diff || {});
|
|
1095
|
+
|
|
1096
|
+
return `
|
|
1097
|
+
<div class="audit-timeline-item">
|
|
1098
|
+
<div class="audit-timeline-dot ${dotClass}"></div>
|
|
1099
|
+
<div class="audit-card">
|
|
1100
|
+
<div class="audit-card-header">
|
|
1101
|
+
<div style="display:flex; align-items:center; gap:6px;">
|
|
1102
|
+
<span class="badge ${actionBadgeClass}" style="text-transform:uppercase; font-size:10px;">${escapeHtml(item.action)}</span>
|
|
1103
|
+
<span class="audit-actor" title="${escapeHtml(item.authCollection || '')}">
|
|
1104
|
+
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
|
|
1105
|
+
<span>${escapeHtml(actorLabel)}</span>
|
|
1106
|
+
</span>
|
|
1107
|
+
</div>
|
|
1108
|
+
<span style="color:var(--text-muted); font-size:11px;" title="${escapeHtml(item.created)}">
|
|
1109
|
+
${new Date(item.created).toLocaleString()}
|
|
1110
|
+
</span>
|
|
1111
|
+
</div>
|
|
1112
|
+
${diffKeys.length === 0 ? `
|
|
1113
|
+
<div style="font-size:12px; color:var(--text-muted); font-style:italic;">No field changes recorded</div>
|
|
1114
|
+
` : `
|
|
1115
|
+
<table class="audit-diff-table">
|
|
1116
|
+
<thead>
|
|
1117
|
+
<tr>
|
|
1118
|
+
<th>Field</th>
|
|
1119
|
+
<th>Before</th>
|
|
1120
|
+
<th></th>
|
|
1121
|
+
<th>After</th>
|
|
1122
|
+
</tr>
|
|
1123
|
+
</thead>
|
|
1124
|
+
<tbody>
|
|
1125
|
+
${diffKeys.map(k => `
|
|
1126
|
+
<tr>
|
|
1127
|
+
<td class="audit-diff-key">${escapeHtml(k)}</td>
|
|
1128
|
+
<td><span class="audit-diff-val-old">${formatAuditValue(item.diff[k]?.old)}</span></td>
|
|
1129
|
+
<td class="audit-diff-arrow">➔</td>
|
|
1130
|
+
<td><span class="audit-diff-val-new">${formatAuditValue(item.diff[k]?.new)}</span></td>
|
|
1131
|
+
</tr>
|
|
1132
|
+
`).join('')}
|
|
1133
|
+
</tbody>
|
|
1134
|
+
</table>
|
|
1135
|
+
`}
|
|
1136
|
+
</div>
|
|
1137
|
+
</div>
|
|
1138
|
+
`;
|
|
1139
|
+
}).join('')}
|
|
1140
|
+
</div>
|
|
1141
|
+
${hasMore ? `
|
|
1142
|
+
<div style="text-align:center; margin-top:1.25rem; padding-top:0.75rem; border-top:1px solid rgba(255,255,255,0.08);">
|
|
1143
|
+
<div style="font-size:11px; color:var(--text-muted); margin-bottom:0.5rem;">
|
|
1144
|
+
Showing ${items.length} of ${total} recorded changes
|
|
1145
|
+
</div>
|
|
1146
|
+
<button class="btn btn-secondary btn-sm" id="btn-drawer-history-load-more" onclick="handleDrawerHistoryLoadMore()" style="width:100%; justify-content:center; padding:8px 12px; font-weight:600;">
|
|
1147
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:6px;"><polyline points="6 9 12 15 18 9"></polyline></svg>
|
|
1148
|
+
Load Older Changes (${total - items.length} remaining)
|
|
1149
|
+
</button>
|
|
1150
|
+
</div>
|
|
1151
|
+
` : total > 25 ? `
|
|
1152
|
+
<div style="text-align:center; margin-top:1.25rem; padding:0.75rem; font-size:11px; color:var(--text-muted); border-top:1px solid rgba(255,255,255,0.08);">
|
|
1153
|
+
✓ All ${total} audit log entries loaded
|
|
1154
|
+
</div>
|
|
1155
|
+
` : ''}
|
|
1156
|
+
`;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function handleDrawerCopyJsonField(btnEl) {
|
|
1160
|
+
if (!btnEl) return;
|
|
1161
|
+
const id = btnEl.getAttribute('data-id');
|
|
1162
|
+
const fieldName = btnEl.getAttribute('data-field');
|
|
1163
|
+
if (id && fieldName) copyJsonField(id, fieldName, btnEl);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function handleDrawerCopyFieldValue(btnEl) {
|
|
1167
|
+
if (!btnEl) return;
|
|
1168
|
+
const id = btnEl.getAttribute('data-id');
|
|
1169
|
+
const fieldName = btnEl.getAttribute('data-field');
|
|
1170
|
+
if (id && fieldName) copyFieldValue(id, fieldName, btnEl);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function copyRecordJson(id, btnEl) {
|
|
1174
|
+
const rec = state.records.find(r => r.id === id);
|
|
1175
|
+
if (!rec) return;
|
|
1176
|
+
const jsonStr = JSON.stringify(rec, null, 2);
|
|
1177
|
+
copyToClipboard(jsonStr, btnEl, 'Record JSON copied!');
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
function copyJsonField(id, fieldName, btnEl) {
|
|
1181
|
+
const rec = state.records.find(r => r.id === id);
|
|
1182
|
+
if (!rec) return;
|
|
1183
|
+
const val = rec[fieldName];
|
|
1184
|
+
const jsonStr = typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
|
|
1185
|
+
copyToClipboard(jsonStr, btnEl, `Copied ${fieldName} JSON!`);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function copyFieldValue(id, fieldName, btnEl) {
|
|
1189
|
+
const rec = state.records.find(r => r.id === id);
|
|
1190
|
+
if (!rec) return;
|
|
1191
|
+
const val = rec[fieldName];
|
|
1192
|
+
copyToClipboard(String(val ?? ''), btnEl, `Copied ${fieldName}!`);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// ==========================================
|
|
1196
|
+
// Visual Access Rule Builder
|
|
1197
|
+
|
|
1198
|
+
function toggleExportMenu(e) {
|
|
1199
|
+
if (e) e.stopPropagation();
|
|
1200
|
+
const menu = document.getElementById('export-dropdown-menu');
|
|
1201
|
+
if (menu) {
|
|
1202
|
+
menu.style.display = menu.style.display === 'block' ? 'none' : 'block';
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
window.addEventListener('click', (e) => {
|
|
1207
|
+
const menu = document.getElementById('export-dropdown-menu');
|
|
1208
|
+
if (menu && !e.target.closest('.dropdown-wrapper')) {
|
|
1209
|
+
menu.style.display = 'none';
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
async function exportData(format) {
|
|
1214
|
+
const menu = document.getElementById('export-dropdown-menu');
|
|
1215
|
+
if (menu) menu.style.display = 'none';
|
|
1216
|
+
|
|
1217
|
+
const col = state.activeCollection;
|
|
1218
|
+
if (!col) return;
|
|
1219
|
+
|
|
1220
|
+
try {
|
|
1221
|
+
toast(`Exporting ${col.name} as ${format.toUpperCase()}...`, 'info');
|
|
1222
|
+
let url = `/api/collections/${col.name}/export?format=${format}`;
|
|
1223
|
+
if (state.recordsFilter) {
|
|
1224
|
+
url += `&filter=${encodeURIComponent(state.recordsFilter)}`;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
const res = await fetch(url, {
|
|
1228
|
+
headers: {
|
|
1229
|
+
Authorization: `Bearer ${state.token}`
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
if (!res.ok) {
|
|
1234
|
+
const err = await res.json().catch(() => ({}));
|
|
1235
|
+
throw new Error(err.message || 'Export failed');
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const blob = await res.blob();
|
|
1239
|
+
const blobUrl = window.URL.createObjectURL(blob);
|
|
1240
|
+
const a = document.createElement('a');
|
|
1241
|
+
a.href = blobUrl;
|
|
1242
|
+
|
|
1243
|
+
const disposition = res.headers.get('content-disposition');
|
|
1244
|
+
let filename = `${col.name}_${new Date().toISOString().slice(0, 10)}.${format}`;
|
|
1245
|
+
if (disposition && disposition.includes('filename="')) {
|
|
1246
|
+
filename = disposition.split('filename="')[1].split('"')[0];
|
|
1247
|
+
} else if (disposition && disposition.includes('filename=')) {
|
|
1248
|
+
filename = disposition.split('filename=')[1].trim();
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
a.download = filename;
|
|
1252
|
+
document.body.appendChild(a);
|
|
1253
|
+
a.click();
|
|
1254
|
+
document.body.removeChild(a);
|
|
1255
|
+
window.URL.revokeObjectURL(blobUrl);
|
|
1256
|
+
|
|
1257
|
+
toast(`Exported ${filename} successfully!`, 'success');
|
|
1258
|
+
} catch (e) {
|
|
1259
|
+
toast(e.message, 'error');
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// CSV Import State & Logic
|
|
1264
|
+
let currentImport = {
|
|
1265
|
+
fileName: '',
|
|
1266
|
+
headers: [],
|
|
1267
|
+
rows: [],
|
|
1268
|
+
mapping: {},
|
|
1269
|
+
continueOnError: true,
|
|
1270
|
+
};
|