Skip to content

Commit

Permalink
Merge branch '1.x' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Mar 23, 2024
2 parents db9632b + 62afa24 commit f220d1f
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 72 deletions.
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,21 @@ And more on the way.

### install

`composer require lara-zeus/tartarus`

## setup
## Installations:

add locales to zeus-tartarus.php
- install laravel
- install filament
or use the [filament installer](https://github.com/lara-zeus/filament-installer) to install both together

```php
'locales' => [
'en' => ['name' => 'English', 'native' => 'English', 'regional' => 'en_GB', 'flag' => 'gb'],
],
```
### Env:
- run `composer require lara-zeus/tartarus`
- run `php artisan tartarus:install `
- run `php artisan migrate:fresh --seed`
- `npm i && npm run dev`
- login: email: `[email protected]` pass: `basebasebase`

`CENTRAL_DOMAIN=domain.test`

### config

- filament-logger.php:
```php
'activity_resource' => \LaraZeus\Erebus\Filament\Clusters\Employees\Resources\ActivityResource::class,
```
## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on recent changes.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
"require": {
"php": "^8.1",
"awcodes/preset-color-picker": "^0.1.0",
"spatie/laravel-package-tools": "^1.16",
"calebporzio/sushi": "^2.4",
"filament/filament": "^3.2",
"filament/spatie-laravel-translatable-plugin": "^3.2",
"lara-zeus/chaos": "^1.0",
"lara-zeus/erebus": "^1.0",
"rickdbcn/filament-email": "^1.0",
"ryangjchandler/blade-tabler-icons": "^2.3",
"spatie/laravel-package-tools": "^1.16",
"spatie/laravel-tags": "^4.6",
"stechstudio/filament-impersonate": "^3.7"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait Configuration
protected Closure | string $navigationGroupLabel = 'Tartarus';

protected array $tartarusModels = [
//'Notification' => \LaraZeus\Tartarus\Models\Notification::class,
'Company' => \LaraZeus\Tartarus\Models\Company::class,
];

public function navigationGroupLabel(Closure | string $label): static
Expand Down
11 changes: 0 additions & 11 deletions src/Filament/Clusters/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Tartarus\Filament\Clusters;

use Filament\Clusters\Cluster;
use Illuminate\Contracts\Support\Htmlable;

class System extends Cluster
{
Expand All @@ -14,16 +13,6 @@ public static function getNavigationLabel(): string
return __('app.System_cluster');
}

public function getTitle(): string | Htmlable
{
return __('app.System_cluster');
}

public function getHeading(): string | Htmlable
{
return __('app.System_cluster');
}

public static function getClusterBreadcrumb(): ?string
{
return __('app.System_cluster');
Expand Down
26 changes: 14 additions & 12 deletions src/Middleware/SetTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Closure;
use Filament\Support\Colors\Color;
use Filament\Support\Facades\FilamentColor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use LaraZeus\Tartarus\Models\Company;
use Symfony\Component\HttpFoundation\Response;

class SetTenant
Expand All @@ -32,17 +32,19 @@ public function handle(Request $request, Closure $next): Response
return $next($request);
}

private function setPanelConfiguration(Model $tenant): void
private function setPanelConfiguration(Company $tenant): void
{
$colorName = str($tenant->primary_color ?? 'Blue')->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
FilamentColor::register([
'primary' => $color,
'secondary' => Color::Amber,
'danger' => Color::Red,
'info' => Color::Blue,
'success' => Color::Green,
'warning' => Color::Yellow,
]);
if ($tenant->primary_color !== null) {
$colorName = str($tenant->primary_color)->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
FilamentColor::register([
'primary' => $color,
'secondary' => Color::Amber,
'danger' => Color::Red,
'info' => Color::Blue,
'success' => Color::Green,
'warning' => Color::Yellow,
]);
}
}
}
15 changes: 12 additions & 3 deletions src/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Company extends Model implements HasAvatar, HasCurrentTenantLabel, HasName
use CompanyRelations;
use HasTranslations;

public function getTenantId(): ?string
{
// @phpstan-ignore-next-line
return auth()->user()?->company_id;
}

public array $translatable = ['name'];

public function saveCompanySettings(array $data): void
Expand Down Expand Up @@ -128,9 +134,12 @@ protected function defaultProfilePhotoUrl(): string
return mb_substr($segment, 0, 1);
})->join(' '));

$colorName = str(tenant()->primary_color ?? 'Blue')->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
$bgColor = 'BFA577';
if (tenant()->primary_color !== null) {
$colorName = str(tenant()->primary_color)->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
}

return sprintf('https://ui-avatars.com/api/?name=%s&color=FFFFFF&background=' . $bgColor, urlencode($name));
}
Expand Down
13 changes: 0 additions & 13 deletions src/Models/CompanyInvitation.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Models/Concerns/CompanyRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use LaraZeus\Tartarus\Models\CompanyInvitation;
use LaraZeus\Tartarus\Models\Employeeship;
use LaraZeus\Tartarus\Models\Settings;

Expand All @@ -16,11 +15,6 @@ public function owner(): BelongsTo
return $this->belongsTo(config('auth.providers.users.model'), 'user_id');
}

public function companyInvitations(): HasMany
{
return $this->hasMany(CompanyInvitation::class);
}

public function users(): BelongsToMany
{
return $this->belongsToMany(config('auth.providers.users.model'), Employeeship::class)
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Concerns/HasCompanies.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function ownsCompany(?Model $company = null): bool
return $this->id === $company->{$this->getForeignKey()};
}

public function belongsToCompany(?Company $company = null): bool
public function belongsToCompany(null | Company | Model $company = null): bool
{
if ($company === null) {
return false;
Expand Down
10 changes: 2 additions & 8 deletions stubs/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use LaraZeus\Tartarus\Models\Concerns\HasCompanies;
use LaraZeus\Tartarus\Models\ConnectedAccount;
use LaraZeus\Tartarus\Models\Employeeship;
use Rinvex\Subscriptions\Traits\HasPlanSubscriptions;
use Spatie\Color\Rgb;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Traits\HasRoles;
Expand All @@ -40,8 +39,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasDefaul
use ChaosModel;
use ForFilament;
use HasCompanies;

/*use HasPlanSubscriptions;*/
use HasRoles;
use HasTranslations;
use TwoFactorAuthenticatable;
Expand All @@ -57,10 +54,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasDefaul
'email_verified_at' => 'datetime',
];

/* *
* @var Company $tenant
*/
public function canAccessTenant(Model | Company $tenant): bool
public function canAccessTenant(null | Company | Model $tenant): bool
{
return $this->belongsToCompany($tenant);
}
Expand All @@ -83,7 +77,7 @@ protected function defaultProfilePhotoUrl(): string
if (tenant() !== null) {
$colorName = str(tenant()?->primary_color ?? 'Blue')->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '') ?? $bgColor;
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
}

return sprintf('https://ui-avatars.com/api/?name=%s&color=fff&background=' . $bgColor, urlencode($name));
Expand Down
Loading

0 comments on commit f220d1f

Please sign in to comment.