Skip to content

Commit 58e2470

Browse files
authored
Merge pull request #88 from devaslanphp/dev
Companies and permissions integration
2 parents 47feb23 + 8a25353 commit 58e2470

57 files changed

Lines changed: 1497 additions & 374 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Core/LogsActivity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getActivitylogOptions(): LogOptions
2222
->logOnly($this->getFillable())
2323
->setDescriptionForEvent(fn(string $eventName) => new HtmlString(
2424
'<div class="flex flex-col gap-1">'
25-
. auth()->user()->name . " " . $eventName . " " . $this->fromCamelCase((new \ReflectionClass($this))->getShortName()) . " " . $this
25+
. (auth()->user()->name ?? '') . " " . $eventName . " " . $this->fromCamelCase((new \ReflectionClass($this))->getShortName()) . " " . $this
2626
. ' <a class="text-primary-500 hover:underline hover:cursor-pointer" target="_blank" href="' . $this->activityLogLink() . '">' . __('See details') . '</a>'
2727
. '</div>'
2828
));
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
3+
namespace App\Http\Livewire\Administration;
4+
5+
use App\Models\Company;
6+
use App\Tables\Columns\UserColumn;
7+
use Filament\Tables\Actions\Action;
8+
use Filament\Tables\Columns\BooleanColumn;
9+
use Filament\Tables\Columns\ImageColumn;
10+
use Filament\Tables\Columns\TagsColumn;
11+
use Filament\Tables\Columns\TextColumn;
12+
use Filament\Tables\Concerns\InteractsWithTable;
13+
use Filament\Tables\Contracts\HasTable;
14+
use Illuminate\Database\Eloquent\Builder;
15+
use Illuminate\Database\Eloquent\Relations\Relation;
16+
use Illuminate\Support\HtmlString;
17+
use Livewire\Component;
18+
19+
class Companies extends Component implements HasTable
20+
{
21+
use InteractsWithTable;
22+
23+
public $selectedCompany;
24+
25+
protected $listeners = ['companySaved', 'companyDeleted'];
26+
27+
public function render()
28+
{
29+
return view('livewire.administration.companies');
30+
}
31+
32+
/**
33+
* Table query definition
34+
*
35+
* @return Builder|Relation
36+
*/
37+
protected function getTableQuery(): Builder|Relation
38+
{
39+
$query = Company::query();
40+
if (auth()->user()->can('View own companies') && !auth()->user()->can('View all companies')) {
41+
$query->where('responsible_id', auth()->user()->id);
42+
} elseif (!auth()->user()->can('View all companies')) {
43+
// Get empty list
44+
$query->whereNull('id');
45+
}
46+
return $query;
47+
}
48+
49+
/**
50+
* Table definition
51+
*
52+
* @return array
53+
*/
54+
protected function getTableColumns(): array
55+
{
56+
return [
57+
ImageColumn::make('logo')
58+
->label(__('Logo'))
59+
->height(30),
60+
61+
TextColumn::make('name')
62+
->label(__('Company name'))
63+
->searchable()
64+
->sortable(),
65+
66+
UserColumn::make('responsible')
67+
->label(__('Responsible'))
68+
->searchable()
69+
->sortable(),
70+
71+
BooleanColumn::make('is_disabled')
72+
->label(__('Company activated'))
73+
->trueIcon('heroicon-o-x-circle')
74+
->falseIcon('heroicon-o-check-circle')
75+
->trueColor('danger')
76+
->falseColor('success')
77+
->searchable()
78+
->sortable(),
79+
80+
TagsColumn::make('users.name')
81+
->label(__('Company users'))
82+
->limit(1)
83+
->searchable()
84+
->sortable(),
85+
86+
TextColumn::make('created_at')
87+
->label(__('Created at'))
88+
->sortable()
89+
->searchable()
90+
->dateTime(),
91+
];
92+
}
93+
94+
/**
95+
* Table actions definition
96+
*
97+
* @return array
98+
*/
99+
protected function getTableActions(): array
100+
{
101+
return [
102+
Action::make('edit')
103+
->icon('heroicon-o-pencil')
104+
->link()
105+
->label(__('Edit company'))
106+
->visible(fn () => auth()->user()->can('Update companies'))
107+
->action(fn(Company $record) => $this->updateCompany($record->id))
108+
];
109+
}
110+
111+
/**
112+
* Table default sort column definition
113+
*
114+
* @return string|null
115+
*/
116+
protected function getDefaultTableSortColumn(): ?string
117+
{
118+
return 'created_at';
119+
}
120+
121+
/**
122+
* Table default sort direction definition
123+
*
124+
* @return string|null
125+
*/
126+
protected function getDefaultTableSortDirection(): ?string
127+
{
128+
return 'desc';
129+
}
130+
131+
/**
132+
* Show update company dialog
133+
*
134+
* @param $id
135+
* @return void
136+
*/
137+
public function updateCompany($id)
138+
{
139+
$this->selectedCompany = Company::find($id);
140+
$this->dispatchBrowserEvent('toggleCompanyModal');
141+
}
142+
143+
/**
144+
* Show create company dialog
145+
*
146+
* @return void
147+
*/
148+
public function createCompany()
149+
{
150+
$this->selectedCompany = new Company();
151+
$this->dispatchBrowserEvent('toggleCompanyModal');
152+
}
153+
154+
/**
155+
* Cancel and close company create / update dialog
156+
*
157+
* @return void
158+
*/
159+
public function cancelCompany()
160+
{
161+
$this->selectedCompany = null;
162+
$this->dispatchBrowserEvent('toggleCompanyModal');
163+
}
164+
165+
/**
166+
* Event launched after a company is created / updated
167+
*
168+
* @return void
169+
*/
170+
public function companySaved()
171+
{
172+
$this->cancelCompany();
173+
}
174+
175+
/**
176+
* Event launched after a company is deleted
177+
*
178+
* @return void
179+
*/
180+
public function companyDeleted()
181+
{
182+
$this->companySaved();
183+
}
184+
}

0 commit comments

Comments
 (0)