add shift no signout hint and disable buttons

This commit is contained in:
Xu 2024-01-22 19:59:12 +01:00 committed by Igor Scheller
parent 76c37a5f18
commit 67b24032a0
6 changed files with 29 additions and 7 deletions

View File

@ -554,7 +554,7 @@ function Shift_signout_allowed(Shift $shift, AngelType $angeltype, $signout_user
return true; return true;
} }
if ($signout_user_id == $user->id && $shift->start->timestamp > time() + config('last_unsubscribe') * 3600) { if ($signout_user_id == $user->id && $shift->start->subHours(config('last_unsubscribe')) > Carbon::now()) {
return true; return true;
} }

View File

@ -352,7 +352,7 @@ function render_table($columns, $rows, $data = true)
* @param string $id * @param string $id
* @return string * @return string
*/ */
function button($href, $label, $class = '', $id = '', $title = '') function button($href, $label, $class = '', $id = '', $title = '', $disabled = false)
{ {
if (!Str::contains(str_replace(['btn-sm', 'btn-xl'], '', $class), 'btn-')) { if (!Str::contains(str_replace(['btn-sm', 'btn-xl'], '', $class), 'btn-')) {
$class = 'btn-secondary' . ($class ? ' ' . $class : ''); $class = 'btn-secondary' . ($class ? ' ' . $class : '');
@ -361,7 +361,7 @@ function button($href, $label, $class = '', $id = '', $title = '')
$idAttribute = $id ? 'id="' . $id . '"' : ''; $idAttribute = $id ? 'id="' . $id . '"' : '';
return '<a ' . $idAttribute . ' href="' . $href return '<a ' . $idAttribute . ' href="' . $href
. '" class="btn ' . $class . '" title="' . $title . '">' . $label . '</a>'; . '" class="btn ' . $class . ($disabled ? ' disabled' : '') . '" title="' . $title . '">' . $label . '</a>';
} }
/** /**
@ -387,9 +387,9 @@ function button_checkbox_selection($name, $label, $value)
* *
* @return string * @return string
*/ */
function button_icon($href, $icon, $class = '', $title = '') function button_icon($href, $icon, $class = '', $title = '', $disabled = false)
{ {
return button($href, icon($icon), $class, '', $title); return button($href, icon($icon), $class, '', $title, $disabled);
} }
/** /**

View File

@ -1,5 +1,6 @@
<?php <?php
use Engelsystem\Helpers\Carbon;
use Engelsystem\Models\AngelType; use Engelsystem\Models\AngelType;
use Engelsystem\Models\Location; use Engelsystem\Models\Location;
use Engelsystem\Models\Shifts\Shift; use Engelsystem\Models\Shifts\Shift;
@ -189,7 +190,10 @@ function Shift_view(
} }
if ($shift_signup_state->getState() === ShiftSignupStatus::SIGNED_UP) { if ($shift_signup_state->getState() === ShiftSignupStatus::SIGNED_UP) {
$content[] = info(__('You are signed up for this shift.'), true); $content[] = info(__('You are signed up for this shift.')
. (($shift->start->subHours(config('last_unsubscribe')) < Carbon::now() && $shift->end > Carbon::now())
? ' ' . __('shift.sign_out.hint', [config('last_unsubscribe')])
: ''), true);
} }
if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) { if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) {
@ -325,7 +329,13 @@ function Shift_view_render_shift_entry(ShiftEntry $shift_entry, $user_shift_admi
} }
$angeltype = $shift_entry->angelType; $angeltype = $shift_entry->angelType;
$disabled = Shift_signout_allowed($shift, $angeltype, $shift_entry->user_id) ? '' : ' btn-disabled'; $disabled = Shift_signout_allowed($shift, $angeltype, $shift_entry->user_id) ? '' : ' btn-disabled';
$entry .= button_icon(shift_entry_delete_link($shift_entry), 'trash', 'btn-sm btn-danger' . $disabled, __('form.delete')); $entry .= button_icon(
shift_entry_delete_link($shift_entry),
'trash',
'btn-sm btn-danger' . $disabled,
__('form.delete'),
!Shift_signout_allowed($shift, $angeltype, $shift_entry->user_id)
);
$entry .= '</div>'; $entry .= '</div>';
} }
return $entry; return $entry;

View File

@ -102,6 +102,10 @@ a .icon-icon_angel {
background-color: $link-color; background-color: $link-color;
} }
a .disabled {
pointer-events: none;
}
.navbar .icon-icon_angel { .navbar .icon-icon_angel {
background-color: $nav-link-disabled-color; background-color: $nav-link-disabled-color;
} }

View File

@ -2095,3 +2095,7 @@ msgstr "Es wurde noch kein Schichttyp erstellt. Ohne können keine Schichten ers
msgid "admin_shifts.no_angeltypes" msgid "admin_shifts.no_angeltypes"
msgstr "Es wurde noch kein Engeltyp erstellt. Ohne können keine Schichten erstellt werden." msgstr "Es wurde noch kein Engeltyp erstellt. Ohne können keine Schichten erstellt werden."
msgid "shift.sign_out.hint"
msgstr "Du kannst dich bis %s Stunden vor dem Start der Schicht austragen. "
"Wenn du nicht zu deiner Schicht kommen kannst, lass dich vom Himmel austragen."

View File

@ -974,3 +974,7 @@ msgstr "No shift type has been created yet. Shifts can't be created without one.
msgid "admin_shifts.no_angeltypes" msgid "admin_shifts.no_angeltypes"
msgstr "No angeltype has been created yet. Shifts can't be created without one." msgstr "No angeltype has been created yet. Shifts can't be created without one."
msgid "shift.sign_out.hint"
msgstr "You can self sign out up to %s hours before the start of the shift. "
"If you can't attend your shift, ask heaven to sign you out."