Skip to content

Commit 32e4b0c

Browse files
committed
Added board to deals
1 parent 3720e1b commit 32e4b0c

File tree

15 files changed

+182
-5
lines changed

15 files changed

+182
-5
lines changed

resources/views/deals/board.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('laravel-crm::layouts.app')
2+
3+
@section('content')
4+
5+
@include('laravel-crm::deals.partials.card-board')
6+
7+
@endsection
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@component('laravel-crm::components.card')
2+
3+
@component('laravel-crm::components.card-header')
4+
5+
@slot('title')
6+
{{ ucfirst(__('laravel-crm::lang.deals')) }}
7+
@endslot
8+
9+
@slot('actions')
10+
@include('laravel-crm::partials.view-types', [
11+
'model' => 'deals',
12+
])
13+
@include('laravel-crm::partials.filters', [
14+
'action' => route('laravel-crm.deals.filter'),
15+
'model' => '\VentureDrake\LaravelCrm\Models\Deal'
16+
])
17+
@can('create crm deals')
18+
<a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.deals.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_deal')) }}</a>
19+
@endcan
20+
@endslot
21+
22+
@endcomponent
23+
24+
@component('laravel-crm::components.card-table')
25+
26+
<livewire:live-deal-board />
27+
28+
@endcomponent
29+
30+
@endcomponent

resources/views/deals/partials/card-index.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
@endslot
88

99
@slot('actions')
10+
@if($pipeline)
11+
@include('laravel-crm::partials.view-types', [
12+
'model' => 'deals',
13+
'viewSetting' => $viewSetting ?? 'list'
14+
])
15+
@endif
16+
1017
@include('laravel-crm::partials.filters', [
1118
'action' => route('laravel-crm.deals.filter'),
1219
'model' => '\VentureDrake\LaravelCrm\Models\Deal'
1320
])
1421
@can('create crm deals')
15-
<span class="float-right"><a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.deals.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_deal')) }}</a></span>
22+
<a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.deals.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_deal')) }}</a>
1623
@endcan
1724
@endslot
1825

resources/views/livewire/kanban-board/record.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'limit' => 3
77
])
88
<div class="mt-2">
9-
<a href="{{ url(route('laravel-crm.leads.show', $record['id'])) }}">LD-{{ $record['id'] }}</a>
9+
<a href="{{ url(route('laravel-crm.'.\Illuminate\Support\Str::plural($model).'.show', $record['id'])) }}">LD-{{ $record['id'] }}</a>
1010
<div class="mb-0 d-inline-block float-right"><i class="fa fa-user-circle" aria-hidden="true"></i></div>
1111
</div>
1212
</div>

resources/views/livewire/kanban-board/stage.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
@endforeach
2020
</div>
2121
<div class="card-footer">
22-
<a href="{{ url(route('laravel-crm.leads.create', ['stage' => $stage['id']])) }}" class="btn btn-primary btn-block">Add lead</a>
22+
<a href="{{ url(route('laravel-crm.'.\Illuminate\Support\Str::plural($model).'.create', ['stage' => $stage['id']])) }}" class="btn btn-primary btn-block">Add
23+
{{ $model }}</a>
2324
</div>
2425
</div>
2526
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="btn-group" role="group" aria-label="Switch view">
2-
<a href="{{ route('laravel-crm.leads.list') }}" type="button" class="btn btn-sm btn-outline-secondary {{ ($viewSetting == 'list') ? 'active' : null }}" data-toggle="tooltip" data-placement="top" title="View {{ $model ?? null }} as list"><i class="fa fa-solid fa-list"></i></a>
3-
<a href="{{ route('laravel-crm.leads.board') }}" type="button" class="btn btn-sm btn-outline-secondary {{ ($viewSetting == 'board') ? 'active' : null }}" data-toggle="tooltip" data-placement="top" title="View {{ $model ?? null }} as board"><i class="fa fas fa-th"></i></a>
2+
<a href="{{ route('laravel-crm.'.$model.'.list') }}" type="button" class="btn btn-sm btn-outline-secondary {{ ($viewSetting == 'list') ? 'active' : null }}" data-toggle="tooltip" data-placement="top" title="View {{ $model ?? null }} as list"><i class="fa fa-solid fa-list"></i></a>
3+
<a href="{{ route('laravel-crm.'.$model.'.board') }}" type="button" class="btn btn-sm btn-outline-secondary {{ ($viewSetting == 'board') ? 'active' : null }}" data-toggle="tooltip" data-placement="top" title="View {{ $model ?? null }} as board"><i class="fa fas fa-th"></i></a>
44
</div>

