Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlencki committed Oct 10, 2023
1 parent 2775b95 commit 45ddfcf
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 9 deletions.
10 changes: 7 additions & 3 deletions app/Eloquent/Models/EquipmentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ public function scopeLabels(Builder $query, ?array $labels): Builder
return $query;
}

foreach ($labels as $label) {
$query->orWhereJsonContains("labels", $label);
}
$query->where(function (Builder $query) use ($labels): Builder {
foreach ($labels as $label) {
$query->orWhereJsonContains("labels", $label);
}

return $query;
});

return $query;
}
Expand Down
40 changes: 39 additions & 1 deletion app/Infrastructure/Http/Controllers/EquipmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,61 @@ class EquipmentController extends Controller
/**
* @throws AuthorizationException
*/
public function index(Request $request): Response
public function index(Request $request): RedirectResponse|Response
{
$this->authorize("manageEquipment");

$searchQuery = $request->query("search");

$equipmentItems = EquipmentItem::query()
->search($searchQuery)
->when(
$request->has("assignee"),
fn($query) => $query->where("assignee_id", $request->query("assignee")),
)
->labels($request->query("labels"))
->orderBy("id_number")
->paginate()
->withQueryString();

$users = User::query()
->orderByProfileField("last_name")
->orderByProfileField("first_name")
->get();

return inertia("Equipment/Index", [
"equipmentItems" => EquipmentItemResource::collection($equipmentItems),
"labels" => EquipmentLabel::query()->pluck("name"),
"users" => SimpleUserResource::collection($users),
"filters" => [
"search" => $searchQuery,
"labels" => $request->query("labels"),
"assignee" => (int)$request->query("assignee"),
],
]);
}

