Skip to content

Commit

Permalink
Merge branch 'staging' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
BertalanD committed Oct 1, 2024
2 parents a6e1754 + 650b910 commit 242b631
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,17 @@ public function delete(ReservableItem $item)

/**
* Sends admins and staff an email notification
* about an allegedly faulty item.
* about an allegedly faulty item,
* with a message provided in a modal dialog.
*/
public function reportFault(ReservableItem $item)
public function reportFault(ReservableItem $item, Request $request)
{
$this->authorize('view', $item);

$validatedData = $request->validate([
'message' => 'nullable|max:2047'
]);

$thoseToNotify = User::whereHas('roles', function ($query) {
$query->whereIn('name', [Role::SYS_ADMIN, Role::STAFF]);
})->get();
Expand All @@ -128,7 +133,8 @@ public function reportFault(ReservableItem $item)
new ReportReservableItemFault(
$item,
$toNotify->name,
user()->name
user()->name,
$validatedData['message']
)
);
}
Expand All @@ -147,7 +153,7 @@ public function toggleOutOfOrder(ReservableItem $item)

$item->update(['out_of_order' => !$item->out_of_order]);

foreach ($item->usersWithActiveReservation as $toNotify) {
foreach ($item->usersWithActiveReservation()->get() as $toNotify) {
Mail::to($toNotify)->queue(new ReservationAffected(
$item,
$toNotify->name
Expand Down
4 changes: 3 additions & 1 deletion app/Mail/Reservations/ReportReservableItemFault.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class ReportReservableItemFault extends Mailable
public ReservableItem $item;
public string $recipient;
public string $reporter;
public ?string $message; // this is an explanation of the problem provided via a modal dialog

/**
* Create a new message instance.
*/
public function __construct(ReservableItem $item, string $recipient, string $reporter)
public function __construct(ReservableItem $item, string $recipient, string $reporter, ?string $message)
{
$this->item = $item;
$this->recipient = $recipient;
$this->reporter = $reporter;
$this->message = $message;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions app/Models/Reservations/ReservableItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ public function users(): BelongsToMany
/**
* The users who currently have a reservation for this item.
*/
public function usersWithActiveReservation(): BelongsToMany
public function usersWithActiveReservation()
{
return $this->belongsToMany(User::class, Reservation::class, 'reservable_item_id', 'user_id')
->wherePivot('reserved_until', '>', Carbon::now());
return User::whereHas('reservations', function ($query) {
$query->where('reservable_item_id', $this->id)
->where('reserved_until', '>', Carbon::now());
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'name' => env('APP_NAME', 'Urán'),

'version' => '3.26.1', // update on release
'version' => '3.26.2', // update on release

'logo_blue_path' => env('APP_ENV', "local") != "production" ? '/img/mars.png' : '/img/uran_blue.png',

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/reservations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'bad_for_non-recurring' => 'Bad request for non-recurring reservation.',
'check_reservations' => 'Please organize your reservations accordingly.',
'create' => 'New reservation', // page title in breadcrumb
'describe_what_happened' => 'Describe what happened in a few sentences.', // when reporting a fault
'edit' => 'Edit reservation', // a page title
'edit_all' => 'For all reservations',
'edit_all_after' => 'For this reservation and all after this one',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/hu/reservations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'bad_for_non-recurring' => 'Nem ismétlődő foglaláshoz ez érvénytelen kérés.',
'check_reservations' => 'Kérjük, ennek megfelelően tervezze újra foglalásait.',
'create' => 'Új foglalás', // page title in breadcrumb
'describe_what_happened' => 'Pár mondatban írja le, mi történt.', // when reporting a fault
'edit' => 'Foglalás szerkesztése', // a page title
'edit_all' => 'Minden foglalásra',
'edit_all_after' => 'Erre és minden későbbi foglalásra',
Expand Down
9 changes: 9 additions & 0 deletions resources/sass/materialize.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ i.material-icons {
.card a {
text-decoration: underline;
}
/* but not a-based buttons */
.card a.btn {
text-decoration: none;
}

blockquote {
margin: 20px 0;
Expand Down Expand Up @@ -301,6 +305,11 @@ body.dark a.btn {
box-sizing: border-box;
}

// for footers of modal dialogs
.modal .modal-footer {
height: auto;
}

@mixin column-count($ct) {
-webkit-column-count: $ct;
-moz-column-count: $ct;
Expand Down
43 changes: 37 additions & 6 deletions resources/views/dormitory/reservations/item_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<th style="max-width: 30%;">@lang('reservations.item_status')</th>
<th style="text-align: right;">@lang('reservations.item_name')</th>
{{-- for fault report buttons --}}
<th style="max-width: 10%;"></th>
<th style="width: 250px;"></th>
</tr>
</thead>
<tbody>
Expand All @@ -28,18 +28,49 @@
</a>
</td>
<td>
{{-- The button triggers a modal dialog in which the user can provide an explanation about the problem. --}}

{{-- modal trigger --}}
<a @class([
'btn',
'waves-effect',
'waves-light',
'modal-trigger',
'right',
'coli' => !$item->out_of_order,
'blue' => !$item->out_of_order,
]) class="" href="#fault-reporting-modal-{{ $item->id }}">{{ __($item->out_of_order ? 'reservations.report_fix' : 'reservations.report_fault') }}</a>

{{-- modal structure --}}
<form method="POST"
action="{{ route('reservations.items.report_fault', ['item' => $item]) }}"
enctype='multipart/form-data'>
@csrf
<x-input.button floating @class([
'right', 'btn-small',
'red' => !$item->out_of_order,
'green' => $item->out_of_order
]) icon="build" />
<div id="fault-reporting-modal-{{ $item->id }}" class="modal">
<div class="modal-content">
<h4>{{ __($item->out_of_order ? 'reservations.report_fix' : 'reservations.report_fault') }}</h4>
<x-input.textarea id="message"
:text="__('general.description')"
:helper="__('reservations.describe_what_happened')"/>
</div>
<div class="modal-footer">
<a href="#!" type="submit" class="waves-effect btn modal-close">@lang('general.cancel')</a>
<button class="waves-effect btn modal-close" type="submit">@lang('general.send')</button>
</div>
</div>
</form>

</td>
</tr>
@endforeach
</tbody>
</table>

@push('scripts')
<script>
// for the modal dialogs
$(document).ready(function(){
$('.modal').modal();
});
</script>
@endpush
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@else
használhatatlannak tűnik.
@endif
</p>
<p>A probléma részletes leírása:</p>
<blockquote>{{ $message }}</blockquote>
<p>
Kérjük, ellenőrizze, hogy valóban ez-e a helyzet;
ha igen, <a href="{{ route('reservations.items.show', ['item' => $item]) }}">jelölje meg itt</a>.
</p>
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/ReservationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ public function test_fault_report(): void
]);

$response = $this->actingAs($collegist)->followingRedirects()->post(
route('reservations.items.report_fault', $item)
route('reservations.items.report_fault', $item),
['message' => null]
);
$response->assertStatus(200);
$item->refresh();
Expand Down

0 comments on commit 242b631

Please sign in to comment.