diff --git a/app/Models/Post.php b/app/Models/Post.php index 8c6bc51b5cf..1ddc239c9a7 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -64,4 +65,18 @@ public function postSections(): HasMany { return $this->hasMany(PostSection::class); } + + protected function title(): Attribute + { + return Attribute::make( + get: function ($value) { + if ($value) { + return $value; + } + + return trans('app.undefined'); + }, + set: fn ($value) => $value, + ); + } } diff --git a/domains/Vault/ManageJournals/Web/Controllers/PostController.php b/domains/Vault/ManageJournals/Web/Controllers/PostController.php index 5cd99d895fa..026d3769b06 100644 --- a/domains/Vault/ManageJournals/Web/Controllers/PostController.php +++ b/domains/Vault/ManageJournals/Web/Controllers/PostController.php @@ -9,15 +9,18 @@ use App\Models\PostTemplate; use App\Models\Vault; use App\Vault\ManageJournals\Services\CreatePost; +use App\Vault\ManageJournals\Services\DestroyPost; use App\Vault\ManageJournals\Services\UpdatePost; use App\Vault\ManageJournals\Web\ViewHelpers\PostCreateViewHelper; use App\Vault\ManageJournals\Web\ViewHelpers\PostEditViewHelper; +use App\Vault\ManageJournals\Web\ViewHelpers\PostShowViewHelper; use App\Vault\ManageVault\Web\ViewHelpers\VaultIndexViewHelper; use Carbon\Carbon; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Inertia\Inertia; +use Redirect; class PostController extends Controller { @@ -78,11 +81,11 @@ public function store(Request $request, int $vaultId, int $journalId, int $templ public function show(Request $request, int $vaultId, int $journalId, int $postId) { $vault = Vault::findOrFail($vaultId); - $journal = Journal::findOrFail($journalId); $post = Post::findOrFail($postId); - return Inertia::render('Vault/Journal/Post/Create', [ + return Inertia::render('Vault/Journal/Post/Show', [ 'layoutData' => VaultIndexViewHelper::layoutData($vault), + 'data' => PostShowViewHelper::data($post, Auth::user()), ]); } @@ -117,4 +120,22 @@ public function update(Request $request, int $vaultId, int $journalId, int $post 'data' => PostHelper::statistics($post), ], 200); } + + public function destroy(Request $request, int $vaultId, int $journalId, int $postId) + { + (new DestroyPost())->execute([ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'vault_id' => $vaultId, + 'journal_id' => $journalId, + 'post_id' => $postId, + ]); + + $journal = Journal::findOrFail($journalId); + + return Redirect::route('journal.show', [ + 'vault' => $vaultId, + 'journal' => $journal, + ]); + } } diff --git a/domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php b/domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php index 5eefbaca488..514ad051da8 100644 --- a/domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php +++ b/domains/Vault/ManageJournals/Web/ViewHelpers/JournalShowViewHelper.php @@ -18,6 +18,13 @@ public static function data(Journal $journal, User $user): array 'id' => $post->id, 'title' => $post->title, 'written_at' => DateHelper::format($post->written_at, $user), + 'url' => [ + 'show' => route('post.show', [ + 'vault' => $journal->vault_id, + 'journal' => $journal->id, + 'post' => $post->id, + ]), + ], ]); return [ diff --git a/domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php b/domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php index 636699a1c4f..b2a4396edcc 100644 --- a/domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php +++ b/domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php @@ -34,10 +34,20 @@ public static function data(Journal $journal, Post $post): array 'journal' => $journal->id, 'post' => $post->id, ]), + 'show' => route('post.show', [ + 'vault' => $journal->vault_id, + 'journal' => $journal->id, + 'post' => $post->id, + ]), 'back' => route('journal.show', [ 'vault' => $journal->vault_id, 'journal' => $journal->id, ]), + 'destroy' => route('post.destroy', [ + 'vault' => $journal->vault_id, + 'journal' => $journal->id, + 'post' => $post->id, + ]), ], ]; } diff --git a/domains/Vault/ManageJournals/Web/ViewHelpers/PostShowViewHelper.php b/domains/Vault/ManageJournals/Web/ViewHelpers/PostShowViewHelper.php index 8c0b54df161..0b4ffb243d4 100644 --- a/domains/Vault/ManageJournals/Web/ViewHelpers/PostShowViewHelper.php +++ b/domains/Vault/ManageJournals/Web/ViewHelpers/PostShowViewHelper.php @@ -2,11 +2,52 @@ namespace App\Vault\ManageJournals\Web\ViewHelpers; -use App\Models\Account; +use App\Helpers\DateHelper; +use App\Models\Post; +use App\Models\PostSection; +use App\Models\User; class PostShowViewHelper { - public static function chooseTemplate(Account $account) + public static function data(Post $post, User $user): array { + $sections = $post->postSections() + ->orderBy('position') + ->whereNotNull('content') + ->get() + ->map(fn (PostSection $section) => [ + 'id' => $section->id, + 'label' => $section->label, + 'content' => $section->content, + ]); + + return [ + 'id' => $post->id, + 'title' => $post->title, + 'title_exists' => $post->title === trans('app.undefined') ? false : true, + 'written_at' => DateHelper::format($post->written_at, $user), + 'published' => $post->published, + 'sections' => $sections, + 'journal' => [ + 'name' => $post->journal->name, + 'url' => [ + 'show' => route('journal.show', [ + 'vault' => $post->journal->vault_id, + 'journal' => $post->journal->id, + ]), + ], + ], + 'url' => [ + 'edit' => route('post.edit', [ + 'vault' => $post->journal->vault_id, + 'journal' => $post->journal->id, + 'post' => $post->id, + ]), + 'back' => route('journal.show', [ + 'vault' => $post->journal->vault_id, + 'journal' => $post->journal->id, + ]), + ], + ]; } } diff --git a/lang/en/app.php b/lang/en/app.php index 38ae9653909..e696aad7ff0 100644 --- a/lang/en/app.php +++ b/lang/en/app.php @@ -70,10 +70,10 @@ 'view_all' => 'View all', 'previous' => 'Previous', 'next' => 'Next', - 'view_all' => 'View all', 'view_map' => 'View on map', 'view_older' => 'Load previous entries', 'download' => 'Download', + 'undefined' => 'Undefined', 'unknown_name' => 'Unknown name', diff --git a/package.json b/package.json index 0a8aaa7cbfe..a06c1612d23 100644 --- a/package.json +++ b/package.json @@ -61,5 +61,8 @@ "hooks": { "pre-commit": "lint-staged" } + }, + "dependencies": { + "@tailwindcss/typography": "^0.5.7" } } diff --git a/phpstan.neon b/phpstan.neon index 12faedf7971..ce6738f5953 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -20,6 +20,7 @@ parameters: - '#Access to an undefined property App\\Models\\LifeEventCategory.*::\$label\.#' - '#Access to an undefined property App\\Models\\LifeEventType.*::\$label.#' - '#Access to an undefined property App\\Models\\Module::\$position\.#' + - '#Access to an undefined property App\\Models\\Post::\$title\.#' - '#Parameter \$get of static method Illuminate\\Database\\Eloquent\\Casts\\Attribute::make\(\) expects \(callable\(mixed, mixed=\): .*\)\|null, Closure\(mixed, mixed\): .* given\.#' - '#Access to an undefined property App\\Models\\.*::\$pivot\.#' diff --git a/resources/js/Pages/Vault/Dashboard/Partials/DueTasks.vue b/resources/js/Pages/Vault/Dashboard/Partials/DueTasks.vue index a491d341f45..08b62435fbe 100644 --- a/resources/js/Pages/Vault/Dashboard/Partials/DueTasks.vue +++ b/resources/js/Pages/Vault/Dashboard/Partials/DueTasks.vue @@ -20,7 +20,7 @@ -
+
  • {{ $t('vault.dashboard_due_tasks_blank') }} diff --git a/resources/js/Pages/Vault/Journal/Post/Edit.vue b/resources/js/Pages/Vault/Journal/Post/Edit.vue index cf97ae33f59..57604402851 100644 --- a/resources/js/Pages/Vault/Journal/Post/Edit.vue +++ b/resources/js/Pages/Vault/Journal/Post/Edit.vue @@ -64,6 +64,14 @@ const update = () => { }) .catch(() => {}); }; + +const destroy = () => { + if (confirm('Are you sure you want to delete this post?')) { + form.delete(props.data.url.destroy, { + onFinish: () => {}, + }); + } +};