From 11e681ba32bb14727d5edc3a9b8df4c2456fd9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 25 Sep 2024 09:02:52 +0100 Subject: [PATCH] close #3214 Enhancement: Document list page add default tab feature --- app/Abstracts/Http/Controller.php | 14 +++ .../View/Components/Documents/Index.php | 16 +++- app/Http/Livewire/Tab/Pin.php | 96 +++++++++++++++++++ app/Traits/ViewComponents.php | 13 +++ config/type.php | 2 + resources/lang/en-GB/general.php | 5 + .../documents/index/content.blade.php | 47 +++++++-- .../views/components/tabs/nav-pin.blade.php | 21 ++++ resources/views/livewire/tab/pin.blade.php | 35 +++++++ 9 files changed, 241 insertions(+), 8 deletions(-) create mode 100644 app/Http/Livewire/Tab/Pin.php create mode 100644 resources/views/components/tabs/nav-pin.blade.php create mode 100644 resources/views/livewire/tab/pin.blade.php diff --git a/app/Abstracts/Http/Controller.php b/app/Abstracts/Http/Controller.php index 07e86d35c..1c2ed8381 100644 --- a/app/Abstracts/Http/Controller.php +++ b/app/Abstracts/Http/Controller.php @@ -100,6 +100,20 @@ abstract class Controller extends BaseController public function setActiveTabForDocuments(): void { + // Added this method to set the active tab for documents + if (! request()->has('list_records') && ! request()->has('search')) { + $tab_pins = setting('favorites.tab.' . user()->id, []); + $tab_pins = json_decode($tab_pins, true); + + if (! empty($tab_pins) && ! empty($tab_pins[$this->type])) { + $data = config('type.document.' . $this->type . '.route.params.' . $tab_pins[$this->type]); + + if (! empty($data)) { + request()->merge($data); + } + } + } + if (request()->get('list_records') == 'all') { return; } diff --git a/app/Abstracts/View/Components/Documents/Index.php b/app/Abstracts/View/Components/Documents/Index.php index 1e652826f..ffdb00ea6 100644 --- a/app/Abstracts/View/Components/Documents/Index.php +++ b/app/Abstracts/View/Components/Documents/Index.php @@ -567,10 +567,24 @@ abstract class Index extends Component $status = $this->getSearchStringValue('status'); - if ($status == 'draft') { + $unpaid = str_replace('status:', '', config('type.document.' . $type . '.route.params.unpaid.search')); + + if ($status == $unpaid) { + return 'unpaid'; + } + + $draft = str_replace('status:', '', config('type.document.' . $type . '.route.params.draft.search')); + + if ($status == $draft) { return 'draft'; } + $suffix = $this->getTabActiveFromSetting($type); + + if (! empty($suffix)) { + return $suffix; + } + return 'unpaid'; } diff --git a/app/Http/Livewire/Tab/Pin.php b/app/Http/Livewire/Tab/Pin.php new file mode 100644 index 000000000..f89228b65 --- /dev/null +++ b/app/Http/Livewire/Tab/Pin.php @@ -0,0 +1,96 @@ + 'render', + 'removedPin' => 'render', + ]; + + public function render(): View + { + $this->pinned = false; + + $pins = setting('favorites.tab.' . user()->id, []); + + if (! empty($pins) && ! $this->pinned) { + $pins = json_decode($pins, true); + $type_pinned = $pins[$this->type] ?? null; + + if (isset($pins[$this->type]) && $this->tab == $type_pinned) { + $this->pinned = true; + } + } + + return view('livewire.tab.pin'); + } + + public function changeStatus($tab) + { + if ($this->pinned) { + $this->removePin($tab); + } else { + $this->addPin($tab); + } + } + + public function addPin($tab) + { + $pins = setting('favorites.tab.' . user()->id, []); + + if (!empty($pins)) { + $pins = json_decode($pins, true); + } + + $type_pinned = $pins[$this->type] ?? null; + + if ($this->tab == $type_pinned) { + return; + } + + $pins[$this->type] = $tab; + + $this->pinned = true; + + setting(['favorites.tab.' . user()->id => json_encode($pins)])->save(); + + $this->dispatch('addedPin'); + } + + public function removePin($tab) + { + $pins = setting('favorites.tab.' . user()->id, []); + + if (!empty($pins)) { + $pins = json_decode($pins, true); + } + + foreach ($pins as $key => $pinned_id) { + if ($pinned_id != $tab) { + continue; + } + + unset($pins[$key]); + $this->pinned = false; + + break; + } + + setting(['favorites.tab.' . user()->id => json_encode($pins)])->save(); + + $this->dispatch('removedPin'); + } +} diff --git a/app/Traits/ViewComponents.php b/app/Traits/ViewComponents.php index 4a931caf5..753161346 100644 --- a/app/Traits/ViewComponents.php +++ b/app/Traits/ViewComponents.php @@ -214,6 +214,19 @@ trait ViewComponents return $script_key; } + public function getTabActiveFromSetting($type) + { + $tabs = setting('favorites.tab.' . user()->id, []); + + if (empty($tabs)) { + return false; + } + + $tabs = json_decode($tabs, true); + + return $tabs[$type] ?? false; + } + protected function getTextPage($type, $textPage) { if (! empty($textPage)) { diff --git a/config/type.php b/config/type.php index 4d7640cce..b3858a397 100644 --- a/config/type.php +++ b/config/type.php @@ -113,6 +113,7 @@ return [ 'params' => [ 'unpaid' => ['search' => 'status:sent,viewed,partial'], 'draft' => ['search' => 'status:draft'], + 'all' => ['list_records' => 'all'], ], ], 'permission' => [ @@ -218,6 +219,7 @@ return [ 'params' => [ 'unpaid' => ['search' => 'status:received,partial'], 'draft' => ['search' => 'status:draft'], + 'all' => ['list_records' => 'all'], ], ], 'permission' => [ diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php index 63659fad5..9176f52c4 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -316,6 +316,11 @@ return [ 'custom' => 'Custom', ], + 'pin_text' => [ + 'pin_tab' => 'Pin default tab', + 'unpin_tab' => 'Unpin default tab', + ], + 'empty' => [ 'documentation' => 'Check out the documentation for more details.', 'items' => 'Items can be products or services. You can use items when creating invoices and bills to have the price, tax etc fields populated.', diff --git a/resources/views/components/documents/index/content.blade.php b/resources/views/components/documents/index/content.blade.php index 710f648a7..83376575a 100644 --- a/resources/views/components/documents/index/content.blade.php +++ b/resources/views/components/documents/index/content.blade.php @@ -5,26 +5,59 @@ @if (! $withoutTabs) - + @stack('document_nav_start') @if ($tabActive == $type . '-unpaid') - + @else - + @endif @if ($tabActive == $type . '-draft') - + @else - + @endif @if ($tabActive == $type . '-all') - + @else - + @endif @stack('document_nav_end') diff --git a/resources/views/components/tabs/nav-pin.blade.php b/resources/views/components/tabs/nav-pin.blade.php new file mode 100644 index 000000000..ef733c557 --- /dev/null +++ b/resources/views/components/tabs/nav-pin.blade.php @@ -0,0 +1,21 @@ +@props(['id', 'name', 'href', 'active', 'type', 'tab']) + +@if (empty($href)) + +
+ {{ $name }} + + +
+
+@else + + + +@endif diff --git a/resources/views/livewire/tab/pin.blade.php b/resources/views/livewire/tab/pin.blade.php new file mode 100644 index 000000000..ea5e67513 --- /dev/null +++ b/resources/views/livewire/tab/pin.blade.php @@ -0,0 +1,35 @@ +