Skip to content

Commit

Permalink
#354 - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
EwelinaSkrzypacz committed Oct 5, 2023
1 parent 86f02dd commit 1e9cab5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
19 changes: 14 additions & 5 deletions app/Eloquent/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function scopeSearch(Builder $query, ?string $text): Builder
);
}

public function scopeOrderByProfileField(Builder $query, string $field, string $direction = 'asc'): Builder
public function scopeOrderByProfileField(Builder $query, string $field, string $direction = "asc"): Builder
{
$profileQuery = Profile::query()->select($field)->whereColumn("users.id", "profiles.user_id");

Expand Down Expand Up @@ -163,16 +163,25 @@ public function routeNotificationForSlack()
public function scopeSortForEmployeesMilestones(Builder $query, ?string $sort): Builder
{
return match ($sort) {
// "birthday-asc" TO DO
// "birthday-desc" TO DO
"seniority-asc" => $query->orderByProfileField('employment_date', 'asc'),
"seniority-desc" => $query->orderByProfileField('employment_date', 'desc'),
// "birthday-asc" TO DO
// "birthday-desc" TO DO
"seniority-asc" => $query->orderByProfileField("employment_date", "asc"),
"seniority-desc" => $query->orderByProfileField("employment_date", "desc"),
default => $query
->orderByProfileField("last_name")
->orderByProfileField("first_name"),
};
}

public function isWorkAnniversaryToday(): bool
{
$today = Carbon::now();

$workAnniversary = $this->profile->employment_date->setYear($today->year);

return $workAnniversary->isToday();
}

protected static function newFactory(): UserFactory
{
return UserFactory::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function toArray($request): array
{
$upcomingBirthday = $this->upcomingBirthday();
$seniority = $this->seniority();
$isSeniorityAnniversaryToday = $this->isWorkAnniversaryToday();

return [
"user" => new SimpleUserResource($this->resource),
Expand All @@ -27,6 +28,7 @@ public function toArray($request): array
["options" => CarbonInterface::ONE_DAY_WORDS, "syntax" => CarbonInterface::DIFF_RELATIVE_TO_NOW],
),
"seniorityDisplayDate" => $seniority,
"isWorkAnniversaryToday" => $isSeniorityAnniversaryToday,
];
}
}
38 changes: 24 additions & 14 deletions resources/js/Pages/EmployeesMilestones.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup>
import Pagination from '@/Shared/Pagination.vue'
import EmptyState from '@/Shared/Feedbacks/EmptyState.vue'
import { MagnifyingGlassIcon, ChevronDownIcon } from '@heroicons/vue/24/outline'
import { reactive, watch } from 'vue'
import { debounce } from 'lodash'
import { Inertia } from '@inertiajs/inertia'
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/vue/24/solid'
import { Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions } from '@headlessui/vue'
import {MagnifyingGlassIcon, ChevronDownIcon} from '@heroicons/vue/24/outline'
import {CalendarDaysIcon} from '@heroicons/vue/24/solid'
import {reactive, watch} from 'vue'
import {debounce} from 'lodash'
import {Inertia} from '@inertiajs/inertia'
import {CheckIcon, ChevronUpDownIcon} from '@heroicons/vue/24/solid'
import {Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions} from '@headlessui/vue'
const sortOptions = [
{
Expand Down Expand Up @@ -54,7 +55,7 @@ watch(form, debounce(() => {
</script>
<template>
<InertiaHead title="Jubileusze" />
<InertiaHead title="Jubileusze"/>
<div class="bg-white shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div>
Expand All @@ -67,7 +68,7 @@ watch(form, debounce(() => {
<div class="flex-1 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" />
<MagnifyingGlassIcon class="w-5 h-5 text-gray-400"/>
</div>
<input
v-model.trim="form.search"
Expand All @@ -88,7 +89,7 @@ watch(form, debounce(() => {
{{ form.sort.name }}
</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" />
<ChevronUpDownIcon class="w-5 h-5 text-gray-400"/>
</span>
</ListboxButton>
Expand Down Expand Up @@ -116,7 +117,7 @@ watch(form, debounce(() => {
v-if="selected"
:class="['text-blumilk-600 absolute inset-y-0 right-0 flex items-center pr-4']"
>
<CheckIcon class="w-5 h-5" />
<CheckIcon class="w-5 h-5"/>
</span>
</li>
</ListboxOption>
Expand Down Expand Up @@ -147,7 +148,7 @@ watch(form, debounce(() => {
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Staż pracy
Staż pracy
</th>
</tr>
</thead>
Expand All @@ -174,10 +175,19 @@ watch(form, debounce(() => {
</div>
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ user.birthdayDisplayDate }} - {{ user.birthdayRelativeDate }}
{{ user.birthdayDisplayDate }} - {{ user.birthdayRelativeDate }}
</td>
<td class="p-4 text-sm text-gray-500 whitespace-nowrap">
{{ user.seniorityDisplayDate }}
<div class="flex gap-1">
{{ user.seniorityDisplayDate }}
<span
v-if="user.isWorkAnniversaryToday"
v-tooltip.right="'okrągła rocznica pracy'"
class="inline-block"
>
<CalendarDaysIcon class="w-5 h-5 text-pink-400"/>
</span>
</div>
</td>
</tr>
<tr
Expand All @@ -200,7 +210,7 @@ watch(form, debounce(() => {
</tbody>
</table>
</div>
<Pagination :pagination="users.meta" />
<Pagination :pagination="users.meta"/>
</div>
</div>
</template>

0 comments on commit 1e9cab5

Please sign in to comment.