* fix css focuses * #90 - wip * #90 - fix to generate PDF * #90 - wip * #90 - wip * #90 - wip * #90 - wip * #90 - fix to calendar * #90 - wip * #90 - fix * #90 - fix lint * #90 - fix * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * #90 - cr fixes * #90 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
parent
459b62500e
commit
cc981b02b4
@ -17,11 +17,29 @@ class ExceptionHandler extends Handler
|
||||
"password_confirmation",
|
||||
];
|
||||
|
||||
protected array $handleByInertia = [
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR,
|
||||
Response::HTTP_SERVICE_UNAVAILABLE,
|
||||
Response::HTTP_TOO_MANY_REQUESTS,
|
||||
419, // CSRF
|
||||
Response::HTTP_NOT_FOUND,
|
||||
Response::HTTP_FORBIDDEN,
|
||||
Response::HTTP_UNAUTHORIZED,
|
||||
];
|
||||
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
$response = parent::render($request, $e);
|
||||
|
||||
if (app()->environment("production") && in_array($response->status(), [500, 503, 429, 419, 404, 403, 401], true)) {
|
||||
if (!app()->environment("production")) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($response->status() === Response::HTTP_METHOD_NOT_ALLOWED) {
|
||||
$response->setStatusCode(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (in_array($response->status(), $this->handleByInertia, true)) {
|
||||
return Inertia::render("Error", [
|
||||
"status" => $response->status(),
|
||||
])
|
||||
|
@ -9,12 +9,14 @@ use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CreateUserAction
|
||||
{
|
||||
public function execute(array $data): User
|
||||
public function execute(array $userData, array $profileData): User
|
||||
{
|
||||
$user = new User($data);
|
||||
$user = new User($userData);
|
||||
|
||||
$user->save();
|
||||
|
||||
$user->profile()->create($profileData);
|
||||
|
||||
$this->createVacationLimitsFor($user);
|
||||
|
||||
return $user;
|
||||
|
19
app/Domain/Actions/UpdateUserAction.php
Normal file
19
app/Domain/Actions/UpdateUserAction.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Actions;
|
||||
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class UpdateUserAction
|
||||
{
|
||||
public function execute(User $user, array $userData, array $profileData): User
|
||||
{
|
||||
$user->update($userData);
|
||||
|
||||
$user->profile->update($profileData);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ class VacationRequestCreatedNotification extends Notification
|
||||
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$user = $this->vacationRequest->user->first_name;
|
||||
$user = $this->vacationRequest->user->profile->first_name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$from = $this->vacationRequest->from->toDisplayString();
|
||||
$to = $this->vacationRequest->to->toDisplayString();
|
||||
@ -92,7 +92,7 @@ class VacationRequestCreatedNotification extends Notification
|
||||
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"appName" => $appName,
|
||||
"creator" => $this->vacationRequest->creator->fullName,
|
||||
"creator" => $this->vacationRequest->creator->profile->full_name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$user = $this->user->first_name;
|
||||
$user = $this->user->profile->first_name;
|
||||
$title = $this->vacationRequest->name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$status = $this->vacationRequest->state->label();
|
||||
$from = $this->vacationRequest->from->toDisplayString();
|
||||
$to = $this->vacationRequest->to->toDisplayString();
|
||||
$days = $this->vacationRequest->vacations()->count();
|
||||
$requester = $this->vacationRequest->user->fullName;
|
||||
$requester = $this->vacationRequest->user->profile->full_name;
|
||||
|
||||
return (new MailMessage())
|
||||
->greeting(__("Hi :user!", [
|
||||
@ -59,7 +59,7 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
"title" => $title,
|
||||
"status" => $status,
|
||||
]))
|
||||
->line(__("The vacation request :title for user :requester has been :status.", [
|
||||
->line(__("The vacation request :title from user :requester has been :status.", [
|
||||
"title" => $title,
|
||||
"requester" => $requester,
|
||||
"status" => $status,
|
||||
|
@ -43,7 +43,7 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$user = $this->user->first_name;
|
||||
$user = $this->user->profile->first_name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$from = $this->vacationRequest->from->toDisplayString();
|
||||
$to = $this->vacationRequest->to->toDisplayString();
|
||||
@ -84,7 +84,7 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
protected function buildDescription(): string
|
||||
{
|
||||
$title = $this->vacationRequest->name;
|
||||
$requester = $this->vacationRequest->user->fullName;
|
||||
$requester = $this->vacationRequest->user->profile->full_name;
|
||||
|
||||
if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) {
|
||||
return __("The vacation request :title from user :requester is waiting for your technical approval.", [
|
||||
|
@ -46,7 +46,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return $this->user->fullName;
|
||||
return $this->user->profile->full_name;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
|
@ -33,7 +33,8 @@ class YearPeriodRetriever
|
||||
$selected = $this->selected();
|
||||
$current = $this->current();
|
||||
|
||||
$years = YearPeriod::query()->whereIn("year", $this->offset($selected->year))->get();
|
||||
$years = YearPeriod::all();
|
||||
|
||||
$navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod));
|
||||
|
||||
return [
|
||||
@ -43,11 +44,6 @@ class YearPeriodRetriever
|
||||
];
|
||||
}
|
||||
|
||||
protected function offset(int $year): array
|
||||
{
|
||||
return range($year - 2, $year + 2);
|
||||
}
|
||||
|
||||
protected function toNavigation(YearPeriod $yearPeriod): array
|
||||
{
|
||||
return [
|
||||
|
63
app/Eloquent/Models/Profile.php
Normal file
63
app/Eloquent/Models/Profile.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\ProfileFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Rackbeat\UIAvatars\HasAvatar;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Eloquent\Helpers\ColorGenerator;
|
||||
|
||||
/**
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $position
|
||||
* @property EmploymentForm $employment_form
|
||||
* @property Carbon $employment_date
|
||||
*/
|
||||
class Profile extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasAvatar;
|
||||
|
||||
protected $primaryKey = "user_id";
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"employment_form" => EmploymentForm::class,
|
||||
"employment_date" => "date",
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getAvatar(): string
|
||||
{
|
||||
return $this->getAvatarGenerator()
|
||||
->backgroundColor(ColorGenerator::generate($this->full_name))
|
||||
->image();
|
||||
}
|
||||
|
||||
public function getfullNameAttribute(): string
|
||||
{
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
|
||||
protected function getAvatarName(): string
|
||||
{
|
||||
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
|
||||
}
|
||||
|
||||
protected static function newFactory(): ProfileFactory
|
||||
{
|
||||
return ProfileFactory::new();
|
||||
}
|
||||
}
|
@ -8,27 +8,20 @@ use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Rackbeat\UIAvatars\HasAvatar;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Helpers\ColorGenerator;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $avatar
|
||||
* @property string $position
|
||||
* @property Role $role
|
||||
* @property EmploymentForm $employment_form
|
||||
* @property Carbon $employment_date
|
||||
* @property Profile $profile
|
||||
* @property Collection $vacationLimits
|
||||
* @property Collection $vacationRequests
|
||||
* @property Collection $vacations
|
||||
@ -38,12 +31,12 @@ class User extends Authenticatable
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
use HasAvatar;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
"role" => Role::class,
|
||||
"last_active_at" => "datetime",
|
||||
"employment_form" => EmploymentForm::class,
|
||||
"employment_date" => "date",
|
||||
];
|
||||
@ -52,6 +45,15 @@ class User extends Authenticatable
|
||||
"remember_token",
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
"profile",
|
||||
];
|
||||
|
||||
public function profile(): HasOne
|
||||
{
|
||||
return $this->hasOne(Profile::class);
|
||||
}
|
||||
|
||||
public function vacationLimits(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationLimit::class);
|
||||
@ -72,18 +74,6 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Vacation::class);
|
||||
}
|
||||
|
||||
public function getAvatar(): string
|
||||
{
|
||||
return $this->getAvatarGenerator()
|
||||
->backgroundColor(ColorGenerator::generate($this->fullName))
|
||||
->image();
|
||||
}
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
return "{$this->first_name} {$this->last_name}";
|
||||
}
|
||||
|
||||
public function hasRole(Role $role): bool
|
||||
{
|
||||
return $this->role === $role;
|
||||
@ -104,9 +94,20 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
return $query
|
||||
->where("first_name", "ILIKE", "%{$text}%")
|
||||
->orWhere("last_name", "ILIKE", "%{$text}%")
|
||||
->orWhere("email", "ILIKE", "%{$text}%");
|
||||
->where("email", "ILIKE", "%{$text}%")
|
||||
->orWhereRelation(
|
||||
"profile",
|
||||
fn(Builder $query) => $query
|
||||
->where("first_name", "ILIKE", "%{$text}%")
|
||||
->orWhere("last_name", "ILIKE", "%{$text}%"),
|
||||
);
|
||||
}
|
||||
|
||||
public function scopeOrderByProfileField(Builder $query, string $field): Builder
|
||||
{
|
||||
$profileQuery = Profile::query()->select($field)->whereColumn("users.id", "profiles.user_id");
|
||||
|
||||
return $query->orderBy($profileQuery);
|
||||
}
|
||||
|
||||
public function scopeWithVacationLimitIn(Builder $query, YearPeriod $yearPeriod): Builder
|
||||
@ -119,11 +120,6 @@ class User extends Authenticatable
|
||||
);
|
||||
}
|
||||
|
||||
protected function getAvatarName(): string
|
||||
{
|
||||
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
|
||||
}
|
||||
|
||||
protected static function newFactory(): UserFactory
|
||||
{
|
||||
return UserFactory::new();
|
||||
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\VacationLimitFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -37,13 +36,6 @@ class VacationLimit extends Model
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
|
||||
public function scopeOrderByUserField(Builder $query, string $field): Builder
|
||||
{
|
||||
$userQuery = User::query()->select($field)->whereColumn("vacation_limits.user_id", "users.id");
|
||||
|
||||
return $query->orderBy($userQuery);
|
||||
}
|
||||
|
||||
protected static function newFactory(): VacationLimitFactory
|
||||
{
|
||||
return VacationLimitFactory::new();
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class MoveUserDataToProfile extends Command
|
||||
{
|
||||
protected $signature = "toby:move-user-data-to-profile";
|
||||
protected $description = "Move user data to their profiles";
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->profile()->updateOrCreate(["user_id" => $user->id], [
|
||||
"first_name" => $user->first_name,
|
||||
"last_name" => $user->last_name,
|
||||
"position" => $user->position,
|
||||
"employment_form" => $user->employment_form,
|
||||
"employment_date" => $user->employment_date,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ class GetAvailableVacationTypesController extends Controller
|
||||
$user = User::query()->find($request->get("user"));
|
||||
|
||||
$types = VacationType::all()
|
||||
->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->employment_form))
|
||||
->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
|
||||
->map(fn(VacationType $type) => [
|
||||
"label" => $type->label(),
|
||||
"value" => $type->value,
|
||||
|
@ -9,21 +9,23 @@ use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\UserVacationStatsRetriever;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Infrastructure\Http\Resources\AbsenceResource;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, UserVacationStatsRetriever $vacationStatsRetriever): Response
|
||||
{
|
||||
public function __invoke(
|
||||
Request $request,
|
||||
YearPeriodRetriever $yearPeriodRetriever,
|
||||
UserVacationStatsRetriever $vacationStatsRetriever,
|
||||
): Response {
|
||||
$user = $request->user();
|
||||
$now = Carbon::now();
|
||||
$yearPeriod = YearPeriod::findByYear($now->year);
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$absences = Vacation::query()
|
||||
->with(["user", "vacationRequest"])
|
||||
@ -32,19 +34,21 @@ class DashboardController extends Controller
|
||||
->get();
|
||||
|
||||
if ($user->can("listAll", VacationRequest::class)) {
|
||||
$vacationRequests = VacationRequest::query()
|
||||
$vacationRequests = $yearPeriod->vacationRequests()
|
||||
->states(VacationRequestStatesRetriever::waitingForUserActionStates($user))
|
||||
->latest("updated_at")
|
||||
->limit(3)
|
||||
->get();
|
||||
} else {
|
||||
$vacationRequests = $user->vacationRequests()
|
||||
->whereBelongsTo($yearPeriod)
|
||||
->latest("updated_at")
|
||||
->limit(3)
|
||||
->get();
|
||||
}
|
||||
|
||||
$holidays = Holiday::query()
|
||||
$holidays = $yearPeriod
|
||||
->holidays()
|
||||
->whereDate("date", ">=", $now)
|
||||
->orderBy("date")
|
||||
->limit(3)
|
||||
|
@ -10,7 +10,7 @@ use Toby\Domain\Enums\Month;
|
||||
use Toby\Domain\UserVacationStatsRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
use Toby\Infrastructure\Http\Resources\SimpleUserResource;
|
||||
|
||||
class MonthlyUsageController extends Controller
|
||||
{
|
||||
@ -27,8 +27,8 @@ class MonthlyUsageController extends Controller
|
||||
$users = User::query()
|
||||
->withVacationLimitIn($currentYearPeriod)
|
||||
->where("id", "!=", $currentUser->id)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->get();
|
||||
|
||||
if ($currentUser->hasVacationLimit($currentYearPeriod)) {
|
||||
@ -45,7 +45,7 @@ class MonthlyUsageController extends Controller
|
||||
$remaining = $limit - $used - $pending;
|
||||
|
||||
$monthlyUsage[] = [
|
||||
"user" => new UserResource($user),
|
||||
"user" => new SimpleUserResource($user),
|
||||
"months" => $vacationsByMonth,
|
||||
"stats" => [
|
||||
"used" => $used,
|
||||
|
@ -28,9 +28,9 @@ class TimesheetController extends Controller
|
||||
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());
|
||||
|
||||
$users = User::query()
|
||||
->where("employment_form", EmploymentForm::EmploymentContract)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->whereRelation("profile", "employment_form", EmploymentForm::EmploymentContract)
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->get();
|
||||
|
||||
$types = VacationType::all()
|
||||
|
@ -9,6 +9,7 @@ use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Actions\CreateUserAction;
|
||||
use Toby\Domain\Actions\UpdateUserAction;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\User;
|
||||
@ -28,8 +29,8 @@ class UserController extends Controller
|
||||
$users = User::query()
|
||||
->withTrashed()
|
||||
->search($request->query("search"))
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->paginate()
|
||||
->withQueryString();
|
||||
|
||||
@ -59,7 +60,7 @@ class UserController extends Controller
|
||||
{
|
||||
$this->authorize("manageUsers");
|
||||
|
||||
$createUserAction->execute($request->data());
|
||||
$createUserAction->execute($request->userData(), $request->profileData());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
@ -83,11 +84,11 @@ class UserController extends Controller
|
||||
/**
|
||||
* @throws AuthorizationException
|
||||
*/
|
||||
public function update(UserRequest $request, User $user): RedirectResponse
|
||||
public function update(UserRequest $request, UpdateUserAction $updateUserAction, User $user): RedirectResponse
|
||||
{
|
||||
$this->authorize("manageUsers");
|
||||
|
||||
$user->update($request->data());
|
||||
$updateUserAction->execute($user, $request->userData(), $request->profileData());
|
||||
|
||||
return redirect()
|
||||
->route("users.index")
|
||||
|
@ -11,7 +11,7 @@ use Toby\Domain\CalendarGenerator;
|
||||
use Toby\Domain\Enums\Month;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
use Toby\Infrastructure\Http\Resources\SimpleUserResource;
|
||||
|
||||
class VacationCalendarController extends Controller
|
||||
{
|
||||
@ -29,8 +29,8 @@ class VacationCalendarController extends Controller
|
||||
|
||||
$users = User::query()
|
||||
->where("id", "!=", $currentUser->id)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->get();
|
||||
|
||||
$users->prepend($currentUser);
|
||||
@ -41,7 +41,7 @@ class VacationCalendarController extends Controller
|
||||
"calendar" => $calendar,
|
||||
"current" => Month::current(),
|
||||
"selected" => $month->value,
|
||||
"users" => UserResource::collection($users),
|
||||
"users" => SimpleUserResource::collection($users),
|
||||
"can" => [
|
||||
"generateTimesheet" => $request->user()->can("generateTimesheet"),
|
||||
],
|
||||
|
@ -11,7 +11,7 @@ use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Infrastructure\Http\Requests\VacationLimitRequest;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
use Toby\Infrastructure\Http\Resources\SimpleUserResource;
|
||||
|
||||
class VacationLimitController extends Controller
|
||||
{
|
||||
@ -24,15 +24,15 @@ class VacationLimitController extends Controller
|
||||
|
||||
$limits = $yearPeriod
|
||||
->vacationLimits()
|
||||
->with("user")
|
||||
->with("user.profile")
|
||||
->has("user")
|
||||
->orderByUserField("last_name")
|
||||
->orderByUserField("first_name")
|
||||
->get();
|
||||
->get()
|
||||
->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}")
|
||||
->values();
|
||||
|
||||
$limitsResource = $limits->map(fn(VacationLimit $limit) => [
|
||||
"id" => $limit->id,
|
||||
"user" => new UserResource($limit->user),
|
||||
"user" => new SimpleUserResource($limit->user),
|
||||
"hasVacation" => $limit->hasVacation(),
|
||||
"days" => $limit->days,
|
||||
"remainingLastYear" => $previousYearPeriod
|
||||
|
@ -27,14 +27,18 @@ use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Http\Requests\VacationRequestRequest;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
use Toby\Infrastructure\Http\Resources\SimpleUserResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
|
||||
|
||||
class VacationRequestController extends Controller
|
||||
{
|
||||
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
|
||||
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response|RedirectResponse
|
||||
{
|
||||
if ($request->user()->can("listAll", VacationRequest::class)) {
|
||||
return redirect()->route("vacation.requests.indexForApprovers");
|
||||
}
|
||||
|
||||
$status = $request->get("status", "all");
|
||||
|
||||
$vacationRequests = $request->user()
|
||||
@ -103,13 +107,13 @@ class VacationRequestController extends Controller
|
||||
->paginate();
|
||||
|
||||
$users = User::query()
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->get();
|
||||
|
||||
return inertia("VacationRequest/IndexForApprovers", [
|
||||
"requests" => VacationRequestResource::collection($vacationRequests),
|
||||
"users" => UserResource::collection($users),
|
||||
"users" => SimpleUserResource::collection($users),
|
||||
"filters" => [
|
||||
"status" => $status,
|
||||
"user" => (int)$user,
|
||||
@ -158,13 +162,13 @@ class VacationRequestController extends Controller
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
$users = User::query()
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->orderByProfileField("last_name")
|
||||
->orderByProfileField("first_name")
|
||||
->get();
|
||||
|
||||
return inertia("VacationRequest/Create", [
|
||||
"vacationTypes" => VacationType::casesToSelect(),
|
||||
"users" => UserResource::collection($users),
|
||||
"users" => SimpleUserResource::collection($users),
|
||||
"can" => [
|
||||
"createOnBehalfOfEmployee" => $request->user()->can("createOnBehalfOfEmployee", VacationRequest::class),
|
||||
"skipFlow" => $request->user()->can("skipFlow", VacationRequest::class),
|
||||
|
@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
@ -18,24 +20,54 @@ class HandleInertiaRequests extends Middleware
|
||||
|
||||
public function share(Request $request): array
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return array_merge(parent::share($request), [
|
||||
"auth" => fn() => [
|
||||
"user" => $user ? new UserResource($user) : null,
|
||||
"can" => [
|
||||
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
|
||||
"manageUsers" => $user ? $user->can("manageUsers") : false,
|
||||
"listAllVacationRequests" => $user ? $user->can("listAll", VacationRequest::class) : false,
|
||||
"listMonthlyUsage" => $user ? $user->can("listMonthlyUsage") : false,
|
||||
],
|
||||
],
|
||||
"flash" => fn() => [
|
||||
"success" => $request->session()->get("success"),
|
||||
"error" => $request->session()->get("error"),
|
||||
"info" => $request->session()->get("info"),
|
||||
],
|
||||
"years" => fn() => $user ? $this->yearPeriodRetriever->links() : [],
|
||||
"auth" => $this->getAuthData($request),
|
||||
"flash" => $this->getFlashData($request),
|
||||
"years" => $this->getYearsData($request),
|
||||
"vacationRequestsCount" => $this->getVacationRequestsCount($request),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getAuthData(Request $request): Closure
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return fn() => [
|
||||
"user" => $user ? new UserResource($user) : null,
|
||||
"can" => [
|
||||
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
|
||||
"manageUsers" => $user ? $user->can("manageUsers") : false,
|
||||
"listAllVacationRequests" => $user ? $user->can("listAll", VacationRequest::class) : false,
|
||||
"listMonthlyUsage" => $user ? $user->can("listMonthlyUsage") : false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFlashData(Request $request): Closure
|
||||
{
|
||||
return fn() => [
|
||||
"success" => $request->session()->get("success"),
|
||||
"error" => $request->session()->get("error"),
|
||||
"info" => $request->session()->get("info"),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getYearsData(Request $request): Closure
|
||||
{
|
||||
return fn(): array => $request->user() ? $this->yearPeriodRetriever->links() : [];
|
||||
}
|
||||
|
||||
protected function getVacationRequestsCount(Request $request): Closure
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return fn(): ?int => $user && $user->can("listAll", VacationRequest::class)
|
||||
? VacationRequest::query()
|
||||
->whereBelongsTo($this->yearPeriodRetriever->selected())
|
||||
->states(
|
||||
VacationRequestStatesRetriever::waitingForUserActionStates($user),
|
||||
)
|
||||
->count()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
21
app/Infrastructure/Http/Middleware/TrackUserLastActivity.php
Normal file
21
app/Infrastructure/Http/Middleware/TrackUserLastActivity.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class TrackUserLastActivity
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$request->user()?->update([
|
||||
"last_active_at" => Carbon::now(),
|
||||
]);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -25,14 +25,20 @@ class UserRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
public function userData(): array
|
||||
{
|
||||
return [
|
||||
"email" => $this->get("email"),
|
||||
"role" => $this->get("role"),
|
||||
];
|
||||
}
|
||||
|
||||
public function profileData(): array
|
||||
{
|
||||
return [
|
||||
"first_name" => $this->get("firstName"),
|
||||
"last_name" => $this->get("lastName"),
|
||||
"email" => $this->get("email"),
|
||||
"position" => $this->get("position"),
|
||||
"role" => $this->get("role"),
|
||||
"employment_form" => $this->get("employmentForm"),
|
||||
"employment_date" => $this->get("employmentDate"),
|
||||
];
|
||||
|
@ -14,7 +14,7 @@ class AbsenceResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"user" => new UserResource($this->user),
|
||||
"user" => new SimpleUserResource($this->user),
|
||||
"date" => $this->date->toDisplayString(),
|
||||
];
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ class HolidayResource extends JsonResource
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"date" => $this->date->toDateString(),
|
||||
"isPast" => $this->date->isPast(),
|
||||
"displayDate" => $this->date->toDisplayString(),
|
||||
"dayOfWeek" => $this->date->dayName,
|
||||
];
|
||||
|
22
app/Infrastructure/Http/Resources/SimpleUserResource.php
Normal file
22
app/Infrastructure/Http/Resources/SimpleUserResource.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SimpleUserResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->profile->full_name,
|
||||
"email" => $this->email,
|
||||
"avatar" => $this->profile->getAvatar(),
|
||||
];
|
||||
}
|
||||
}
|
@ -14,13 +14,13 @@ class UserFormDataResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"firstName" => $this->first_name,
|
||||
"lastName" => $this->last_name,
|
||||
"firstName" => $this->profile->first_name,
|
||||
"lastName" => $this->profile->last_name,
|
||||
"email" => $this->email,
|
||||
"role" => $this->role,
|
||||
"position" => $this->position,
|
||||
"employmentForm" => $this->employment_form,
|
||||
"employmentDate" => $this->employment_date->toDateString(),
|
||||
"position" => $this->profile->position,
|
||||
"employmentForm" => $this->profile->employment_form,
|
||||
"employmentDate" => $this->profile->employment_date->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,15 @@ class UserResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->fullName,
|
||||
"name" => $this->profile->full_name,
|
||||
"email" => $this->email,
|
||||
"role" => $this->role->label(),
|
||||
"position" => $this->position,
|
||||
"avatar" => $this->getAvatar(),
|
||||
"position" => $this->profile->position,
|
||||
"avatar" => $this->profile->getAvatar(),
|
||||
"deleted" => $this->trashed(),
|
||||
"employmentForm" => $this->employment_form->label(),
|
||||
"employmentDate" => $this->employment_date->toDisplayString(),
|
||||
"lastActiveAt" => $this->last_active_at?->toDateTimeString(),
|
||||
"employmentForm" => $this->profile->employment_form->label(),
|
||||
"employmentDate" => $this->profile->employment_date->toDisplayString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class VacationRequestActivityResource extends JsonResource
|
||||
return [
|
||||
"date" => $this->created_at->toDisplayString(),
|
||||
"time" => $this->created_at->format("H:i"),
|
||||
"user" => $this->user ? $this->user->fullName : __("System"),
|
||||
"user" => $this->user ? $this->user->profile->full_name : __("System"),
|
||||
"state" => $this->to,
|
||||
];
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class VacationRequestResource extends JsonResource
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"name" => $this->name,
|
||||
"user" => new UserResource($this->user),
|
||||
"user" => new SimpleUserResource($this->user),
|
||||
"type" => $this->type,
|
||||
"state" => $this->state,
|
||||
"from" => $this->from->toDisplayString(),
|
||||
|
@ -21,7 +21,7 @@ class ClearVacationRequestDaysInGoogleCalendar implements ShouldQueue
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
foreach ($this->vacationRequest->event_ids as $eventId) {
|
||||
foreach ($this->vacationRequest->event_ids ?? [] as $eventId) {
|
||||
$calendarEvent = Event::find($eventId);
|
||||
|
||||
if ($calendarEvent->googleEvent->getStatus() !== "cancelled") {
|
||||
|
@ -32,7 +32,7 @@ class SendVacationRequestDaysToGoogleCalendar implements ShouldQueue
|
||||
$ranges = $this->prepareRanges($days);
|
||||
|
||||
foreach ($ranges as $range) {
|
||||
$text = "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->fullName} [{$this->vacationRequest->name}]";
|
||||
$text = "{$this->vacationRequest->type->label()} - {$this->vacationRequest->user->profile->full_name} [{$this->vacationRequest->name}]";
|
||||
|
||||
$event = Event::create([
|
||||
"name" => $text,
|
||||
|
28
database/factories/ProfileFactory.php
Normal file
28
database/factories/ProfileFactory.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Eloquent\Models\Profile;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class ProfileFactory extends Factory
|
||||
{
|
||||
protected $model = Profile::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
"user_id" => User::factory(),
|
||||
"first_name" => $this->faker->firstName(),
|
||||
"last_name" => $this->faker->lastName(),
|
||||
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
|
||||
"position" => $this->faker->jobTitle(),
|
||||
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
@ -5,10 +5,9 @@ declare(strict_types=1);
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
use Toby\Eloquent\Models\Profile;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class UserFactory extends Factory
|
||||
@ -18,17 +17,21 @@ class UserFactory extends Factory
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
"first_name" => $this->faker->firstName(),
|
||||
"last_name" => $this->faker->lastName(),
|
||||
"email" => $this->faker->unique()->safeEmail(),
|
||||
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
|
||||
"position" => $this->faker->jobTitle(),
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
|
||||
"remember_token" => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): self
|
||||
{
|
||||
return $this->afterCreating(function (User $user): void {
|
||||
if (!$user->profile()->exists()) {
|
||||
Profile::factory()->for($user)->create();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function admin(): static
|
||||
{
|
||||
return $this->state([
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create("profiles", function (Blueprint $table): void {
|
||||
$table->foreignIdFor(User::class)->primary();
|
||||
$table->string("first_name")->nullable();
|
||||
$table->string("last_name")->nullable();
|
||||
$table->string("position")->nullable();
|
||||
$table->string("employment_form")->nullable();
|
||||
$table->date("employment_date")->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists("profiles");
|
||||
}
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Artisan::call("toby:move-user-data-to-profile");
|
||||
|
||||
Schema::table("users", function (Blueprint $table): void {
|
||||
$table->dropColumn("first_name");
|
||||
$table->dropColumn("last_name");
|
||||
$table->dropColumn("position");
|
||||
$table->dropColumn("employment_form");
|
||||
$table->dropColumn("employment_date");
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table("users", function (Blueprint $table): void {
|
||||
$table->string("first_name")->nullable();
|
||||
$table->string("last_name")->nullable();
|
||||
$table->string("position")->nullable();
|
||||
$table->string("employment_form")->nullable();
|
||||
$table->date("employment_date")->nullable();
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table("users", function (Blueprint $table): void {
|
||||
$table->timestamp("last_active_at")->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table("users", function (Blueprint $table): void {
|
||||
$table->dropColumn("last_active_at");
|
||||
});
|
||||
}
|
||||
};
|
@ -30,75 +30,87 @@ class DemoSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
$user = User::factory([
|
||||
"first_name" => "Jan",
|
||||
"last_name" => "Kowalski",
|
||||
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::Administrator,
|
||||
"employment_date" => Carbon::createFromDate(2021, 12, 31),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Jan",
|
||||
"last_name" => "Kowalski",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "programista",
|
||||
"employment_date" => Carbon::createFromDate(2021, 12, 31),
|
||||
])
|
||||
->create();
|
||||
|
||||
User::factory([
|
||||
"first_name" => "Anna",
|
||||
"last_name" => "Nowak",
|
||||
"email" => "anna.nowak@example.com",
|
||||
"employment_form" => EmploymentForm::CommissionContract,
|
||||
"position" => "tester",
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromDate(2021, 5, 10),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Anna",
|
||||
"last_name" => "Nowak",
|
||||
"employment_form" => EmploymentForm::CommissionContract,
|
||||
"position" => "tester",
|
||||
"employment_date" => Carbon::createFromDate(2021, 5, 10),
|
||||
])
|
||||
->create();
|
||||
|
||||
User::factory([
|
||||
"first_name" => "Tola",
|
||||
"last_name" => "Sawicka",
|
||||
"email" => "tola.sawicka@example.com",
|
||||
"employment_form" => EmploymentForm::B2bContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::Employee,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Tola",
|
||||
"last_name" => "Sawicka",
|
||||
"employment_form" => EmploymentForm::B2bContract,
|
||||
"position" => "programista",
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
])
|
||||
->create();
|
||||
|
||||
$technicalApprover = User::factory([
|
||||
"first_name" => "Maciej",
|
||||
"last_name" => "Ziółkowski",
|
||||
"email" => "maciej.ziolkowski@example.com",
|
||||
"employment_form" => EmploymentForm::BoardMemberContract,
|
||||
"position" => "programista",
|
||||
"role" => Role::TechnicalApprover,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Maciej",
|
||||
"last_name" => "Ziółkowski",
|
||||
"employment_form" => EmploymentForm::BoardMemberContract,
|
||||
"position" => "programista",
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
])
|
||||
->create();
|
||||
|
||||
$administrativeApprover = User::factory([
|
||||
"first_name" => "Katarzyna",
|
||||
"last_name" => "Zając",
|
||||
"email" => "katarzyna.zajac@example.com",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "dyrektor",
|
||||
"role" => Role::AdministrativeApprover,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Katarzyna",
|
||||
"last_name" => "Zając",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "dyrektor",
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
])
|
||||
->create();
|
||||
|
||||
User::factory([
|
||||
"first_name" => "Miłosz",
|
||||
"last_name" => "Borowski",
|
||||
"email" => "milosz.borowski@example.com",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "administrator",
|
||||
"role" => Role::Administrator,
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
"remember_token" => Str::random(10),
|
||||
])
|
||||
->hasProfile([
|
||||
"first_name" => "Miłosz",
|
||||
"last_name" => "Borowski",
|
||||
"employment_form" => EmploymentForm::EmploymentContract,
|
||||
"position" => "administrator",
|
||||
"employment_date" => Carbon::createFromDate(2021, 1, 4),
|
||||
])
|
||||
->create();
|
||||
|
||||
$users = User::all();
|
||||
@ -118,7 +130,7 @@ class DemoSeeder extends Seeder
|
||||
->afterCreating(function (YearPeriod $yearPeriod) use ($users): void {
|
||||
foreach ($users as $user) {
|
||||
VacationLimit::factory([
|
||||
"days" => $user->employment_form === EmploymentForm::EmploymentContract ? 26 : null,
|
||||
"days" => $user->profile->employment_form === EmploymentForm::EmploymentContract ? 26 : null,
|
||||
])
|
||||
->for($yearPeriod)
|
||||
->for($user)
|
||||
|
@ -14,8 +14,8 @@ const types = [
|
||||
text: 'Urlop wypoczynkowy',
|
||||
value: 'vacation',
|
||||
icon: WhiteBalanceSunnyIcon,
|
||||
color: 'text-amber-300',
|
||||
border: 'border-amber-300',
|
||||
color: 'text-yellow-500',
|
||||
border: 'border-yellow-500',
|
||||
},
|
||||
{
|
||||
text: 'Urlop na żądanie',
|
||||
|
@ -39,7 +39,7 @@
|
||||
offset-distance="0"
|
||||
>
|
||||
<div :class="[day.isPendingVacation && 'mx-0.5']">
|
||||
<button :class="[day.isPendingVacation && `border-dashed`, `${getVacationBorder(day)} isolate bg-white w-full hover:bg-blumilk-25 border-b-4 py-1.5 font-medium`]">
|
||||
<button :class="[day.isPendingVacation && `border-dashed`, `${getVacationBorder(day)} isolate bg-white w-full hover:bg-blumilk-25 border-b-4 py-1.5 font-medium focus:outline-blumilk-500`]">
|
||||
<time
|
||||
:datetime="day.date.toISODate()"
|
||||
:class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'mx-auto flex h-7 w-7 p-4 items-center justify-center']"
|
||||
@ -58,7 +58,7 @@
|
||||
hover
|
||||
offset-distance="0"
|
||||
>
|
||||
<button class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent">
|
||||
<button class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent focus:outline-blumilk-500">
|
||||
<time
|
||||
:datetime="day.date.toISODate()"
|
||||
:class="[ day.isToday && 'bg-blumilk-500 font-semibold text-white rounded-full', 'text-red-700 font-bold mx-auto flex h-7 w-7 p-4 items-center justify-center']"
|
||||
@ -74,7 +74,7 @@
|
||||
</Popper>
|
||||
<button
|
||||
v-else
|
||||
class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent"
|
||||
class="py-1.5 w-full font-medium bg-white hover:bg-blumilk-25 border-b-4 border-transparent focus:outline-blumilk-500"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date.toISODate()"
|
||||
|
@ -11,20 +11,21 @@
|
||||
v-if="previousMonth"
|
||||
as="button"
|
||||
:href="`/vacation/calendar/${previousMonth.value}`"
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
>
|
||||
<ChevronLeftIcon class="w-5 h-5" />
|
||||
</InertiaLink>
|
||||
<span
|
||||
v-else
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
class="flex justify-center items-center p-2 text-gray-400 bg-gray-100 rounded-l-md border border-r-0 border-gray-300 md:px-2 md:w-9"
|
||||
>
|
||||
<ChevronLeftIcon class="w-5 h-5" />
|
||||
</span>
|
||||
<InertiaLink
|
||||
v-if="years.current.year === years.selected.year"
|
||||
as="button"
|
||||
:href="`/vacation/calendar/${currentMonth.value}`"
|
||||
class="hidden focus:relative items-center p-2 text-sm font-medium text-gray-700 hover:text-gray-900 bg-white hover:bg-gray-50 border-y border-gray-300 md:flex"
|
||||
class="hidden focus:relative items-center p-2 text-sm font-medium text-gray-700 hover:text-gray-900 bg-white hover:bg-gray-50 border-y border-gray-300 focus:outline-blumilk-500 md:flex"
|
||||
>
|
||||
Dzisiaj
|
||||
</InertiaLink>
|
||||
@ -32,13 +33,13 @@
|
||||
v-if="nextMonth"
|
||||
as="button"
|
||||
:href="`/vacation/calendar/${nextMonth.value}`"
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 focus:outline-blumilk-500 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
>
|
||||
<ChevronRightIcon class="w-5 h-5" />
|
||||
</InertiaLink>
|
||||
<span
|
||||
v-else
|
||||
class="flex focus:relative justify-center items-center p-2 text-gray-400 hover:text-gray-500 bg-white rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9 md:hover:bg-gray-50"
|
||||
class="flex justify-center items-center p-2 text-gray-400 bg-gray-100 rounded-r-md border border-l-0 border-gray-300 md:px-2 md:w-9"
|
||||
>
|
||||
<ChevronRightIcon class="w-5 h-5" />
|
||||
</span>
|
||||
|
@ -14,8 +14,14 @@
|
||||
v-else
|
||||
:requests="vacationRequests.data"
|
||||
/>
|
||||
<AbsenceList :absences="absences.data" />
|
||||
<UpcomingHolidays :holidays="holidays.data" />
|
||||
<AbsenceList
|
||||
v-if="years.current.year === years.selected.year"
|
||||
:absences="absences.data"
|
||||
/>
|
||||
<UpcomingHolidays
|
||||
v-if="years.current.year === years.selected.year"
|
||||
:holidays="holidays.data"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -35,5 +41,6 @@ defineProps({
|
||||
holidays: Object,
|
||||
can: Object,
|
||||
stats: Object,
|
||||
years: Object,
|
||||
})
|
||||
</script>
|
||||
|
@ -49,9 +49,9 @@
|
||||
<tr
|
||||
v-for="holiday in holidays.data"
|
||||
:key="holiday.id"
|
||||
class="hover:bg-blumilk-25"
|
||||
:class="[holiday.isPast ? 'bg-gray-100' : 'hover:bg-blumilk-25']"
|
||||
>
|
||||
<td class="p-4 text-sm font-semibold text-gray-500 capitalize whitespace-nowrap">
|
||||
<td class="p-4 text-sm font-semibold text-gray-700 capitalize whitespace-nowrap">
|
||||
{{ holiday.name }}
|
||||
</td>
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
|
@ -112,7 +112,7 @@
|
||||
</ListboxLabel>
|
||||
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
|
||||
<ListboxButton
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.role, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.role }"
|
||||
>
|
||||
<span class="block truncate">{{ form.role.label }}</span>
|
||||
@ -166,7 +166,7 @@
|
||||
</ListboxLabel>
|
||||
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
|
||||
<ListboxButton
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
|
||||
>
|
||||
<span class="block truncate">{{ form.employmentForm.label }}</span>
|
||||
|
@ -112,7 +112,7 @@
|
||||
</ListboxLabel>
|
||||
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
|
||||
<ListboxButton
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
|
||||
>
|
||||
<span class="block truncate">{{ form.role.label }}</span>
|
||||
@ -170,7 +170,7 @@
|
||||
</ListboxLabel>
|
||||
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
|
||||
<ListboxButton
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
|
||||
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
|
||||
>
|
||||
<span class="block truncate">{{ form.employmentForm.label }}</span>
|
||||
|
@ -46,6 +46,12 @@
|
||||
>
|
||||
Rola
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
|
||||
>
|
||||
Ostatnia aktywność
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
|
||||
@ -97,6 +103,9 @@
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
{{ user.role }}
|
||||
</td>
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
{{ user.lastActiveAt ? DateTime.fromSQL(user.lastActiveAt).toRelative() : '-' }}
|
||||
</td>
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
{{ user.position }}
|
||||
</td>
|
||||
@ -150,7 +159,7 @@
|
||||
:href="`/users/${user.id}`"
|
||||
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
|
||||
>
|
||||
<TrashIcon class="mr-2 w-5 h-5 text-red-500" /> Usuń
|
||||
<BanIcon class="mr-2 w-5 h-5 text-red-500" /> Zablokuj
|
||||
</InertiaLink>
|
||||
</MenuItem>
|
||||
</div>
|
||||
@ -201,8 +210,9 @@ import { ref, watch } from 'vue'
|
||||
import { Inertia } from '@inertiajs/inertia'
|
||||
import { debounce } from 'lodash'
|
||||
import { SearchIcon } from '@heroicons/vue/outline'
|
||||
import { DotsVerticalIcon, PencilIcon, TrashIcon, RefreshIcon } from '@heroicons/vue/solid'
|
||||
import { DotsVerticalIcon, PencilIcon, BanIcon, RefreshIcon } from '@heroicons/vue/solid'
|
||||
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
|
||||
import { DateTime } from 'luxon'
|
||||
import Pagination from '@/Shared/Pagination'
|
||||
|
||||
const props = defineProps({
|
||||
|
@ -63,7 +63,7 @@
|
||||
leave-to-class="opacity-0"
|
||||
>
|
||||
<ListboxOptions
|
||||
class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm"
|
||||
class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm"
|
||||
>
|
||||
<ListboxOption
|
||||
v-for="user in users.data"
|
||||
@ -156,7 +156,7 @@
|
||||
leave-from-class="opacity-100"
|
||||
leave-to-class="opacity-0"
|
||||
>
|
||||
<ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm">
|
||||
<ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm">
|
||||
<ListboxOption
|
||||
v-for="vacationType in vacationTypes"
|
||||
:key="vacationType.value"
|
||||
|
@ -19,7 +19,7 @@
|
||||
<button
|
||||
v-for="(status, index) in statuses"
|
||||
:key="index"
|
||||
:class="[status.value === filters.status ? 'text-blumilk-600 font-semibold' : 'hover:bg-blumilk-25 text-gray-700 focus:z-10', 'group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center']"
|
||||
:class="[status.value === filters.status ? 'text-blumilk-600 font-semibold' : 'hover:bg-blumilk-25 text-gray-700 focus:z-10', 'group relative min-w-0 flex-1 overflow-hidden focus:outline-blumilk-500 bg-white py-4 px-4 text-sm font-medium text-center']"
|
||||
@click="form.status = status"
|
||||
>
|
||||
<span>{{ status.name }}</span>
|
||||
@ -140,7 +140,7 @@
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline"
|
||||
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline focus:outline-blumilk-500"
|
||||
>
|
||||
{{ request.name }}
|
||||
</InertiaLink>
|
||||
@ -163,13 +163,13 @@
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="flex justify-around"
|
||||
class="flex justify-around focus:outline-blumilk-500"
|
||||
>
|
||||
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
|
||||
</InertiaLink>
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="absolute inset-0"
|
||||
class="absolute inset-0 focus:outline-blumilk-500"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -219,7 +219,7 @@
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline"
|
||||
class="font-semibold text-blumilk-600 hover:text-blumilk-500 hover:underline focus:outline-blumilk-500"
|
||||
>
|
||||
{{ request.name }}
|
||||
</InertiaLink>
|
||||
@ -257,13 +257,13 @@
|
||||
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="flex justify-around"
|
||||
class="flex justify-around focus:outline-blumilk-500"
|
||||
>
|
||||
<ChevronRightIcon class="block w-6 h-6 fill-blumilk-500" />
|
||||
</InertiaLink>
|
||||
<InertiaLink
|
||||
:href="`/vacation/requests/${request.id}`"
|
||||
class="absolute inset-0"
|
||||
class="absolute inset-0 focus:outline-blumilk-500"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
65
resources/js/Shared/InertiaLink.js
Normal file
65
resources/js/Shared/InertiaLink.js
Normal file
@ -0,0 +1,65 @@
|
||||
import { h, ref } from 'vue'
|
||||
import { Inertia, mergeDataIntoQueryString, shouldIntercept } from '@inertiajs/inertia'
|
||||
|
||||
export default {
|
||||
name: 'InertiaLink',
|
||||
props: {
|
||||
as: {
|
||||
type: String,
|
||||
default: 'a',
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
href: {
|
||||
type: String,
|
||||
},
|
||||
method: {
|
||||
type: String,
|
||||
default: 'get',
|
||||
},
|
||||
replace: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
preserveScroll: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
preserveState: {
|
||||
type: Boolean,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
setup(props, { slots, attrs }) {
|
||||
const processing = ref(false)
|
||||
|
||||
return props => {
|
||||
const as = props.as.toLowerCase()
|
||||
const method = props.method.toLowerCase()
|
||||
const [href, data] = mergeDataIntoQueryString(method, props.href || '', props.data, 'brackets')
|
||||
|
||||
return h(props.as, {
|
||||
...attrs,
|
||||
...as === 'a' ? { href } : {},
|
||||
onClick: (event) => {
|
||||
if (shouldIntercept(event)) {
|
||||
event.preventDefault()
|
||||
|
||||
Inertia.visit(href, {
|
||||
data: data,
|
||||
method: method,
|
||||
replace: props.replace,
|
||||
preserveScroll: props.preserveScroll,
|
||||
preserveState: props.preserveState ?? (method !== 'get'),
|
||||
onBefore: () => !processing.value,
|
||||
onStart: () => processing.value = true,
|
||||
onFinish: () => processing.value = false,
|
||||
})
|
||||
}
|
||||
},
|
||||
}, slots)
|
||||
}
|
||||
},
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
<MainMenu
|
||||
:auth="auth"
|
||||
:years="years"
|
||||
:vacation-requests-count="vacationRequestsCount"
|
||||
/>
|
||||
<main class="flex flex-col flex-1 py-8 lg:ml-64">
|
||||
<div class="lg:px-4">
|
||||
@ -21,6 +22,7 @@ const props = defineProps({
|
||||
flash: Object,
|
||||
auth: Object,
|
||||
years: Object,
|
||||
vacationRequestsCount: Number,
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
|
@ -71,12 +71,12 @@
|
||||
</InertiaLink>
|
||||
</div>
|
||||
<div class="pt-3 mt-3">
|
||||
<div class="px-2 space-y-1">
|
||||
<div class="py-1 px-2 space-y-1">
|
||||
<InertiaLink
|
||||
v-for="item in navigation"
|
||||
:key="item.name"
|
||||
:href="item.href"
|
||||
:class="[$page.component === item.component ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-base font-medium rounded-md']"
|
||||
:class="[$page.component.startsWith(item.section) ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-base font-medium rounded-md']"
|
||||
@click="sidebarOpen = false;"
|
||||
>
|
||||
<component
|
||||
@ -84,6 +84,12 @@
|
||||
class="shrink-0 mr-4 w-6 h-6 text-blumilk-200"
|
||||
/>
|
||||
{{ item.name }}
|
||||
<span
|
||||
v-if="item.badge"
|
||||
class="py-0.5 px-2.5 ml-3 text-xs font-semibold text-gray-600 bg-gray-100 rounded-full 2xl:inline-block"
|
||||
>
|
||||
{{ item.badge }}
|
||||
</span>
|
||||
</InertiaLink>
|
||||
</div>
|
||||
</div>
|
||||
@ -107,7 +113,7 @@
|
||||
<nav class="flex overflow-y-auto flex-col flex-1 px-2 mt-5 divide-y divide-blumilk-800">
|
||||
<InertiaLink
|
||||
href="/"
|
||||
:class="[$page.component === 'Dashboard' ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']"
|
||||
:class="[$page.component === 'Dashboard' ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 mt-1 text-sm leading-6 font-medium rounded-md']"
|
||||
>
|
||||
<HomeIcon class="shrink-0 mr-4 w-6 h-6 text-blumilk-200" />
|
||||
Strona główna
|
||||
@ -117,13 +123,19 @@
|
||||
v-for="item in navigation"
|
||||
:key="item.name"
|
||||
:href="item.href"
|
||||
:class="[$page.component === item.component ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']"
|
||||
:class="[$page.component.startsWith(item.section) ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']"
|
||||
>
|
||||
<component
|
||||
:is="item.icon"
|
||||
class="shrink-0 mr-4 w-6 h-6 text-blumilk-200"
|
||||
/>
|
||||
{{ item.name }}
|
||||
<span
|
||||
v-if="item.badge"
|
||||
class="py-0.5 px-2.5 ml-3 text-xs font-semibold text-gray-600 bg-gray-100 rounded-full 2xl:inline-block"
|
||||
>
|
||||
{{ item.badge }}
|
||||
</span>
|
||||
</InertiaLink>
|
||||
</div>
|
||||
</nav>
|
||||
@ -152,7 +164,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<MenuButton
|
||||
class="inline-flex justify-center py-2 px-4 w-full text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
|
||||
class="inline-flex justify-center py-2 px-4 w-full text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blumilk-500 shadow-sm"
|
||||
>
|
||||
{{ years.selected.year }}
|
||||
<ChevronDownIcon class="-mr-1 ml-2 w-5 h-5" />
|
||||
@ -288,6 +300,7 @@ import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/solid'
|
||||
const props = defineProps({
|
||||
auth: Object,
|
||||
years: Object,
|
||||
vacationRequestsCount: Number,
|
||||
})
|
||||
|
||||
const sidebarOpen = ref(false)
|
||||
@ -297,42 +310,43 @@ const navigation = computed(() =>
|
||||
{
|
||||
name: 'Moje wnioski',
|
||||
href: '/vacation/requests/me',
|
||||
component: 'VacationRequest/Index',
|
||||
section: 'VacationRequest',
|
||||
icon: DocumentTextIcon,
|
||||
can: true,
|
||||
can: !props.auth.can.listAllVacationRequests,
|
||||
},
|
||||
{
|
||||
name: 'Lista wniosków',
|
||||
href: '/vacation/requests',
|
||||
component: 'VacationRequest/IndexForApprovers',
|
||||
section: 'VacationRequest',
|
||||
icon: CollectionIcon,
|
||||
can: props.auth.can.listAllVacationRequests,
|
||||
badge: props.vacationRequestsCount,
|
||||
},
|
||||
{
|
||||
name: 'Kalendarz urlopów',
|
||||
href: '/vacation/calendar',
|
||||
component: 'Calendar',
|
||||
section: 'Calendar',
|
||||
icon: CalendarIcon,
|
||||
can: true,
|
||||
},
|
||||
{
|
||||
name: 'Wykorzystanie urlopu',
|
||||
href: '/vacation/monthly-usage',
|
||||
component: 'MonthlyUsage',
|
||||
section: 'MonthlyUsage',
|
||||
icon: AdjustmentsIcon,
|
||||
can: props.auth.can.listMonthlyUsage,
|
||||
},
|
||||
{
|
||||
name: 'Dni wolne',
|
||||
href: '/holidays',
|
||||
component: 'Holidays/Index',
|
||||
section: 'Holidays/',
|
||||
icon: StarIcon,
|
||||
can: true,
|
||||
},
|
||||
{
|
||||
name: 'Limity urlopów',
|
||||
href: '/vacation/limits',
|
||||
component: 'VacationLimits',
|
||||
section: 'VacationLimits',
|
||||
icon: SunIcon,
|
||||
can: props.auth.can.manageVacationLimits,
|
||||
},
|
||||
@ -340,14 +354,14 @@ const navigation = computed(() =>
|
||||
|
||||
name: 'Podsumowanie roczne',
|
||||
href: '/vacation/annual-summary',
|
||||
component: 'AnnualSummary',
|
||||
section: 'AnnualSummary',
|
||||
icon: ClipboardListIcon,
|
||||
can: true,
|
||||
},
|
||||
{
|
||||
name: 'Użytkownicy',
|
||||
href: '/users',
|
||||
component: 'Users/Index',
|
||||
section: 'Users/',
|
||||
icon: UserGroupIcon,
|
||||
can: props.auth.can.manageUsers,
|
||||
},
|
||||
|
@ -53,6 +53,7 @@
|
||||
|
||||
<script setup>
|
||||
import useVacationTypeInfo from '@/Composables/vacationTypeInfo'
|
||||
import Status from '@/Shared/Status'
|
||||
|
||||
defineProps({
|
||||
requests: Object,
|
||||
|
@ -1,10 +1,12 @@
|
||||
import { createApp, h } from 'vue'
|
||||
import { createInertiaApp, Head, Link } from '@inertiajs/inertia-vue3'
|
||||
import { createInertiaApp, Head } from '@inertiajs/inertia-vue3'
|
||||
import { InertiaProgress } from '@inertiajs/progress'
|
||||
import AppLayout from '@/Shared/Layout/AppLayout'
|
||||
import Flatpickr from 'flatpickr'
|
||||
import { Settings } from 'luxon'
|
||||
import { Polish } from 'flatpickr/dist/l10n/pl.js'
|
||||
import Toast from 'vue-toastification'
|
||||
import InertiaLink from '@/Shared/InertiaLink'
|
||||
|
||||
createInertiaApp({
|
||||
resolve: name => {
|
||||
@ -23,7 +25,7 @@ createInertiaApp({
|
||||
timeout: 3000,
|
||||
pauseOnFocusLoss: false,
|
||||
})
|
||||
.component('InertiaLink', Link)
|
||||
.component('InertiaLink', InertiaLink)
|
||||
.component('InertiaHead', Head)
|
||||
.mount(el)
|
||||
},
|
||||
@ -44,3 +46,4 @@ Flatpickr.setDefaults({
|
||||
disableMobile: true,
|
||||
})
|
||||
|
||||
Settings.defaultLocale = 'pl'
|
||||
|
@ -59,12 +59,12 @@
|
||||
"Vacation type: :type": "Rodzaj wniosku: :type",
|
||||
"From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)",
|
||||
"Click here for details": "Kliknij, aby zobaczyć szczegóły",
|
||||
"Vacation request :title is waiting for your technical approval": "Wniosek urlopowy :title czeka na akceptacje techniczną",
|
||||
"Vacation request :title is waiting for your administrative approval": "Wniosek urlopowy :title czeka na akceptacje administracyjną",
|
||||
"The vacation request :title from user :requester is waiting for your technical approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację techniczną.",
|
||||
"The vacation request :title from user :requester is waiting for your administrative approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację administracyjną.",
|
||||
"Vacation request :title is waiting for your technical approval": "Wniosek urlopowy :title czeka na akceptację techniczną",
|
||||
"Vacation request :title is waiting for your administrative approval": "Wniosek urlopowy :title czeka na akceptację administracyjną",
|
||||
"The vacation request :title from user :requester is waiting for your technical approval.": "Wniosek urlopowy :title użytkownika :requester czeka na Twoją akceptację techniczną.",
|
||||
"The vacation request :title from user :requester is waiting for your administrative approval.": "Wniosek urlopowy :title użytkownika :requester czeka na Twoją akceptację administracyjną.",
|
||||
"Vacation request :title has been :status": "Wniosek urlopowy :title został :status",
|
||||
"The vacation request :title for user :requester has been :status.": "Wniosek urlopowy :title od użytkownika :requester został :status.",
|
||||
"The vacation request :title from user :requester has been :status.": "Wniosek urlopowy :title użytkownika :requester został :status.",
|
||||
"Vacation request :title has been created on your behalf": "Wniosek urlopowy :title został utworzony w Twoim imieniu",
|
||||
"The vacation request :title has been created correctly by user :creator on your behalf in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title w Twoim imieniu przez użytkownika :creator."
|
||||
}
|
||||
|
@ -54,14 +54,14 @@
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ $vacationRequest->user->fullName }}</td>
|
||||
<td>{{ $vacationRequest->user->profile->fullName }}</td>
|
||||
<td>Legnica, {{ $vacationRequest->created_at->format("d.m.Y") }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="helper-text">imię i nazwisko</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ $vacationRequest->user->position }}</td>
|
||||
<td>{{ $vacationRequest->user->profile->position }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="helper-text">stanowisko</td>
|
||||
|
@ -15,18 +15,26 @@ use Toby\Infrastructure\Http\Controllers\UserController;
|
||||
use Toby\Infrastructure\Http\Controllers\VacationCalendarController;
|
||||
use Toby\Infrastructure\Http\Controllers\VacationLimitController;
|
||||
use Toby\Infrastructure\Http\Controllers\VacationRequestController;
|
||||
use Toby\Infrastructure\Http\Middleware\TrackUserLastActivity;
|
||||
|
||||
Route::middleware("auth")->group(function (): void {
|
||||
Route::middleware(["auth", TrackUserLastActivity::class])->group(function (): void {
|
||||
Route::get("/", DashboardController::class)
|
||||
->name("dashboard");
|
||||
Route::post("/logout", LogoutController::class);
|
||||
|
||||
Route::resource("users", UserController::class);
|
||||
Route::resource("users", UserController::class)
|
||||
->except("show")
|
||||
->whereNumber("user");
|
||||
Route::post("/users/{user}/restore", [UserController::class, "restore"])
|
||||
->whereNumber("user")
|
||||
->withTrashed();
|
||||
|
||||
Route::resource("holidays", HolidayController::class);
|
||||
Route::resource("holidays", HolidayController::class)
|
||||
->except("show")
|
||||
->whereNumber("holiday");
|
||||
|
||||
Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
|
||||
->whereNumber("yearPeriod")
|
||||
->name("year-periods.select");
|
||||
|
||||
Route::prefix("/vacation")->as("vacation.")->group(function (): void {
|
||||
@ -49,23 +57,30 @@ Route::middleware("auth")->group(function (): void {
|
||||
->name("requests.create");
|
||||
Route::post("/requests", [VacationRequestController::class, "store"])
|
||||
->name("requests.store");
|
||||
|
||||
Route::get("/requests/{vacationRequest}", [VacationRequestController::class, "show"])
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.show");
|
||||
Route::get("/requests/{vacationRequest}/download", [VacationRequestController::class, "download"])
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.download");
|
||||
Route::post("/requests/{vacationRequest}/reject", [VacationRequestController::class, "reject"])
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.reject");
|
||||
Route::post("/requests/{vacationRequest}/cancel", [VacationRequestController::class, "cancel"])
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.cancel");
|
||||
Route::post("/requests/{vacationRequest}/accept-as-technical", [VacationRequestController::class, "acceptAsTechnical"], )
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.accept-as-technical");
|
||||
Route::post("/requests/{vacationRequest}/accept-as-administrative", [VacationRequestController::class, "acceptAsAdministrative"], )
|
||||
->whereNumber("vacationRequest")
|
||||
->name("requests.accept-as-administrative");
|
||||
|
||||
Route::get("/monthly-usage", MonthlyUsageController::class)
|
||||
->name("monthly-usage");
|
||||
Route::get("/annual-summary", AnnualSummaryController::class)
|
||||
->name("annual-summmary");
|
||||
->name("annual-summary");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -25,6 +25,7 @@ class HolidayTest extends FeatureTestCase
|
||||
|
||||
$this->actingAs($user)
|
||||
->get("/holidays")
|
||||
->assertOk()
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
->component("Holidays/Index")
|
||||
|
38
tests/Feature/TrackLastActivityMiddlewareTest.php
Normal file
38
tests/Feature/TrackLastActivityMiddlewareTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class TrackLastActivityMiddlewareTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testLastActiveAtFieldIsUpdatedWhenUserDidRequest(): void
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
||||
Carbon::setTestNow($now);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertDatabaseHas("users", [
|
||||
"id" => $user->id,
|
||||
"last_active_at" => null,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get("/")
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas("users", [
|
||||
"id" => $user->id,
|
||||
"last_active_at" => $now,
|
||||
]);
|
||||
}
|
||||
}
|
@ -34,25 +34,30 @@ class UserTest extends FeatureTestCase
|
||||
|
||||
public function testAdminCanSearchUsersList(): void
|
||||
{
|
||||
User::factory([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User1",
|
||||
])->create();
|
||||
User::factory()
|
||||
->hasprofile([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User1",
|
||||
])
|
||||
->create();
|
||||
|
||||
User::factory([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User2",
|
||||
])->create();
|
||||
User::factory()
|
||||
->hasProfile([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User2",
|
||||
])->create();
|
||||
|
||||
User::factory([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User3",
|
||||
])->create();
|
||||
User::factory()
|
||||
->hasProfile([
|
||||
"first_name" => "Test",
|
||||
"last_name" => "User3",
|
||||
])->create();
|
||||
|
||||
$admin = User::factory([
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
])->admin()->create();
|
||||
$admin = User::factory()
|
||||
->hasProfile([
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
])->admin()->create();
|
||||
|
||||
$this->assertDatabaseCount("users", 4);
|
||||
|
||||
@ -99,11 +104,20 @@ class UserTest extends FeatureTestCase
|
||||
])
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$user = User::query()
|
||||
->where("email", "john.doe@example.com")
|
||||
->first();
|
||||
|
||||
$this->assertDatabaseHas("users", [
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
"id" => $user->id,
|
||||
"email" => "john.doe@example.com",
|
||||
"role" => Role::Employee->value,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas("profiles", [
|
||||
"user_id" => $user->id,
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
"position" => "Test position",
|
||||
"employment_form" => EmploymentForm::B2bContract->value,
|
||||
"employment_date" => Carbon::now()->toDateString(),
|
||||
@ -118,12 +132,12 @@ class UserTest extends FeatureTestCase
|
||||
|
||||
Carbon::setTestNow();
|
||||
|
||||
$this->assertDatabaseHas("users", [
|
||||
"first_name" => $user->first_name,
|
||||
"last_name" => $user->last_name,
|
||||
"email" => $user->email,
|
||||
"employment_form" => $user->employment_form->value,
|
||||
"employment_date" => $user->employment_date->toDateString(),
|
||||
$this->assertDatabaseHas("profiles", [
|
||||
"user_id" => $user->id,
|
||||
"first_name" => $user->profile->first_name,
|
||||
"last_name" => $user->profile->last_name,
|
||||
"employment_form" => $user->profile->employment_form->value,
|
||||
"employment_date" => $user->profile->employment_date->toDateString(),
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)
|
||||
@ -139,10 +153,15 @@ class UserTest extends FeatureTestCase
|
||||
->assertSessionHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas("users", [
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
"id" => $user->id,
|
||||
"email" => "john.doe@example.com",
|
||||
"role" => Role::Employee->value,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas("profiles", [
|
||||
"user_id" => $user->id,
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
"position" => "Test position",
|
||||
"employment_form" => EmploymentForm::B2bContract->value,
|
||||
"employment_date" => Carbon::now()->toDateString(),
|
||||
|
@ -17,7 +17,8 @@ class VacationCalendarTest extends FeatureTestCase
|
||||
{
|
||||
$administrativeApprover = User::factory()->administrativeApprover()->create();
|
||||
|
||||
User::factory(["employment_form" => EmploymentForm::EmploymentContract])
|
||||
User::factory()
|
||||
->hasProfile(["employment_form" => EmploymentForm::EmploymentContract])
|
||||
->count(10)
|
||||
->create();
|
||||
|
||||
|
@ -9,6 +9,7 @@ use Tests\TestCase;
|
||||
use Tests\Traits\InteractsWithYearPeriods;
|
||||
use Toby\Domain\Actions\CreateUserAction;
|
||||
use Toby\Domain\Actions\CreateYearPeriodAction;
|
||||
use Toby\Eloquent\Models\Profile;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
@ -31,9 +32,10 @@ class VacationLimitTest extends TestCase
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
$createUserAction = $this->app->make(CreateUserAction::class);
|
||||
|
||||
$dumpData = User::factory()->raw();
|
||||
$dumpUserData = User::factory()->raw();
|
||||
$dumpProfileData = Profile::factory()->raw();
|
||||
|
||||
$user = $createUserAction->execute($dumpData);
|
||||
$user = $createUserAction->execute($dumpUserData, $dumpProfileData);
|
||||
|
||||
$this->assertDatabaseCount("vacation_limits", 1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user