src/Http/Controllers/DealController.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use VentureDrake\LaravelCrm\Models\Deal;
1212
use VentureDrake\LaravelCrm\Models\Organisation;
1313
use VentureDrake\LaravelCrm\Models\Person;
14+
use VentureDrake\LaravelCrm\Models\Pipeline;
1415
use VentureDrake\LaravelCrm\Services\DealService;
1516
use VentureDrake\LaravelCrm\Services\OrganisationService;
1617
use VentureDrake\LaravelCrm\Services\PersonService;
@@ -46,6 +47,18 @@ public function __construct(DealService $dealService, PersonService $personServi
4647
*/
4748
public function index(Request $request)
4849
{
50+
$viewSetting = auth()->user()->crmSettings()->where('name', 'view_deals')->first();
51+
52+
if(! $viewSetting) {
53+
auth()->user()->crmSettings()->create([
54+
'name' => 'view_deals',
55+
'value' => 'list',
56+
]);
57+
} elseif($viewSetting->value == 'board') {
58+
return redirect(route('laravel-crm.deals.board'));
59+
}
60+
61+
4962
Deal::resetSearchValue($request);
5063
$params = Deal::filters($request);
5164

@@ -57,6 +70,8 @@ public function index(Request $request)
5770

5871
return view('laravel-crm::deals.index', [
5972
'deals' => $deals,
73+
'viewSetting' => $viewSetting->value ?? null,
74+
'pipeline' => Pipeline::where('model', get_class(new Deal()))->first(),
6075
]);
6176
}
6277

@@ -361,4 +376,45 @@ public function reopen(Deal $deal)
361376

362377
return back();
363378
}
379+
380+
public function list(Request $request)
381+
{
382+
auth()->user()->crmSettings()->updateOrCreate([
383+
'name' => 'view_deals',
384+
], [
385+
'value' => 'list',
386+
]);
387+
388+
return redirect(route('laravel-crm.deals.index'));
389+
}
390+
391+
/**
392+
* Display a listing of the resource.
393+
*
394+
* @return \Illuminate\Http\Response
395+
*/
396+
public function board(Request $request)
397+
{
398+
$viewSetting = auth()->user()->crmSettings()->where('name', 'view_deals')->first();
399+
400+
auth()->user()->crmSettings()->updateOrCreate([
401+
'name' => 'view_deals',
402+
], [
403+
'value' => 'board',
404+
]);
405+
406+
Deal::resetSearchValue($request);
407+
$params = Deal::filters($request);
408+
409+
if (Deal::filter($params)->get()->count() < 30) {
410+
$deals = Deal::filter($params)->latest()->get();
411+
} else {
412+
$deals = Deal::filter($params)->latest()->paginate(30);
413+
}
414+
415+
return view('laravel-crm::deals.board', [
416+
'deals' => $deals,
417+
'viewSetting' => $viewSetting->value ?? null
418+
]);
419+
}
364420
}

src/Http/Livewire/KanbanBoard/KanbanBoard.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class KanbanBoard extends Component
99
{
10+
public $model;
11+
1012
public $sortable;
1113
public $sortableBetweenStages;
1214

src/Http/Livewire/LiveDealBoard.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\Http\Livewire;
4+
5+
use Illuminate\Support\Collection;
6+
use VentureDrake\LaravelCrm\Http\Livewire\KanbanBoard\KanbanBoard;
7+
use VentureDrake\LaravelCrm\Models\Deal;
8+
use VentureDrake\LaravelCrm\Models\Pipeline;
9+
10+
class LiveDealBoard extends KanbanBoard
11+
{
12+
public $model = 'deal';
13+
14+
public function stages(): Collection
15+
{
16+
if($pipeline = Pipeline::where('model', get_class(new Deal()))->first()) {
17+
return $pipeline->pipelineStages()
18+
->orderBy('order')
19+
->orderBy('id')
20+
->get();
21+
}
22+
}
23+
24+
public function onStageChanged($recordId, $stageId, $fromOrderedIds, $toOrderedIds)
25+
{
26+
Deal::find($recordId)->update([
27+
'pipeline_stage_id' => $stageId
28+
]);
29+
}
30+
31+
public function records(): Collection
32+
{
33+
return Deal::get()
34+
->map(function (Deal $deal) {
35+
return [
36+
'id' => $deal->id,
37+
'title' => $deal->title,
38+
'labels' => $deal->labels,
39+
'stage' => $deal->pipelineStage->id ?? $this->firstStageId(),
40+
];
41+
});
42+
}
43+
}

src/Http/Livewire/LiveLeadBoard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class LiveLeadBoard extends KanbanBoard
1111
{
12+
public $model = 'lead';
1213
public function stages(): Collection
1314
{
1415
if($pipeline = Pipeline::where('model', get_class(new Lead()))->first()) {

0 commit comments

Comments
 (0)