feat(dashboard): enhance widget availability and initialization
All checks were successful
Deploy to production / deploy (push) Successful in 3m2s
All checks were successful
Deploy to production / deploy (push) Successful in 3m2s
- Updated `getAvailableWidgets` method in `DashboardService` to merge default widget types with database entries, ensuring immediate visibility of new widgets post-deployment. - Introduced `DASHBOARD_WIDGET_TYPE_DEFAULTS` in `initializeWidgetTypes` for canonical widget types, facilitating API merging when database entries are absent. - Modified `StatusBar.vue` to utilize a computed property for quick access children, improving menu item handling and visibility based on user context. - Enhanced `LoggedInView.vue` to dynamically return localized widget labels, improving user experience with accurate translations.
This commit is contained in:
@@ -1,24 +1,62 @@
|
||||
import BaseService from './BaseService.js';
|
||||
import UserDashboard from '../models/community/user_dashboard.js';
|
||||
import WidgetType from '../models/type/widget_type.js';
|
||||
import { DASHBOARD_WIDGET_TYPE_DEFAULTS } from '../utils/initializeWidgetTypes.js';
|
||||
|
||||
class DashboardService extends BaseService {
|
||||
/**
|
||||
* Liste aller möglichen (verfügbaren) Widget-Typen.
|
||||
* @returns {Promise<Array<{ id: number, label: string, endpoint: string, description: string|null, orderId: number }>>}
|
||||
* Merge: Code-Defaults (immer) + DB-Zeilen; fehlende Defaults erscheinen mit synthetischer id,
|
||||
* damit neue Widgets nach Deploy sofort unter „Widget hinzufügen“ sichtbar sind.
|
||||
* @returns {Promise<Array<{ id: number|string, label: string, endpoint: string, description: string|null, orderId: number }>>}
|
||||
*/
|
||||
async getAvailableWidgets() {
|
||||
const rows = await WidgetType.findAll({
|
||||
order: [['orderId', 'ASC'], ['id', 'ASC']],
|
||||
attributes: ['id', 'label', 'endpoint', 'description', 'orderId']
|
||||
});
|
||||
return rows.map(r => ({
|
||||
id: r.id,
|
||||
label: r.label,
|
||||
endpoint: r.endpoint,
|
||||
description: r.description ?? null,
|
||||
orderId: r.orderId
|
||||
}));
|
||||
const dbByEndpoint = new Map(rows.map((r) => [r.endpoint, r]));
|
||||
const defaultEndpoints = new Set(DASHBOARD_WIDGET_TYPE_DEFAULTS.map((d) => d.endpoint));
|
||||
|
||||
const sortedDefaults = [...DASHBOARD_WIDGET_TYPE_DEFAULTS].sort(
|
||||
(a, b) => (a.orderId || 0) - (b.orderId || 0)
|
||||
);
|
||||
|
||||
const ordered = [];
|
||||
for (const def of sortedDefaults) {
|
||||
const existing = dbByEndpoint.get(def.endpoint);
|
||||
if (existing) {
|
||||
ordered.push({
|
||||
id: existing.id,
|
||||
label: existing.label,
|
||||
endpoint: existing.endpoint,
|
||||
description: existing.description ?? null,
|
||||
orderId: existing.orderId
|
||||
});
|
||||
} else {
|
||||
ordered.push({
|
||||
id: `ep:${def.endpoint}`,
|
||||
label: def.label,
|
||||
endpoint: def.endpoint,
|
||||
description: def.description ?? null,
|
||||
orderId: def.orderId ?? 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const r of rows) {
|
||||
if (!defaultEndpoints.has(r.endpoint)) {
|
||||
ordered.push({
|
||||
id: r.id,
|
||||
label: r.label,
|
||||
endpoint: r.endpoint,
|
||||
description: r.description ?? null,
|
||||
orderId: r.orderId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user