Skip to content

Commit

Permalink
Added long + short description
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko259 committed Aug 2, 2024
1 parent 3d6d0bc commit 7fbd69b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 24 deletions.
12 changes: 8 additions & 4 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function store(Request $request)
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'description' => 'nullable',
'short_description' => 'nullable|max:280',
'long_description' => 'nullable',
'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',
Expand Down Expand Up @@ -88,7 +89,8 @@ public function store(Request $request)
$event = Event::create([
'calendar_id' => $request->input('calendar_id'),
'title' => $request->input('title'),
'description' => $request->input('description'),
'short_description' => $request->input('short_description'),
'long_description' => $request->input('long_description'),
'start_date' => Carbon::parse($request->input('start_date'))->format('Y-m-d H:i'),
'end_date' => Carbon::parse($request->input('end_date'))->format('Y-m-d H:i'),
'recurrence_interval' => $request->input('event_type') == '0' ? null : $request->input('recurrence_interval'),
Expand Down Expand Up @@ -146,7 +148,8 @@ public function update(Request $request, Event $event)
'calendar_id' => 'required|exists:calendars,id',
'area' => 'required|exists:areas,id',
'title' => 'required|string|max:255',
'description' => 'nullable',
'short_description' => 'nullable|max:280',
'long_description' => 'nullable',
'start_date' => 'required|date_format:Y-m-d H:i|after_or_equal:' . Carbon::parse($event->start_date)->format('Y-m-d H:i'),
'end_date' => 'required|date_format:Y-m-d H:i|after_or_equal:start_date',
'event_type' => 'integer',
Expand Down Expand Up @@ -190,7 +193,8 @@ public function update(Request $request, Event $event)
$event->update([
'calendar_id' => $request->input('calendar_id'),
'title' => $request->input('title'),
'description' => $request->input('description'),
'short_description' => $request->input('short_description'),
'long_description' => $request->input('long_description'),
'start_date' => Carbon::parse($request->input('start_date'))->format('Y-m-d H:i'),
'end_date' => Carbon::parse($request->input('end_date'))->format('Y-m-d H:i'),
'recurrence_interval' => $request->input('event_type') == '0' ? null : $request->input('recurrence_interval'),
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Event extends Model
'id',
'calendar_id',
'title',
'description',
'short_description',
'long_description',
'start_date',
'end_date',
'recurrence_interval',
Expand Down Expand Up @@ -113,7 +114,8 @@ public function generateRecurrences()

$recurrences[] = new Event([
'title' => $this->title,
'description' => $this->description,
'short_description' => $this->short_description,
'long_description' => $this->long_description,
'start_date' => $start,
'end_date' => $end,
'calendar_id' => $this->calendar_id,
Expand Down
3 changes: 2 additions & 1 deletion database/factories/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function definition(): array
return [
'calendar_id' => Calendar::factory()->create()->id,
'title' => $this->faker->sentence(1),
'description' => $this->faker->paragraph(),
'short_description' => $this->faker->text(280),
'long_description' => $this->faker->paragraph(),
'start_date' => now()->addDays(1)->format('Y-m-d H:i:s'),
'end_date' => now()->addDays(1)->addHours(2)->format('Y-m-d H:i:s'),
'recurrence_interval' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public function up(): void
$table->increments('id');
$table->unsignedInteger('calendar_id');
$table->string('title');
$table->text('description')->nullable();
$table->text('short_description')->nullable();
$table->text('long_description')->nullable();
$table->timestamp('start_date');
$table->timestamp('end_date')->nullable();
$table->integer('recurrence_interval')->nullable(); // E.g., 1 for every day, 2 for every second day
Expand Down
3 changes: 0 additions & 3 deletions database/seeders/EventSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace Database\Seeders;

use App\Models\Area;
use App\Models\Calendar;
use App\Models\Event;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;

class EventSeeder extends Seeder
{
Expand Down
27 changes: 22 additions & 5 deletions resources/views/events/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@
</div>

<div class="form-group mb-4">
<label for="description" class="form-label my-1 me-2">Description</label>
<textarea class="form-control @error('description') is-invalid @enderror" name="description" id="description" rows="8">{{ old('description') }}</textarea>
@error('description')
<span class="text-danger">{{ $errors->first('description') }}</span>
<label for="short_description" class="form-label my-1 me-2">Short Description (max 280 characters)</label>
<textarea class="form-control @error('short_description') is-invalid @enderror" name="short_description" id="short_description" rows="8">{{ old('short_description') }}</textarea>
@error('short_description')
<span class="text-danger">{{ $errors->first('short_description') }}</span>
@enderror
</div>

<div class="form-group mb-4">
<label for="long_description" class="form-label my-1 me-2">Event Description</label>
<textarea class="form-control @error('long_description') is-invalid @enderror" name="long_description" id="long_description" rows="8">{{ old('long_description') }}</textarea>
@error('long_description')
<span class="text-danger">{{ $errors->first('long_description') }}</span>
@enderror
</div>

Expand Down Expand Up @@ -153,7 +161,16 @@
<script type="module">
document.addEventListener("DOMContentLoaded", function() {
var simplemde1 = new SimpleMDE({
element: document.getElementById('description'),
element: document.getElementById('short_description'),
status: false,
toolbar: ["bold", "italic", "heading-3", "|", "quote", "unordered-list", "ordered-list", "|", "link", "preview", "side-by-side", "fullscreen", "|", "guide"],
insertTexts: {
link: ["[","](link)"],
}
});
var simplemde2 = new SimpleMDE({
element: document.getElementById('long_description'),
status: false,
toolbar: ["bold", "italic", "heading-3", "|", "quote", "unordered-list", "ordered-list", "|", "link", "preview", "side-by-side", "fullscreen", "|", "guide"],
insertTexts: {
Expand Down
27 changes: 22 additions & 5 deletions resources/views/events/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@
</div>

<div class="form-group mb-4">
<label for="description" class="form-label my-1 me-2">Description</label>
<textarea class="form-control @error('description') is-invalid @enderror" name="description" id="description" rows="8">{{ $event->description }}</textarea>
@error('description')
<span class="text-danger">{{ $errors->first('description') }}</span>
<label for="short_description" class="form-label my-1 me-2">Short Description (max 280 characters)</label>
<textarea class="form-control @error('short_description') is-invalid @enderror" name="short_description" id="short_description" rows="8">{{ $event->short_description }}</textarea>
@error('short_description')
<span class="text-danger">{{ $errors->first('short_description') }}</span>
@enderror
</div>

<div class="form-group mb-4">
<label for="long_description" class="form-label my-1 me-2">Event Description</label>
<textarea class="form-control @error('long_description') is-invalid @enderror" name="long_description" id="long_description" rows="8">{{ $event->long_description }}</textarea>
@error('long_description')
<span class="text-danger">{{ $errors->first('long_description') }}</span>
@enderror
</div>

Expand Down Expand Up @@ -157,7 +165,16 @@
<script type="module">
document.addEventListener("DOMContentLoaded", function() {
var simplemde1 = new SimpleMDE({
element: document.getElementById('description'),
element: document.getElementById('short_description'),
status: false,
toolbar: ["bold", "italic", "heading-3", "|", "quote", "unordered-list", "ordered-list", "|", "link", "preview", "side-by-side", "fullscreen", "|", "guide"],
insertTexts: {
link: ["[","](link)"],
}
});
var simplemde2 = new SimpleMDE({
element: document.getElementById('long_description'),
status: false,
toolbar: ["bold", "italic", "heading-3", "|", "quote", "unordered-list", "ordered-list", "|", "link", "preview", "side-by-side", "fullscreen", "|", "guide"],
insertTexts: {
Expand Down
9 changes: 6 additions & 3 deletions tests/Feature/Models/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public function test_normal_event_can_be_created() : void
'area' => $area->id,
'calendar_id' => $calendar->id,
'title' => $this->faker->sentence(1),
'description' => $this->faker->paragraph(),
'short_description' => $this->faker->text(280),
'long_description' => $this->faker->paragraph(),
'start_date' => now()->addDays(1)->format('Y-m-d H:i'),
'end_date' => now()->addDays(1)->addHours(2)->format('Y-m-d H:i'),
'recurrence_interval' => null,
Expand Down Expand Up @@ -169,7 +170,8 @@ public function test_recurrent_event_can_be_created() : void
'area' => $area->id,
'calendar_id' => $calendar->id,
'title' => 'Test Event',
'description' => $this->faker->paragraph(),
'short_description' => $this->faker->text(280),
'long_description' => $this->faker->paragraph(),
'start_date' => $startDate,
'end_date' => $endDate,
'recurrence_interval' => 1,
Expand Down Expand Up @@ -226,7 +228,8 @@ public function test_event_can_be_updated(): void
'area' => $area->id,
'calendar_id' => $calendar->id,
'title' => $this->faker->sentence(1),
'description' => $this->faker->paragraph(),
'short_description' => $this->faker->text(280),
'long_description' => $this->faker->paragraph(),
'start_date' => now()->addDays(1)->format('Y-m-d H:i'),
'end_date' => now()->addDays(1)->addHours(2)->format('Y-m-d H:i'),
'recurrence_interval' => null,
Expand Down

0 comments on commit 7fbd69b

Please sign in to comment.