Files
orion/app/modules/tenancy/static/admin/js/platform-detail.js
Samir Boulahtit 4e28d91a78 refactor: migrate templates and static files to self-contained modules
Templates Migration:
- Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.)
- Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.)
- Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms)
- Migrate public templates to modules (billing, marketplace, cms)
- Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/)
- Migrate letzshop partials to marketplace module

Static Files Migration:
- Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file)
- Migrate vendor JS to modules: tenancy (4 files), core (2 files)
- Migrate shared JS: vendor-selector.js to core, media-picker.js to cms
- Migrate storefront JS: storefront-layout.js to core
- Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/)
- Update all template references to use module_static paths

Naming Consistency:
- Rename static/platform/ to static/public/
- Rename app/templates/platform/ to app/templates/public/
- Update all extends and static references

Documentation:
- Update module-system.md with shared templates documentation
- Update frontend-structure.md with new module JS organization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 14:34:16 +01:00

140 lines
4.0 KiB
JavaScript

/**
* Platform Detail - Alpine.js Component
*
* Displays platform overview, stats, and quick actions.
*/
const platformDetailLog = window.LogConfig.createLogger('PLATFORM_DETAIL');
function platformDetail() {
return {
// Inherit base layout functionality from init-alpine.js
...data(),
// Page identification
currentPage: 'platform-detail',
// State
platform: null,
stats: null,
recentPages: [],
loading: true,
error: null,
platformCode: null,
// Lifecycle
async init() {
platformDetailLog.info('=== PLATFORM DETAIL PAGE INITIALIZING ===');
// Duplicate initialization guard
if (window._platformDetailInitialized) {
platformDetailLog.warn('Platform detail page already initialized, skipping...');
return;
}
window._platformDetailInitialized = true;
try {
// Extract platform code from URL
const path = window.location.pathname;
const match = path.match(/\/admin\/platforms\/([^\/]+)$/);
if (match) {
this.platformCode = match[1];
platformDetailLog.info('Viewing platform:', this.platformCode);
await Promise.all([
this.loadPlatform(),
this.loadRecentPages(),
]);
} else {
platformDetailLog.error('No platform code in URL');
this.error = 'Platform code not found in URL';
this.loading = false;
}
platformDetailLog.info('=== PLATFORM DETAIL PAGE INITIALIZATION COMPLETE ===');
} catch (error) {
window.LogConfig.logError(error, 'Platform Detail Init');
this.error = 'Failed to initialize page';
this.loading = false;
}
},
// API Methods
async loadPlatform() {
try {
const response = await apiClient.get(`/admin/platforms/${this.platformCode}`);
this.platform = response;
platformDetailLog.info(`Loaded platform: ${this.platformCode}`);
} catch (err) {
platformDetailLog.error('Error loading platform:', err);
this.error = err.message || 'Failed to load platform';
throw err;
} finally {
this.loading = false;
}
},
async loadRecentPages() {
try {
// Load recent content pages for this platform
const response = await apiClient.get(`/admin/content-pages?platform_code=${this.platformCode}&limit=5`);
this.recentPages = response.items || response || [];
platformDetailLog.info(`Loaded ${this.recentPages.length} recent pages`);
} catch (err) {
platformDetailLog.error('Error loading recent pages:', err);
// Non-fatal - don't throw
this.recentPages = [];
}
},
// Helper Methods
getPlatformIcon(code) {
const icons = {
main: 'home',
oms: 'clipboard-list',
loyalty: 'star',
sitebuilder: 'template',
};
return icons[code] || 'globe-alt';
},
getPageTypeLabel(page) {
if (page.is_platform_page) return 'Marketing';
if (page.vendor_id) return 'Vendor Override';
return 'Vendor Default';
},
getPageTypeBadgeClass(page) {
if (page.is_platform_page) {
return 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200';
}
if (page.vendor_id) {
return 'bg-teal-100 text-teal-800 dark:bg-teal-900 dark:text-teal-200';
}
return 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200';
},
formatDate(dateString) {
if (!dateString) return '—';
const date = new Date(dateString);
return date.toLocaleDateString('fr-LU', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
},
getPlatformUrl() {
if (!this.platform) return '#';
if (this.platform.domain) {
return `https://${this.platform.domain}`;
}
// Development URL
if (this.platform.code === 'main') {
return '/';
}
return `/platforms/${this.platform.code}/`;
},
};
}