feat: local sections in sub-events can use festival-level time slots
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,22 @@ final class TimeSlotController extends Controller
|
|||||||
|
|
||||||
$timeSlots = $event->timeSlots()->orderBy('date')->orderBy('start_time')->get();
|
$timeSlots = $event->timeSlots()->orderBy('date')->orderBy('start_time')->get();
|
||||||
|
|
||||||
|
if ($event->isSubEvent() && request()->boolean('include_parent') && $event->parent_event_id) {
|
||||||
|
$parentTimeSlots = TimeSlot::where('event_id', $event->parent_event_id)
|
||||||
|
->with('event')
|
||||||
|
->orderBy('date')
|
||||||
|
->orderBy('start_time')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$timeSlots->load('event');
|
||||||
|
$timeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'sub_event'));
|
||||||
|
$parentTimeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'festival'));
|
||||||
|
|
||||||
|
$timeSlots = $timeSlots->merge($parentTimeSlots)
|
||||||
|
->sortBy([['date', 'asc'], ['start_time', 'asc']])
|
||||||
|
->values();
|
||||||
|
}
|
||||||
|
|
||||||
return TimeSlotResource::collection($timeSlots);
|
return TimeSlotResource::collection($timeSlots);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Http\Requests\Api\V1;
|
namespace App\Http\Requests\Api\V1;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
final class StoreShiftRequest extends FormRequest
|
final class StoreShiftRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,16 @@ final class StoreShiftRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'time_slot_id' => ['required', 'ulid', 'exists:time_slots,id'],
|
'time_slot_id' => ['required', 'ulid', Rule::exists('time_slots', 'id')->where(function ($query) {
|
||||||
|
$event = $this->route('event');
|
||||||
|
$eventIds = [$event->id];
|
||||||
|
|
||||||
|
if ($event->isSubEvent() && $event->parent_event_id) {
|
||||||
|
$eventIds[] = $event->parent_event_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->whereIn('event_id', $eventIds);
|
||||||
|
})],
|
||||||
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
|
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
|
||||||
'title' => ['nullable', 'string', 'max:255'],
|
'title' => ['nullable', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
@@ -28,8 +38,10 @@ final class StoreShiftRequest extends FormRequest
|
|||||||
'report_time' => ['nullable', 'date_format:H:i'],
|
'report_time' => ['nullable', 'date_format:H:i'],
|
||||||
'actual_start_time' => ['nullable', 'date_format:H:i'],
|
'actual_start_time' => ['nullable', 'date_format:H:i'],
|
||||||
'actual_end_time' => ['nullable', 'date_format:H:i'],
|
'actual_end_time' => ['nullable', 'date_format:H:i'],
|
||||||
|
'end_date' => ['nullable', 'date'],
|
||||||
'is_lead_role' => ['nullable', 'boolean'],
|
'is_lead_role' => ['nullable', 'boolean'],
|
||||||
'allow_overlap' => ['nullable', 'boolean'],
|
'allow_overlap' => ['nullable', 'boolean'],
|
||||||
|
'events_during_shift' => ['nullable', 'array'],
|
||||||
'status' => ['nullable', 'in:draft,open,full,in_progress,completed,cancelled'],
|
'status' => ['nullable', 'in:draft,open,full,in_progress,completed,cancelled'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Http\Requests\Api\V1;
|
namespace App\Http\Requests\Api\V1;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
final class UpdateShiftRequest extends FormRequest
|
final class UpdateShiftRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,16 @@ final class UpdateShiftRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'time_slot_id' => ['sometimes', 'ulid', 'exists:time_slots,id'],
|
'time_slot_id' => ['sometimes', 'ulid', Rule::exists('time_slots', 'id')->where(function ($query) {
|
||||||
|
$event = $this->route('event');
|
||||||
|
$eventIds = [$event->id];
|
||||||
|
|
||||||
|
if ($event->isSubEvent() && $event->parent_event_id) {
|
||||||
|
$eventIds[] = $event->parent_event_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->whereIn('event_id', $eventIds);
|
||||||
|
})],
|
||||||
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
|
'location_id' => ['nullable', 'ulid', 'exists:locations,id'],
|
||||||
'title' => ['nullable', 'string', 'max:255'],
|
'title' => ['nullable', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
@@ -28,8 +38,10 @@ final class UpdateShiftRequest extends FormRequest
|
|||||||
'report_time' => ['nullable', 'date_format:H:i'],
|
'report_time' => ['nullable', 'date_format:H:i'],
|
||||||
'actual_start_time' => ['nullable', 'date_format:H:i'],
|
'actual_start_time' => ['nullable', 'date_format:H:i'],
|
||||||
'actual_end_time' => ['nullable', 'date_format:H:i'],
|
'actual_end_time' => ['nullable', 'date_format:H:i'],
|
||||||
|
'end_date' => ['nullable', 'date'],
|
||||||
'is_lead_role' => ['nullable', 'boolean'],
|
'is_lead_role' => ['nullable', 'boolean'],
|
||||||
'allow_overlap' => ['nullable', 'boolean'],
|
'allow_overlap' => ['nullable', 'boolean'],
|
||||||
|
'events_during_shift' => ['nullable', 'array'],
|
||||||
'status' => ['sometimes', 'in:draft,open,full,in_progress,completed,cancelled'],
|
'status' => ['sometimes', 'in:draft,open,full,in_progress,completed,cancelled'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Http\Resources\Api\V1;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
final class TimeSlotResource extends JsonResource
|
final class TimeSlotResource extends JsonResource
|
||||||
{
|
{
|
||||||
@@ -17,9 +18,11 @@ final class TimeSlotResource extends JsonResource
|
|||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'person_type' => $this->person_type,
|
'person_type' => $this->person_type,
|
||||||
'date' => $this->date->toDateString(),
|
'date' => $this->date->toDateString(),
|
||||||
'start_time' => $this->start_time,
|
'start_time' => Carbon::parse($this->start_time)->format('H:i'),
|
||||||
'end_time' => $this->end_time,
|
'end_time' => Carbon::parse($this->end_time)->format('H:i'),
|
||||||
'duration_hours' => $this->duration_hours,
|
'duration_hours' => $this->duration_hours,
|
||||||
|
'source' => $this->resource->getAttribute('source'),
|
||||||
|
'event_name' => $this->whenLoaded('event', fn () => $this->event->name),
|
||||||
'created_at' => $this->created_at->toIso8601String(),
|
'created_at' => $this->created_at->toIso8601String(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,30 @@ class TimeSlotTest extends TestCase
|
|||||||
->assertJson(['data' => ['name' => 'Vrijdag Avond Updated']]);
|
->assertJson(['data' => ['name' => 'Vrijdag Avond Updated']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_update_cross_org_returns_403(): void
|
||||||
|
{
|
||||||
|
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
||||||
|
|
||||||
|
Sanctum::actingAs($this->outsider);
|
||||||
|
|
||||||
|
$response = $this->putJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}", [
|
||||||
|
'name' => 'Hacked',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_destroy_cross_org_returns_403(): void
|
||||||
|
{
|
||||||
|
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
||||||
|
|
||||||
|
Sanctum::actingAs($this->outsider);
|
||||||
|
|
||||||
|
$response = $this->deleteJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}");
|
||||||
|
|
||||||
|
$response->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
public function test_destroy_deletes_time_slot(): void
|
public function test_destroy_deletes_time_slot(): void
|
||||||
{
|
{
|
||||||
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
$timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ import { useTimeSlotList } from '@/composables/api/useTimeSlots'
|
|||||||
import { requiredValidator } from '@core/utils/validators'
|
import { requiredValidator } from '@core/utils/validators'
|
||||||
import type { Shift, ShiftStatus } from '@/types/section'
|
import type { Shift, ShiftStatus } from '@/types/section'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
eventId: string
|
eventId: string
|
||||||
sectionId: string
|
sectionId: string
|
||||||
shift?: Shift | null
|
shift?: Shift | null
|
||||||
|
isSubEvent?: boolean
|
||||||
|
}>(), {
|
||||||
|
isSubEvent: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
openTimeSlots: []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const modelValue = defineModel<boolean>({ required: true })
|
const modelValue = defineModel<boolean>({ required: true })
|
||||||
@@ -17,8 +24,9 @@ const eventIdRef = computed(() => props.eventId)
|
|||||||
const sectionIdRef = computed(() => props.sectionId)
|
const sectionIdRef = computed(() => props.sectionId)
|
||||||
|
|
||||||
const isEditing = computed(() => !!props.shift)
|
const isEditing = computed(() => !!props.shift)
|
||||||
|
const isSubEventRef = computed(() => props.isSubEvent)
|
||||||
|
|
||||||
const { data: timeSlots } = useTimeSlotList(eventIdRef)
|
const { data: timeSlots } = useTimeSlotList(eventIdRef, { includeParent: isSubEventRef })
|
||||||
const { mutate: createShift, isPending: isCreating } = useCreateShift(eventIdRef, sectionIdRef)
|
const { mutate: createShift, isPending: isCreating } = useCreateShift(eventIdRef, sectionIdRef)
|
||||||
const { mutate: updateShift, isPending: isUpdating } = useUpdateShift(eventIdRef, sectionIdRef)
|
const { mutate: updateShift, isPending: isUpdating } = useUpdateShift(eventIdRef, sectionIdRef)
|
||||||
|
|
||||||
@@ -64,12 +72,39 @@ watch(
|
|||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
const timeSlotItems = computed(() =>
|
const timeSlotItems = computed(() => {
|
||||||
timeSlots.value?.map(ts => ({
|
if (!timeSlots.value?.length) return []
|
||||||
title: `${ts.name} — ${ts.date} ${ts.start_time}–${ts.end_time}`,
|
|
||||||
value: ts.id,
|
const hasFestival = timeSlots.value.some(ts => ts.source === 'festival')
|
||||||
})) ?? [],
|
if (!hasFestival) {
|
||||||
)
|
return timeSlots.value.map(ts => ({
|
||||||
|
title: `${ts.name} — ${ts.date} ${ts.start_time}–${ts.end_time}`,
|
||||||
|
value: ts.id,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
const subEventSlots = timeSlots.value.filter(ts => ts.source !== 'festival')
|
||||||
|
const festivalSlots = timeSlots.value.filter(ts => ts.source === 'festival')
|
||||||
|
const items: Array<{ title: string; value?: string; type?: string }> = []
|
||||||
|
|
||||||
|
if (subEventSlots.length) {
|
||||||
|
items.push({ title: subEventSlots[0]?.event_name ?? 'Programma', type: 'subheader' })
|
||||||
|
items.push(...subEventSlots.map(ts => ({
|
||||||
|
title: `${ts.name} — ${ts.date} ${ts.start_time}–${ts.end_time}`,
|
||||||
|
value: ts.id,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (festivalSlots.length) {
|
||||||
|
items.push({ title: festivalSlots[0]?.event_name ?? 'Festival', type: 'subheader' })
|
||||||
|
items.push(...festivalSlots.map(ts => ({
|
||||||
|
title: `${ts.name} — ${ts.date} ${ts.start_time}–${ts.end_time}`,
|
||||||
|
value: ts.id,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
return items
|
||||||
|
})
|
||||||
|
|
||||||
const statusOptions = [
|
const statusOptions = [
|
||||||
{ title: 'Concept', value: 'draft' },
|
{ title: 'Concept', value: 'draft' },
|
||||||
@@ -148,20 +183,39 @@ function onSubmit() {
|
|||||||
@after-leave="!isEditing && resetForm()"
|
@after-leave="!isEditing && resetForm()"
|
||||||
>
|
>
|
||||||
<VCard :title="isEditing ? 'Shift bewerken' : 'Shift toevoegen'">
|
<VCard :title="isEditing ? 'Shift bewerken' : 'Shift toevoegen'">
|
||||||
<VCardText>
|
<VForm
|
||||||
<VForm
|
ref="refVForm"
|
||||||
ref="refVForm"
|
@submit.prevent="onSubmit"
|
||||||
@submit.prevent="onSubmit"
|
>
|
||||||
>
|
<VCardText>
|
||||||
<VRow>
|
<VRow>
|
||||||
<VCol cols="12">
|
<VCol cols="12">
|
||||||
<AppSelect
|
<AppSelect
|
||||||
|
v-if="timeSlotItems.length"
|
||||||
v-model="form.time_slot_id"
|
v-model="form.time_slot_id"
|
||||||
label="Time Slot"
|
label="Time Slot"
|
||||||
:items="timeSlotItems"
|
:items="timeSlotItems"
|
||||||
:rules="[requiredValidator]"
|
:rules="[requiredValidator]"
|
||||||
:error-messages="errors.time_slot_id"
|
:error-messages="errors.time_slot_id"
|
||||||
/>
|
/>
|
||||||
|
<VAlert
|
||||||
|
v-else
|
||||||
|
type="info"
|
||||||
|
variant="tonal"
|
||||||
|
>
|
||||||
|
<div class="d-flex align-center justify-space-between flex-wrap gap-2">
|
||||||
|
<span>Maak eerst een time slot aan</span>
|
||||||
|
<VBtn
|
||||||
|
size="small"
|
||||||
|
variant="text"
|
||||||
|
color="primary"
|
||||||
|
prepend-icon="tabler-clock"
|
||||||
|
@click="emit('openTimeSlots'); modelValue = false"
|
||||||
|
>
|
||||||
|
Time Slots beheren
|
||||||
|
</VBtn>
|
||||||
|
</div>
|
||||||
|
</VAlert>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12">
|
<VCol cols="12">
|
||||||
<AppTextField
|
<AppTextField
|
||||||
@@ -169,6 +223,7 @@ function onSubmit() {
|
|||||||
label="Titel / Rol"
|
label="Titel / Rol"
|
||||||
placeholder="Tapper, Barhoofd, Stage Manager..."
|
placeholder="Tapper, Barhoofd, Stage Manager..."
|
||||||
:error-messages="errors.title"
|
:error-messages="errors.title"
|
||||||
|
autocomplete="one-time-code"
|
||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol
|
<VCol
|
||||||
@@ -253,6 +308,7 @@ function onSubmit() {
|
|||||||
label="Instructies"
|
label="Instructies"
|
||||||
rows="3"
|
rows="3"
|
||||||
:error-messages="errors.instructions"
|
:error-messages="errors.instructions"
|
||||||
|
autocomplete="one-time-code"
|
||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12">
|
<VCol cols="12">
|
||||||
@@ -264,24 +320,24 @@ function onSubmit() {
|
|||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
</VRow>
|
</VRow>
|
||||||
</VForm>
|
</VCardText>
|
||||||
</VCardText>
|
<VCardActions>
|
||||||
<VCardActions>
|
<VSpacer />
|
||||||
<VSpacer />
|
<VBtn
|
||||||
<VBtn
|
variant="text"
|
||||||
variant="text"
|
@click="modelValue = false"
|
||||||
@click="modelValue = false"
|
>
|
||||||
>
|
Annuleren
|
||||||
Annuleren
|
</VBtn>
|
||||||
</VBtn>
|
<VBtn
|
||||||
<VBtn
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
:loading="isPending"
|
:loading="isPending"
|
||||||
@click="onSubmit"
|
>
|
||||||
>
|
{{ isEditing ? 'Opslaan' : 'Toevoegen' }}
|
||||||
{{ isEditing ? 'Opslaan' : 'Toevoegen' }}
|
</VBtn>
|
||||||
</VBtn>
|
</VCardActions>
|
||||||
</VCardActions>
|
</VForm>
|
||||||
</VCard>
|
</VCard>
|
||||||
</VDialog>
|
</VDialog>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -13,12 +13,16 @@ interface PaginatedResponse<T> {
|
|||||||
data: T[]
|
data: T[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTimeSlotList(eventId: Ref<string>) {
|
export function useTimeSlotList(eventId: Ref<string>, options?: { includeParent?: Ref<boolean> }) {
|
||||||
|
const includeParent = options?.includeParent
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['time-slots', eventId],
|
queryKey: ['time-slots', eventId, includeParent],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
const params = includeParent?.value ? { include_parent: 'true' } : {}
|
||||||
const { data } = await apiClient.get<PaginatedResponse<TimeSlot>>(
|
const { data } = await apiClient.get<PaginatedResponse<TimeSlot>>(
|
||||||
`/events/${eventId.value}/time-slots`,
|
`/events/${eventId.value}/time-slots`,
|
||||||
|
{ params },
|
||||||
)
|
)
|
||||||
|
|
||||||
return data.data
|
return data.data
|
||||||
|
|||||||
Reference in New Issue
Block a user