Skip to content

Timezone switch on status page (#191) #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/lang/de/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'site_name_label' => 'Seitenname',
'about_this_site_label' => 'Über diese Seite',
'timezone_label' => 'Zeitzone',
'timezone_other' => 'Andere',
'incident_days_label' => 'Vorfalltage',
'major_outage_threshold_label' => 'Schwellenwert für schwere Ausfälle',
'refresh_rate_label' => 'Automatisch Seite neuladen',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de_AT/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'site_name_label' => 'Seitenname',
'about_this_site_label' => 'Über diese Seite',
'timezone_label' => 'Zeitzone',
'timezone_other' => 'Andere',
'incident_days_label' => 'Vorfalltage',
'major_outage_threshold_label' => 'Schwellenwert für schwere Ausfälle',
'refresh_rate_label' => 'Automatisch Seite neuladen',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de_CH/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'site_name_label' => 'Seitenname',
'about_this_site_label' => 'Über diese Seite',
'timezone_label' => 'Zeitzone',
'timezone_other' => 'Andere',
'incident_days_label' => 'Vorfalltage',
'major_outage_threshold_label' => 'Schwellenwert für schwere Ausfälle',
'refresh_rate_label' => 'Automatisch Seite neuladen',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'site_name_label' => 'Site Name',
'about_this_site_label' => 'About This Site',
'timezone_label' => 'Timezone',
'timezone_other' => 'Other',
'browser_default' => 'Browser Default',
'incident_days_label' => 'Incident Days',
'major_outage_threshold_label' => 'Major Outage Threshold',
'refresh_rate_label' => 'Automatically Refresh Page',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/nl/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'site_name_label' => 'Pagina naam',
'about_this_site_label' => 'Over deze site',
'timezone_label' => 'Tijdzone',
'timezone_other' => 'Overig',
'browser_default' => 'Gebruik browserstandaard',
'incident_days_label' => 'Incidentendagen',
'major_outage_threshold_label' => 'Drempel voor ernstige storingen',
'refresh_rate_label' => 'Pagina automatisch opnieuw laden',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/ph/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'site_name_label' => 'Pangalan ng Site',
'about_this_site_label' => 'Tungkol sa Site na Ito',
'timezone_label' => 'Oras na Rehiyon',
'timezone_other' => 'Iba pang mga oras',
'incident_days_label' => 'Mga Araw ng Insidente',
'major_outage_threshold_label' => 'Limitasyon ng Malaking Pagka-aberya',
'refresh_rate_label' => 'Awtomatikong I-refresh ang Pahina',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/pt_BR/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'site_name_label' => 'Nome do Site',
'about_this_site_label' => 'Sobre Este Site',
'timezone_label' => 'Fuso Horário',
'timezone_other' => 'Outro',
'incident_days_label' => 'Dias de Incidentes',
'major_outage_threshold_label' => 'Limite de Indisponibilidade Total',
'refresh_rate_label' => 'Atualizar Página Automaticamente',
Expand Down
18 changes: 13 additions & 5 deletions resources/views/components/footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
</div>
@endif
@if($showTimezone)
<div>
{!! preg_replace(
<div id="cachet-footer-timezone" data-timezone="{{ $timezone }}" data-label=""></div>
<script defer async>
document.addEventListener('DOMContentLoaded', function () {
const timeZoneLabel = '{!! preg_replace(
'/\*(.*?)\*/',
'<span class="font-semibold">$1</span>',
__('cachet::cachet.all_times_shown_in', ['timezone' => $timezone])
) !!}
</div>
__('cachet::cachet.all_times_shown_in', ['timezone' => ':timezone:'])
) !!}'
let footerTimeZone = document.getElementById('cachet-footer-timezone').dataset.timezone;
if (footerTimeZone === '-') {
footerTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
}
document.getElementById('cachet-footer-timezone').innerHTML = timeZoneLabel.replace(':timezone:', footerTimeZone);
});
</script>
@endif
</footer>
@endif
8 changes: 4 additions & 4 deletions resources/views/components/incident.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{{ \Cachet\Facades\CachetView::renderHook(\Cachet\View\RenderHook::STATUS_PAGE_INCIDENTS_BEFORE) }}
<div class="relative flex flex-col gap-5" x-data="{ forDate: new Date(@js($date)) }">
<h3 class="text-xl font-semibold"><time datetime="{{ $date }}" x-text="forDate.toLocaleDateString()"></time></h3>
<h3 class="text-xl font-semibold"><time datetime="{{ $date }}" x-text="forDate.toLocaleDateString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time></h3>
@forelse($incidents as $incident)
<div x-data="{ timestamp: new Date(@js($incident->timestamp)) }" class="bg-white border divide-y rounded-lg ml-9 dark:divide-zinc-700 dark:border-zinc-700 dark:bg-white/5">
<div @class([
Expand All @@ -32,7 +32,7 @@
@endauth
</div>
<span class="text-xs text-zinc-500 dark:text-zinc-400">
{{ $incident->timestamp->diffForHumans() }} — <time datetime="{{ $incident->timestamp->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
{{ $incident->timestamp->diffForHumans() }} — <time datetime="{{ $incident->timestamp->toW3cString() }}" x-text="timestamp.toLocaleString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time>
</span>
</div>
<div class="flex justify-start sm:justify-end">
Expand All @@ -53,7 +53,7 @@
<x-cachet::incident-update-status :status="$update->status" />
<h3 class="text-lg font-semibold">{{ $update->status->getLabel() }}</h3>
<span class="text-xs text-zinc-500 dark:text-zinc-400">
{{ $update->created_at->diffForHumans() }} — <time datetime="{{ $update->created_at->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
{{ $update->created_at->diffForHumans() }} — <time datetime="{{ $update->created_at->toW3cString() }}" x-text="timestamp.toLocaleString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time>
</span>
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-accent-content prose-a:underline prose-p:leading-normal">{!! $update->formattedMessage() !!}</div>
</div>
Expand All @@ -62,7 +62,7 @@
<x-cachet::incident-update-status :status="IncidentStatusEnum::unknown" />

<span class="text-xs text-zinc-500 dark:text-zinc-400">
{{ $incident->timestamp->diffForHumans() }} — <time datetime="{{ $incident->timestamp->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
{{ $incident->timestamp->diffForHumans() }} — <time datetime="{{ $incident->timestamp->toW3cString() }}" x-text="timestamp.toLocaleString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time>
</span>
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-accent-content prose-a:underline prose-p:leading-normal">{!! $incident->formattedMessage() !!}</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/schedule.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</h3>
</div>
<span class="text-xs text-zinc-500 dark:text-zinc-400">
{{ $schedule->scheduled_at->diffForHumans() }} — <time datetime="{{ $schedule->scheduled_at->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
{{ $schedule->scheduled_at->diffForHumans() }} — <time datetime="{{ $schedule->scheduled_at->toW3cString()}}" x-text="timestamp.toLocaleString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time>
</span>
</div>

Expand All @@ -30,7 +30,7 @@
@foreach ($schedule->updates as $update)
<div class="relative py-4" x-data="{ timestamp: new Date(@js($update->created_at)) }">
<span class="text-xs text-zinc-500 dark:text-zinc-400">
{{ $update->created_at->diffForHumans() }} — <time datetime="{{ $update->created_at->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
{{ $update->created_at->diffForHumans() }} — <time datetime="{{ $update->created_at->toW3cString() }}" x-text="timestamp.toLocaleString(@if($appSettings->timezone !== '-')undefined, {timeZone: '{{$appSettings->timezone}}'}@endif )"></time>
</span>
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-accent-content prose-a:underline prose-p:leading-normal">{!! $update->formattedMessage() !!}</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/CachetCoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private function registerPublishing(): void
*/
private function registerBladeComponents(): void
{
view()->share('appSettings', app(AppSettings::class));
Blade::componentNamespace('Cachet\\View\\Components', 'cachet');

$this->callAfterResolving(Factory::class, function (Factory $factory) {
Expand Down
18 changes: 9 additions & 9 deletions src/Filament/Pages/Settings/ManageCachet.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function form(Form $form): Form

Forms\Components\Select::make('timezone')
->label(__('cachet::settings.manage_cachet.timezone_label'))
->options(fn () => collect(timezone_identifiers_list())
->mapToGroups(
fn ($timezone) => [
Str::of($timezone)
->before('/')
->toString() => [$timezone => $timezone],
]
)
->map(fn ($group) => $group->collapse()))
->options(fn () => [__('cachet::settings.manage_cachet.timezone_other') => ['-' => __('cachet::settings.manage_cachet.browser_default')], ...collect(timezone_identifiers_list())
->mapToGroups(
fn($timezone) => [
Str::of($timezone)
->before('/')
->toString() => [$timezone => $timezone],
]
)
->map(fn($group) => $group->collapse())->toArray()])
->searchable()
->suffixIcon('heroicon-o-globe-alt'),

Expand Down
2 changes: 2 additions & 0 deletions src/Settings/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Cachet\Settings;

use Cachet\Enums\IncidentStatusEnum;
use Cachet\Enums\MetricTypeEnum;
use Spatie\LaravelSettings\Settings;

class AppSettings extends Settings
Expand Down