Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 28, 2023
1 parent 8375c62 commit 6897176
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Concerns/HasUlid.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function bootHasUlid()
// Generate ULID if none provided
static::creating(function (Model $model) {
if (! $model->{$model->ulidColumn}) {
$model->{$model->ulidColumn} = (string) Str::ulid();
$model->{$model->ulidColumn} = strtolower((string) Str::ulid());
}
});

Expand Down
75 changes: 75 additions & 0 deletions app/Filament/Resources/ServiceResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\ServiceResource\Pages;
use App\Models\Service;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class ServiceResource extends Resource
{
protected static ?string $model = Service::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function getNavigationGroup(): ?string
{
return __('navigation.configurations._group');
}

public static function getNavigationLabel(): string
{
return __('navigation.configurations.services');
}

public static function getModelLabel(): string
{
return __('service.label.singular');
}

public static function getPluralModelLabel(): string
{
return __('service.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label(__('service.field.name'))
->searchable(),

TextColumn::make('interventions_count')
->counts('interventions'),

])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
->visible(fn (Service $record) => ! $record->interventions_count),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ManageServices::route('/'),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/ServiceResource/Pages/ManageServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\ServiceResource\Pages;

use App\Filament\Resources\ServiceResource;
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;

class ManageServices extends ManageRecords
{
protected static string $resource = ServiceResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
25 changes: 25 additions & 0 deletions app/Models/Intervention.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Models;

use App\Concerns\BelongsToOrganization;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Intervention extends Model
{
use BelongsToOrganization;
use HasFactory;
use HasUlids;

public $with = ['service'];

public function service(): BelongsTo
{
return $this->belongsTo(Service::class);
}
}
6 changes: 6 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Filament\Models\Contracts\HasAvatar;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
Expand Down Expand Up @@ -42,6 +43,11 @@ public function users(): MorphToMany
return $this->morphedByMany(User::class, 'model', 'model_has_organizations');
}

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

public function registerMediaCollections(): void
{
$this->addMediaCollection('logo')
Expand Down
23 changes: 23 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Models;

use App\Concerns\BelongsToOrganization;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Service extends Model
{
use BelongsToOrganization;
use HasFactory;
use HasUlids;

public function interventions(): HasMany
{
return $this->hasMany(Intervention::class);
}
}
3 changes: 1 addition & 2 deletions app/Providers/Filament/OrganizationPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Support\Enums\Alignment;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
Expand Down Expand Up @@ -63,7 +62,7 @@ public function panel(Panel $panel): Panel
// Widgets\AccountWidget::class,
])
->bootUsing(function () {
Page::formActionsAlignment(Alignment::End);
Page::alignFormActionsEnd();
})
->databaseNotifications()
->plugins([
Expand Down
26 changes: 26 additions & 0 deletions database/factories/InterventionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Intervention>
*/
class InterventionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->paragraph(),
];
}
}
12 changes: 12 additions & 0 deletions database/factories/OrganizationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Database\Factories;

use App\Models\City;
use App\Models\Intervention;
use App\Models\Organization;
use App\Models\Service;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\Sequence;
Expand Down Expand Up @@ -53,6 +55,16 @@ public function configure(): static
->pluck('id')
->toArray()
);

Service::factory()
->count(5)
->for($organization)
->has(
Intervention::factory()
->count(5)
->for($organization)
)
->create();
});
}
}
26 changes: 26 additions & 0 deletions database/factories/ServiceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Service>
*/
class ServiceFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->paragraph(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public function up(): void
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('prior_name')->nullable();
$table->string('full_name')->virtualAs(<<<'SQL'
NULLIF(CONCAT_WS(" ", first_name, last_name), " ")
SQL);

$table->string('civil_status')->nullable();
$table->decimal('cnp', 13, 0)->nullable();
Expand Down
22 changes: 22 additions & 0 deletions database/migrations/2023_11_28_124405_create_services_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use App\Models\Organization;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('services', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->timestamps();
$table->string('name');
$table->text('description')->nullable();
$table->foreignIdFor(Organization::class)->constrained()->cascadeOnDelete();
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use App\Models\Organization;
use App\Models\Service;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('interventions', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->timestamps();
$table->string('name');
$table->text('description')->nullable();
$table->foreignIdFor(Service::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(Organization::class)->constrained()->cascadeOnDelete();
});
}
};
16 changes: 16 additions & 0 deletions lang/ro/intervention.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

return [

'label' => [
'singular' => 'intervenție',
'plural' => 'Intervenții',
],

'field' => [
'name' => 'Numele intervenției',
'description' => 'Descrierea intervenției',
],
];
1 change: 1 addition & 0 deletions lang/ro/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

'configurations' => [
'_group' => 'Configurări',
'services' => 'Nomenclator servicii',
'staff' => 'Staff',
],

Expand Down
16 changes: 16 additions & 0 deletions lang/ro/service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

return [

'label' => [
'singular' => 'serviciu',
'plural' => 'Servicii',
],

'field' => [
'name' => 'Numele serviciului',
'description' => 'Descrierea serviciului',
],
];

0 comments on commit 6897176

Please sign in to comment.