opsdash-app/opsdash/lib/Service/OverviewCorePayloadComposer.php
blade34242 4da913a47d Add active profile name to email recap and targets widget
- Persist active_preset to backend on every save (PersistController)
- Read active_preset back on page load via OverviewLoadContextService and OverviewCorePayloadComposer
- Seed activePresetRef from onCoreLoaded so the pill shows on every page load, not just the session where a profile was loaded
- Watch lastLoadedPreset → activePresetRef so loading or saving a profile updates the widget live
- TimeTargetsCard: new presetLabel prop renders a brand-colored pill next to the title
- targets_v2 buildProps passes ctx.activePreset as presetLabel
- WidgetRenderContext carries activePreset field
- ReportRenderService: show profile name as frosted pill in hero card when set
- ReportSummaryService: include active_preset in email summary payload
- Fix activity highlights sprintf arg mismatch (extra 'Quiet days' literal)
- Redesign all email sections as widget-style cards matching app visual language
2026-05-19 10:07:45 +07:00

79 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\Opsdash\Service;
final class OverviewCorePayloadComposer {
/**
* @param array{
* includeAll: bool,
* includes: array<string,bool>,
* userSettings: array<string, mixed>,
* calendars: array<int, array<string, mixed>>,
* selected: array<int, string>,
* colorsById: array<string, string>,
* colorsByName: array<string, string>,
* groupsById: array<string, int>,
* targetsWeek: array<string, mixed>,
* targetsMonth: array<string, mixed>,
* targetsConfig: array<string, mixed>,
* themePreference: string,
* reportingConfig: array<string, mixed>,
* deckSettings: array<string, mixed>,
* widgets: array<int, mixed>,
* widgetPresets: array<string, mixed>,
* onboarding: array<string, mixed>
* } $context
* @return array<string, mixed>
*/
public function compose(array $context): array {
$includeAll = (bool)$context['includeAll'];
$includes = $context['includes'];
$shouldInclude = fn(string $key): bool => $includeAll || isset($includes[$key]);
$payload = [];
if ($shouldInclude('userSettings') || isset($includes['core'])) {
$payload['userSettings'] = $context['userSettings'];
}
if ($shouldInclude('calendars') || isset($includes['core'])) {
$payload['calendars'] = $context['calendars'];
}
if ($shouldInclude('selected') || isset($includes['core'])) {
$payload['selected'] = $context['selected'];
}
if ($shouldInclude('colors') || isset($includes['core'])) {
$payload['colors'] = ['byId' => $context['colorsById'], 'byName' => $context['colorsByName']];
}
if ($shouldInclude('groups') || isset($includes['core'])) {
$payload['groups'] = ['byId' => $context['groupsById']];
}
if ($shouldInclude('targets') || isset($includes['core'])) {
$payload['targets'] = ['week' => $context['targetsWeek'], 'month' => $context['targetsMonth']];
}
if ($shouldInclude('targetsConfig') || isset($includes['core'])) {
$payload['targetsConfig'] = $context['targetsConfig'];
}
if ($shouldInclude('themePreference') || isset($includes['core'])) {
$payload['themePreference'] = $context['themePreference'];
}
if ($shouldInclude('reportingConfig') || isset($includes['core'])) {
$payload['reportingConfig'] = $context['reportingConfig'];
}
if ($shouldInclude('deckSettings') || isset($includes['core'])) {
$payload['deckSettings'] = $context['deckSettings'];
}
if ($shouldInclude('widgets') || isset($includes['core'])) {
$payload['widgets'] = $context['widgets'];
if (!empty($context['widgetPresets'])) {
$payload['widgetPresets'] = $context['widgetPresets'];
}
}
if ($shouldInclude('onboarding') || isset($includes['core'])) {
$payload['onboarding'] = $context['onboarding'];
}
if (isset($context['activePreset']) && $context['activePreset'] !== '') {
$payload['activePreset'] = $context['activePreset'];
}
return $payload;
}
}