/**
* @throws AuthorizationException
*/
public function indexForEmployee(Request $request): RedirectResponse|Response
{
$searchQuery = $request->query("search");

$equipmentItems = EquipmentItem::query()
->search($searchQuery)
->labels($request->query("labels"))
->where("assignee_id", $request->user()->id)
->orderBy("id_number")
->paginate()
->withQueryString();

return inertia("Equipment/IndexForEmployee", [
"equipmentItems" => EquipmentItemResource::collection($equipmentItems),
"labels" => EquipmentLabel::query()->pluck("name"),
"filters" => [
"search" => $searchQuery,
"labels" => $request->query("labels"),
],
]);
}
Expand Down
112 changes: 108 additions & 4 deletions resources/js/Pages/Equipment/Index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script setup>
import EmptyState from '@/Shared/Feedbacks/EmptyState.vue'
import {
Listbox,
ListboxButton, ListboxLabel,

Check failure on line 5 in resources/js/Pages/Equipment/Index.vue

View workflow job for this annotation

GitHub Actions / Test & lint JS stuff

'ListboxLabel' is defined but never used
ListboxOption,
ListboxOptions,
Menu,
MenuButton,
MenuItem,
Expand All @@ -12,24 +16,34 @@ import { reactive, watch } from 'vue'
import { debounce } from 'lodash'
import { Inertia } from '@inertiajs/inertia'
import MultipleCombobox from '@/Shared/Forms/MultipleCombobox.vue'
import { EllipsisVerticalIcon, PencilIcon, TrashIcon, CheckIcon, XMarkIcon } from '@heroicons/vue/24/solid'
import {
EllipsisVerticalIcon,
PencilIcon,
TrashIcon,
CheckIcon,
XMarkIcon,
ChevronUpDownIcon,
} from '@heroicons/vue/24/solid'
const props = defineProps({
auth: Object,
equipmentItems: Object,
labels: Array,
filters: Object,
users: Array,
})
const form = reactive({
search: props.filters.search,
labels: [],
labels: props.filters.labels ?? [],
assignee: props.users.data.find(user => user.id === props.filters.assignee) ?? null,
})
watch(form, debounce(() => {
Inertia.get('/equipment-items', {
search: form.search,
labels: form.labels,
assignee: form.assignee?.id,
}, {
preserveState: true,
replace: true,
Expand Down Expand Up @@ -68,15 +82,15 @@ watch(form, debounce(() => {
</div>
</div>
<div class="border-t border-gray-200">
<div class="flex-1 items-end grid grid-cols-1 p-4 md:grid-cols-3 gap-4">
<div class="items-end grid grid-cols-1 p-4 md:grid-cols-3 gap-4">
<div class="relative">
<div class="pointer-events-none absolute inset-y-0 left-0 pl-3 flex items-center">
<MagnifyingGlassIcon class="w-5 h-5 text-gray-400" />
</div>
<input
v-model.trim="form.search"
type="search"
class="inline-block align-baseline py-2 pr-3 pl-10 w-full max-w-lg sm:text-sm placeholder:text-gray-500 focus:text-gray-900 focus:placeholder:text-gray-400 bg-white rounded-md border border-gray-300 focus:border-blumilk-500 focus:outline-none focus:ring-1 focus:ring-blumilk-500 sm:text-sm"
class="inline-block align-baseline py-2 pr-3 pl-10 w-full placeholder:text-gray-500 focus:text-gray-900 focus:placeholder:text-gray-400 bg-white rounded-md border border-gray-300 focus:border-blumilk-500 focus:outline-none focus:ring-1 focus:ring-blumilk-500 sm:text-sm"
placeholder="Szukaj"
>
</div>
Expand All @@ -85,6 +99,96 @@ watch(form, debounce(() => {
placeholder="Etykiety"
:items="labels"
/>
<Listbox
v-model="form.assignee"
as="div"
>
<div class="relative mt-1 sm:mt-0">
<ListboxButton
class="relative py-2 pr-10 pl-3 w-full h-10 text-left bg-white rounded-md border border-gray-300 focus:border-blumilk-500 focus:outline-none focus:ring-1 focus:ring-blumilk-500 shadow-sm cursor-default sm:text-sm placeholder:text-gray-500 focus:text-gray-800 focus:placeholder:text-gray-400 "
>
<span
v-if="form.assignee === null"
class="text-gray-500"
>
Przydzielona osoba
</span>
<span
v-else
class="flex items-center"
>
<img
:src="form.assignee.avatar"
class="shrink-0 w-6 h-6 rounded-full"
>
<span class="block ml-3 truncate">{{ form.assignee.name }}</span>
</span>
<span class="flex absolute inset-y-0 right-0 items-center pr-2 pointer-events-none">
<ChevronUpDownIcon class="w-5 h-5 text-gray-400" />
</span>
</ListboxButton>
<transition
leave-active-class="transition ease-in duration-100"
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 ring-black ring-opacity-5 shadow-lg sm:text-sm"
>
<ListboxOption
v-for="user in users.data"
:key="user.id"
v-slot="{ active }"
as="template"
:value="user"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"
>
<div class="flex items-center">
<img
:src="user.avatar"
class="shrink-0 w-6 h-6 rounded-full"
>
<span
:class="[form.assignee?.id === user.id ? 'font-semibold' : 'font-normal', 'ml-3 block truncate']"
>
{{ user.name }}
</span>
</div>
<span
v-if="form.assignee?.id === user.id"
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
>
<CheckIcon class="w-5 h-5" />
</span>
</li>
</ListboxOption>
<ListboxOption
v-slot="{ active }"
as="template"
:value="null"
>
<li
:class="[active ? 'bg-gray-100' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']"
>
<div class="flex items-center">
Brak
</div>
<span
v-if="form.assignee === null"
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
>
<CheckIcon class="w-5 h-5" />
</span>
</li>
</ListboxOption>
</ListboxOptions>
</transition>
</div>
</Listbox>
</div>
<div class="overflow-auto xl:overflow-visible">
<table class="min-w-full divide-y divide-gray-200">
Expand Down
Loading

0 comments on commit 45ddfcf

Please sign in to comment.