Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Opportunity Pipeline View #211

Merged
merged 1 commit into from
Oct 16, 2024
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
87 changes: 87 additions & 0 deletions app/Filament/App/Resources/OpportunityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,93 @@

namespace App\Filament\App\Resources;

use App\Filament\App\Resources\OpportunityResource\Pages;
use App\Models\Opportunity;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class OpportunityResource extends Resource
{
protected static ?string $model = Opportunity::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
{
return $form
->schema([
// Your form schema here
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('value')
->money()
->sortable(),
Tables\Columns\TextColumn::make('stage.name')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPipelineTable(Table $table): Table
{
return $table
->columns([
Tables\Columns\ViewColumn::make('pipeline')
->view('livewire.opportunity-pipeline')
->label('Pipeline View')
])
->paginated(false);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListOpportunities::route('/'),
'create' => Pages\CreateOpportunity::route('/create'),
'edit' => Pages\EditOpportunity::route('/{record}/edit'),
];
}
}

namespace App\Filament\App\Resources;

use Filament\Forms;
use Filament\Tables;
use Filament\Forms\Form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use App\Filament\App\Resources\OpportunityResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

use Illuminate\Contracts\View\View;
use Illuminate\Contracts\View\View;
use Filament\Tables\Table;

class ListOpportunities extends ListRecords
{
Expand All @@ -20,8 +18,8 @@ protected function getHeaderActions(): array
];
}

public function table(): View
public function table(Table $table): Table
{
return OpportunityResource::getPipelineView();
return OpportunityResource::getPipelineTable($table);
}
}
42 changes: 42 additions & 0 deletions app/Http/Livewire/OpportunityPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Pipeline;
use App\Models\Deal;
use App\Models\Stage;
use Filament\Tables\Table;

class OpportunityPipeline extends Component
{
public $stages;
public $deals;
public Table $table;

public function mount(Table $table)
{
$this->table = $table;
$this->loadPipeline();
}

public function loadPipeline()
{
$pipeline = Pipeline::first();
$this->stages = $pipeline->stages;
$this->deals = Deal::all()->groupBy('stage_id');
}

public function updateDealStage($dealId, $stageId)
{
$deal = Deal::findOrFail($dealId);
$deal->stage_id = $stageId;
$deal->save();

$this->loadPipeline();
}

public function render()
{
return view('livewire.opportunity-pipeline');
}
}

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Pipeline;
use App\Models\Deal;
Expand Down
52 changes: 27 additions & 25 deletions resources/views/livewire/opportunity-pipeline.blade.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<div class="opportunity-pipeline">
<div class="flex overflow-x-auto">
@foreach($stages as $stage)
<div class="flex-shrink-0 w-64 p-4 bg-gray-100 rounded-lg mr-4">
<h3 class="text-lg font-semibold mb-4">{{ $stage->name }}</h3>
<div class="stage-deals"
data-stage-id="{{ $stage->id }}"
x-data="{ draggable: true }"
x-init="
new Sortable($el, {
group: 'deals',
animation: 150,
onEnd: function(evt) {
@this.call('updateDealStage', evt.item.dataset.dealId, evt.to.dataset.stageId);
}
})
">
@foreach($deals[$stage->id] ?? [] as $deal)
<div class="deal-card bg-white p-3 rounded shadow mb-2" data-deal-id="{{ $deal->id }}">
<h4 class="font-semibold">{{ $deal->name }}</h4>
<p class="text-sm text-gray-600">{{ $deal->value }}</p>
</div>
@endforeach
<div id="opportunity-pipeline-wrapper">
<div class="opportunity-pipeline">
<div class="flex overflow-x-auto">
@foreach($stages as $stage)
<div class="flex-shrink-0 w-64 p-4 bg-gray-100 rounded-lg mr-4">
<h3 class="text-lg font-semibold mb-4">{{ $stage->name }}</h3>
<div class="stage-deals"
data-stage-id="{{ $stage->id }}"
x-data="{ draggable: true }"
x-init="
new Sortable($el, {
group: 'deals',
animation: 150,
onEnd: function(evt) {
@this.call('updateDealStage', evt.item.dataset.dealId, evt.to.dataset.stageId);
}
})
">
@foreach($deals[$stage->id] ?? [] as $deal)
<div class="deal-card bg-white p-3 rounded shadow mb-2" data-deal-id="{{ $deal->id }}">
<h4 class="font-semibold">{{ $deal->name }}</h4>
<p class="text-sm text-gray-600">{{ $deal->value }}</p>
</div>
@endforeach
</div>
</div>
</div>
@endforeach
@endforeach
</div>
</div>
</div>
Loading