Skip to content

Commit

Permalink
Design updates + recurrence_end before start_date issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko259 committed Aug 4, 2024
1 parent 400d24a commit 8405dbd
Showing 6 changed files with 29 additions and 24 deletions.
2 changes: 0 additions & 2 deletions app/Helpers/EventHelper.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@

enum EventHelper: string
{
case NONE = '0';
case DAY = 'day';
case WEEK = 'week';
case MONTH = 'month';
@@ -13,7 +12,6 @@ enum EventHelper: string
public static function labels() : array
{
return [
self::NONE->value => 'None',
self::DAY->value => 'Daily',
self::WEEK->value => 'Weekly',
self::MONTH->value => 'Monthly',
17 changes: 11 additions & 6 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@ public function store(Request $request)
'start_date' => 'required|date_format:Y-m-d H:i|after_or_equal:today',
'end_date' => 'required|date_format:Y-m-d H:i|after_or_equal:start_date',
'event_type' => 'integer',
'recurrence_interval' => 'nullable|integer',
'recurrence_unit' => 'nullable|string|max:255',
'recurrence_end_date' => 'nullable|date_format:Y-m-d H:i|after_or_equal:end_date',
'recurrence_interval' => 'required_if:event_type,1|integer',
'recurrence_unit' => 'required_if:event_type,1|string|max:255|not_in:0',
'recurrence_end_date' => 'required_if:event_type,1|date_format:Y-m-d H:i|after_or_equal:end_date',
'image' => 'nullable|image|mimes:jpeg,jpg,png|max:2048',
]);

@@ -143,9 +143,9 @@ public function update(Request $request, Event $event)
'start_date' => 'required|date_format:Y-m-d H:i|after_or_equal:today',
'end_date' => 'required|date_format:Y-m-d H:i|after_or_equal:start_date',
'event_type' => 'integer',
'recurrence_interval' => 'nullable|integer',
'recurrence_unit' => 'nullable|string|max:255',
'recurrence_end_date' => 'nullable|date_format:Y-m-d H:i|after_or_equal:end_date',
'recurrence_interval' => 'required_if:event_type,1|integer',
'recurrence_unit' => 'required_if:event_type,1|string|max:255|not_in:0',
'recurrence_end_date' => 'required_if:event_type,1|date_format:Y-m-d H:i|after_or_equal:end_date',
'image' => 'nullable|image|mimes:jpeg,jpg,png|max:2048',
]);

