Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/Livewire/Projects/CreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class CreateProject extends Component
{
use WithFileUploads;

public string $title, $slug, $tools, $summary, $coverImageFilename, $repoLink;
public string $title, $slug, $tools, $summary, $coverImageFilename;
public string|null $repoLink = null;
public $coverImage;
public bool $standout;
public bool $openSource = true, $standout;

protected $rules = [
'title' => ['required', 'max:255'],
Expand All @@ -23,14 +24,17 @@ class CreateProject extends Component
'coverImage' => ['required', 'image', 'max:1024'],
'coverImageFilename' => ['required', 'unique:projects,cover_img_filename', 'max:255'],
'summary' => ['required', 'max:255'],
'repoLink' => ['required', 'max:255', 'url']
'repoLink' => ['nullable', 'max:255', 'url']
];

public function store(): void
{
$this->authorize('create', Project::class);
$this->validate();
try {
if (!$this->openSource) {
$this->repoLink = null;
}
Project::writeCoverImage($this->coverImageFilename, $this->coverImage);
Project::create([
'title' => $this->title,
Expand All @@ -44,7 +48,6 @@ public function store(): void
$this->redirectRoute('management.portfolio.index');
} catch (Throwable $th) {
Log::error($th->getMessage());
$this->redirectRoute('management.portfolio.index');
session()->flash('error', $th->getMessage());
}
}
Expand Down
11 changes: 8 additions & 3 deletions app/Livewire/Projects/EditProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class EditProject extends Component
use WithFileUploads;

public Project $project;
public string $title, $slug, $tools, $summary, $coverImageFilename, $repoLink;
public string $title, $slug, $tools, $summary, $coverImageFilename;
public string|null $repoLink = null;
public $coverImage;
public bool $standout;
public bool $openSource, $standout;

protected $rules = [
'title' => ['required', 'max:255'],
Expand All @@ -26,7 +27,7 @@ class EditProject extends Component
'coverImage' => ['nullable', 'image', 'max:1024'],
'coverImageFilename' => ['required', 'unique:projects,cover_img_filename', 'max:255'],
'summary' => ['required', 'max:255'],
'repoLink' => ['required', 'max:255', 'url']
'repoLink' => ['nullable', 'max:255', 'url']
];

public function mount(string $slug): void
Expand All @@ -41,6 +42,7 @@ public function mount(string $slug): void
$this->tools = $this->project->tools;
$this->summary = $this->project->summary;
$this->coverImageFilename = $this->project->cover_img_filename;
$this->openSource = $this->project->repo_link != null;
$this->repoLink = $this->project->repo_link;
$this->standout = $this->project->standout == '1';
}
Expand All @@ -50,6 +52,9 @@ public function update(): void
$this->authorize('update', $this->project);
$this->validate($this->rules());
try {
if (!$this->openSource) {
$this->repoLink = null;
}
$this->project->updateCoverImage($this->coverImageFilename, $this->coverImage);
$this->project->update([
'title' => $this->title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('repo_link')->nullable()->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('repo_link')->change();
});
}
};
12 changes: 8 additions & 4 deletions resources/views/livewire/portfolio/portfolio-index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ function hideAdminPanel() {
<article class="m-1 px-5 py-6 border border-divider rounded-lg">
<div class="flex justify-between items-center gap-2">
<flux:heading class="text-xl mb-0.5!">{{ $project->title }}</flux:heading>
<a href="{{ $project->repo_link }}" target="_blank">
<img src="/images/brands/github-mark.png" alt="GitHub Icon" class="h-6 dark:hidden" />
<img src="/images/brands/github-mark-white.png" alt="GitHub Icon" class="h-6 hidden dark:block" />
</a>
@if($project->repo_link != null)
<a href="{{ $project->repo_link }}" target="_blank">
<img src="/images/brands/github-mark.png" alt="GitHub Icon" class="h-6 dark:hidden" />
<img src="/images/brands/github-mark-white.png" alt="GitHub Icon" class="h-6 hidden dark:block" />
</a>
@else
<flux:text size="sm" class="uppercase text-zinc-500">Closed source</flux:text>
@endif
</div>
<flux:subheading size="md" class="mt-1.5 text-zinc-700 dark:text-zinc-50">{{ $project->summary }}</flux:subheading>
<img src="{{ $project->getCoverImagePath() }}" alt="Cover image" class="my-3 w-full"/>
Expand Down
11 changes: 9 additions & 2 deletions resources/views/livewire/projects/create-project.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
</div>
</div>

<flux:input wire:model="repoLink" :label="__('Repository Link')" type="text" />
<flux:checkbox wire:model="openSource" :label="__('Open Source')"/>

<flux:checkbox wire:model="standout" :label="__('Standout?')" />
<div wire:show="openSource">
<flux:input wire:model="repoLink" :label="__('Repository Link')" type="text" />
</div>

<div class="space-y-2">
<flux:checkbox wire:model="standout" :label="__('Standout')"/>
<flux:text>Standout projects are displayed on the home page and appear larger than standard projects on the portfolio page.</flux:text>
</div>

<div class="flex items-center justify-between gap-2">
<flux:button iconLeading="arrow-left" href="{{ route('management.portfolio.index') }}" class="hover:cursor-pointer">{{ __('Cancel') }}</flux:button>
Expand Down
11 changes: 9 additions & 2 deletions resources/views/livewire/projects/edit-project.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@

<img src="{{ $project->getCoverImagePath() }}" alt="Cover image" class="w-50" />

<flux:input wire:model="repoLink" :label="__('Repository Link')" type="text" />
<flux:checkbox wire:model="openSource" :label="__('Open Source')"/>

<flux:checkbox wire:model="standout" :label="__('Standout?')" />
<div wire:show="openSource">
<flux:input wire:model="repoLink" :label="__('Repository Link')" type="text" />
</div>

<div class="space-y-2">
<flux:checkbox wire:model="standout" :label="__('Standout')"/>
<flux:text>Standout projects are displayed on the home page and appear larger than standard projects on the portfolio page.</flux:text>
</div>

<div class="flex items-center justify-between gap-2">
<div class="flex gap-2">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/projects/project-index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div id="projects-container" class="space-y-6">
@foreach($projects as $project)
<livewire:projects.project-cell :project="$project" />
<livewire:projects.project-cell :project="$project" wire:key="project-cell-{{ $project->id }}" />
@endforeach
</div>
</div>
Expand Down
30 changes: 21 additions & 9 deletions tests/Feature/Projects/CreateProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function test_cannot_create_project_without_summary(): void
$response->assertHasErrors('summary');
}

public function test_cannot_create_project_without_repo_link(): void
public function test_cannot_create_project_with_invalid_repo_link(): void
{
$this->actingAsAdmin();

Expand All @@ -221,13 +221,15 @@ public function test_cannot_create_project_without_repo_link(): void
->set('coverImage', UploadedFile::fake()->image('test-img.png'))
->set('coverImageFilename', 'test-img.png')
->set('summary', 'Test summary')
->set('repoLink', 'https://invalid link/')
->call('store');

$response->assertHasErrors('repoLink');
}

public function test_cannot_create_project_with_invalid_repo_link(): void
public function test_project_creation_adds_database_row(): void
{
Storage::fake('portfolio');
$this->actingAsAdmin();

$response = Livewire::test(CreateProject::class)
Expand All @@ -237,15 +239,25 @@ public function test_cannot_create_project_with_invalid_repo_link(): void
->set('coverImage', UploadedFile::fake()->image('test-img.png'))
->set('coverImageFilename', 'test-img.png')
->set('summary', 'Test summary')
->set('repoLink', 'https://invalid link/')
->set('repoLink', 'https://test.link/')
->set('standout', true)
->call('store');

$response->assertHasErrors('repoLink');
$response->assertHasNoErrors();

$this->assertDatabaseHas('projects', [
'title' => 'Test Title',
'slug' => 'test-slug',
'tools' => 'Test languages',
'cover_img_filename' => 'test-img.png',
'summary' => 'Test summary',
'repo_link' => 'https://test.link/',
'standout' => true
]);
}

public function test_project_creation_adds_database_row(): void
public function test_repo_link_not_set_if_open_source_unchecked(): void
{
Storage::fake('portfolio');
$this->actingAsAdmin();

$response = Livewire::test(CreateProject::class)
Expand All @@ -256,7 +268,7 @@ public function test_project_creation_adds_database_row(): void
->set('coverImageFilename', 'test-img.png')
->set('summary', 'Test summary')
->set('repoLink', 'https://test.link/')
->set('standout', true)
->set('openSource', false)
->call('store');

$response->assertHasNoErrors();
Expand All @@ -267,8 +279,8 @@ public function test_project_creation_adds_database_row(): void
'tools' => 'Test languages',
'cover_img_filename' => 'test-img.png',
'summary' => 'Test summary',
'repo_link' => 'https://test.link/',
'standout' => 1
'repo_link' => null,
'standout' => false
]);
}

