-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from devaslanphp/dev
Migrate configuration to DB
- Loading branch information
Showing
54 changed files
with
2,530 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Administration; | ||
|
||
use App\Models\TicketPriority; | ||
use Filament\Forms\Components\Grid; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Livewire\Component; | ||
|
||
class TicketPriorities extends Component implements HasForms | ||
{ | ||
use InteractsWithForms; | ||
|
||
public $search; | ||
public $selectedPriority; | ||
|
||
protected $listeners = ['prioritySaved', 'priorityDeleted']; | ||
|
||
public function mount(): void | ||
{ | ||
$this->form->fill(); | ||
} | ||
|
||
public function render() | ||
{ | ||
$query = TicketPriority::query(); | ||
if ($this->search) { | ||
$query->where('title', 'like', '%' . $this->search . '%') | ||
->orWhere('text_color', 'like', '%' . $this->search . '%') | ||
->orWhere('bg_color', 'like', '%' . $this->search . '%') | ||
->orWhere('icon', 'like', '%' . $this->search . '%'); | ||
} | ||
$priorities = $query->paginate(); | ||
return view('livewire.administration.ticket-priorities', compact('priorities')); | ||
} | ||
|
||
/** | ||
* Form schema definition | ||
* | ||
* @return array | ||
*/ | ||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
Grid::make(1) | ||
->schema([ | ||
TextInput::make('search') | ||
->label(__('Search for tickets priorities')) | ||
->disableLabel() | ||
->type('search') | ||
->placeholder(__('Search for tickets priorities')), | ||
]), | ||
]; | ||
} | ||
|
||
/** | ||
* Search for tickets statutses | ||
* | ||
* @return void | ||
*/ | ||
public function search(): void | ||
{ | ||
$data = $this->form->getState(); | ||
$this->search = $data['search'] ?? null; | ||
} | ||
|
||
/** | ||
* Show update priority dialog | ||
* | ||
* @param $id | ||
* @return void | ||
*/ | ||
public function updatePriority($id) | ||
{ | ||
$this->selectedPriority = TicketPriority::find($id); | ||
$this->dispatchBrowserEvent('togglePriorityModal'); | ||
} | ||
|
||
/** | ||
* Show create priority dialog | ||
* | ||
* @return void | ||
*/ | ||
public function createPriority() | ||
{ | ||
$this->selectedPriority = new TicketPriority(); | ||
$this->dispatchBrowserEvent('togglePriorityModal'); | ||
} | ||
|
||
/** | ||
* Cancel and close priority create / update dialog | ||
* | ||
* @return void | ||
*/ | ||
public function cancelPriority() | ||
{ | ||
$this->selectedPriority = null; | ||
$this->dispatchBrowserEvent('togglePriorityModal'); | ||
} | ||
|
||
/** | ||
* Event launched after a priority is created / updated | ||
* | ||
* @return void | ||
*/ | ||
public function prioritySaved() { | ||
$this->search(); | ||
$this->cancelPriority(); | ||
} | ||
|
||
/** | ||
* Event launched after a priority is deleted | ||
* | ||
* @return void | ||
*/ | ||
public function priorityDeleted() { | ||
$this->prioritySaved(); | ||
} | ||
} |
172 changes: 172 additions & 0 deletions
172
app/Http/Livewire/Administration/TicketPrioritiesDialog.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Administration; | ||
|
||
use App\Models\TicketPriority; | ||
use Closure; | ||
use Filament\Forms\Components\ColorPicker; | ||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Filament\Notifications\Actions\Action; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\HtmlString; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Validation\Rules\Unique; | ||
use Livewire\Component; | ||
|
||
class TicketPrioritiesDialog extends Component implements HasForms | ||
{ | ||
use InteractsWithForms; | ||
|
||
public TicketPriority $priority; | ||
public bool $deleteConfirmationOpened = false; | ||
|
||
protected $listeners = ['doDeletePriority', 'cancelDeletePriority']; | ||
|
||
public function mount(): void | ||
{ | ||
$this->form->fill([ | ||
'title' => $this->priority->title, | ||
'text_color' => $this->priority->text_color, | ||
'bg_color' => $this->priority->bg_color, | ||
'icon' => $this->priority->icon, | ||
]); | ||
} | ||
|
||
|
||
public function render() | ||
{ | ||
return view('livewire.administration.ticket-priorities-dialog'); | ||
} | ||
|
||
/** | ||
* Form schema definition | ||
* | ||
* @return array | ||
*/ | ||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
TextInput::make('title') | ||
->label(__('Title')) | ||
->maxLength(255) | ||
->unique(table: TicketPriority::class, column: 'title', ignorable: fn () => $this->priority, callback: function (Unique $rule) { | ||
return $rule->withoutTrashed(); | ||
}) | ||
->required(), | ||
|
||
ColorPicker::make('text_color') | ||
->label(__('Text color')) | ||
->required(), | ||
|
||
ColorPicker::make('bg_color') | ||
->label(__('Background color')) | ||
->required(), | ||
|
||
Select::make('icon') | ||
->label(__('Icon')) | ||
->reactive() | ||
->searchable() | ||
->required() | ||
->hint(fn(Closure $get) => $get('icon') ? new HtmlString(__('Selected icon:') . ' <i class="fa fa-2x ' . $get('icon') . '"></i>') : '') | ||
->helperText(new HtmlString(__("Check the <a href='https://fontawesome.com/icons' target='_blank' class='text-blue-500 underline'>fontawesome icons here</a> to choose your right icon"))) | ||
->options(DB::table('icons')->get()->pluck('icon', 'icon')->toArray()), | ||
]; | ||
} | ||
|
||
/** | ||
* Create / Update the priority | ||
* | ||
* @return void | ||
*/ | ||
public function save(): void | ||
{ | ||
$data = $this->form->getState(); | ||
if (!$this->priority?->id) { | ||
$priority = TicketPriority::create([ | ||
'title' => $data['title'], | ||
'text_color' => $data['text_color'], | ||
'bg_color' => $data['bg_color'], | ||
'icon' => $data['icon'], | ||
'slug' => Str::slug($data['title'], '_') | ||
]); | ||
Notification::make() | ||
->success() | ||
->title(__('Priority created')) | ||
->body(__('The priority has been created')) | ||
->send(); | ||
} else { | ||
$this->priority->title = $data['title']; | ||
$this->priority->text_color = $data['text_color']; | ||
$this->priority->bg_color = $data['bg_color']; | ||
$this->priority->icon = $data['icon']; | ||
$this->priority->slug = Str::slug($data['title'], '_'); | ||
$this->priority->save(); | ||
Notification::make() | ||
->success() | ||
->title(__('Priority updated')) | ||
->body(__('The priority\'s details has been updated')) | ||
->send(); | ||
} | ||
$this->emit('prioritySaved'); | ||
} | ||
|
||
/** | ||
* Delete an existing priority | ||
* | ||
* @return void | ||
*/ | ||
public function doDeletePriority(): void | ||
{ | ||
$this->priority->delete(); | ||
$this->deleteConfirmationOpened = false; | ||
$this->emit('priorityDeleted'); | ||
Notification::make() | ||
->success() | ||
->title(__('Priority deleted')) | ||
->body(__('The priority has been deleted')) | ||
->send(); | ||
} | ||
|
||
/** | ||
* Cancel the deletion of a priority | ||
* | ||
* @return void | ||
*/ | ||
public function cancelDeletePriority(): void | ||
{ | ||
$this->deleteConfirmationOpened = false; | ||
} | ||
|
||
/** | ||
* Show the delete priority confirmation dialog | ||
* | ||
* @return void | ||
* @throws \Exception | ||
*/ | ||
public function deletePriority(): void | ||
{ | ||
$this->deleteConfirmationOpened = true; | ||
Notification::make() | ||
->warning() | ||
->title(__('Priority deletion')) | ||
->body(__('Are you sure you want to delete this priority?')) | ||
->actions([ | ||
Action::make('confirm') | ||
->label(__('Confirm')) | ||
->color('danger') | ||
->button() | ||
->close() | ||
->emit('doDeletePriority'), | ||
Action::make('cancel') | ||
->label(__('Cancel')) | ||
->close() | ||
->emit('cancelDeletePriority') | ||
]) | ||
->persistent() | ||
->send(); | ||
} | ||
} |
Oops, something went wrong.