Skip to content

Commit

Permalink
Merge pull request #28 from codions/features
Browse files Browse the repository at this point in the history
Display items within the project layout
  • Loading branch information
fabioassuncao committed Jul 12, 2023
2 parents 15fa360 + a95bc76 commit 1ba413e
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 229 deletions.
42 changes: 0 additions & 42 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,14 @@

namespace App\Http\Controllers;

use App\Enums\ItemActivity;
use App\Models\Item;
use App\Models\Project;
use App\Settings\GeneralSettings;
use Filament\Notifications\Notification;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Spatie\Activitylog\Models\Activity;

class ItemController extends Controller
{
public function show($projectId, $itemId = null)
{
$project = null;

if (! $itemId) {
$item = Item::query()->visibleForCurrentUser()->where('slug', $projectId)->firstOrFail();
} else {
$project = Project::query()->visibleForCurrentUser()->where('slug', $projectId)->firstOrFail();

$item = $project->items()->visibleForCurrentUser()->where('items.slug', $itemId)->firstOrFail();
}

$showGitHubLink = app(GeneralSettings::class)->show_github_link;

$activities = $item->activities()->with('causer')->latest()->limit(10)->get()->filter(function (Activity $activity) use ($showGitHubLink) {
if (! $showGitHubLink && ItemActivity::getForActivity($activity) === ItemActivity::LinkedToIssue) {
return false;
}

return true;
})->map(function (Activity $activity) {
$itemActivity = ItemActivity::getForActivity($activity);

if ($itemActivity !== null) {
$activity->description = $itemActivity->getTranslation($activity->properties->get('attributes'));
}

return $activity;
});

return view('item', [
'project' => $project,
'board' => $item->board,
'item' => $item->load('tags'),
'user' => $item->user,
'activities' => $activities,
]);
}

public function edit($id)
{
$item = auth()->user()->items()->findOrFail($id);
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Livewire/Items/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public function submit()
$this->private_content = '';
$this->reply = null;

if ($this->item->project) {
$this->redirectRoute('projects.items.show', [$this->item->project, $this->item]);
}

$this->redirectRoute('items.show', [$this->item]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Items/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function submit()

$this->notify('success', trans('items.item_created'));

$this->redirectRoute('projects.items.show', [$this->project, $item]);
$this->redirectRoute('items.show', $item);
}

public function render()
Expand Down
69 changes: 69 additions & 0 deletions app/Http/Livewire/Items/Show.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Http\Livewire\Items;

use App\Enums\ItemActivity;
use App\Models\Item;
use App\Settings\GeneralSettings;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;

class Show extends Component
{
public $project;

public $board;

public $item;

public $user;

public $activities;

public function mount($item)
{
$this->item = Item::query()->visibleForCurrentUser()->where('slug', $item)->firstOrFail();

$showGitHubLink = app(GeneralSettings::class)->show_github_link;

$this->activities = $this->item->activities()->with('causer')->latest()->limit(10)->get()->filter(function (Activity $activity) use ($showGitHubLink) {
if (! $showGitHubLink && ItemActivity::getForActivity($activity) === ItemActivity::LinkedToIssue) {
return false;
}

return true;
})->map(function (Activity $activity) {
$itemActivity = ItemActivity::getForActivity($activity);

if ($itemActivity !== null) {
$activity->description = $itemActivity->getTranslation($activity->properties->get('attributes'));
}

return $activity;
});

$this->project = $this->item->project;
$this->board = $this->item->board;
$this->item = $this->item->load('tags');
$this->user = $this->item->user;
}

public function render(): View
{
$layout = $this->project
? \App\View\Components\Layouts\Project::class
: \App\View\Components\Layouts\App::class;

return view('livewire.item.show')
->layout($layout)
->layoutData([
'project' => $this->project,
'breadcrumbs' => [
['title' => $this->project->title, 'url' => route('projects.home', $this->project)],
['title' => $this->board->title, 'url' => route('projects.boards.show', [$this->project, $this->board])],
['title' => $this->item->title, 'url' => route('items.show', $this->item)],
],
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Modals/Item/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function submit()
});
}

return redirect()->route('items.show', $item->slug);
return $this->redirectRoute('items.show', $item->slug);
}

public function setSimilarItems($state): void
Expand Down
10 changes: 1 addition & 9 deletions app/Http/Livewire/My.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ protected function getTableColumns(): array
protected function getTableRecordUrlUsing(): ?Closure
{
return function ($record) {
if (! $record->board) {
return route('items.show', $record);
}

if (! $record->project) {
return route('items.show', $record);
}

return route('projects.items.show', [$record->project, $record]);
return route('items.show', $record);
};
}

Expand Down
6 changes: 1 addition & 5 deletions app/Http/Livewire/Welcome/RecentItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ protected function getTableRecordUrlUsing(): ?Closure
return route('items.show', $record);
}

if (! $record->project) {
return route('items.show', $record);
}

return route('projects.items.show', [$record->project, $record]);
return route('items.show', $record);
};
}

Expand Down
145 changes: 0 additions & 145 deletions resources/views/item.blade.php

This file was deleted.

6 changes: 3 additions & 3 deletions resources/views/layouts/project.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class="w-10 h-10 text-gray-500 dark:text-gray-400"/>
<a
@class([
'flex items-center h-10 px-2 space-x-2 transition rounded-lg ',
'text-white bg-brand-500' => request()->is('projects/*/boards*'),
'hover:bg-gray-500/5 focus:bg-brand-500/10 focus:text-brand-600 focus:outline-none' => !request()->is('projects/*/boards*')
'text-white bg-brand-500' => (request()->is('projects/*/boards*') || request()->is('items*')),
'hover:bg-gray-500/5 focus:bg-brand-500/10 focus:text-brand-600 focus:outline-none' => (!request()->is('projects/*/boards*') && !request()->is('items*'))
])
href="{{ route('projects.boards', $project) }}">

<x-heroicon-o-view-boards class="w-5 h-5 {{ !request()->is('projects/*/boards*') ? 'text-gray-500' : '' }}"/>
<x-heroicon-o-view-boards class="w-5 h-5 {{ (!request()->is('projects/*/boards*') && !request()->is('items*')) ? 'text-gray-500' : '' }}"/>
<span class="font-medium">{{ trans('projects.roadmap') }}</span>
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/board/item-card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span class="">{{ $item->total_votes }}</span>
</div>

<a href="{{ route('projects.items.show', [$project, $item]) }}" class="flex-1">
<a href="{{ route('items.show', $item) }}" class="flex-1">
<p class="font-bold text-lg group-hover:text-brand-500">{{ $item->title }}</p>
<p>{{ $item->excerpt }}</p>
</a>
Expand Down
Loading

0 comments on commit 1ba413e

Please sign in to comment.