Add day of event to date dropdowns, move task notice

This commit is contained in:
Xu 2023-11-15 17:34:40 +01:00 committed by Igor Scheller
parent ecc3976c27
commit 44efd910c6
8 changed files with 26 additions and 22 deletions

View File

@ -224,9 +224,8 @@ function angeltype_controller_shiftsFilterDays(AngelType $angeltype)
$days = []; $days = [];
foreach ($all_shifts as $shift) { foreach ($all_shifts as $shift) {
$day = Carbon::make($shift['start'])->format('Y-m-d'); $day = Carbon::make($shift['start'])->format('Y-m-d');
$dayFormatted = Carbon::make($shift['start'])->format(__('Y-m-d'));
if (!isset($days[$day])) { if (!isset($days[$day])) {
$days[$day] = $dayFormatted; $days[$day] = dateWithEventDay($day);
} }
} }
ksort($days); ksort($days);

View File

@ -28,7 +28,7 @@ function location_controller(): array
foreach ($all_shifts as $shift) { foreach ($all_shifts as $shift) {
$day = $shift->start->format('Y-m-d'); $day = $shift->start->format('Y-m-d');
if (!isset($days[$day])) { if (!isset($days[$day])) {
$days[$day] = $shift->start->format(__('Y-m-d')); $days[$day] = dateWithEventDay($day);
} }
} }

View File

@ -3,6 +3,8 @@
declare(strict_types=1); declare(strict_types=1);
use Engelsystem\Renderer\Twig\Extensions\Globals; use Engelsystem\Renderer\Twig\Extensions\Globals;
use Engelsystem\Helpers\Carbon;
use Engelsystem\Helpers\DayOfEvent;
function theme_id(): int function theme_id(): int
{ {
@ -25,3 +27,16 @@ function theme_type(): string
{ {
return theme()['type']; return theme()['type'];
} }
function dateWithEventDay(string $day): string
{
$date = Carbon::createFromFormat('Y-m-d', $day);
$dayOfEvent = DayOfEvent::get($date);
$dateFormatted = $date->format(__('Y-m-d'));
if (!config('enable_show_day_of_event') || is_null($dayOfEvent)) {
return $dateFormatted;
}
return $dateFormatted . ' (' . $dayOfEvent . ')';
}

View File

@ -286,7 +286,7 @@ function view_user_shifts()
} }
$formattedDays = collect($days)->map(function ($value) { $formattedDays = collect($days)->map(function ($value) {
return Carbon::make($value)->format(__('Y-m-d')); return dateWithEventDay(Carbon::make($value)->format('Y-m-d'));
})->toArray(); })->toArray();
$link = button(url('/admin-shifts'), icon('plus-lg'), 'add'); $link = button(url('/admin-shifts'), icon('plus-lg'), 'add');
@ -321,7 +321,10 @@ function view_user_shifts()
$types, $types,
$shiftsFilter->getTypes(), $shiftsFilter->getTypes(),
'types', 'types',
icon('person-lines-fill') . __('angeltypes.angeltypes') . '<sup>1</sup>', icon('person-lines-fill') . __('angeltypes.angeltypes')
. ' <small><span class="bi bi-info-circle-fill text-info" data-bs-toggle="tooltip" title="'
. __('The tasks shown here are influenced by the angeltypes you joined already!')
. '"></span></small>',
$ownAngelTypes $ownAngelTypes
), ),
'filled_select' => make_select( 'filled_select' => make_select(
@ -330,12 +333,6 @@ function view_user_shifts()
'filled', 'filled',
icon('person-fill-slash') . __('Occupancy') icon('person-fill-slash') . __('Occupancy')
), ),
'task_notice' =>
'<sup>1</sup>'
. __('The tasks shown here are influenced by the angeltypes you joined already!')
. ' <a href="' . url('/angeltypes/about') . '">'
. __('Description of the jobs.')
. '</a>',
'shifts_table' => msg() . $shiftCalendarRenderer->render(), 'shifts_table' => msg() . $shiftCalendarRenderer->render(),
'ical_text' => div('mt-3', ical_hint()), 'ical_text' => div('mt-3', ical_hint()),
'filter' => __('Filter'), 'filter' => __('Filter'),

View File

@ -49,7 +49,7 @@ class ShiftsFilterRenderer
$toolbar = []; $toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) { if ($this->daySelectionEnabled && !empty($this->days)) {
$selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime()); $selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime());
$selected_day_formatted = date(__('Y-m-d'), $this->shiftsFilter->getStartTime()); $selected_day_formatted = dateWithEventDay($selected_day);
$day_dropdown_items = []; $day_dropdown_items = [];
foreach ($this->days as $value => $day) { foreach ($this->days as $value => $day) {
$link = $page_link . '&shifts_filter_day=' . $value; $link = $page_link . '&shifts_filter_day=' . $value;

View File

@ -856,9 +856,6 @@ msgstr ""
"Die Schichten, die hier angezeigt werden, sind von Deinen Einstellungen " "Die Schichten, die hier angezeigt werden, sind von Deinen Einstellungen "
"(Engeltypen/Aufgaben) abhängig!" "(Engeltypen/Aufgaben) abhängig!"
msgid "Description of the jobs."
msgstr "Beschreibung der Aufgaben."
msgid "Filter" msgid "Filter"
msgstr "Filter" msgstr "Filter"

View File

@ -70,11 +70,6 @@
<div class="col col-12 col-sm-5 col-md-12 col-lg-7 col-xl-5 col-xxl-4">%type_select%</div> <div class="col col-12 col-sm-5 col-md-12 col-lg-7 col-xl-5 col-xxl-4">%type_select%</div>
<div class="col col-12 col-sm-3 col-md-12 col-lg-5 col-xl-3 col-xxl-4">%filled_select%</div> <div class="col col-12 col-sm-3 col-md-12 col-lg-5 col-xl-3 col-xxl-4">%filled_select%</div>
</div> </div>
<div class="row">
<div class="col col-md-12 m-1">
<p>%task_notice%</p>
</div>
</div>
</div> </div>
</div> </div>

View File

@ -14,7 +14,7 @@ class DayOfEvent
* the first day of the event will be 0, else 1. * the first day of the event will be 0, else 1.
* Returns null if "event_start" is not set. * Returns null if "event_start" is not set.
*/ */
public static function get(): int | null public static function get(Carbon $date = null): int | null
{ {
$startOfEvent = config('event_start'); $startOfEvent = config('event_start');
@ -24,8 +24,9 @@ class DayOfEvent
/** @var Carbon $startOfEvent */ /** @var Carbon $startOfEvent */
$startOfEvent = $startOfEvent->copy()->startOfDay(); $startOfEvent = $startOfEvent->copy()->startOfDay();
$date = $date ?: Carbon::now();
$now = Carbon::now()->startOfDay(); $now = $date->startOfDay();
$diff = $startOfEvent->diffInDays($now, false); $diff = $startOfEvent->diffInDays($now, false);
if ($diff >= 0) { if ($diff >= 0) {