Expand Down
43 changes: 30 additions & 13 deletions tests/Feature/Projects/EditProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@ public function test_cannot_remove_summary(): void
$response->assertHasErrors('summary');
}

public function test_cannot_remove_repo_link(): void
{
$this->actingAsAdmin();
$project = Project::factory()->create(['slug' => 'test-slug']);

$response = Livewire::test(EditProject::class, ['slug' => $project->slug])
->set('repoLink', '')
->call('update');

$response->assertHasErrors('repoLink');
}

public function test_cannot_change_to_invalid_repo_link(): void
{
$this->actingAsAdmin();
Expand Down Expand Up @@ -246,7 +234,36 @@ public function test_project_edit_modifies_database_row(): void
'cover_img_filename' => 'new-test-img.png',
'summary' => 'New test summary',
'repo_link' => 'https://test.link/new',
'standout' => 0
'standout' => false
]);
}

public function test_repo_link_removed_when_open_source_unchecked(): void
{
$this->actingAsAdmin();
$project = Project::factory()->create([
'title' => 'Test Title',
'slug' => 'test-slug',
'tools' => 'Test languages',
'cover_img_filename' => 'test-img.png',
'summary' => 'Test Summary',
'repo_link' => 'https://test.link/',
'standout' => false
]);

Livewire::test(EditProject::class, ['slug' => $project->slug])
->set('openSource', false)
->call('update')
->assertHasNoErrors();

$this->assertDatabaseHas('projects', [
'title' => 'Test Title',
'slug' => 'test-slug',
'tools' => 'Test languages',
'cover_img_filename' => 'test-img.png',
'summary' => 'Test Summary',
'repo_link' => null,
'standout' => false
]);
}

Expand Down