Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Plugin to customize the server load calculation ([#956])
- Save selected room tab in url to preserve selection on reload ([#977])
- Sorting the room history list ([#1004])
- Search and filter options to list of personalized room links ([#1007])

### Changed
- Renamed env option OWN_ROOMS_PAGINATION_PAGE_SIZE to ROOM_PAGINATION_PAGE_SIZE (OWN_ROOMS_PAGINATION_PAGE_SIZE deprecated) ([#373])
Expand All @@ -46,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Layout of room features tab view ([#967])
- **Breaking:** Time periods for room token expiration ([#968])
- Layout of the room history list ([#1004])
- Layout of the personalized room links list ([#1007])

### Fixed
- Issue frontend recompiled on every restart due to a hashing issue ([#792])
Expand Down Expand Up @@ -94,6 +96,7 @@ You can find the changelog for older versions there [here](https://github.com/TH
[#968]: https://github.com/THM-Health/PILOS/pull/968
[#977]: https://github.com/THM-Health/PILOS/pull/977
[#1004]: https://github.com/THM-Health/PILOS/pull/1004
[#1007]: https://github.com/THM-Health/PILOS/pull/1007

[unreleased]: https://github.com/THM-Health/PILOS/compare/v3.0.2...develop
[v3.0.0]: https://github.com/THM-Health/PILOS/releases/tag/v3.0.0
Expand Down
51 changes: 49 additions & 2 deletions app/Http/Controllers/api/v1/RoomTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace App\Http\Controllers\api\v1;

use App\Enums\RoomUserRole;
use App\Http\Controllers\Controller;
use App\Http\Requests\RoomTokenRequest;
use App\Http\Resources\RoomToken as RoomTokenResource;
use App\Models\Room;
use App\Models\RoomToken;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Response;
use Log;
Expand All @@ -19,9 +21,54 @@ class RoomTokenController extends Controller
* @param Room $room Room for which the tokens should be listed.
* @return AnonymousResourceCollection
*/
public function index(Room $room)
public function index(Room $room, Request $request)
{
return RoomTokenResource::collection($room->tokens);
$additional = [];

// Sort by column, fallback/default is firstname
$sortBy = match ($request->get('sort_by')) {
'lastname' => 'lastname',
'last_usage' => 'last_usage',
default => 'firstname',
};

// Sort direction, fallback/default is asc
$sortOrder = match ($request->get('sort_direction')) {
'desc' => 'desc',
default => 'asc',
};

// Filter by role, fallback/default is no filter
$filter = match ($request->get('filter')) {
'participant_role' => ['role', RoomUserRole::USER],
'moderator_role' => ['role', RoomUserRole::MODERATOR],
default => null,
};

// Get all tokens of the room and sort them
$resource = $room->tokens()->orderBy($sortBy, $sortOrder);

// count all before applying filters
$additional['meta']['total_no_filter'] = $resource->count();

// Apply search query if set
if ($request->has('search')) {
// Split search query into single words and search for them in firstname and lastname
$searchQueries = explode(' ', preg_replace('/\s\s+/', ' ', $request->search));
foreach ($searchQueries as $searchQuery) {
$resource = $resource->where(function ($query) use ($searchQuery) {
$query->where('firstname', 'like', '%'.$searchQuery.'%')
->orWhere('lastname', 'like', '%'.$searchQuery.'%');
});
}
}

// Apply filter if set, first element is the column, second the value to query
if ($filter) {
$resource = $resource->where($filter[0], $filter[1]);
}

return RoomTokenResource::collection($resource->paginate(setting('pagination_page_size')))->additional($additional);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lang/de/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'stale_model' => 'Der :model-Datensatz wurde in der Zwischenzeit geändert!',
'token_not_found' => 'Der personalisierte Raumlink konnte nicht gefunden werden.',
],
'filter_no_results' => 'Keine Ergebnisse gefunden',
'firstname' => 'Vorname',
'flash' => [
'client_error' => 'Es ist ein unbekannter Fehler in der Anwendung aufgetreten!',
Expand Down
8 changes: 8 additions & 0 deletions lang/de/rooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@
'delete' => 'Personalisierten Raumlink löschen',
'edit' => 'Personalisierten Raumlink bearbeiten',
'expires' => 'Verfallsdatum',
'expires_at' => 'Läuft ab am :date',
'filter' => [
'all' => 'Alle',
'moderator_role' => 'Nur Moderatoren',
'participant_role' => 'Nur Teilnehmer',
],
'last_usage' => 'Zuletzt verwendet',
'last_used_at' => 'Zuletzt verwendet am :date',
'last_used_never' => 'Noch nie verwendet',
'nodata' => 'Keine personalisierten Raumlinks vorhanden!',
'room_link_copied' => 'Der persionalisierte Raumlink für :firstname :lastname wurde in Ihre Zwischenablage kopiert.',
'title' => 'Personalisierte Raumlinks',
Expand Down
1 change: 1 addition & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'stale_model' => 'The :model entity was updated in the meanwhile!',
'token_not_found' => 'The personalized room link could not be found.',
],
'filter_no_results' => 'No results found',
'firstname' => 'Firstname',
'flash' => [
'client_error' => 'An unknown error occurred in the application!',
Expand Down
8 changes: 8 additions & 0 deletions lang/en/rooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,15 @@
'delete' => 'Delete personalized room link',
'edit' => 'Edit personalized room link',
'expires' => 'Expiry date',
'expires_at' => 'Expires at :date',
'filter' => [
'all' => 'All',
'moderator_role' => 'Only moderators',
'participant_role' => 'Only participants',
],
'last_usage' => 'Last used',
'last_used_at' => 'Last used at :date',
'last_used_never' => 'Never used',
'nodata' => 'No personalized room links available!',
'room_link_copied' => 'The personalized room link for :firstname :lastname was copied to your clipboard.',
'title' => 'Personalized room links',
Expand Down
Loading