diff --git a/CHANGELOG.md b/CHANGELOG.md index 6187a275..ba5d8086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,20 @@ All notable changes are written here, newest first, in the [Keep a Changelog](ht ## [Unreleased] +### Added + +- **Group** widget on status screens: one card behind the widgets wholly inside it, which then draw no card of their own (**Show card** is locked off). Groups nest, a group moves with all it holds when dragged by the space between its widgets, and it cannot be made smaller than them. Its title is off by default. +- A screen's **Margin** around the grid and **Spacing** between its widgets: none, small, medium (as before) or large. With no spacing, tiles have square corners and neighbours share one border. +- The **QR code** widget's style: the Lumberjack logo on or off, the code's color and a background, its modules, its eyes as a set or outer and inner apart, and up to 3 filters, each picked from pictures of the QR library's own parts, with **Reset** per section. A style phones could not read reliably is refused when saved. +- What a screen's header shows: the logo, the title (or a title of its own), team, projects, environment, period, the count of widgets needing attention and the live state can each be turned off; offline always shows. The header comes in four sizes, and its title grows to the clock's size with nothing under it. The clock can show seconds and the date, in a format of five or one of its own from tokens (`ddd D. MMM`), in the app's language, the TV's own, or one picked. +- **Move to another team** in a project's danger zone, for owners and admins of both teams. The project's own alert rules and channels go with it; links to the old team's rules and channels, MCP token access, the old team's screens' references and assignees or watchers outside the new team are dropped. A taken slug or issue prefix is replaced in the dialog, and each move is in the audit log. +- MCP: `update_screen` sets `margin`, `gap` and `header`; the design guide covers groups and these settings. + ### Changed +- Screen settings are in tabs (**Display**, **Look**, **Data**, **Header**); **Aspect** and **Orientation** moved there from the designer's toolbar. +- Spacing, alignment, text and title sizes, theme, fit, aspect and orientation are picked from pictures of what they do, and a screen's projects and header parts from switches. +- `list_widget_types` leaves out the designer's pictures of the QR code's parts. - The **Mail domain** check's form and docs say what a DKIM selector is entered as (the name only, such as `dkim`) and where to find it. ## [0.11.1] - 2026-11-15 diff --git a/app/Domains/Administration/Enums/AdminAction.php b/app/Domains/Administration/Enums/AdminAction.php index 339e32d0..a445fcfd 100644 --- a/app/Domains/Administration/Enums/AdminAction.php +++ b/app/Domains/Administration/Enums/AdminAction.php @@ -20,6 +20,7 @@ enum AdminAction: string case PublicStatsRotated = 'public_stats_rotated'; case PublicStatsChanged = 'public_stats_changed'; case PublicStatsDisabled = 'public_stats_disabled'; + case ProjectMoved = 'project_moved'; case ScreenShared = 'screen_shared'; case ScreenShareChanged = 'screen_share_changed'; case ScreenShareRotated = 'screen_share_rotated'; diff --git a/app/Domains/Live/Observers/LiveModelObserver.php b/app/Domains/Live/Observers/LiveModelObserver.php index 164a594f..068ba672 100644 --- a/app/Domains/Live/Observers/LiveModelObserver.php +++ b/app/Domains/Live/Observers/LiveModelObserver.php @@ -166,10 +166,16 @@ private function retention(RetentionPolicy $policy): void private function projectChanged(Project $project, bool $createdOrDeleted): void { - if ($createdOrDeleted || $project->wasChanged(['name', 'slug'])) { + if ($createdOrDeleted || $project->wasChanged(['name', 'slug', 'team_id'])) { $this->team->execute($project->team_id, TeamChangeKind::Projects); } + // Moved to another team: the old one lists it no more. + if ($project->wasChanged('team_id')) { + $this->team->execute((int) $project->getPrevious()['team_id'], TeamChangeKind::Projects); + $this->admin->execute(AdminChangeKind::Teams); + } + if ($createdOrDeleted) { $this->admin->execute(AdminChangeKind::Teams); diff --git a/app/Domains/Mcp/Tools/Screens/GetScreenDesignGuide.php b/app/Domains/Mcp/Tools/Screens/GetScreenDesignGuide.php index 75355d0b..685e3673 100644 --- a/app/Domains/Mcp/Tools/Screens/GetScreenDesignGuide.php +++ b/app/Domains/Mcp/Tools/Screens/GetScreenDesignGuide.php @@ -51,13 +51,20 @@ class GetScreenDesignGuide extends Tool ## Widgets {id, type, source, x, y, w, h, title, options, scope} - id: unique on the screen, any short string; keep it when moving a widget. - - x, y from 0; w, h in cells. Inside the grid, no overlaps. + - x, y from 0; w, h in cells. Inside the grid, no overlaps, but for groups. + - A group (type group) is one card behind the widgets wholly inside it, on fewer cells than + it; those draw no card of their own. Groups nest. Moving a group, move what it holds too. - source: an id from list_widget_types, for types that have sources. - options: only the keys of the type's fields. - scope: over the screen's scope: projects (uuids), environment, period, and for some sources release, filter, domain. Empty projects means every project. - rotate: on rotating types, source ids or {source, seconds, title, options, scope}. + ## Screen settings + update_screen also sets the room around the grid (margin) and between widgets (gap), and what + the header shows (header: parts to hide, a title, the clock's date, its format and language, + seconds, size). + ## Data sources Use source external_json with options.data_source set to the uuid; a list wants a rows source. Use source calendar for an iCalendar feed. A connected source fetches on first diff --git a/app/Domains/Mcp/Tools/Screens/ListWidgetTypes.php b/app/Domains/Mcp/Tools/Screens/ListWidgetTypes.php index a9da2345..fea70c8a 100644 --- a/app/Domains/Mcp/Tools/Screens/ListWidgetTypes.php +++ b/app/Domains/Mcp/Tools/Screens/ListWidgetTypes.php @@ -47,7 +47,19 @@ public function handle(Request $request): Response } return isset($widgets[$type]) - ? Response::json(['type' => $type, 'schema' => $widgets[$type], 'sources' => $sources[$type] ?? []]) + ? Response::json(['type' => $type, 'schema' => self::withoutIcons($widgets[$type]), 'sources' => $sources[$type] ?? []]) : Response::error('Unknown widget type; see list_widget_types without a type.'); } + + /** + * A type's sections without the pictures its choices have for the designer (the QR + * library's SVGs): an agent picks by name and label. + * + * @param list>}> $sections + * @return list>}> + */ + private static function withoutIcons(array $sections): array + { + return array_map(fn (array $section): array => [...$section, 'fields' => array_map(fn (array $field): array => array_diff_key($field, ['icons' => true]), $section['fields'])], $sections); + } } diff --git a/app/Domains/Mcp/Tools/Screens/UpdateScreen.php b/app/Domains/Mcp/Tools/Screens/UpdateScreen.php index f2681373..71ef9a00 100644 --- a/app/Domains/Mcp/Tools/Screens/UpdateScreen.php +++ b/app/Domains/Mcp/Tools/Screens/UpdateScreen.php @@ -39,9 +39,12 @@ public function schema(JsonSchema $schema): array 'aspect' => $schema->string(), 'orientation' => $schema->string(), 'fit' => $schema->string(), + 'margin' => $schema->string()->description('Room around the grid: none, s, m or l.'), + 'gap' => $schema->string()->description('Room between widgets: none, s, m or l.'), 'show_header' => $schema->boolean(), 'show_clock' => $schema->boolean(), 'clock_format' => $schema->string()->description('24 or 12.'), + 'header' => $schema->object()->description('{hide: [logo|name|team|projects|environment|period|attention|live], title: a title instead of the name or null, date: bool, seconds: bool, date_format: short|long|medium|numeric|iso|custom, date_pattern: tokens for custom (YYYY YY MMMM MMM MM M DD D dddd ddd, [literal text]), locale: null for the app\'s language, browser, or a tag such as da or en-GB, size: s|m|l|xl, how large the header is}: the clock\'s date and seconds.'), 'light_from' => $schema->string()->description('HH:MM.'), 'light_to' => $schema->string()->description('HH:MM.'), 'timezone' => $schema->string()->description('Null: each viewer\'s own.'), diff --git a/app/Domains/Mcp/Tools/Screens/UpdateScreenLayout.php b/app/Domains/Mcp/Tools/Screens/UpdateScreenLayout.php index 4b5e5699..ddad0fe2 100644 --- a/app/Domains/Mcp/Tools/Screens/UpdateScreenLayout.php +++ b/app/Domains/Mcp/Tools/Screens/UpdateScreenLayout.php @@ -23,7 +23,7 @@ class UpdateScreenLayout extends Tool protected string $name = 'update_screen_layout'; - protected string $description = 'Replaces a screen grid and all its widgets, live on every TV showing it. Send every widget you want to keep. Widgets may not overlap.'; + protected string $description = 'Replaces a screen grid and all its widgets, live on every TV showing it. Send every widget you want to keep. Widgets may not overlap, but for those wholly inside a group (type group).'; public function __construct( private readonly UpdateScreenLayoutAction $update, diff --git a/app/Domains/Projects/Actions/MoveProjectToTeamAction.php b/app/Domains/Projects/Actions/MoveProjectToTeamAction.php new file mode 100644 index 00000000..e086f6e9 --- /dev/null +++ b/app/Domains/Projects/Actions/MoveProjectToTeamAction.php @@ -0,0 +1,101 @@ +whereKey($project->id)->lockForUpdate()->firstOrFail(); + $from = $project->team; + + // Its own channels go with it; the old team's are no longer its to send to. + DB::table('notification_channels')->where('project_id', $project->id)->update(['team_id' => $target->id]); + $staleRules = DB::table('alert_rules')->where('team_id', $from->id)->select('id'); + $staleChannels = DB::table('notification_channels')->where('team_id', $from->id)->select('id'); + DB::table('project_alert_rule_channel')->where('project_id', $project->id) + ->where(fn ($q) => $q->whereIn('alert_rule_id', $staleRules)->orWhereIn('notification_channel_id', $staleChannels)) + ->delete(); + DB::table('alert_rule_notification_channel') + ->where(fn ($q) => $q->whereIn('alert_rule_id', DB::table('alert_rules')->where('project_id', $project->id)->select('id'))->whereIn('notification_channel_id', $staleChannels)) + ->orWhere(fn ($q) => $q->whereIn('alert_rule_id', $staleRules)->whereIn('notification_channel_id', DB::table('notification_channels')->where('project_id', $project->id)->select('id'))) + ->delete(); + + // Tokens of the new team get no access by themselves. + DB::table('mcp_token_project')->where('project_id', $project->id)->delete(); + + $members = DB::table('team_user')->where('team_id', $target->id)->select('user_id'); + $issues = DB::table('issues')->where('project_id', $project->id)->select('id'); + DB::table('issues')->where('project_id', $project->id)->whereNotNull('assigned_user_id')->whereNotIn('assigned_user_id', $members)->update(['assigned_user_id' => null]); + DB::table('issue_watchers')->whereIn('issue_id', $issues)->whereNotIn('user_id', $members)->delete(); + + $this->removeFromScreens($project, $from); + + $project->update(['team_id' => $target->id, 'slug' => $slug, 'issue_prefix' => $issuePrefix]); + $this->audit->execute($by, AdminAction::ProjectMoved, $project->name, ['project' => $project->uuid, 'from' => $from->name, 'to' => $target->name]); + }); + + $project->refresh()->setRelation('team', $target); + + return $project; + } + + /** + * Takes the project out of every scope of the old team's screens. A scope left with no + * project would mean every project of the team, so it keeps NO_PROJECT instead and shows + * nothing, as a widget pointing only outside its screen's projects already does. + */ + private function removeFromScreens(Project $project, Team $from): void + { + $uuid = $project->uuid; + $strip = function (mixed $scope) use ($uuid): mixed { + $projects = is_array($scope) ? (array) ($scope['projects'] ?? []) : []; + + if (! in_array($uuid, $projects, true)) { + return $scope; + } + + return [...$scope, 'projects' => array_values(array_diff($projects, [$uuid])) ?: [WidgetScope::NO_PROJECT]]; + }; + + // A widget has a scope, and so may each value it rotates through. + $scoped = fn (mixed $item): mixed => is_array($item) && array_key_exists('scope', $item) ? [...$item, 'scope' => $strip($item['scope'])] : $item; + + // A screen it is not on stays as it is: saving skips an unchanged one. + Screen::query()->where('team_id', $from->id)->get()->each(function (Screen $screen) use ($strip, $scoped): void { + $screen->scope = $strip($screen->scope); + $screen->widgets = array_map(fn (array $widget): array => [ + ...$scoped($widget), + ...(is_array($widget['rotate'] ?? null) ? ['rotate' => array_map($scoped, $widget['rotate'])] : []), + ], $screen->widgets); + $this->saveScreen->execute($screen); + }); + } +} diff --git a/app/Domains/Projects/Http/Controllers/ProjectController.php b/app/Domains/Projects/Http/Controllers/ProjectController.php index a0490489..569cf7da 100644 --- a/app/Domains/Projects/Http/Controllers/ProjectController.php +++ b/app/Domains/Projects/Http/Controllers/ProjectController.php @@ -7,12 +7,15 @@ use App\Domains\Issues\Models\Issue; use App\Domains\Projects\Actions\CreateProjectAction; use App\Domains\Projects\Actions\DeleteProjectAction; +use App\Domains\Projects\Actions\MoveProjectToTeamAction; +use App\Domains\Projects\Http\Requests\MoveProjectRequest; use App\Domains\Projects\Http\Requests\StoreProjectRequest; use App\Domains\Projects\Models\Project; use App\Domains\Projects\Models\ProjectAgent; use App\Domains\Shared\Enums\Period; use App\Domains\Shared\Support\Percentiles; use App\Domains\Shared\Support\TimeSeries; +use App\Domains\Teams\Models\Team; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; @@ -119,4 +122,14 @@ public function destroy(Request $request, Project $project, DeleteProjectAction return redirect()->route('projects.index')->with('status', __('projects.deleted')); } + + public function move(MoveProjectRequest $request, Project $project, MoveProjectToTeamAction $action): RedirectResponse + { + /** @var Team $target validated */ + $target = $request->target(); + $action->execute($project, $target, $request->string('slug')->toString(), $request->string('issue_prefix')->toString(), $request->user()); + + // Opening it there makes the new team the current one (FollowProjectTeam). + return redirect()->route('projects.settings', $project)->with('status', __('projects.moved', ['team' => $target->name])); + } } diff --git a/app/Domains/Projects/Http/Controllers/ProjectSettingsController.php b/app/Domains/Projects/Http/Controllers/ProjectSettingsController.php index 4dc51d71..f0b202fe 100644 --- a/app/Domains/Projects/Http/Controllers/ProjectSettingsController.php +++ b/app/Domains/Projects/Http/Controllers/ProjectSettingsController.php @@ -31,6 +31,8 @@ use App\Domains\Retention\Presenters\RetentionPresenter; use App\Domains\Shared\Support\Scrubber; use App\Domains\SourceMaps\Models\SourceMap; +use App\Domains\Teams\Models\Team; +use App\Models\User; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -107,6 +109,7 @@ public function edit(Request $request, Project $project, ProjectPresenter $prese ], // One entry per agent provider; Claude is the first. 'triage' => [app(ClaudeTriageWorkflow::class)->describe($project, url('/'))], + 'move_targets' => $this->moveTargets($request->user(), $project), 'repository' => $repository === null ? null : [ 'provider' => $repository->provider->value, 'repository' => $repository->repository, @@ -117,6 +120,36 @@ public function edit(Request $request, Project $project, ProjectPresenter $prese ]); } + /** + * The teams the user may move the project to, each with the slug and issue prefix it + * would have there: its own, or with a number added where the team has them already. + * + * @return list + */ + private function moveTargets(User $user, Project $project): array + { + $teams = ($user->isAdmin() ? Team::query()->get() : $user->teams) + ->filter(fn (Team $team): bool => $user->can('move', [$project, $team])) + ->sortBy('name'); + $taken = Project::query()->whereIn('team_id', $teams->modelKeys())->get(['team_id', 'slug', 'issue_prefix'])->groupBy('team_id'); + + return array_values($teams->map(function (Team $team) use ($project, $taken): array { + $projects = $taken->get($team->id, collect()); + $slug = $project->slug; + $prefix = $project->issuePrefix(); + + for ($n = 2; $projects->contains('slug', $slug); $n++) { + $slug = $project->slug.'-'.$n; + } + + for ($n = 2; $projects->contains('issue_prefix', $prefix); $n++) { + $prefix = mb_substr($project->issuePrefix(), 0, 8 - strlen((string) $n)).$n; + } + + return ['uuid' => $team->uuid, 'name' => $team->name, 'slug' => $slug, 'issue_prefix' => $prefix]; + })->all()); + } + public function update(UpdateProjectRequest $request, Project $project, UpdateProjectAction $action): RedirectResponse { $action->execute( diff --git a/app/Domains/Projects/Http/Requests/MoveProjectRequest.php b/app/Domains/Projects/Http/Requests/MoveProjectRequest.php new file mode 100644 index 00000000..289a6ccf --- /dev/null +++ b/app/Domains/Projects/Http/Requests/MoveProjectRequest.php @@ -0,0 +1,61 @@ +route('project'); + } + + /** The team it moves to; null when there is none by that uuid, which validation reports. */ + public function target(): ?Team + { + $uuid = (string) $this->input('team'); + + return once(fn (): ?Team => Str::isUuid($uuid) ? Team::query()->where('uuid', $uuid)->first() : null); + } + + public function authorize(): bool + { + $target = $this->target(); + + return $target === null + ? $this->user()?->can('update', $this->project()) ?? false + : $this->user()?->can('move', [$this->project(), $target]) ?? false; + } + + protected function prepareForValidation(): void + { + $this->merge(['issue_prefix' => strtoupper(trim((string) $this->input('issue_prefix')))]); + } + + /** @return array */ + public function messages(): array + { + return ['issue_prefix.regex' => __('projects.issue_prefix_invalid')]; + } + + /** @return array */ + public function rules(): array + { + $teamId = $this->target()?->id; + + return [ + 'team' => ['bail', 'required', 'uuid', Rule::exists('teams', 'uuid')], + // Free in the team it moves to, as on creating one there. + 'slug' => ['required', 'string', 'max:100', 'alpha_dash:ascii', Rule::unique('projects', 'slug')->where('team_id', $teamId)], + 'issue_prefix' => ['required', 'string', 'min:2', 'max:8', 'regex:/^[A-Z][A-Z0-9]*$/', Rule::unique('projects', 'issue_prefix')->where('team_id', $teamId)], + ]; + } +} diff --git a/app/Domains/Projects/Policies/ProjectPolicy.php b/app/Domains/Projects/Policies/ProjectPolicy.php index c3df673d..11fe5d71 100644 --- a/app/Domains/Projects/Policies/ProjectPolicy.php +++ b/app/Domains/Projects/Policies/ProjectPolicy.php @@ -5,6 +5,7 @@ namespace App\Domains\Projects\Policies; use App\Domains\Projects\Models\Project; +use App\Domains\Teams\Models\Team; use App\Models\User; class ProjectPolicy @@ -26,4 +27,12 @@ public function delete(User $user, Project $project): bool { return $user->canAdministerTeam($project->team); } + + /** + * Moving to another team takes administering both. + */ + public function move(User $user, Project $project, Team $target): bool + { + return $target->id !== $project->team_id && $user->canAdministerTeam($project->team) && $user->canAdministerTeam($target); + } } diff --git a/app/Domains/Screens/Actions/ExportScreenAction.php b/app/Domains/Screens/Actions/ExportScreenAction.php index 7f9a43a3..e9b5f676 100644 --- a/app/Domains/Screens/Actions/ExportScreenAction.php +++ b/app/Domains/Screens/Actions/ExportScreenAction.php @@ -57,9 +57,12 @@ public function execute(Screen $screen): array 'aspect' => $screen->aspect->value, 'orientation' => $screen->orientation->value, 'fit' => $screen->fit->value, + 'margin' => $screen->margin->value, + 'gap' => $screen->gap->value, 'show_header' => $screen->show_header, 'show_clock' => $screen->show_clock, 'clock_format' => $screen->clock_format, + 'header' => Screen::header($screen->header), 'theme' => $screen->theme->value, 'light_from' => $screen->light_from, 'light_to' => $screen->light_to, diff --git a/app/Domains/Screens/Actions/ImportScreenAction.php b/app/Domains/Screens/Actions/ImportScreenAction.php index 81e8ad67..4e6e054e 100644 --- a/app/Domains/Screens/Actions/ImportScreenAction.php +++ b/app/Domains/Screens/Actions/ImportScreenAction.php @@ -10,6 +10,7 @@ use App\Domains\Screens\Enums\ScreenAspect; use App\Domains\Screens\Enums\ScreenFit; use App\Domains\Screens\Enums\ScreenOrientation; +use App\Domains\Screens\Enums\ScreenSpacing; use App\Domains\Screens\Enums\ScreenTheme; use App\Domains\Screens\Models\Screen; use App\Domains\Screens\Support\ScreenFile; @@ -17,6 +18,7 @@ use App\Domains\Screens\Support\WidgetSchema; use App\Domains\Shared\Enums\Period; use App\Domains\Teams\Models\Team; +use Closure; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; @@ -70,10 +72,29 @@ public function read(Team $team, array $document): ScreenImport 'screen.aspect' => ['required', Rule::enum(ScreenAspect::class)], 'screen.orientation' => ['required', Rule::enum(ScreenOrientation::class)], 'screen.fit' => ['required', Rule::enum(ScreenFit::class)], + // Files from before they could be chosen have neither. + 'screen.margin' => ['sometimes', Rule::enum(ScreenSpacing::class)], + 'screen.gap' => ['sometimes', Rule::enum(ScreenSpacing::class)], 'screen.show_header' => ['required', 'boolean'], // Files from before the clock could be hidden show it. 'screen.show_clock' => ['sometimes', 'boolean'], 'screen.clock_format' => ['sometimes', 'in:24,12'], + 'screen.header' => ['sometimes', 'array'], + 'screen.header.hide' => ['array'], + 'screen.header.hide.*' => ['string', Rule::in(Screen::HEADER_PARTS)], + 'screen.header.title' => ['nullable', 'string', 'max:100'], + 'screen.header.date' => ['boolean'], + 'screen.header.seconds' => ['boolean'], + 'screen.header.date_format' => ['string', Rule::in(Screen::DATE_FORMATS)], + 'screen.header.date_pattern' => ['nullable', 'required_if:screen.header.date_format,custom', 'string', 'max:60', function (string $attribute, mixed $value, Closure $fail): void { + $problem = is_string($value) ? Screen::datePatternProblem($value) : null; + + if ($problem !== null) { + $fail($problem === '' ? __('ui/screens.validation.date_empty') : __('ui/screens.validation.date_token', ['token' => $problem])); + } + }], + 'screen.header.locale' => ['nullable', 'string', 'regex:'.Screen::LOCALE_PATTERN], + 'screen.header.size' => ['string', Rule::in(Screen::HEADER_SIZES)], 'screen.theme' => ['required', Rule::enum(ScreenTheme::class)], 'screen.light_from' => $time, 'screen.light_to' => $time, @@ -213,9 +234,12 @@ public function read(Team $team, array $document): ScreenImport 'aspect' => ScreenAspect::from((string) $file['aspect']), 'orientation' => ScreenOrientation::from((string) $file['orientation']), 'fit' => ScreenFit::from((string) $file['fit']), + 'margin' => ScreenSpacing::from((string) ($file['margin'] ?? ScreenSpacing::Medium->value)), + 'gap' => ScreenSpacing::from((string) ($file['gap'] ?? ScreenSpacing::Medium->value)), 'show_header' => (bool) $file['show_header'], 'show_clock' => (bool) ($file['show_clock'] ?? true), 'clock_format' => in_array($file['clock_format'] ?? null, ['24', '12'], true) ? $file['clock_format'] : '24', + 'header' => Screen::header(is_array($file['header'] ?? null) ? $file['header'] : null), 'theme' => ScreenTheme::from((string) $file['theme']), 'light_from' => (string) $file['light_from'], 'light_to' => (string) $file['light_to'], diff --git a/app/Domains/Screens/Actions/UpdateScreenAction.php b/app/Domains/Screens/Actions/UpdateScreenAction.php index 36ecfa2f..cdcf3a9b 100644 --- a/app/Domains/Screens/Actions/UpdateScreenAction.php +++ b/app/Domains/Screens/Actions/UpdateScreenAction.php @@ -8,6 +8,7 @@ use App\Domains\Screens\Enums\ScreenAspect; use App\Domains\Screens\Enums\ScreenFit; use App\Domains\Screens\Enums\ScreenOrientation; +use App\Domains\Screens\Enums\ScreenSpacing; use App\Domains\Screens\Enums\ScreenTheme; use App\Domains\Screens\Models\Screen; use App\Models\User; @@ -23,11 +24,11 @@ public function __construct( * Name, the display's aspect and orientation and how it fits another, whether the header shows, theme and its schedule, time zone and * the default scope; open kiosks follow. * - * @param array{name?: string, aspect?: ScreenAspect, orientation?: ScreenOrientation, fit?: ScreenFit, show_header?: bool, show_clock?: bool, clock_format?: string, theme?: ScreenTheme, light_from?: string, light_to?: string, timezone?: string|null, scope?: array{projects: list, environment: string|null, period: string}} $settings + * @param array{name?: string, aspect?: ScreenAspect, orientation?: ScreenOrientation, fit?: ScreenFit, margin?: ScreenSpacing, gap?: ScreenSpacing, show_header?: bool, show_clock?: bool, clock_format?: string, header?: array{hide: list, title: string|null, date: bool, seconds: bool, date_format: string, date_pattern: string|null, locale: string|null, size: string}, theme?: ScreenTheme, light_from?: string, light_to?: string, timezone?: string|null, scope?: array{projects: list, environment: string|null, period: string}} $settings */ public function execute(Screen $screen, array $settings, User|McpToken|null $by = null, ?int $revision = null): Screen { - $screen->fill(array_intersect_key($settings, array_flip(['name', 'aspect', 'orientation', 'fit', 'show_header', 'show_clock', 'clock_format', 'theme', 'light_from', 'light_to', 'timezone', 'scope']))); + $screen->fill(array_intersect_key($settings, array_flip(['name', 'aspect', 'orientation', 'fit', 'margin', 'gap', 'show_header', 'show_clock', 'clock_format', 'header', 'theme', 'light_from', 'light_to', 'timezone', 'scope']))); return $this->save->execute($screen, $by, $revision); } diff --git a/app/Domains/Screens/Enums/ScreenSpacing.php b/app/Domains/Screens/Enums/ScreenSpacing.php new file mode 100644 index 00000000..b8d1235d --- /dev/null +++ b/app/Domains/Screens/Enums/ScreenSpacing.php @@ -0,0 +1,17 @@ + ['sometimes', 'required', Rule::enum(ScreenAspect::class)], 'orientation' => ['sometimes', 'required', Rule::enum(ScreenOrientation::class)], 'fit' => ['sometimes', 'required', Rule::enum(ScreenFit::class)], + 'margin' => ['sometimes', 'required', Rule::enum(ScreenSpacing::class)], + 'gap' => ['sometimes', 'required', Rule::enum(ScreenSpacing::class)], 'show_header' => ['sometimes', 'required', 'boolean'], 'show_clock' => ['sometimes', 'required', 'boolean'], 'clock_format' => ['sometimes', 'required', Rule::in(['24', '12'])], + 'header' => ['sometimes', 'required', 'array'], + 'header.hide' => ['array'], + 'header.hide.*' => ['string', Rule::in(Screen::HEADER_PARTS)], + 'header.title' => ['nullable', 'string', 'max:100'], + 'header.date' => ['boolean'], + 'header.seconds' => ['boolean'], + 'header.date_format' => ['string', Rule::in(Screen::DATE_FORMATS)], + 'header.date_pattern' => ['nullable', 'required_if:header.date_format,custom', 'string', 'max:60', function (string $attribute, mixed $value, Closure $fail): void { + $problem = is_string($value) ? Screen::datePatternProblem($value) : null; + + if ($problem !== null) { + $fail($problem === '' ? __('ui/screens.validation.date_empty') : __('ui/screens.validation.date_token', ['token' => $problem])); + } + }], + 'header.locale' => ['nullable', 'string', 'regex:'.Screen::LOCALE_PATTERN], + 'header.size' => ['string', Rule::in(Screen::HEADER_SIZES)], 'light_from' => ['sometimes', 'required', ...$time], 'light_to' => ['sometimes', 'required', ...$time], // Empty: the viewer's own time zone. 'timezone' => ['sometimes', 'nullable', 'timezone:all_with_bc', 'not_in:Factory'], 'scope' => ['sometimes', 'required', 'array'], 'scope.projects' => ['present_with:scope', 'array'], - 'scope.projects.*' => ['string', Rule::in($screen->team->projects()->pluck('uuid')->all())], + // NO_PROJECT: what is left when its last project moved to another team. + 'scope.projects.*' => ['string', Rule::in([...$screen->team->projects()->pluck('uuid')->all(), WidgetScope::NO_PROJECT])], 'scope.environment' => ['nullable', 'string', 'max:64'], 'scope.period' => ['required_with:scope', Rule::enum(Period::class)], ]; @@ -76,7 +98,7 @@ public static function settingsFrom(array $input): array { $settings = array_intersect_key($input, array_flip(['name', 'light_from', 'light_to', 'timezone', 'clock_format'])); - foreach (['theme' => ScreenTheme::class, 'aspect' => ScreenAspect::class, 'orientation' => ScreenOrientation::class, 'fit' => ScreenFit::class] as $key => $enum) { + foreach (['theme' => ScreenTheme::class, 'aspect' => ScreenAspect::class, 'orientation' => ScreenOrientation::class, 'fit' => ScreenFit::class, 'margin' => ScreenSpacing::class, 'gap' => ScreenSpacing::class] as $key => $enum) { if (array_key_exists($key, $input)) { $settings[$key] = $enum::from((string) $input[$key]); } @@ -88,6 +110,10 @@ public static function settingsFrom(array $input): array } } + if (array_key_exists('header', $input)) { + $settings['header'] = Screen::header((array) $input['header']); + } + if (array_key_exists('scope', $input)) { $environment = $input['scope']['environment'] ?? null; $settings['scope'] = [ diff --git a/app/Domains/Screens/Models/Screen.php b/app/Domains/Screens/Models/Screen.php index 4f5cf453..295a331d 100644 --- a/app/Domains/Screens/Models/Screen.php +++ b/app/Domains/Screens/Models/Screen.php @@ -8,6 +8,7 @@ use App\Domains\Screens\Enums\ScreenAspect; use App\Domains\Screens\Enums\ScreenFit; use App\Domains\Screens\Enums\ScreenOrientation; +use App\Domains\Screens\Enums\ScreenSpacing; use App\Domains\Screens\Enums\ScreenTheme; use App\Domains\Teams\Models\Team; use Carbon\CarbonImmutable; @@ -39,6 +40,9 @@ * @property bool $show_header whether the TV shows the name, scope, live state and clock above the grid * @property bool $show_clock whether that header shows the clock * @property string $clock_format '24' or '12' hours + * @property array|null $header what the header shows; see header() + * @property ScreenSpacing $margin the room around the grid + * @property ScreenSpacing $gap the room between widgets * @property ScreenTheme $theme * @property string $light_from HH:MM * @property string $light_to HH:MM @@ -52,7 +56,7 @@ * @property CarbonImmutable|null $created_at * @property CarbonImmutable|null $updated_at */ -#[Fillable(['team_id', 'name', 'cols', 'rows', 'aspect', 'orientation', 'fit', 'show_header', 'show_clock', 'clock_format', 'theme', 'light_from', 'light_to', 'timezone', 'scope', 'widgets', 'share_key', 'share_key_hash', 'share_titles'])] +#[Fillable(['team_id', 'name', 'cols', 'rows', 'aspect', 'orientation', 'fit', 'margin', 'gap', 'show_header', 'show_clock', 'clock_format', 'header', 'theme', 'light_from', 'light_to', 'timezone', 'scope', 'widgets', 'share_key', 'share_key_hash', 'share_titles'])] #[Hidden(['share_key', 'share_key_hash'])] #[UseEloquentBuilder(ScreenBuilder::class)] #[UseFactory(ScreenFactory::class)] @@ -62,8 +66,40 @@ class Screen extends Model use HasFactory; use HasUuids; + /** Parts of the header a screen can hide; being offline always shows. */ + public const array HEADER_PARTS = ['logo', 'name', 'team', 'projects', 'environment', 'period', 'attention', 'live']; + + /** How the header's clock writes the date: a format the browser words, or custom (date_pattern). */ + public const array DATE_FORMATS = ['short', 'long', 'medium', 'numeric', 'iso', 'custom']; + + /** + * A custom date's pieces: [text] as it is, a token, other letters (not a token, so + * refused) or anything else as it is. The tokens as frame.tsx's kioskDate() writes them. + */ + public const string DATE_TOKENS = '/\[[^\]]*\]|YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D|[A-Za-z]+|[^A-Za-z\[]+|\[/'; + + /** + * What is wrong with a custom date pattern, as frame.tsx's datePatternProblem(): the + * first piece outside [brackets] that is no token, '' when it has no token, else null. + */ + public static function datePatternProblem(string $pattern): ?string + { + preg_match_all(self::DATE_TOKENS, $pattern, $matches); + $pieces = collect($matches[0]); + $token = fn (string $piece): bool => preg_match('/^(YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D)$/', $piece) === 1; + + return $pieces->first(fn (string $piece): bool => ! $token($piece) && preg_match('/^\[.*\]$/', $piece) !== 1 && preg_match('/[A-Za-z\[]/', $piece) === 1) + ?? ($pieces->contains($token) ? null : ''); + } + + /** How large the header is drawn, medium as before. */ + public const array HEADER_SIZES = ['s', 'm', 'l', 'xl']; + + /** The header's language: browser, or a language tag such as da or en-GB; null is the app's. */ + public const string LOCALE_PATTERN = '/^(browser|[a-z]{2,3}(-[A-Z]{2})?)$/'; + /** What a version of a screen holds; not its identity or share link. */ - public const array DESIGN = ['name', 'cols', 'rows', 'aspect', 'orientation', 'fit', 'show_header', 'show_clock', 'clock_format', 'theme', 'light_from', 'light_to', 'timezone', 'scope', 'widgets']; + public const array DESIGN = ['name', 'cols', 'rows', 'aspect', 'orientation', 'fit', 'margin', 'gap', 'show_header', 'show_clock', 'clock_format', 'header', 'theme', 'light_from', 'light_to', 'timezone', 'scope', 'widgets']; public const int MIN_COLS = 2; @@ -94,17 +130,47 @@ public function getRouteKeyName(): string return 'uuid'; } + /** + * What the header shows, whole: the parts hidden, a title instead of the name, whether + * the clock has the date and seconds, how it writes the date and in which language, + * and how large it is. Stored or given, with anything else + * dropped; nothing stored is everything, as before it could be chosen. + * + * @param array|null $given + * @return array{hide: list, title: string|null, date: bool, seconds: bool, date_format: string, date_pattern: string|null, locale: string|null, size: string} + */ + public static function header(?array $given): array + { + $title = trim((string) ($given['title'] ?? '')); + $pattern = trim((string) ($given['date_pattern'] ?? '')); + $locale = (string) ($given['locale'] ?? ''); + + return [ + 'hide' => array_values(array_unique(array_intersect(array_filter((array) ($given['hide'] ?? []), is_string(...)), self::HEADER_PARTS))), + 'title' => $title !== '' ? $title : null, + 'date' => (bool) ($given['date'] ?? false), + 'seconds' => (bool) ($given['seconds'] ?? false), + 'date_format' => in_array($given['date_format'] ?? null, self::DATE_FORMATS, true) ? $given['date_format'] : 'short', + 'date_pattern' => $pattern !== '' ? $pattern : null, + 'locale' => preg_match(self::LOCALE_PATTERN, $locale) === 1 ? $locale : null, + 'size' => in_array($given['size'] ?? null, self::HEADER_SIZES, true) ? $given['size'] : 'm', + ]; + } + protected function casts(): array { return [ 'aspect' => ScreenAspect::class, 'orientation' => ScreenOrientation::class, 'fit' => ScreenFit::class, + 'margin' => ScreenSpacing::class, + 'gap' => ScreenSpacing::class, 'show_header' => 'boolean', 'show_clock' => 'boolean', 'theme' => ScreenTheme::class, 'cols' => 'integer', 'rows' => 'integer', + 'header' => 'array', 'scope' => 'array', 'widgets' => 'array', 'share_key' => 'encrypted', diff --git a/app/Domains/Screens/Presenters/ScreenPresenter.php b/app/Domains/Screens/Presenters/ScreenPresenter.php index 56b93be9..9021f1bf 100644 --- a/app/Domains/Screens/Presenters/ScreenPresenter.php +++ b/app/Domains/Screens/Presenters/ScreenPresenter.php @@ -50,9 +50,12 @@ public function present(Screen $screen): array 'aspect' => $screen->aspect->value, 'orientation' => $screen->orientation->value, 'fit' => $screen->fit->value, + 'margin' => $screen->margin->value, + 'gap' => $screen->gap->value, 'show_header' => $screen->show_header, 'show_clock' => $screen->show_clock, 'clock_format' => $screen->clock_format, + 'header' => Screen::header($screen->header), 'theme' => $screen->theme->value, 'light_from' => $screen->light_from, 'light_to' => $screen->light_to, diff --git a/app/Domains/Screens/Support/ScreenLayout.php b/app/Domains/Screens/Support/ScreenLayout.php index cd7ee989..c31d253d 100644 --- a/app/Domains/Screens/Support/ScreenLayout.php +++ b/app/Domains/Screens/Support/ScreenLayout.php @@ -69,34 +69,70 @@ public static function positioned(array $widgets, int $cols, int $rows): array } /** - * Indexes of widgets that cover a cell an earlier widget already covers. + * Indexes of widgets that cover a cell an earlier widget already covers, besides a + * widget lying wholly inside a group. * * @param list> $widgets positioned * @return list */ public static function overlapping(array $widgets): array { - $taken = []; + $kept = []; $overlapping = []; foreach ($widgets as $i => $widget) { - $x = (int) $widget['x']; - $y = (int) $widget['y']; - $w = max(1, (int) $widget['w']); - $h = max(1, (int) $widget['h']); - - if (! self::free($taken, $x, $y, $w, $h)) { + if (collect($kept)->contains(fn (array $other): bool => self::clash($widget, $other))) { $overlapping[] = $i; continue; } - self::take($taken, $x, $y, $w, $h); + $kept[] = $widget; } return $overlapping; } + /** + * Whether a group holds a widget, a group too: one wholly inside it, on fewer cells (a + * 1 x 1 group holds nothing). The group draws one card behind the widgets it holds. + * + * @param array $group positioned + * @param array $widget positioned + */ + public static function holds(array $group, array $widget): bool + { + [$g, $w] = [self::box($group), self::box($widget)]; + + return ($group['type'] ?? null) === 'group' && $w !== $g + && $w['x'] >= $g['x'] && $w['y'] >= $g['y'] + && $w['x'] + $w['w'] <= $g['x'] + $g['w'] && $w['y'] + $w['h'] <= $g['y'] + $g['h']; + } + + /** + * Whether two widgets cover a common cell, unless one is a group holding the other. + * + * @param array $a + * @param array $b + */ + private static function clash(array $a, array $b): bool + { + [$p, $q] = [self::box($a), self::box($b)]; + $apart = $p['x'] >= $q['x'] + $q['w'] || $q['x'] >= $p['x'] + $p['w'] + || $p['y'] >= $q['y'] + $q['h'] || $q['y'] >= $p['y'] + $p['h']; + + return ! $apart && ! self::holds($a, $b) && ! self::holds($b, $a); + } + + /** + * @param array $widget positioned + * @return array{x: int, y: int, w: int, h: int} + */ + private static function box(array $widget): array + { + return ['x' => (int) $widget['x'], 'y' => (int) $widget['y'], 'w' => max(1, (int) $widget['w']), 'h' => max(1, (int) $widget['h'])]; + } + /** @param array $widget */ private static function hasPosition(array $widget): bool { diff --git a/app/Domains/Screens/Support/ScreenQr.php b/app/Domains/Screens/Support/ScreenQr.php index e8516b56..299dd5e0 100644 --- a/app/Domains/Screens/Support/ScreenQr.php +++ b/app/Domains/Screens/Support/ScreenQr.php @@ -7,6 +7,7 @@ use ExeQue\Qr\Builders\Rendered; use ExeQue\Qr\Facades\Qr; use ExeQue\Qr\Rendering\ScanSafety; +use ExeQue\Qr\Validation\StyleRule; /** * The QR codes Lumberjack draws, in the `lumberjack` style of config/qr.php: amber on @@ -50,10 +51,43 @@ public static function widgetSvg(array $options): ?string default => $value('url') === '' ? null : Qr::url($value('url')), }; - // Transparent, so the tile shows through. Amber has too little contrast for the - // guard on white, so that one guard is off; the rest still apply. The mark has - // no plate. - return $qr?->style('lumberjack')->background(null)->scanSafety(new ScanSafety(minContrast: null, inverted: null))->logo(file: resource_path('images/qr-mark.svg'), size: self::LOGO_SIZE, shape: 'circle')->svg()->contents(); + if ($qr === null) { + return null; + } + + // Transparent unless a background is picked, so the tile shows through. Without + // one there is nothing to measure the colors against, so the contrast guard is + // off; a code lighter than its ground is fine on a dark screen. The rest apply. + $background = $value('qr_background') ?: null; + $qr = $qr->style(StyleRule::toStyle(self::style($options), base: 'lumberjack')) + ->background($background) + ->scanSafety(new ScanSafety(minContrast: $background === null ? null : 3.0, inverted: null)); + + // The mark has no plate. + return (($options['qr_logo'] ?? true) ? $qr->logo(file: resource_path('images/qr-mark.svg'), size: self::LOGO_SIZE, shape: 'circle') : $qr) + ->svg() + ->contents(); + } + + /** + * A QR code widget's style options (WidgetSchema's qr_style section) as the library's + * style input, over the `lumberjack` style: the same modules and eyes when none are picked. + * + * @param array $options + * @return array + */ + private static function style(array $options): array + { + $paint = $options['qr_color'] ?? null; + $eyes = ($options['qr_eyes'] ?? 'mix') === 'custom' + ? ['outer' => ['shape' => $options['qr_outer'] ?? 'rounded'], 'inner' => ['shape' => $options['qr_inner'] ?? 'soft']] + : ['preset' => $options['qr_eyes'] ?? 'mix']; + + return array_filter([ + 'modules' => array_filter(['shape' => $options['qr_module'] ?? 'rounded', 'paint' => $paint]), + 'eyes' => array_filter([...$eyes, 'paint' => $paint]), + 'filters' => array_map(fn (string $name): array => ['name' => $name], (array) ($options['qr_filters'] ?? [])), + ]); } /** diff --git a/app/Domains/Screens/Support/WidgetSchema.php b/app/Domains/Screens/Support/WidgetSchema.php index dbb31097..477e7150 100644 --- a/app/Domains/Screens/Support/WidgetSchema.php +++ b/app/Domains/Screens/Support/WidgetSchema.php @@ -5,13 +5,19 @@ namespace App\Domains\Screens\Support; use App\Domains\Screens\Actions\ResolveWidgetDataAction; +use App\Domains\Screens\Data\WidgetScope; use App\Domains\Screens\Enums\ReleaseScope; use App\Domains\Screens\Enums\WidgetType; use App\Domains\Screens\Models\Screen; use App\Domains\Shared\Enums\Period; use Closure; use DateTimeZone; +use ExeQue\Qr\Exceptions\ScanSafetyException; +use ExeQue\Qr\Facades\Qr; +use ExeQue\Qr\Qr as QrManager; use Illuminate\Validation\Rule; +use ReflectionClass; +use Throwable; /** * The shape of a status screen widget and the options each type takes: one schema that @@ -47,7 +53,7 @@ final class WidgetSchema ]; /** Widgets drawn by the client alone, without a source. */ - public const array LAYOUT_TYPES = ['clock', 'countdown', 'message', 'qr', 'media', 'empty']; + public const array LAYOUT_TYPES = ['clock', 'countdown', 'message', 'qr', 'media', 'empty', 'group']; /** Types that can rotate through several sources on one tile. */ public const array ROTATING_TYPES = ['stat', 'gauge', 'chart', 'list', 'health']; @@ -57,6 +63,12 @@ final class WidgetSchema public const int MAX_WIDGETS = 48; + /** Filters of the QR library that need options of their own (colors, shapes, regions), so none here. */ + private const array QR_FILTERS_WITH_OPTIONS = ['mixed-shape', 'palette', 'gradient-fill', 'by-role', 'region', 'eye-palette', 'compound']; + + /** Filters on one QR code, at most. */ + public const int MAX_QR_FILTERS = 3; + /** Addresses one media widget shows in turn. */ public const int MAX_SLIDES = 20; @@ -208,6 +220,8 @@ public static function rules(string $prefix, mixed $widget, int $cols, int $rows { $type = is_array($widget) && is_string($widget['type'] ?? null) ? $widget['type'] : ''; $data = WidgetType::tryFrom($type); + // A scope left with no project when one moved to another team keeps NO_PROJECT; it saves as it is. + $projects = [...$projects, WidgetScope::NO_PROJECT]; $source = fn (string $attribute, mixed $value, Closure $fail) => $data !== null && is_string($value) && WidgetSources::has($data, $value) ? null : $fail(__('ui/screens.validation.source')); @@ -287,6 +301,8 @@ public static function rules(string $prefix, mixed $widget, int $cols, int $rows }], // A local date and time, as an gives it. 'datetime' => ['nullable', 'date_format:Y-m-d\TH:i'], + 'color' => ['nullable', 'string', 'regex:/^#[0-9a-fA-F]{6}$/'], + 'choices' => ['nullable', 'array', 'max:'.($field['max'] ?? count($field['options']))], 'textarea' => ['nullable', 'string', 'max:500'], default => ['nullable', 'string', 'max:200'], }; @@ -294,6 +310,23 @@ public static function rules(string $prefix, mixed $widget, int $cols, int $rows if ($field['type'] === 'checks') { $rules["{$attribute}.*"] = ['string', 'uuid']; } + + if ($field['type'] === 'choices') { + $rules["{$attribute}.*"] = ['string', Rule::in($field['options'])]; + } + } + + // A QR code's colors and filters must still scan: drawn once as the TV will, on a link. + if ($type === 'qr') { + $rules["{$prefix}.options"][] = function (string $attribute, mixed $value, Closure $fail): void { + try { + ScreenQr::widgetSvg([...(array) $value, 'content' => 'link', 'url' => 'https://lumberjack.example/a/link/of/some/length']); + } catch (ScanSafetyException) { + $fail(__('ui/screens.validation.qr_unscannable')); + } catch (Throwable) { + // A name it does not know: the field's own rule says so. + } + }; } return $rules; @@ -395,7 +428,7 @@ private static function cleanOptions(array $fields, array $given): array $options[$key] = match ($field['type']) { 'toggle' => (bool) $value, 'number' => (float) $value, - 'checks' => array_values(array_unique(array_map('strval', (array) $value))), + 'checks', 'choices' => array_values(array_unique(array_map('strval', (array) $value))), default => (string) $value, }; } @@ -403,6 +436,39 @@ private static function cleanOptions(array $fields, array $given): array return $options; } + /** + * A pick of the QR library's parts (modules, eyes, filters): every one it has, each with + * the icon it ships and its label. With custom, the eyes can also be picked part by part. + * + * @return array + */ + private static function qrPicker(string $key, string $kind, ?string $default, bool $custom = false): array + { + $manifest = Qr::manifest(); + $names = array_values(array_diff(array_map(strval(...), array_keys($manifest[$kind])), $kind === 'filters' ? self::QR_FILTERS_WITH_OPTIONS : [])); + $folder = dirname((string) (new ReflectionClass(QrManager::class))->getFileName(), 2).'/resources/icons/'.match ($kind) { + 'outerEyes' => 'outer-eyes', + 'innerEyes' => 'inner-eyes', + default => $kind, + }; + $icons = collect($names) + ->mapWithKeys(fn (string $name): array => [$name => @file_get_contents("{$folder}/{$name}.svg") ?: null]) + ->filter() + ->all(); + $labels = collect($names)->mapWithKeys(fn (string $name): array => [$name => $manifest['labels'][$manifest['locales'][0]][$kind][$name] ?? $name])->all(); + + return [ + 'key' => $key, + 'type' => 'select', + 'options' => $custom ? [...$names, 'custom'] : $names, + 'icons' => $icons, + 'labels' => $custom ? [...$labels, 'custom' => __('ui/screens.fields.'.$key.'.custom')] : $labels, + 'default' => $default, + 'data' => true, + 'span' => 2, + ]; + } + /** * @param list> $fields * @return array{id: string, fields: list>} @@ -606,6 +672,20 @@ private static function build(): array ]), $text('caption', 2), ]), + // The QR library's style, a section each: closed, the grids are long. + $section('qr_look', [ + $toggle('qr_logo', true, true), + // Unset: the brand amber, no background; swatch is what the color picker opens on. + ['key' => 'qr_color', 'type' => 'color', 'default' => null, 'swatch' => config('qr.colors.amber'), 'data' => true, 'span' => 1], + ['key' => 'qr_background', 'type' => 'color', 'default' => null, 'swatch' => '#ffffff', 'data' => true, 'span' => 1], + ]), + $section('qr_modules', [self::qrPicker('qr_module', 'modules', 'rounded')]), + $section('qr_eyes', [ + self::qrPicker('qr_eyes', 'eyes', 'mix', custom: true), + [...self::qrPicker('qr_outer', 'outerEyes', 'rounded'), 'when' => ['qr_eyes' => ['custom']]], + [...self::qrPicker('qr_inner', 'innerEyes', 'soft'), 'when' => ['qr_eyes' => ['custom']]], + ]), + $section('qr_filters', [[...self::qrPicker('qr_filters', 'filters', null), 'type' => 'choices', 'max' => self::MAX_QR_FILTERS]]), $display(false), ], 'media' => [ @@ -622,6 +702,14 @@ private static function build(): array $display(false), ], 'empty' => [], + // One card behind the widgets wholly inside it (ScreenLayout::holds()), its title off at first. + 'group' => [ + $section('display', [ + $toggle('show_title', false), + $select('title_size', ['s', 'm', 'l', 'xl'], 'm'), + $select('align', ['left', 'center'], 'left'), + ]), + ], ]; } } diff --git a/database/factories/ScreenFactory.php b/database/factories/ScreenFactory.php index 84d4dec9..2cfc0a3c 100644 --- a/database/factories/ScreenFactory.php +++ b/database/factories/ScreenFactory.php @@ -9,6 +9,7 @@ use App\Domains\Screens\Enums\ScreenAspect; use App\Domains\Screens\Enums\ScreenFit; use App\Domains\Screens\Enums\ScreenOrientation; +use App\Domains\Screens\Enums\ScreenSpacing; use App\Domains\Screens\Enums\ScreenTheme; use App\Domains\Screens\Models\Screen; use App\Domains\Teams\Models\Team; @@ -29,6 +30,8 @@ public function definition(): array 'aspect' => ScreenAspect::Wide, 'orientation' => ScreenOrientation::Landscape, 'fit' => ScreenFit::Keep, + 'margin' => ScreenSpacing::Medium, + 'gap' => ScreenSpacing::Medium, 'show_header' => true, 'show_clock' => true, 'clock_format' => '24', diff --git a/database/migrations/2026_11_18_100000_add_margin_and_gap_to_screens_table.php b/database/migrations/2026_11_18_100000_add_margin_and_gap_to_screens_table.php new file mode 100644 index 00000000..ac826e89 --- /dev/null +++ b/database/migrations/2026_11_18_100000_add_margin_and_gap_to_screens_table.php @@ -0,0 +1,27 @@ +string('margin', 4)->default('m')->after('fit'); + $table->string('gap', 4)->default('m')->after('margin'); + }); + } + + public function down(): void + { + Schema::table('screens', function (Blueprint $table): void { + $table->dropColumn(['margin', 'gap']); + }); + } +}; diff --git a/database/migrations/2026_11_18_110000_add_header_to_screens_table.php b/database/migrations/2026_11_18_110000_add_header_to_screens_table.php new file mode 100644 index 00000000..9b8d1972 --- /dev/null +++ b/database/migrations/2026_11_18_110000_add_header_to_screens_table.php @@ -0,0 +1,27 @@ +json('header')->nullable()->after('clock_format'); + }); + } + + public function down(): void + { + Schema::table('screens', function (Blueprint $table): void { + $table->dropColumn('header'); + }); + } +}; diff --git a/docs/mcp.md b/docs/mcp.md index c0674ed4..f371a5f3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -301,29 +301,29 @@ For `weekly_summary`, `settings` is `{day, time}`: `day` 1 to 7 (1 is Monday) an ### Screens -| Tool | Needs | Does | Arguments | -| ------------------------- | ----------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `list_screens` | `screens: read` | Screens in the team. | none | -| `get_screen` | `screens: read` | Layout and widgets. | **`screen`** | -| `list_widget_types` | `screens: read` | Widgets and their options. | `type` | -| `get_screen_data` | `screens: read` | Widget data as shown. | **`screen`**, `widget` | -| `list_screen_versions` | `screens: read` | Saved versions. | **`screen`** | -| `preview_screen` | `screens: read` | Signed preview link. | **`screen`** | -| `get_screen_design_guide` | `screens: read` | Design guide for agents. | none | -| `create_screen` | `screens: write` | New screen. | **`name`**, `template` | -| `update_screen` | `screens: write` | Name, theme, settings. | **`screen`**, **`revision`**, `name`, `theme`, `aspect`, `orientation`, `fit`, `show_header`, `show_clock`, `clock_format`, `light_from`, `light_to`, `timezone`, `scope` | -| `update_screen_layout` | `screens: write` | Grid layout. | **`screen`**, **`revision`**, **`cols`**, **`rows`**, **`widgets`** | -| `update_screen_widget` | `screens: write` | One widget. | **`screen`**, **`revision`**, **`id`**, **`widget`** | -| `restore_screen_version` | `screens: write` | Restore a version. | **`screen`**, **`revision`**, **`version`** | -| `export_screen` | `screens: read` | Screen as a file. | **`screen`** | -| `list_displays` | `screens: read` | Paired displays. | none | -| `list_screen_viewers` | `screens: read` | Who has it open. | **`screen`** | -| `duplicate_screen` | `screens: write` | Copy a screen. | **`screen`** | -| `reload_screen` | `screens: write` | Reload its TVs. | **`screen`** | -| `import_screen` | `screens: manage` | Screen from a file. | **`json`** | -| `assign_display` | `screens: manage` | What a display shows. | **`display`**, **`screen`** | -| `set_screen_share` | `screens: manage` | Public share link. Can make data public. | **`screen`**, **`enabled`**, `include_titles` | -| `delete_screen` | `screens: manage` | Delete a screen. Deletes. | **`screen`** | +| Tool | Needs | Does | Arguments | +| ------------------------- | ----------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `list_screens` | `screens: read` | Screens in the team. | none | +| `get_screen` | `screens: read` | Layout and widgets. | **`screen`** | +| `list_widget_types` | `screens: read` | Widgets and their options. | `type` | +| `get_screen_data` | `screens: read` | Widget data as shown. | **`screen`**, `widget` | +| `list_screen_versions` | `screens: read` | Saved versions. | **`screen`** | +| `preview_screen` | `screens: read` | Signed preview link. | **`screen`** | +| `get_screen_design_guide` | `screens: read` | Design guide for agents. | none | +| `create_screen` | `screens: write` | New screen. | **`name`**, `template` | +| `update_screen` | `screens: write` | Name, theme, settings. | **`screen`**, **`revision`**, `name`, `theme`, `aspect`, `orientation`, `fit`, `margin`, `gap`, `show_header`, `show_clock`, `clock_format`, `header`, `light_from`, `light_to`, `timezone`, `scope` | +| `update_screen_layout` | `screens: write` | Grid layout. | **`screen`**, **`revision`**, **`cols`**, **`rows`**, **`widgets`** | +| `update_screen_widget` | `screens: write` | One widget. | **`screen`**, **`revision`**, **`id`**, **`widget`** | +| `restore_screen_version` | `screens: write` | Restore a version. | **`screen`**, **`revision`**, **`version`** | +| `export_screen` | `screens: read` | Screen as a file. | **`screen`** | +| `list_displays` | `screens: read` | Paired displays. | none | +| `list_screen_viewers` | `screens: read` | Who has it open. | **`screen`** | +| `duplicate_screen` | `screens: write` | Copy a screen. | **`screen`** | +| `reload_screen` | `screens: write` | Reload its TVs. | **`screen`** | +| `import_screen` | `screens: manage` | Screen from a file. | **`json`** | +| `assign_display` | `screens: manage` | What a display shows. | **`display`**, **`screen`** | +| `set_screen_share` | `screens: manage` | Public share link. Can make data public. | **`screen`**, **`enabled`**, `include_titles` | +| `delete_screen` | `screens: manage` | Delete a screen. Deletes. | **`screen`** | ### Project settings diff --git a/docs/projects.md b/docs/projects.md index 64093783..d7ed6ce5 100644 --- a/docs/projects.md +++ b/docs/projects.md @@ -277,6 +277,22 @@ or through MCP. Lumberjack warns 14 days before the token expires. +## Moving a project to another team + +**Move to another team** in the **Danger zone** moves the project with its data, tokens and +connections to a team you are owner or admin of; you must be owner or admin of its team +too. A slug or issue prefix the other team already has is replaced in the dialog. The move +also: + +- moves the project's own alert rules and channels, and drops links to the old team's; + the project then follows the new team's rules and channels; +- takes the project out of MCP tokens: give a token access again where it should have it; +- takes it out of the old team's screens; a screen or widget left with no project shows + nothing; +- clears assignees and watchers of its issues who are not in the new team. + +Each move is in the [audit log](./administration). + ## Deleting a project The **Danger zone** deletes the project and all its data, after you type the project's diff --git a/docs/screens.md b/docs/screens.md index c800e085..9bb377df 100644 --- a/docs/screens.md +++ b/docs/screens.md @@ -78,16 +78,17 @@ every kiosk, paired TV and share link that shows the screen reload its page. size swaps them. - **Resize**: drag any edge or corner. A widget only grows into free cells. - **Remove**: select the widget and press Delete. +- **Group**: add a [Group](./widgets#group) and drop widgets on it. The group draws one + card behind the widgets wholly inside it; drag it by the space between them to move it + with all it holds. ![Dragging a widget onto a free cell](./screenshots/screen-designer-drop.png) ### The grid -A screen is a grid of 2 to 12 columns and 2 to 12 rows. A widget's size in cells is its -size on the TV. +A screen is a grid of 2 to 12 columns and 2 to 12 rows, set in the toolbar. A widget's +size in cells is its size on the TV. -- **Aspect** is the shape of the display: 16:9 (the default), 16:10, 4:3, 21:9 or 32:9, - landscape or portrait. - **Preview at** shows the screen at a given resolution: **Fit** (the default), the size each TV showing the screen reports, common resolutions for the aspect, or **Custom**. It is a setting of your browser, not of the screen. @@ -97,22 +98,38 @@ not show on the TV until you place them again or remove them. ### Screen settings -Click the grid's background, press Escape, or use **Screen settings** in the toolbar: - -- **Name**. -- **Projects**, environment and period: what every widget shows unless it picks its own. - No project ticked means every project of the team, new ones included. Ticked projects - are also a limit: a widget can then only pick among them, its health checks, data - sources and filter names come from them alone, and **All of the screen's projects** - replaces **All in the team**. A widget that pointed at another project before shows - nothing until it is set again. A share link names only the screen's projects. -- **Time zone**: for the clock and the theme schedule. Empty means each TV uses its own. -- **Show header**, and **Show the clock in the header** in 24 or 12 hours. The header - shows the screen's name, projects and period, how many widgets need attention, whether - it is live, and the time. -- The [theme](#theme). -- **On a different screen**: on a display of another shape, **Keep its shape** (the - default) centers the screen with bars around it, and **Fill the display** stretches it. +Click the grid's background, press Escape, or use **Screen settings** in the toolbar. The +**Name** is at the top, the rest in four tabs: + +- **Display**: + - **On a different screen**: on a display of another shape, **Keep its shape** (the + default) centers the screen with bars around it, and **Fill the display** stretches it. + - **Aspect**, the shape of the display: 16:9 (the default), 16:10, 4:3, 21:9, 43:18 or + 32:9, and **Orientation**, landscape or portrait. +- **Look**: + - The [theme](#theme). + - **Margin**, the room around the grid, and **Spacing**, the room between widgets: + **None**, **Small**, **Medium** (the default) or **Large**. With no spacing, tiles + have square corners and neighbours share one border. +- **Data**: **All projects**, or the projects picked, the environment and the period: what + every widget shows unless it picks its own. **All projects** takes in new ones too. + Picked projects are also a limit: a widget can then only pick among them, its health + checks, data sources and filter names come from them alone, and **All of the screen's + projects** replaces **All in the team**. A widget that pointed at another project before + shows nothing until it is set again. A share link names only the screen's projects. +- **Header**: + - **Show header**, its **Header size** (small, medium, large or huge), and a + **Title** of its own instead of the screen's name. + - **Shows**: the logo, the title, the team, the projects, the environment, the period, + how many widgets need attention, and whether it is live. Each can be turned off; when + a TV is offline, that always shows. With nothing under the title, the title is as + large as the clock. + - **Show the clock in the header**, in 24 or 12 hours, with **Seconds** and the + **Date**. The date takes a format (such as Tue 18 Nov, 18.11.2026 or 2026-11-18) or + **Own format** from tokens: `YYYY` or `YY` year, `MMMM`, `MMM`, `MM` or `M` month, + `dddd` or `ddd` weekday, `DD` or `D` day, other text in `[brackets]`. **Language of + the date**: the app's, the TV's own, or one picked. + - **Time zone**: for the clock and the theme schedule. Empty means each TV uses its own. ### Incident mode diff --git a/docs/widgets.md b/docs/widgets.md index 6c7ae1ad..f43ac553 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -7,8 +7,8 @@ screen's grid. The designer's palette has two groups: something Lumberjack measured. Each picks what it shows under **Shows** and uses the screen's projects, environment and period unless it sets its own. When the screen has projects ticked, a widget's own projects are among them. -- **Layout** widgets (Clock and text, Countdown, Message, QR code, Image, video or page) - show their own settings. They have no source, scope or period. +- **Layout** widgets (Clock and text, Countdown, Message, QR code, Image, video or page, + Group) show their own settings. They have no source, scope or period. The screenshots on this page come from the **Widget gallery** screen. Run `php artisan db:seed --class=ShowcaseWidgetsSeeder` to add it to the Local Team of a @@ -57,7 +57,8 @@ The default, and **Align** center with **Vertically** in the middle. - **Green border while all is ok** (data widgets). - **Show card**: when off, the tile has no background or border while all is well. They - come back when it is degraded, down or recovering. + come back when it is degraded, down or recovering. A widget in a [group](#group) has no + card of its own; the group draws one. ![A health check with the default green border](./screenshots/widget-display-ok.png) ![The same check without the green border](./screenshots/widget-display-no-ok-border.png) ![The same check without a card](./screenshots/widget-display-no-card.png) @@ -524,6 +525,18 @@ A link, a wifi network or any text as a QR code. - **Text**. - **Line under the code**: such as "Guest wifi". +Its style is in four sections, each with **Reset** back to Lumberjack's own: + +- **Logo and colors**: **Lumberjack logo in the middle**, the **Code color** (amber by + default) and a **Background** (none by default, so the tile shows through). +- **Modules**: the shape of the code's dots, such as squares, dots, hearts or flowing. +- **Eyes**: the three corner squares, as one of the sets, or **Outer and inner apart**. +- **Filters**: up to 3, such as mixed rotation, jitter or a wave, applied in the order + picked. + +A style phones could not read reliably, such as colors too close together or filters too +strong, is refused when saved. + Share links show the code too, wifi password included. ## Image, video or page @@ -551,6 +564,14 @@ take turns as a slideshow. The address must be http or https, reachable from the TV, and https when Lumberjack runs on https. Pages that forbid framing stay blank. +## Group + +One card behind other widgets, so they read as one. A widget belongs to a group while it +lies wholly inside it, on fewer cells than the group; it keeps its place on the grid and +draws no card of its own. Groups nest. Drag a group by the space between its widgets to +move it with all it holds; it cannot be made smaller than its widgets. Its title is off +by default. + ## Empty cell Older screens may have an **Empty cell** widget. It still works but is no longer offered, diff --git a/lang/en/projects.php b/lang/en/projects.php index 6c88fe17..e9dbaacd 100644 --- a/lang/en/projects.php +++ b/lang/en/projects.php @@ -5,6 +5,7 @@ return [ 'created' => 'Project created. Copy the server token now; it is shown once.', 'deleted' => 'Project deleted. Its data is removed in the background.', + 'moved' => 'Project moved to :team.', 'issue_prefix_invalid' => 'Use 2 to 8 capital letters and digits, starting with a letter.', 'saved' => 'Settings saved.', 'server_token' => 'Server token', diff --git a/lang/en/ui/admin.php b/lang/en/ui/admin.php index 79b82849..d112bbf3 100644 --- a/lang/en/ui/admin.php +++ b/lang/en/ui/admin.php @@ -134,7 +134,7 @@ 'subject' => 'Subject', 'details' => 'Details', 'empty' => 'Nothing yet', - 'empty_body' => 'Every administrator action is recorded here: teams created, opened or deleted, users invited, suspended or reinstated, administration granted or revoked, password resets, and changes to public stats, shared status screens and paired TVs.', + 'empty_body' => 'Every administrator action is recorded here: teams created, opened or deleted, users invited, suspended or reinstated, administration granted or revoked, password resets, and changes to public stats, shared status screens and paired TVs, and projects moved between teams.', 'actions' => [ 'team_created' => 'Created team', 'team_deleted' => 'Deleted team', @@ -156,6 +156,7 @@ 'screen_unshared' => 'Stopped sharing a status screen', 'display_paired' => 'Paired a TV', 'display_removed' => 'Removed a TV', + 'project_moved' => 'Moved a project to another team', ], ], 'retention' => [ diff --git a/lang/en/ui/screens.php b/lang/en/ui/screens.php index 7f533cc4..b28b0aae 100644 --- a/lang/en/ui/screens.php +++ b/lang/en/ui/screens.php @@ -149,6 +149,7 @@ 'qr' => 'QR code', 'media' => 'Image, video or page', 'empty' => 'Empty cell', + 'group' => 'Group', ], // What each type is for, under its name in the palette. @@ -166,6 +167,7 @@ 'qr' => 'A link, the guest wifi or any text to scan', 'media' => 'A picture or camera, a video, YouTube or a web page', 'empty' => 'Blank space; not shown on the TV', + 'group' => 'One card behind the widgets you put on it', ], 'palette' => [ @@ -242,6 +244,8 @@ 'external' => 'External', ], 'inspector' => [ + 'card_in_group' => 'The group it lies in draws the card.', + 'reset' => 'Reset', 'label' => 'Settings', 'period' => 'Over', 'period_screen' => 'Screen default', @@ -291,6 +295,7 @@ 'no_checks' => 'The team has no health checks yet.', 'checks_hint' => 'None picked: every check of the projects, new ones included. One picked: that check alone, with its uptime and timeline.', 'empty_hint' => 'Keeps this space empty on the TV. Resize it to make a gap of any size.', + 'group_hint' => 'Drop widgets on it to show them as one card. Drag it between them to move it with all it holds.', ], // The display a screen is designed for: its shape, then which way it stands. @@ -317,13 +322,55 @@ 'hint' => 'What every widget shows unless it picks its own. Click a widget to change it.', 'name' => 'Name', 'projects' => 'Projects', - 'projects_hint' => 'None ticked: every project of the team, new ones included.', + 'all_projects' => 'All projects', + 'projects_hint' => 'All projects takes in new ones too; picked projects stay as they are.', 'timezone' => 'Time zone', 'timezone_hint' => 'For the clock and for switching between light and dark. Empty: each TV uses its own (the browser\'s) time zone.', 'browser_timezone' => 'The browser\'s time zone', 'show_clock' => 'Show the clock in the header', + 'header_title' => 'Title', + 'header_size' => 'Header size', + 'header_shows' => 'Shows', + 'header_shows_hint' => 'Offline always shows, so stale numbers never pass for live ones.', + 'header_parts' => [ + 'logo' => 'Logo', + 'name' => 'Title', + 'team' => 'Team', + 'projects' => 'Projects', + 'environment' => 'Environment', + 'period' => 'Period', + 'attention' => 'Problems', + 'live' => 'Live', + ], + 'clock_date' => 'Date', + 'clock_seconds' => 'Seconds', + 'date_format' => 'Date format', + 'date_custom' => 'Own format…', + 'date_pattern' => 'Own format', + 'date_pattern_hint' => 'YYYY year, MMMM, MMM, MM or M month, dddd or ddd weekday, DD or D day; other text in [brackets]. Now: :example', + 'locale' => 'Language of the date', + 'locale_app' => 'The app\'s language', + 'locale_browser' => 'The TV\'s own (browser)', + 'locale_automatic' => 'Automatic', + 'locale_languages' => 'Languages', 'fit' => 'On a different screen', 'fit_hint' => 'A display of another shape than the screen\'s shows it as designed, centered with bars around it, or stretched to fill it.', + 'margin' => 'Margin', + 'gap' => 'Spacing', + 'schedule_short' => 'Day and night', + 'sections' => [ + 'display' => 'Display', + 'appearance' => 'Look', + 'data' => 'Data', + 'time' => 'Header', + ], + ], + // How much room a screen leaves around its grid and between its widgets. + 'spacing' => [ + 'none' => 'None', + 's' => 'Small', + 'm' => 'Medium', + 'l' => 'Large', ], 'sections' => [ @@ -338,6 +385,10 @@ 'countdown' => 'Countdown', 'message' => 'Message', 'qr' => 'QR code', + 'qr_look' => 'Logo and colors', + 'qr_modules' => 'Modules', + 'qr_eyes' => 'Eyes', + 'qr_filters' => 'Filters', 'media' => 'Media', 'rotation' => 'Rotation', 'scope' => 'Scope', @@ -468,6 +519,14 @@ 'security' => ['label' => 'Security', 'options' => ['WPA' => 'WPA', 'WEP' => 'WEP', 'nopass' => 'None']], 'hidden_network' => ['label' => 'Hidden network'], 'qr_text' => ['label' => 'Text', 'placeholder' => 'Anything a phone should read'], + 'qr_logo' => ['label' => 'Lumberjack logo in the middle'], + 'qr_color' => ['label' => 'Code color', 'unset' => 'Amber', 'reset' => 'Back to amber'], + 'qr_background' => ['label' => 'Background', 'unset' => 'None', 'reset' => 'No background'], + 'qr_module' => ['label' => 'Modules'], + 'qr_eyes' => ['label' => 'Eyes', 'custom' => 'Outer and inner apart'], + 'qr_outer' => ['label' => 'Outer eye'], + 'qr_inner' => ['label' => 'Inner eye'], + 'qr_filters' => ['label' => 'Filters', 'hint' => 'Up to :max, applied in the order picked.'], 'caption' => ['label' => 'Line under the code', 'placeholders' => ['link' => 'Our status page', 'wifi' => 'Guest wifi', 'text' => 'Scan me', 'image' => 'The loading dock', 'video' => 'This week\'s release', 'page' => 'Grafana']], 'media' => ['label' => 'Shows', 'options' => ['image' => 'An image or camera', 'video' => 'A video', 'page' => 'A web page or YouTube']], 'media_url' => ['label' => 'Addresses', 'placeholder' => 'https://', 'hint' => 'Several show in turn, the same one on every TV at once.'], @@ -834,5 +893,8 @@ 'source' => 'This widget cannot show that.', 'duplicate_id' => 'Two widgets have the same id.', 'overlap' => 'This widget covers a cell another widget already uses.', + 'date_token' => '":token" is no part of a date; put text in [brackets].', + 'date_empty' => 'Put at least one part of the date in, such as D, MMM or YYYY.', + 'qr_unscannable' => 'Phones could not read this code reliably: pick colors further apart, or fewer or milder filters.', ], ]; diff --git a/lang/en/ui/settings.php b/lang/en/ui/settings.php index 4be849d5..940353b3 100644 --- a/lang/en/ui/settings.php +++ b/lang/en/ui/settings.php @@ -313,5 +313,20 @@ 'type_name' => 'Type :name to confirm', // Button 'confirm' => 'Delete project permanently', + 'move_title' => 'Move to another team', + 'move_description' => 'Moves the project with all its data, issues, keys and settings to another team you administer. Its SDKs keep sending as they do.', + 'move_no_teams' => 'You administer no other team to move it to.', + // Button + 'move' => 'Move to another team…', + 'move_dialog_title' => 'Move :name to another team', + 'move_consequences' => 'What ties the project to this team is let go:', + 'move_screens' => 'Status screens of this team stop showing it; a widget that showed only this project shows nothing.', + 'move_alerts' => 'Links to this team\'s alert rules and channels are removed; the project then follows the new team\'s. Its own rules and channels go with it.', + 'move_tokens' => 'MCP tokens lose access to it, here and in the new team, until they are given it.', + 'move_people' => 'Assignees and watchers who are not in the new team are cleared. History is kept.', + 'move_team' => 'Team', + 'move_suggested' => 'A number is added where the team has the slug or issue prefix already.', + // Button + 'move_confirm' => 'Move to :team', ], ]; diff --git a/resources/css/screen.css b/resources/css/screen.css index 1a666fa0..938e64a7 100644 --- a/resources/css/screen.css +++ b/resources/css/screen.css @@ -174,6 +174,30 @@ outline-offset: 2px; } +/* A group's title line, the room the widgets on its top row leave it (GROUP_TITLE_LINE). */ +.lj-tile[data-kind='group'] .lj-tile-title { + line-height: 1.2; +} + +/* + * No space between widgets: square corners, and each tile half a pixel over its + * neighbours, so two borders make one line. A tile with a problem lies on top, its + * color whole. + */ +.lj-grid[data-gap='none'] > .lj-tile { + margin: -0.5px; + border-radius: 0; +} + +.lj-grid[data-gap='none'] + > .lj-tile:is( + [data-status='degraded'], + [data-status='down'], + [data-status='recovering'] + ) { + z-index: 1; +} + /* Kiosk: an empty cell is a gap, not a tile. */ .lj-kiosk .lj-tile[data-kind='empty'] { border-color: transparent; diff --git a/resources/js/components/lj/screen/frame.tsx b/resources/js/components/lj/screen/frame.tsx index d277d0ca..57c16798 100644 --- a/resources/js/components/lj/screen/frame.tsx +++ b/resources/js/components/lj/screen/frame.tsx @@ -3,7 +3,7 @@ import type { ComponentProps, ReactNode, Ref } from 'react'; import { LogMark } from '@/components/lj/logo'; import { useT } from '@/lib/i18n'; import { cn } from '@/lib/utils'; -import type { Screen } from './types'; +import type { HeaderPart, Screen } from './types'; type Size = { w: number; h: number }; @@ -80,6 +80,12 @@ function useWindowSize(): Size { return size; } +/** How large each header size draws it, medium as before. */ +const HEADER_ZOOM: Record = { s: 0.8, m: 1, l: 1.3, xl: 1.65 }; + +/** How much of the medium margin and gap each spacing is. */ +const SPACING: Record = { none: 0, s: 0.5, m: 1, l: 1.6 }; + /** * A screen as the TV shows it, header and grid, laid out at a display's size: the * kiosk's whole window, or the designer's preview of a resolution. Everything inside @@ -122,6 +128,7 @@ export function KioskFrame({ const turned = kiosk && !view && rotation !== 0; const size = view ?? windowSize; const box = fitBox(size, ratioOf(screen), screen.fit); + const margin = SPACING[screen.margin] ?? 1; return (
{screen.show_header && ( -
+
- -
-

- {header.title} -

- - {header.subtitle} + {!screen.header.hide.includes('logo') && ( + + )} +
+ {!screen.header.hide.includes('name') && ( +

+ {header.title} +

+ )} + {header.subtitle && ( + + {header.subtitle} + + )}
@@ -184,7 +211,7 @@ export function KioskFrame({ (screen.show_header ? ( banner ) : ( -
+
{banner}
))} @@ -193,13 +220,15 @@ export function KioskFrame({
screen.scope.projects.includes(p.uuid)) .map((p) => p.name) : [t('screens.kiosk.all_projects')]; + const parts: [HeaderPart, string][] = [ + ['team', team], + ['projects', names.join(', ')], + [ + 'environment', + screen.scope.environment ?? t('screens.kiosk.all_environments'), + ], + ['period', t(`screens.periods.${screen.scope.period}`)], + ]; - return [ - team, - names.join(', '), - screen.scope.environment ?? t('screens.kiosk.all_environments'), - t(`screens.periods.${screen.scope.period}`), - ].join(' · '); + return parts + .filter(([part]) => !screen.header.hide.includes(part)) + .map(([, text]) => text) + .join(' · '); +} + +/** The language the header writes in: the screen's, the TV's (browser), else the app's. */ +export function kioskLocale(screen: Screen): string { + return screen.header.locale === 'browser' + ? navigator.language + : (screen.header.locale ?? (document.documentElement.lang || 'en')); } /** A time as the screen's clock shows it, in the screen's time zone (else the browser's). */ export function kioskClock(screen: Screen, at: number): string { - return new Intl.DateTimeFormat(document.documentElement.lang || 'en', { + return new Intl.DateTimeFormat(kioskLocale(screen), { timeZone: screen.timezone ?? undefined, hour: '2-digit', minute: '2-digit', + second: screen.header.seconds ? '2-digit' : undefined, hourCycle: screen.clock_format === '12' ? 'h12' : 'h23', }).format(new Date(at)); } +/** The formats the browser words, by Screen::DATE_FORMATS. */ +const DATE_OPTIONS: Record = { + short: { weekday: 'short', day: 'numeric', month: 'short' }, + long: { weekday: 'long', day: 'numeric', month: 'long' }, + medium: { day: 'numeric', month: 'short', year: 'numeric' }, + numeric: { day: '2-digit', month: '2-digit', year: 'numeric' }, +}; + +/** + * A custom date's pieces, as Screen::DATE_TOKENS reads them: [text] as it is, a token, + * other letters (no token: refused) or anything else as it is. + */ +const DATE_PIECES = + /\[[^\]]*\]|YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D|[A-Za-z]+|[^A-Za-z[]+|\[/g; +const DATE_TOKEN = /^(YYYY|YY|MMMM|MMM|MM|M|dddd|ddd|DD|D)$/; + +/** A custom pattern's first piece that is no token, '' when it has no token, else null. */ +export function datePatternProblem(pattern: string): string | null { + const pieces = pattern.match(DATE_PIECES) ?? []; + const unknown = pieces.find( + (p) => + !DATE_TOKEN.test(p) && !/^\[.*\]$/.test(p) && /[A-Za-z[]/.test(p), + ); + + return unknown ?? (pieces.some((p) => DATE_TOKEN.test(p)) ? null : ''); +} + +/** The date by the header's clock, as the screen writes it; null without one. */ +export function kioskDate(screen: Screen, at: number): string | null { + const { date, date_format: format, date_pattern: pattern } = screen.header; + + if (!date) { + return null; + } + + const locale = kioskLocale(screen); + const timeZone = screen.timezone ?? undefined; + const part = (options: Intl.DateTimeFormatOptions, type: string) => + new Intl.DateTimeFormat(locale, { timeZone, ...options }) + .formatToParts(new Date(at)) + .find((p) => p.type === type)?.value ?? ''; + const tokens: Record string> = { + YYYY: () => part({ year: 'numeric' }, 'year'), + YY: () => part({ year: '2-digit' }, 'year'), + MMMM: () => part({ month: 'long' }, 'month'), + MMM: () => part({ month: 'short' }, 'month'), + MM: () => part({ month: '2-digit' }, 'month'), + M: () => part({ month: 'numeric' }, 'month'), + dddd: () => part({ weekday: 'long' }, 'weekday'), + ddd: () => part({ weekday: 'short' }, 'weekday'), + DD: () => part({ day: '2-digit' }, 'day'), + D: () => part({ day: 'numeric' }, 'day'), + }; + + if (format === 'iso') { + return `${tokens.YYYY()}-${tokens.MM()}-${tokens.DD()}`; + } + + if (format === 'custom') { + return pattern && datePatternProblem(pattern) === null + ? (pattern.match(DATE_PIECES) ?? []) + .map((p) => tokens[p]?.() ?? p.replace(/^\[(.*)\]$/, '$1')) + .join('') + : null; + } + + return new Intl.DateTimeFormat(locale, { + timeZone, + ...(DATE_OPTIONS[format] ?? DATE_OPTIONS.short), + }).format(new Date(at)); +} + /** * Room for a screen in the designer: at a previewed size, scaled down to the width it has * and the window's height less the toolbar (never up), the outside taking the scaled @@ -312,7 +433,13 @@ export function KioskStatus({ attention, offline, clock, + date = null, + hide = [], }: { + /** The date by the clock, as the screen writes it; null without one. */ + date?: string | null; + /** Parts the screen's header hides; being offline always shows. */ + hide?: HeaderPart[]; attention: number; /** "Offline since 12:03", or null while live. */ offline: string | null; @@ -323,19 +450,23 @@ export function KioskStatus({ return ( <> - {attention > 0 && offline === null && ( - - {t('screens.kiosk.attention', {}, attention)} - - )} + {attention > 0 && + offline === null && + !hide.includes('attention') && ( + + {t('screens.kiosk.attention', {}, attention)} + + )} {offline === null ? ( - - + !hide.includes('live') && ( + + + ) ) : ( )} + {clock !== null && date !== null && ( + + {date} + + )} {clock !== null && ( {clock} diff --git a/resources/js/components/lj/screen/inspector.tsx b/resources/js/components/lj/screen/inspector.tsx index f9ee427f..07efb79e 100644 --- a/resources/js/components/lj/screen/inspector.tsx +++ b/resources/js/components/lj/screen/inspector.tsx @@ -7,7 +7,25 @@ const CONNECTED_SHAPES: Record = { }; import { TreeSelect } from '@/components/lj/tree-select'; -import { Plus, Settings, X } from 'lucide-react'; +import type { TreeOption } from '@/components/lj/tree-select'; +import { + AlignCenter, + AlignLeft, + AlignVerticalJustifyCenter, + AlignVerticalJustifyStart, + Expand, + Moon, + Plus, + RectangleHorizontal, + RectangleVertical, + Scaling, + Shrink, + SlidersHorizontal, + Sun, + SunMoon, + Settings, + X, +} from 'lucide-react'; import { useEffect, useRef, useState, useSyncExternalStore } from 'react'; import type { ReactNode } from 'react'; import { @@ -27,13 +45,22 @@ import type { RotateItem, Schema, SchemaField, + DateFormat, Screen, + ScreenSpacing, Source, Sources, Widget, WidgetScope, } from './types'; -import { MAX_SLIDES, MAX_ZONES, ROTATING_KINDS } from './types'; +import { datePatternProblem, kioskDate } from './frame'; +import { + DATE_FORMATS, + HEADER_PARTS, + MAX_SLIDES, + MAX_ZONES, + ROTATING_KINDS, +} from './types'; export type Catalog = { schema: Schema; @@ -75,6 +102,10 @@ export type Catalog = { filters?: Record; /** What some filter names are shown as, by name. */ filterLabels?: Record; + /** Widgets a group holds: the group draws their card. */ + grouped?: string[]; + /** The shapes a screen can have, such as 16:9 (ScreenAspect). */ + aspects?: string[]; }; const ALL = '*'; @@ -87,6 +118,216 @@ const chip = (on: boolean) => : 'border-line-strong bg-rail text-ink-2 hover:text-ink', ); +/** A letter as large as each text size draws, relative to the others. */ +const SIZE_GLYPHS: Record = Object.fromEntries( + Object.entries({ s: 11, m: 14, l: 17, xl: 20 }).map(([size, px]) => [ + size, + + A + , + ]), +); + +/** Options picked from icons that show what each does, with the icon per value. */ +const CHOICE_ICONS: Record> = { + align: { left: , center: }, + valign: { + top: , + middle: , + }, + text_size: { auto: , ...SIZE_GLYPHS }, + title_size: SIZE_GLYPHS, +}; + +/** Room around the grid or between widgets, per ScreenSpacing, in the icons' units. */ +const SPACING_ROOM: Record = { + none: 0, + s: 1.5, + m: 3, + l: 4.5, +}; + +/** + * A screen's margin or gap as a picture: a widget inset that far in the screen, or two + * widgets that far apart (square and on one line at none, as the screen draws them). + */ +function SpacingIcon({ + kind, + value, +}: { + kind: 'margin' | 'gap'; + value: ScreenSpacing; +}) { + const room = SPACING_ROOM[value]; + const w = (14 - room) / 2; + + return ( + + ); +} + +/** A screen's shape as a picture: a frame of its width over its height. */ +function AspectIcon({ ratio }: { ratio: number }) { + const w = ratio >= 1 ? 14 : 14 * ratio; + const h = ratio >= 1 ? 14 / ratio : 14; + + return ( + + ); +} + +/** + * Values as icons, each over its name, the picked ones lit: a row of a few, or a grid of + * many (the QR library's parts). Several values make it a pick of several. + */ +function IconChoice({ + label, + value, + options, + onChange, + grid = false, +}: { + label: string; + value: string | string[]; + options: { value: string; label: string; icon: ReactNode }[]; + onChange: (value: string) => void; + grid?: boolean; +}) { + const many = Array.isArray(value); + const on = (v: string) => (many ? value.includes(v) : v === value); + const box = useRef(null); + + // A scrolling grid shows what is picked, the first time it shows (its section opened). + useEffect(() => { + const el = box.current; + + if (!el) { + return; + } + + const seen = new ResizeObserver(() => { + if (el.clientHeight === 0) { + return; + } + + seen.disconnect(); + const first = el.querySelector( + '[aria-checked="true"], [aria-pressed="true"]', + ); + + if (first) { + el.scrollTop = + first.getBoundingClientRect().top - + el.getBoundingClientRect().top - + 4; + } + }); + seen.observe(el); + + return () => seen.disconnect(); + }, []); + + return ( +
+ {options.map((o) => ( + + ))} +
+ ); +} + function Section({ title, open, @@ -501,6 +742,137 @@ export function WidgetInspector({ ); } + // The QR library's parts come with pictures of their own, as SVG it ships. + const pictures = field.icons + ? Object.fromEntries( + Object.entries(field.icons).map(([v, svg]) => [ + v, + , + ]), + ) + : undefined; + const icons = CHOICE_ICONS[field.key] ?? pictures; + // A field's name, with a way back to the default once it is changed. + const labelWithReset = (key: string, changed: boolean) => ( + + {fieldLabel(key)} + {changed && ( + + )} + + ); + const optionLabel = (v: string) => + field.labels?.[v] ?? t(`screens.fields.${field.key}.options.${v}`); + + if (field.type === 'color') { + const color = typeof raw === 'string' ? raw : null; + + return ( +
+ +
+ + target.set(field.key, e.target.value) + } + className="h-8 w-10 shrink-0 cursor-pointer rounded border border-line-strong bg-rail p-0.5" + /> + {color ? ( + + ) : ( + + {t(`screens.fields.${field.key}.unset`)} + + )} +
+
+ ); + } + + if (field.type === 'choices' && icons) { + const picked = Array.isArray(raw) ? raw : []; + const max = field.max ?? Infinity; + + return ( +
+ {labelWithReset(field.key, picked.length > 0)} + ({ + value: v, + label: optionLabel(v), + icon: icons[v], + }))} + onChange={(v) => { + const next = picked.includes(v) + ? picked.filter((p) => p !== v) + : [...picked, v].slice(-max); + + target.set( + field.key, + next.length > 0 ? next : null, + ); + }} + /> + + {t(`screens.fields.${field.key}.hint`, { max })} + +
+ ); + } + + if (icons && field.type === 'select' && !scope && !inherited) { + return ( +
+ {labelWithReset( + field.key, + raw !== undefined && raw !== null, + )} + 5} + label={fieldLabel(field.key)} + value={String(raw ?? field.default)} + options={(field.options ?? []).map((v) => ({ + value: v, + label: optionLabel(v), + icon: icons[v] ?? , + }))} + onChange={(v) => + target.set( + field.key, + v === field.default ? null : v, + ) + } + /> +
+ ); + } + // An External JSON value's paths are set in a dialog, summed up here. // A connected source's answer has no history to compare with or to draw. if (connected && ['compare', 'sparkline'].includes(field.key)) { @@ -642,6 +1014,10 @@ export function WidgetInspector({ source?.low_is_bad ?? false) : option(schema, widget, field.key) === true; + // In a group the group's card is the one drawn: none of its own to show. + const lockedOff = + field.key === 'card' && + (catalog.grouped ?? []).includes(widget.id); return ( ); } @@ -1335,9 +1720,9 @@ export function WidgetInspector({ const value = ( <> - {widget.type === 'empty' && ( + {(widget.type === 'empty' || widget.type === 'group') && (

- {t('screens.inspector.empty_hint')} + {t(`screens.inspector.${widget.type}_hint`)}

)} @@ -1768,6 +2153,98 @@ export function WidgetInspector({ } /** Settings of the whole screen, shown while no widget is selected. */ +/** + * Languages a screen's header can write the date in, besides the app's and the TV's: a + * language alone, or by country where they write dates differently. + */ +const LOCALES = [ + 'da', + 'sv', + 'nb', + 'fi', + 'is', + 'en-GB', + 'en-US', + 'en-AU', + 'de-DE', + 'de-AT', + 'de-CH', + 'fr-FR', + 'fr-BE', + 'fr-CA', + 'nl-NL', + 'nl-BE', + 'es-ES', + 'es-MX', + 'pt-PT', + 'pt-BR', + 'it', + 'pl', + 'cs', + 'et', + 'lv', + 'lt', + 'ja', + 'zh-CN', +]; + +/** A language's or country's name, in the page's language. */ +function displayName(code: string, type: 'language' | 'region'): string { + try { + return ( + new Intl.DisplayNames([document.documentElement.lang || 'en'], { + type, + }).of(code) ?? code + ); + } catch { + return code; + } +} + +/** + * The languages for a tree: the app's and the TV's own under Automatic (app stands for + * none), then every language, those with countries by country under its name. + */ +function localeOptions( + automatic: string, + app: string, + browser: string, + languages: string, +): TreeOption[] { + const base = (code: string) => code.split('-')[0]; + + return [ + { value: 'app', label: app, path: [automatic] }, + { value: 'browser', label: browser, path: [automatic] }, + ...LOCALES.map((code) => { + const [language, region] = code.split('-'); + const countries = LOCALES.filter( + (c) => base(c) === language, + ).length; + + return countries > 1 && region + ? { + value: code, + label: displayName(region, 'region'), + path: [languages, displayName(language, 'language')], + keywords: code, + } + : { + value: code, + label: displayName(code, 'language'), + path: [languages], + keywords: code, + }; + }), + ]; +} + +const SETTINGS_TABS = ['display', 'appearance', 'data', 'time'] as const; +type SettingsTab = (typeof SETTINGS_TABS)[number]; + +/** The settings tab open last, kept while the designer is open: back from a widget, it is still there. */ +let lastSettingsTab: SettingsTab = 'display'; + export function ScreenSettings({ screen, catalog, @@ -1782,9 +2259,23 @@ export function ScreenSettings({ }) { const t = useT(); const scope = screen.scope; + const hint = 'col-span-2 text-xs text-ink-3'; + const [tab, setTab] = useState(lastSettingsTab); + const pickTab = (id: SettingsTab) => { + lastSettingsTab = id; + setTab(id); + }; + const setProjects = (projects: string[]) => + onChange({ scope: { ...scope, projects } }); + const patternProblem = + screen.header.date_format === 'custom' + ? datePatternProblem(screen.header.date_pattern ?? '') + : null; + const setHeader = (changes: Partial) => + onChange({ header: { ...screen.header, ...changes } }); return ( -
+

{t('screens.settings.title')} @@ -1804,227 +2295,700 @@ export function ScreenSettings({ onChange={(e) => onChange({ name: e.target.value })} />

-
- - {t('screens.settings.projects')} - - {catalog.teamProjects.map((p) => ( -
+ + {tab === 'display' && ( +
+
+ + {t('screens.settings.fit')} + + , + }, + { + value: 'fill', + label: t('screens.fit.fill'), + icon: , + }, + ]} + onChange={(v) => + onChange({ fit: v as Screen['fit'] }) + } + /> +
+ + {t('screens.settings.fit_hint')} + +
+ + {t('screens.designer.aspect')} + + { + const [w, h] = a.split(':').map(Number); + + return { + value: a, + label: t(`screens.aspect.${a}`), + icon: ( + + ), + }; + }, + )} + onChange={(v) => onChange({ aspect: v })} + /> +
+
+ + {t('screens.designer.orientation')} + + ({ + value: o, + label: t(`screens.orientation.${o}`), + icon: + o === 'landscape' ? ( + + ) : ( + + ), + }), + )} + onChange={(v) => onChange({ - scope: { - ...scope, - projects: e.target.checked - ? [...scope.projects, p.uuid] - : scope.projects.filter( - (u) => u !== p.uuid, - ), - }, + orientation: v as Screen['orientation'], }) } /> - {p.name} - - ))} - - {t('screens.settings.projects_hint')} - - -
-
- - +
-
- - + )} + + {tab === 'appearance' && ( +
+
+ + {t('screens.designer.theme')} + + , + }, + { + value: 'light', + label: t('screens.theme.light'), + icon: , + }, + { + value: 'schedule', + label: t('screens.settings.schedule_short'), + icon: , + }, + ]} + onChange={(v) => + onChange({ theme: v as Screen['theme'] }) + } + /> +
+ {screen.theme === 'schedule' && ( + <> + {(['light_from', 'light_to'] as const).map( + (key) => ( +
+ + + e.target.value && + onChange({ + [key]: e.target.value, + }) + } + /> +
+ ), + )} + + {t('screens.theme.schedule')} ·{' '} + {t('screens.designer.now_theme', { + theme: t(`screens.theme.${theme}`), + })} + + + )} + {(['margin', 'gap'] as const).map((key) => ( +
+ + {t(`screens.settings.${key}`)} + + ({ + value: s, + label: t(`screens.spacing.${s}`), + icon: ( + + ), + }), + )} + onChange={(v) => + onChange({ [key]: v as ScreenSpacing }) + } + /> +
+ ))}
-
-
- - onChange({ timezone: zone || null })} - /> - - {t('screens.settings.timezone_hint')} - -
- - {screen.show_header && ( - )} - {screen.show_header && screen.show_clock && ( -
- - + onChange({ + scope: { + ...scope, + environment: e.target.value || null, + }, + }) + } + > + - ))} - + {catalog.environments.map((env) => ( + + ))} + +
+
+ + +
)} -
- - - {screen.theme === 'schedule' && ( - <> -
-
+ + {screen.show_header && ( +
+ + {t('screens.settings.header_size')} + + ({ + value: size, + label: t( + `screens.fields.title_size.options.${size}`, + ), + icon: SIZE_GLYPHS[size], + }), + )} + onChange={(v) => + setHeader({ + size: v as Screen['header']['size'], + }) + } + /> +
+ )} + {screen.show_header && ( + <> +
- e.target.value && - onChange({ light_from: e.target.value }) + setHeader({ + title: e.target.value || null, + }) } />
-
- - - e.target.value && - onChange({ light_to: e.target.value }) +
+ + {t('screens.settings.header_shows')} + +
+ {HEADER_PARTS.map((part) => { + const on = + !screen.header.hide.includes(part); + const label = t( + `screens.settings.header_parts.${part}`, + ); + + return ( + + ); + })} +
+ + {t('screens.settings.header_shows_hint')} + +
+ + + )} + {screen.show_header && screen.show_clock && ( + <> +
+ + {t('screens.fields.format.label')} + + ({ + value: format, + label: t( + `screens.fields.format.options.${format}`, + ), + icon: ( + + {format} + + ), + }), + )} + onChange={(v) => + onChange({ + clock_format: v as '24' | '12', + }) } />
-
- - {t('screens.designer.now_theme', { - theme: t(`screens.theme.${theme}`), - })} - - - )} -
-
- - - - {t('screens.settings.fit_hint')} - -
+ {(['date', 'seconds'] as const).map((key) => ( + + ))} + {screen.header.date && ( + <> +
+ + +
+ {screen.header.date_format === 'custom' && ( +
+ + + setHeader({ + date_pattern: + e.target.value || + null, + }) + } + /> + + {patternProblem === null + ? t( + 'screens.settings.date_pattern_hint', + { + example: + kioskDate( + screen, + Date.now(), + ) ?? '', + }, + ) + : patternProblem === '' + ? t( + 'screens.validation.date_empty', + ) + : t( + 'screens.validation.date_token', + { + token: patternProblem, + }, + )} + +
+ )} +
+ + + setHeader({ + locale: + locale && + locale !== 'app' + ? locale + : null, + }) + } + placeholder={t( + 'screens.settings.locale_app', + )} + searchPlaceholder={t( + 'screens.picker.search', + )} + noMatches={t( + 'screens.picker.no_matches', + )} + /> +
+ + )} + + )} +
+ + + onChange({ timezone: zone || null }) + } + /> +
+ + {t('screens.settings.timezone_hint')} + +
+ )}
); } diff --git a/resources/js/components/lj/screen/lib.ts b/resources/js/components/lj/screen/lib.ts index f5c59018..23b6b85f 100644 --- a/resources/js/components/lj/screen/lib.ts +++ b/resources/js/components/lj/screen/lib.ts @@ -565,7 +565,7 @@ export function newWidgetId(): string { return 'w' + Math.random().toString(36).slice(2, 10); } -type Box = Pick; +type Box = Pick & { type?: WidgetKind }; /** Whether a widget lies inside the grid, so the TV shows it. */ export function fits(box: Box, cols: number, rows: number): boolean { @@ -577,7 +577,25 @@ export function fits(box: Box, cols: number, rows: number): boolean { ); } -/** Whether no widget but `except` covers a cell of the box, inside the grid or not. */ +/** + * Whether a group holds a widget, a group too: one wholly inside it, on fewer cells (a + * 1 x 1 group holds nothing). ScreenLayout::holds(). + */ +export function groupHolds(group: Box, box: Box): boolean { + return ( + group.type === 'group' && + (box.w < group.w || box.h < group.h) && + box.x >= group.x && + box.y >= group.y && + box.x + box.w <= group.x + group.w && + box.y + box.h <= group.y + group.h + ); +} + +/** + * Whether no widget but `except` covers a cell of the box, inside the grid or not; a + * group holding the box, or held by it, is no obstacle. + */ export function isFree(widgets: Widget[], box: Box, except?: string): boolean { return widgets.every( (o) => @@ -585,10 +603,48 @@ export function isFree(widgets: Widget[], box: Box, except?: string): boolean { o.x >= box.x + box.w || box.x >= o.x + o.w || o.y >= box.y + box.h || - box.y >= o.y + o.h, + box.y >= o.y + o.h || + groupHolds(o, box) || + groupHolds(box, o), ); } +/** + * Widgets in the order they are drawn: groups first, outer before inner, so each lies + * behind what it holds; the others keep their order. + */ +export function layered(widgets: Widget[]): Widget[] { + const order = (w: Widget) => (w.type === 'group' ? -w.w * w.h : 0); + + return [...widgets].sort((a, b) => order(a) - order(b)); +} + +/** + * A widget moved to a top left, a group with all it holds: the new top left of each, or + * null when one would leave the grid or land on another widget. + */ +export function moveTo( + widgets: Widget[], + cols: number, + rows: number, + widget: Widget, + to: { x: number; y: number }, +): Record | null { + const going = widgets.filter( + (o) => o.id === widget.id || groupHolds(widget, o), + ); + const rest = widgets.filter((o) => !going.includes(o)); + const moved = going.map((o) => ({ + ...o, + x: o.x + to.x - widget.x, + y: o.y + to.y - widget.y, + })); + + return moved.every((o) => canPlace(rest, cols, rows, o)) + ? Object.fromEntries(moved.map((o) => [o.id, { x: o.x, y: o.y }])) + : null; +} + /** Whether a widget can go there: inside the grid, on cells no other widget covers. */ export function canPlace( widgets: Widget[], @@ -685,9 +741,11 @@ export function swapTarget( moving: Widget, cell: { x: number; y: number }, ): string | null { + // A group under the pointer is where the widget goes, not one to trade places with. const other = widgets.find( (o) => o.id !== moving.id && + o.type !== 'group' && cell.x >= o.x && cell.x < o.x + o.w && cell.y >= o.y && diff --git a/resources/js/components/lj/screen/types.ts b/resources/js/components/lj/screen/types.ts index 5167648c..74afaf4d 100644 --- a/resources/js/components/lj/screen/types.ts +++ b/resources/js/components/lj/screen/types.ts @@ -40,7 +40,8 @@ export type WidgetKind = | 'message' | 'qr' | 'media' - | 'empty'; + | 'empty' + | 'group'; export type WidgetScope = { projects?: string[]; @@ -57,6 +58,33 @@ export type ScreenTheme = 'dark' | 'light' | 'schedule'; /** ScreenAspect: the display's shape, landscape; ScreenOrientation turns it on its side. */ export type ScreenOrientation = 'landscape' | 'portrait'; +/** None, small, medium (what screens had before it could be chosen) or large. */ +export type ScreenSpacing = 'none' | 's' | 'm' | 'l'; + +/** Parts of the header a screen can hide; being offline always shows. Screen::HEADER_PARTS. */ +export const HEADER_PARTS = [ + 'logo', + 'name', + 'team', + 'projects', + 'environment', + 'period', + 'attention', + 'live', +] as const; +export type HeaderPart = (typeof HEADER_PARTS)[number]; + +/** Screen::DATE_FORMATS. */ +export const DATE_FORMATS = [ + 'short', + 'long', + 'medium', + 'numeric', + 'iso', + 'custom', +] as const; +export type DateFormat = (typeof DATE_FORMATS)[number]; + export type Screen = { uuid: string; name: string; @@ -67,12 +95,32 @@ export type Screen = { orientation: ScreenOrientation; /** On a display of another shape: keep the screen's (bars around it) or fill it. */ fit: 'keep' | 'fill'; + /** Room around the grid; see ScreenSpacing. */ + margin: ScreenSpacing; + /** Room between widgets; see ScreenSpacing. */ + gap: ScreenSpacing; /** Whether the TV shows the name, scope, live state and clock above the grid. */ show_header: boolean; /** Whether that header shows the clock. */ show_clock: boolean; /** The header's clock: '24' or '12' hours. */ clock_format: '24' | '12'; + /** What the header shows; see Screen::header(). */ + header: { + hide: HeaderPart[]; + /** Instead of the screen's name; null: the name. */ + title: string | null; + /** The clock's date and seconds. */ + date: boolean; + seconds: boolean; + date_format: DateFormat; + /** Tokens for a custom date; see kioskDate(). */ + date_pattern: string | null; + /** Null: the app's language; browser: the TV's; else a tag such as da. */ + locale: string | null; + /** How large the header is drawn: s, m (as before), l or xl. */ + size: 's' | 'm' | 'l' | 'xl'; + }; theme: ScreenTheme; light_from: string; light_to: string; @@ -99,11 +147,21 @@ export type SchemaField = { | 'textarea' | 'number' | 'checks' + | 'color' + | 'choices' | 'data_source' | 'timezone' | 'projects' | 'environment'; options?: string[]; + /** An SVG picture per option (the QR library's parts), picked from a grid of them. */ + icons?: Record; + /** Each option's label, where it comes with the options (the QR library's). */ + labels?: Record; + /** Choices: how many may be picked. */ + max?: number; + /** A color field: what the picker opens on while unset. */ + swatch?: string; /** The options under headings: group id to its values. */ groups?: Record; default: string | boolean | null; @@ -167,6 +225,7 @@ export const LAYOUT_KINDS: WidgetKind[] = [ 'qr', 'media', 'empty', + 'group', ]; export const ROTATING_KINDS: WidgetKind[] = [ 'stat', diff --git a/resources/js/components/lj/screen/widgets.tsx b/resources/js/components/lj/screen/widgets.tsx index 05ea47cc..05d153d8 100644 --- a/resources/js/components/lj/screen/widgets.tsx +++ b/resources/js/components/lj/screen/widgets.tsx @@ -222,6 +222,9 @@ const TITLE_SIZE: Record = { xl: 'calc(var(--lj-cell-font) * 1.7)', }; +/** A group's title line, as tall as its font times this (screen.css). */ +const GROUP_TITLE_LINE = 1.2; + const TEXT_SCALE: Record = { auto: 1, s: 0.85, @@ -365,6 +368,8 @@ export type TileProps = { incident?: boolean; designer?: boolean; flash?: boolean; + /** The groups holding the tile, which draw its card: it has none of its own. */ + holders?: Widget[]; /** Extra content above the tile's own: the designer's badge and resize handle. */ decoration?: ReactNode; /** In the tile's top right corner, the period label moving aside: the designer's gear. */ @@ -373,6 +378,29 @@ export type TileProps = { onStatus?: (id: string, status: Status) => void; } & Omit, 'children'>; +/** + * How far down a widget on a group's top row starts: below the group's top padding and + * title line, for each group holding it whose title shows. + */ +function titleInset( + schema: Schema, + holders: Widget[], + widget: Widget, +): string | undefined { + const above = holders + .filter( + (g) => + g.y === widget.y && + option(schema, g, 'show_title') !== false, + ) + .map( + (g) => + `0.8 * var(--lj-cell-font) + ${TITLE_SIZE[option(schema, g, 'title_size') ?? 'm']} * ${GROUP_TITLE_LINE}`, + ); + + return above.length > 0 ? `calc(${above.join(' + ')})` : undefined; +} + /** * One tile of a screen, the same in the designer and on the TV. Its type draws the data * of the source it shows now; its state colors it. @@ -389,6 +417,7 @@ export function WidgetTile({ incident = false, designer = false, flash = false, + holders = [], decoration, corner, onStatus, @@ -472,7 +501,9 @@ export function WidgetTile({ single ?? source?.label ?? t(`screens.kinds.${widget.type}`)); - const showTitle = opt('show_title') !== false; + // An empty cell has no title. + const showTitle = + opt('show_title') !== false && widget.type !== 'empty'; useEffect(() => { onStatus?.(widget.id, status); @@ -530,7 +561,9 @@ export function WidgetTile({ let body: ReactNode = null; - if (widget.type === 'empty') { + if (widget.type === 'group') { + body = null; + } else if (widget.type === 'empty') { body = designer ? ( {t('screens.kinds.empty')} @@ -608,7 +641,11 @@ export function WidgetTile({ className={cn('lj-tile', className)} data-kind={widget.type} // No card: no background or border while calm; a problem still brings them. - data-plain={opt('card') === false || undefined} + data-plain={ + holders.length > 0 || + opt('card') === false || + undefined + } // Media to the tile's edges; its title and line keep their room. data-bare={ (widget.type === 'media' && @@ -625,6 +662,7 @@ export function WidgetTile({ style={{ gridColumn: `${widget.x + 1} / span ${widget.w}`, gridRow: `${widget.y + 1} / span ${widget.h}`, + marginTop: titleInset(schema, holders, stored), textAlign: align, ['--lj-text-scale' as string]: TEXT_SCALE[textSize] ?? 1, visibility: hidden && !designer ? 'hidden' : undefined, @@ -633,18 +671,14 @@ export function WidgetTile({ }} > {decoration} - {(corner || - (showTitle && - widget.type !== 'empty' && - title && - cornerText)) && ( + {(corner || (showTitle && title && cornerText)) && ( // The corner label, as far from the top as from the right edge, with the // designer's gear taking its place while it shows. - {showTitle && widget.type !== 'empty' && title && ( + {showTitle && title && ( )} - {showTitle && widget.type !== 'empty' && title && ( + {showTitle && title && ( // Invisible twins of the label keep room for it on the right, and on the // left too for a centered title, so that stays centered on the tile.
(targets[0]); + const [slug, setSlug] = useState(target?.slug ?? ''); + const [prefix, setPrefix] = useState(target?.issue_prefix ?? ''); + const pick = (next: MoveTarget | undefined) => { + setTarget(next); + setSlug(next?.slug ?? ''); + setPrefix(next?.issue_prefix ?? ''); + }; + + return ( +
+

+ {t('settings.danger.move_title')} +

+

+ {t('settings.danger.move_description')} +

+ {targets.length === 0 ? ( +

+ {t('settings.danger.move_no_teams')} +

+ ) : ( +
+ +
+ )} + + +
setOpen(false)} + className="flex flex-col gap-4" + > + {({ errors, processing }) => ( + <> + + + {t( + 'settings.danger.move_dialog_title', + { + name: project.name, + }, + )} + + + {t('settings.danger.move_consequences')} + + +
    +
  • {t('settings.danger.move_screens')}
  • +
  • {t('settings.danger.move_alerts')}
  • +
  • {t('settings.danger.move_tokens')}
  • +
  • {t('settings.danger.move_people')}
  • +
+ + + + + + setSlug(e.target.value) + } + required + maxLength={100} + spellCheck={false} + /> + + + + setPrefix( + e.target.value + .toUpperCase() + .replace(/[^A-Z0-9]/g, ''), + ) + } + required + minLength={2} + maxLength={8} + spellCheck={false} + /> + + + + + + + )} +
+
+
+
+ ); +} + +function DangerSection({ project, move_targets }: Props) { const t = useT(); const [confirming, setConfirming] = useState(false); const [typed, setTyped] = useState(''); @@ -2493,6 +2671,7 @@ function DangerSection({ project }: Props) { return (
+

{t('settings.danger.description')}

{!confirming ? (
diff --git a/resources/js/pages/screens/edit.tsx b/resources/js/pages/screens/edit.tsx index bc88de91..d8f27576 100644 --- a/resources/js/pages/screens/edit.tsx +++ b/resources/js/pages/screens/edit.tsx @@ -7,7 +7,6 @@ import type { MouseEvent as ReactMouseEvent, PointerEvent, } from 'react'; -import { RectangleHorizontal, RectangleVertical } from 'lucide-react'; import { toast } from 'sonner'; import { Relative, useNow } from '@/components/lj/relative'; import { @@ -15,7 +14,9 @@ import { KioskStatus, PreviewScale, kioskClock, + kioskDate, kioskSubtitle, + kioskTitle, } from '@/components/lj/screen/frame'; import { ScreenSettings, @@ -25,6 +26,9 @@ import { import type { Catalog } from '@/components/lj/screen/inspector'; import { canPlace, + groupHolds, + layered, + moveTo, swapGroup, swapTarget, firstFree, @@ -162,6 +166,7 @@ const STARTERS: Record = { qr: null, media: null, empty: null, + group: null, }; /** A transparent pixel, as the drag picture of a tile moved on the grid. */ @@ -256,9 +261,12 @@ type Settings = Pick< | 'aspect' | 'orientation' | 'fit' + | 'margin' + | 'gap' | 'show_header' | 'show_clock' | 'clock_format' + | 'header' | 'theme' | 'light_from' | 'light_to' @@ -315,9 +323,12 @@ const SETTINGS: (keyof Settings)[] = [ 'aspect', 'orientation', 'fit', + 'margin', + 'gap', 'show_header', 'show_clock', 'clock_format', + 'header', 'theme', 'light_from', 'light_to', @@ -461,7 +472,7 @@ export default function EditScreen(props: Props) { w: number; h: number; ok: boolean; - /** Dropping here moves these widgets to the dragged one's old cells. */ + /** Dropping here moves these widgets too: to the dragged one's old cells, or along with a group. */ swap?: Record; } | null>(null); const resizing = useRef<{ @@ -516,6 +527,10 @@ export default function EditScreen(props: Props) { periods: PERIODS, filters, filterLabels: props.filter_labels ?? {}, + aspects: props.aspects, + grouped: screen.widgets + .filter((w) => screen.widgets.some((g) => groupHolds(g, w))) + .map((w) => w.id), }; // The data follows what is saved, so a widget refetches once its new settings are stored. const { data } = useScreenData( @@ -652,11 +667,45 @@ export default function EditScreen(props: Props) { setSelected(widget.id); }; - /** Whether the widget may take that box; the screen's other widgets stay put. */ + /** + * Whether the widget may take that box; the screen's other widgets stay put. A group + * keeps all it holds, so it never gets smaller than its widgets. + */ const placeable = ( id: string | undefined, - box: { x: number; y: number; w: number; h: number }, - ) => canPlace(latest.current.widgets, screen.cols, screen.rows, box, id); + box: { x: number; y: number; w: number; h: number; type?: WidgetKind }, + ) => { + const widgets = latest.current.widgets; + const widget = widgets.find((w) => w.id === id); + const next = { type: widget?.type, ...box }; + + return ( + canPlace(widgets, screen.cols, screen.rows, next, id) && + (!widget || + widgets.every( + (o) => !groupHolds(widget, o) || groupHolds(next, o), + )) + ); + }; + + /** A widget moved, a group with all it holds, when they all fit there. */ + const move = (widget: Widget, to: { x: number; y: number }) => { + const moves = moveTo( + latest.current.widgets, + screen.cols, + screen.rows, + widget, + to, + ); + + if (moves) { + setWidgets((widgets) => + widgets.map((w) => + moves[w.id] ? { ...w, ...moves[w.id] } : w, + ), + ); + } + }; const remove = (id: string) => { setWidgets((widgets) => widgets.filter((w) => w.id !== id)); @@ -773,14 +822,18 @@ export default function EditScreen(props: Props) { const fromTop = widget.y > 0 && widget.y + widget.h >= screen.rows; const w = Math.max(1, widget.w + (fromLeft ? -dx : dx)); const h = Math.max(1, widget.h + (fromTop ? -dy : dy)); - const box = e.shiftKey - ? { - x: fromLeft ? widget.x + widget.w - w : widget.x, - y: fromTop ? widget.y + widget.h - h : widget.y, - w, - h, - } - : { x: widget.x + dx, y: widget.y + dy, w: widget.w, h: widget.h }; + if (!e.shiftKey) { + move(widget, { x: widget.x + dx, y: widget.y + dy }); + + return; + } + + const box = { + x: fromLeft ? widget.x + widget.w - w : widget.x, + y: fromTop ? widget.y + widget.h - h : widget.y, + w, + h, + }; if (placeable(widget.id, box)) { patch(widget.id, box); @@ -914,14 +967,31 @@ export default function EditScreen(props: Props) { const cell = cellAt(e.clientX, e.clientY); let box = { x: cell.x - d.dx, y: cell.y - d.dy, w: d.w, h: d.h }; - let ok = placeable(d.tile, box); - let swap: Record | undefined; const moving = d.tile ? latest.current.widgets.find((w) => w.id === d.tile) : undefined; + // A group takes all it holds along. + const moves = moving + ? moveTo( + latest.current.widgets, + screen.cols, + screen.rows, + moving, + box, + ) + : null; + let ok = moving + ? moves !== null + : placeable(undefined, { ...box, type: d.kind }); + let swap: Record | undefined = + moves && moving + ? Object.fromEntries( + Object.entries(moves).filter(([id]) => id !== moving.id), + ) + : undefined; // Onto other widgets: swap places when they fit, the footprint shows where it goes. - if (!ok && moving) { + if (!ok && moving && moving.type !== 'group') { // Whole widgets under the footprint trade places with it as a group. const group = swapGroup( latest.current.widgets, @@ -1031,10 +1101,10 @@ export default function EditScreen(props: Props) { const outside = screen.widgets.filter( (w) => !fits(w, screen.cols, screen.rows), ); - // Top left to bottom right, so Tab follows the screen. - const tiles = screen.widgets - .filter(inGrid) - .sort((a, b) => a.y - b.y || a.x - b.x); + // Top left to bottom right, so Tab follows the screen; groups behind what they hold. + const tiles = layered( + screen.widgets.filter(inGrid).sort((a, b) => a.y - b.y || a.x - b.x), + ); const current = screen.widgets.find((w) => w.id === selected) ?? null; const theme = themeAt(screen, now); const [aw, ah] = screen.aspect.split(':').map(Number); @@ -1141,6 +1211,9 @@ export default function EditScreen(props: Props) { clockFormat={screen.clock_format} pinned={widget.id === selected ? pinned : undefined} incident={incident} + holders={screen.widgets.filter((g) => + groupHolds(g, widget), + )} designer tabIndex={0} role="button" @@ -1820,73 +1893,6 @@ export default function EditScreen(props: Props) { ))} - -
- {(['landscape', 'portrait'] as const).map( - (o) => ( - - ), - )} -