Skip to content
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

#377 - calendar months dropdown #468

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Set up node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 22
node-version: 22.4.1

- name: Instal npm dependencies
run: npm clean-install
Expand Down
32 changes: 30 additions & 2 deletions app/Http/Controllers/VacationCalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace Toby\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Inertia\Response;
use Toby\Domain\CalendarGenerator;
use Toby\Enums\Month;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Http\Resources\SimpleUserResource;
use Toby\Models\User;
use Toby\Models\YearPeriod;

class VacationCalendarController extends Controller
{
Expand All @@ -20,12 +23,25 @@ public function index(
YearPeriodRetriever $yearPeriodRetriever,
CalendarGenerator $calendarGenerator,
?string $month = null,
): Response {
?int $year = null,
): Response|RedirectResponse {
if ($year !== null) {
return $this->changeYearPeriod($request, $month, $year);
}

$month = Month::fromNameOrCurrent((string)$month);
$currentUser = $request->user();
$withTrashedUsers = $currentUser->canSeeInactiveUsers();

$yearPeriod = $yearPeriodRetriever->selected();
$previousYearPeriod = YearPeriod::query()
->where("year", "<", $yearPeriod->year)
->orderBy("year", "desc")
->first();
$nextYearPeriod = YearPeriod::query()
->where("year", ">", $yearPeriod->year)
->orderBy("year")
->first();
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());

$users = User::query()
Expand All @@ -42,9 +58,21 @@ public function index(
return inertia("Calendar", [
"calendar" => $calendar,
"current" => Month::current(),
"selected" => $month->value,
"selectedMonth" => $month->value,
"users" => SimpleUserResource::collection($users),
"withBlockedUsers" => $withTrashedUsers,
"previousYearPeriod" => $previousYearPeriod,
"nextYearPeriod" => $nextYearPeriod,
]);
}

private function changeYearPeriod(Request $request, string $month, int $year): RedirectResponse
{
$yearPeriod = YearPeriod::query()->where("year", $year)->firstOrFail();
$request->session()->put(YearPeriodRetriever::SESSION_KEY, $yearPeriod->id);
Cache::forget("selected_year_period");

return redirect()->route("calendar", ["month" => $month])
->with("info", __("Year period changed."));
}
}
1 change: 1 addition & 0 deletions lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Holiday updated.": "Dzień wolny zaktualizowany.",
"Holiday deleted.": "Dzień wolny usunięty.",
"Selected year period changed.": "Wybrany rok zmieniony.",
"Year period changed.": "Zmieniono rok.",
"Vacation limits updated.": "Limity urlopów zaktualizowane.",
"Request created.": "Wniosek utworzony.",
"Request accepted.": "Wniosek zaakceptowany.",
Expand Down
Loading
Loading