@@ -218,6 +218,11 @@ public function destroy(Event $event)
{
$this->authorize('destroy', $event);

// Delete the old image if it exists
if ($event->image && $event->parent()->isEmpty()) {
Storage::disk('public')->delete('banners/' . $event->image);
}

$event->delete();

$event->children()->delete();
13 changes: 6 additions & 7 deletions resources/views/events/create.blade.php
Original file line number Diff line number Diff line change
@@ -23,16 +23,16 @@

<div class="form-group mb-4">
<label for="calendar" class="form-label my-1 me-2">Calendar</label>
<select name="calendar_id" id="calendar" class="form-control my-1 me-sm-2 @error('calendar') is-invalid @enderror" required>
<select name="calendar_id" id="calendar" class="form-control my-1 me-sm-2 @error('calendar_id') is-invalid @enderror" required>
<option disabled selected>Select Calendar</option>
@foreach ($calendars as $calendar)
@can('view', $calendar)
<option value="{{ $calendar->id }}" {{ old('calendar_id') == $calendar->id ? 'selected' : '' }}>{{ $calendar->name }} ({{ $calendar->public == 1 ? 'Public' : 'Private' }})</option>
@endcan
@endforeach
</select>
@error('calendar')
<span class="text-danger">{{ $errors->first('calendar') }}</span>
@error('calendar_id')
<span class="text-danger">{{ $errors->first('calendar_id') }}</span>
@enderror
</div>

@@ -89,21 +89,20 @@
<hr class="my-4">

<div class="form-check">
<input class="form-check-input" type="radio" name="event_type" id="standard_event" value="2" {{ old('event_type') == 1 || old('event_type') == null ? 'checked' : '' }}>
<input class="form-check-input" type="radio" name="event_type" id="standard_event" value="0" {{ old('event_type') == 0 ? 'checked' : '' }}>
<label class="form-check-label" for="standard_event">
Standard Event
</label>
</div>

<div class="form-check mb-4">
<input type="hidden" name="event_type" value="0">
<input class="form-check-input" type="radio" name="event_type" id="is_recurring" value="1" data-toggle="collapse" data-target="#recurringOptions" aria-expanded="false" aria-controls="recurringOptions" {{ old('recurrence_interval') != null && old('recurrence_unit') != null ? 'checked' : '' }}>
<input class="form-check-input" type="radio" name="event_type" id="is_recurring" value="1" data-toggle="collapse" data-target="#recurringOptions" aria-expanded="false" aria-controls="recurringOptions" {{ old('event_type') == 1 ? 'checked' : '' }}>
<label class="form-check-label" for="is_recurring">
Recurring Event
</label>
</div>

<div id="recurringOptions" class="collapse col-xs-12 col-sm-12 col-md-12 mb-2">
<div id="recurringOptions" class="collapse col-xs-12 col-sm-12 col-md-12 mb-2 {{ old('event_type') == 1 ? 'show' : '' }}">
<div class="col-xs-12 col-sm-12 col-md-12 mb-2">
<div class="form-group">
<label for="recurrence_unit" class="form-label my-1 me-2">Recurrence Type</label>
10 changes: 5 additions & 5 deletions resources/views/events/edit.blade.php
Original file line number Diff line number Diff line change
@@ -24,16 +24,16 @@

<div class="form-group mb-4">
<label for="calendar" class="form-label my-1 me-2">Calendar</label>
<select name="calendar_id" id="calendar" class="form-control my-1 me-sm-2 @error('calendar') is-invalid @enderror" required>
<select name="calendar_id" id="calendar" class="form-control my-1 me-sm-2 @error('calendar_id') is-invalid @enderror" required>
<option disabled>Select Calendar</option>
@foreach ($calendars as $calendar)
@can('view', $calendar)
<option value="{{ $calendar->id }}" {{ $event->calendar_id == $calendar->id ? 'selected' : '' }}>{{ $calendar->name }}</option>
@endcan
@endforeach
</select>
@error('calendar')
<span class="text-danger">{{ $errors->first('calendar') }}</span>
@error('calendar_id')
<span class="text-danger">{{ $errors->first('calendar_id') }}</span>
@enderror
</div>

@@ -93,7 +93,7 @@
<hr class="my-4">

<div class="form-check">
<input class="form-check-input" type="radio" name="event_type" id="standard_event" value="2" {{ $event->recurrence_interval != 1 ? 'checked' : '' }}>
<input class="form-check-input" type="radio" name="event_type" id="standard_event" value="2" {{ $event->recurrence_interval == null ? 'checked' : '' }}>
<label class="form-check-label" for="standard_event">
Standard Event
</label>
@@ -107,7 +107,7 @@
</label>
</div>

<div id="recurringOptions" class="collapse col-xs-12 col-sm-12 col-md-12 mb-2">
<div id="recurringOptions" class="collapse col-xs-12 col-sm-12 col-md-12 mb-2 {{ $event->recurrence_interval != null && $event->recurrence_unit != null ? 'show' : '' }}">
<div class="col-xs-12 col-sm-12 col-md-12 mb-2">
<div class="form-group">
<label for="recurrence_unit" class="form-label my-1 me-2">Recurrence Type</label>
9 changes: 6 additions & 3 deletions resources/views/events/index.blade.php
Original file line number Diff line number Diff line change
@@ -41,8 +41,11 @@
<td>{{ \Carbon\Carbon::parse($event->start_date)->format('d-m-Y H:i') }}z</td>
<td>{{ \Carbon\Carbon::parse($event->end_date)->format('d-m-Y H:i') }}z</td>
<td class="text-center text-white">
@if ($event->parent_id != null && $event->recurrence_interval != null)
<a href="{{ route('events.edit', $event->parent) }}">{{ $event->parent->title }}</a>
@if ($event->children->isNotEmpty())
<p class="text-success mb-0">Parent</p>
@elseif($event->parent_id != null)
<a href="{{ route('events.edit', $event->parent) }}" class="flex-grow-1">{{ $event->parent->title }}</a>
<p class="text-muted mt-auto">Id: {{ $event->parent_id }}</p>
@endif
</td>
<td>
@@ -55,7 +58,7 @@
onsubmit="return confirm('Are you sure you want to delete this event? - {{ $event->title }}')">
@method('DELETE')
@csrf
<button class="btn btn-sm btn-danger" type="submit"><i class="fas fa-trash" aria-hidden="true"></i> Delete</button>
<button class="btn btn-sm btn-danger" type="submit"><i class="fas fa-trash" aria-hidden="true"></i> Delete @if ($event->children->isNotEmpty()) all recurring @elseif($event->parent_id != null) occurance @endif</button>
</form>
@endcan
</td>
2 changes: 1 addition & 1 deletion resources/views/events/show.blade.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
</div>
<div>
<i class="fas fa-calendar-alt"></i>
<strong>Recurrence End Date:</strong> {{ \Carbon\Carbon::parse($event->recurrence_end_date)->format('F j, Y, H:i') }}z
<strong>Recurrence End Date:</strong> {{ \Carbon\Carbon::parse($event->recurrence_end_date)->format('F j, Y') }}z
</div>
@endif

0 comments on commit 8405dbd

Please sign in to comment.