This commit is contained in:
EwelinaLasowy 2022-04-13 11:40:44 +02:00
parent 4af0482a93
commit 2f27c83411
9 changed files with 310 additions and 1 deletions

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Models;
use Database\Factories\KeyFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $id
* @property User $owner
* @property User $previousOwner
*/
class Key extends Model
{
use HasFactory;
protected $guarded = [];
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, "owner_id");
}
public function previousOwner(): BelongsTo
{
return $this->belongsTo(User::class, "previous_owner_id");
}
protected static function newFactory(): KeyFactory
{
return KeyFactory::new();
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Response;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\Key;
use Toby\Infrastructure\Http\Resources\KeyResource;
class KeysController extends Controller
{
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
{
$keys = Key::query()->get();
return inertia("Keys/Index", [
"keys" => KeyResource::collection($keys),
]);
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class KeyResource extends JsonResource
{
public static $wrap = null;
public function toArray($request): array
{
return [
"id" => $this->id,
"owner" => new UserResource($this->owner),
"previousOwner" => new UserResource($this->previousOwner),
"updatedAt" => $this->updated_at->toDatetimeString(),
];
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Eloquent\Models\Key;
use Toby\Eloquent\Models\User;
class KeyFactory extends Factory
{
protected $model = Key::class;
public function definition(): array
{
return [
"owner_id" => User::factory(),
"previous_owner_id" => User::factory(),
];
}
}

View File

@ -0,0 +1,25 @@
<?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("keys", function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(User::class, "owner_id")->constrained("users")->cascadeOnDelete();
$table->foreignIdFor(User::class, "previous_owner_id")->constrained("users")->cascadeOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists("keys");
}
};

View File

@ -8,6 +8,7 @@ use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Toby\Domain\PolishHolidaysRetriever; use Toby\Domain\PolishHolidaysRetriever;
use Toby\Domain\VacationDaysCalculator; use Toby\Domain\VacationDaysCalculator;
use Toby\Eloquent\Models\Key;
use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\VacationLimit; use Toby\Eloquent\Models\VacationLimit;
use Toby\Eloquent\Models\VacationRequest; use Toby\Eloquent\Models\VacationRequest;
@ -85,5 +86,12 @@ class DatabaseSeeder extends Seeder
}) })
->create(); ->create();
} }
foreach ($users as $user) {
Key::factory()
->for($user, "owner")
->for($user, "previousOwner")
->create();
}
} }
} }

View File

@ -0,0 +1,162 @@
<template>
<InertiaHead title="Klucze" />
<div class="bg-white shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div>
<h2 class="text-lg font-medium leading-6 text-gray-900">
Klucze
</h2>
</div>
<div v-if="true">
<InertiaLink
href="#"
class="inline-flex items-center py-3 px-4 text-sm font-medium leading-4 text-white bg-blumilk-600 hover:bg-blumilk-700 rounded-md border border-transparent focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 shadow-sm"
>
Dodaj klucz
</InertiaLink>
</div>
</div>
<div class="border-t border-gray-200">
<div class="overflow-auto xl:overflow-visible">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Nazwa
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Właściciel
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Od kiedy
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Od kogo
</th>
<th
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
/>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-100">
<tr
v-for="key in keys.data"
:key="key.id"
class="hover:bg-blumilk-25"
>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
Klucz nr {{ key.id }}
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ key.owner.name }}
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ key.updatedAt }}
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ key.previousOwner.name }}
</td>
<td class="p-4 text-sm text-right text-gray-500 whitespace-nowrap">
<Menu
v-if="true"
as="div"
class="inline-block relative text-left"
>
<MenuButton class="flex items-center text-gray-400 hover:text-gray-600 rounded-full focus:outline-none focus:ring-2 focus:ring-blumilk-500 focus:ring-offset-2 focus:ring-offset-gray-100">
<DotsVerticalIcon
class="w-5 h-5"
aria-hidden="true"
/>
</MenuButton>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems class="absolute right-0 z-10 mt-2 w-56 bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg origin-top-right">
<div class="py-1">
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
:href="`#`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
>
<DominoMaskIcon class="mr-2 w-5 h-5 text-purple-500" /> Zabierz klucze
</InertiaLink>
</MenuItem>
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
:href="`#`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
>
<HandshakeIcon class="mr-2 w-5 h-5 text-emerald-500" /> Daj klucze
</InertiaLink>
</MenuItem>
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
as="button"
method="delete"
:preserve-scroll="true"
:href="`#`"
: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ń
</InertiaLink>
</MenuItem>
</div>
</MenuItems>
</transition>
</Menu>
</td>
</tr>
<tr v-if="!keys.data.length">
<td
colspan="100%"
class="py-4 text-xl leading-5 text-center text-gray-700"
>
Brak danych
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup>
import { DotsVerticalIcon, TrashIcon } from '@heroicons/vue/solid'
import DominoMaskIcon from 'vue-material-design-icons/DominoMask.vue'
import HandshakeIcon from 'vue-material-design-icons/Handshake.vue'
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
defineProps({
keys: Object,
can: Object,
})
</script>s

View File

@ -282,6 +282,7 @@ import {
CalendarIcon, CalendarIcon,
DocumentTextIcon, DocumentTextIcon,
AdjustmentsIcon, AdjustmentsIcon,
KeyIcon,
} from '@heroicons/vue/outline' } from '@heroicons/vue/outline'
import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/solid' import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/solid'
@ -337,7 +338,6 @@ const navigation = computed(() =>
can: props.auth.can.manageVacationLimits, can: props.auth.can.manageVacationLimits,
}, },
{ {
name: 'Podsumowanie roczne', name: 'Podsumowanie roczne',
href: '/vacation/annual-summary', href: '/vacation/annual-summary',
component: 'AnnualSummary', component: 'AnnualSummary',
@ -351,5 +351,13 @@ const navigation = computed(() =>
icon: UserGroupIcon, icon: UserGroupIcon,
can: props.auth.can.manageUsers, can: props.auth.can.manageUsers,
}, },
{
name: 'Klucze',
href: '/keys',
component: 'Keys/Index',
icon: KeyIcon,
can: true,
},
].filter(item => item.can)) ].filter(item => item.can))
</script> </script>

View File

@ -7,6 +7,7 @@ use Toby\Infrastructure\Http\Controllers\AnnualSummaryController;
use Toby\Infrastructure\Http\Controllers\DashboardController; use Toby\Infrastructure\Http\Controllers\DashboardController;
use Toby\Infrastructure\Http\Controllers\GoogleController; use Toby\Infrastructure\Http\Controllers\GoogleController;
use Toby\Infrastructure\Http\Controllers\HolidayController; use Toby\Infrastructure\Http\Controllers\HolidayController;
use Toby\Infrastructure\Http\Controllers\KeysController;
use Toby\Infrastructure\Http\Controllers\LogoutController; use Toby\Infrastructure\Http\Controllers\LogoutController;
use Toby\Infrastructure\Http\Controllers\MonthlyUsageController; use Toby\Infrastructure\Http\Controllers\MonthlyUsageController;
use Toby\Infrastructure\Http\Controllers\SelectYearPeriodController; use Toby\Infrastructure\Http\Controllers\SelectYearPeriodController;
@ -28,6 +29,7 @@ Route::middleware("auth")->group(function (): void {
Route::resource("holidays", HolidayController::class); Route::resource("holidays", HolidayController::class);
Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class) Route::post("year-periods/{yearPeriod}/select", SelectYearPeriodController::class)
->name("year-periods.select"); ->name("year-periods.select");
Route::resource("keys", KeysController::class);
Route::prefix("/vacation")->as("vacation.")->group(function (): void { Route::prefix("/vacation")->as("vacation.")->group(function (): void {
Route::get("/limits", [VacationLimitController::class, "edit"]) Route::get("/limits", [VacationLimitController::class, "edit"])