Skip to content

Commit 2ef5668

Browse files
author
John Wesely
committed
Merge branch 'main' of github.com:TappNetwork/Filament-Forms
2 parents 2f82cd9 + 4ffffc5 commit 2ef5668

14 files changed

+66
-79
lines changed

database/factories/FilamentFormFieldFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class FilamentFormFieldFactory extends Factory
1717
public function definition(): array
1818
{
1919
return [
20-
'label' => $this->faker->text(rand(25,60)).'?',
21-
'hint' => rand(0, 5) > 4 ? $this->faker->text(rand(50,100)) : null,
22-
'required' => (rand(0,2) > 1),
20+
'label' => $this->faker->text(rand(25, 60)).'?',
21+
'hint' => rand(0, 5) > 4 ? $this->faker->text(rand(50, 100)) : null,
22+
'required' => (rand(0, 2) > 1),
2323
];
2424
}
2525
}

database/seeders/FilamentFormSeeder.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use Faker\Factory;
66
use Faker\Generator;
7-
use Tapp\FilamentForms\Models\FilamentForm;
87
use Illuminate\Database\Seeder;
9-
use Tapp\FilamentForms\Models\FilamentFormField;
108
use Tapp\FilamentForms\Enums\FilamentFieldTypeEnum;
9+
use Tapp\FilamentForms\Models\FilamentForm;
10+
use Tapp\FilamentForms\Models\FilamentFormField;
1111

1212
class FilamentFormSeeder extends Seeder
1313
{
@@ -32,17 +32,17 @@ public function run(): void
3232

3333
public function generateQuestions(FilamentForm $form): void
3434
{
35-
$count = rand(5,10);
35+
$count = rand(5, 10);
3636

37-
for ($i = 0; $i < $count; ++$i) {
37+
for ($i = 0; $i < $count; $i++) {
3838
$field = FilamentFormField::factory()->create([
3939
'type' => $this->randomType(),
4040
'filament_form_id' => $form->id,
4141
'order' => $i,
4242
]);
4343

4444
if ($field->type->hasOptions()) {
45-
$field->options = $this->generateOptions();
45+
$field->options = $this->generateOptions();
4646
}
4747

4848
$field->save();
@@ -51,11 +51,11 @@ public function generateQuestions(FilamentForm $form): void
5151

5252
public function generateOptions(): array
5353
{
54-
$count = rand(3,6);
54+
$count = rand(3, 6);
5555

5656
$options = [];
5757

58-
for ($i = 0; $i < $count; ++$i) {
58+
for ($i = 0; $i < $count; $i++) {
5959
array_push($options, $this->faker->bs());
6060
}
6161

@@ -71,6 +71,6 @@ public function randomType(): FilamentFieldTypeEnum
7171
FilamentFieldTypeEnum::CHECKBOX,
7272
];
7373

74-
return $seededFieldTypes[rand(0,3)];
74+
return $seededFieldTypes[rand(0, 3)];
7575
}
7676
}

src/Enums/FilamentFieldTypeEnum.php

+9-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function fromString(string $type): ?self
2626
return $case;
2727
}
2828
}
29+
2930
return null; // Return null if no match is found
3031
}
3132

@@ -36,13 +37,12 @@ public function getLabel(): ?string
3637

3738
public function fieldName(): string
3839
{
39-
return match($this)
40-
{
40+
return match ($this) {
4141
self::TEXT => 'Text Input',
4242
self::TEXTAREA => 'Textarea',
4343
self::SELECT => 'Select',
4444
self::RICH_EDITOR => 'Rich Editor',
45-
self::TOGGLE => 'Toggle',
45+
self::TOGGLE => 'Toggle',
4646
self::CHECKBOX => 'Checkbox',
4747
self::RADIO => 'Radio',
4848
self::DATE_TIME_PICKER => 'DateTime Picker',
@@ -55,13 +55,12 @@ public function fieldName(): string
5555

5656
public function className(): string
5757
{
58-
return match($this)
59-
{
58+
return match ($this) {
6059
self::TEXT => 'Filament\Forms\Components\TextInput',
6160
self::TEXTAREA => 'Filament\Forms\Components\Textarea',
6261
self::SELECT => 'Filament\Forms\Components\Select',
6362
self::RICH_EDITOR => 'Filament\Forms\Components\RichEditor',
64-
self::TOGGLE => 'Filament\Forms\Components\Toggle',
63+
self::TOGGLE => 'Filament\Forms\Components\Toggle',
6564
self::CHECKBOX => 'Filament\Forms\Components\Checkbox',
6665
self::RADIO => 'Filament\Forms\Components\Radio',
6766
self::DATE_TIME_PICKER => 'Filament\Forms\Components\DateTimePicker',
@@ -74,13 +73,12 @@ public function className(): string
7473

7574
public function hasOptions(): bool
7675
{
77-
return match($this)
78-
{
76+
return match ($this) {
7977
self::TEXT => false,
8078
self::TEXTAREA => false,
8179
self::SELECT => true,
8280
self::RICH_EDITOR => false,
83-
self::TOGGLE => false,
81+
self::TOGGLE => false,
8482
self::CHECKBOX => false,
8583
self::RADIO => true,
8684
self::DATE_TIME_PICKER => false,
@@ -93,13 +91,12 @@ public function hasOptions(): bool
9391

9492
public function isBool(): bool
9593
{
96-
return match($this)
97-
{
94+
return match ($this) {
9895
self::TEXT => false,
9996
self::TEXTAREA => false,
10097
self::SELECT => false,
10198
self::RICH_EDITOR => false,
102-
self::TOGGLE => true,
99+
self::TOGGLE => true,
103100
self::CHECKBOX => true,
104101
self::RADIO => false,
105102
self::DATE_TIME_PICKER => false,

src/Exports/FilamentFormUsersExport.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Tapp\FilamentForms\Exports;
44

5-
use Tapp\FilamentForms\Models\FilamentForm;
6-
use Tapp\FilamentForms\Models\FilamentFormUser;
7-
use Maatwebsite\Excel\Concerns\WithMapping;
85
use Illuminate\Database\Eloquent\Collection;
9-
use Maatwebsite\Excel\Concerns\WithHeadings;
106
use Maatwebsite\Excel\Concerns\FromCollection;
7+
use Maatwebsite\Excel\Concerns\WithHeadings;
8+
use Maatwebsite\Excel\Concerns\WithMapping;
9+
use Tapp\FilamentForms\Models\FilamentForm;
1110

12-
class FilamentFormUsersExport implements FromCollection, WithMapping, WithHeadings
11+
class FilamentFormUsersExport implements FromCollection, WithHeadings, WithMapping
1312
{
1413
public Collection $entries;
1514

@@ -64,6 +63,4 @@ public function headings(): array
6463

6564
return $headings;
6665
}
67-
68-
6966
}

src/Filament/Resources/FilamentFormResource.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
namespace Tapp\FilamentForms\Filament\Resources;
44

55
use Filament\Forms;
6-
use Filament\Tables;
76
use Filament\Forms\Form;
8-
use Filament\Tables\Table;
97
use Filament\Resources\Resource;
10-
use Illuminate\Database\Eloquent\Builder;
11-
use Tapp\FilamentForms\Models\FilamentForm;
12-
use Illuminate\Database\Eloquent\SoftDeletingScope;
13-
use Tapp\FilamentForms\Filament\Resources\FilamentFormResource\RelationManagers\FilamentFormUsersRelationManager;
8+
use Filament\Tables;
9+
use Filament\Tables\Table;
1410
use Tapp\FilamentForms\Filament\Resources\FilamentFormResource\RelationManagers\FilamentFormFieldsRelationManager;
11+
use Tapp\FilamentForms\Filament\Resources\FilamentFormResource\RelationManagers\FilamentFormUsersRelationManager;
12+
use Tapp\FilamentForms\Models\FilamentForm;
1513

1614
class FilamentFormResource extends Resource
1715
{

src/Filament/Resources/FilamentFormResource/Pages/CreateFilamentForm.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tapp\FilamentForms\Filament\Resources\FilamentFormResource\Pages;
44

5-
use Filament\Actions;
65
use Filament\Resources\Pages\CreateRecord;
76
use Tapp\FilamentForms\Filament\Resources\FilamentFormResource;
87

src/Filament/Resources/FilamentFormResource/RelationManagers/FilamentFormFieldsRelationManager.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
namespace Tapp\FilamentForms\Filament\Resources\FilamentFormResource\RelationManagers;
44

5-
use Filament\Forms;
6-
use Filament\Tables;
7-
use Filament\Forms\Get;
8-
use Filament\Forms\Form;
9-
use Filament\Tables\Table;
10-
use Tapp\FilamentForms\Enums\FilamentFieldTypeEnum;
115
use Filament\Forms\Components\Select;
12-
use Filament\Forms\Components\Toggle;
13-
use Filament\Tables\Columns\IconColumn;
14-
use Filament\Tables\Columns\TextColumn;
156
use Filament\Forms\Components\TagsInput;
167
use Filament\Forms\Components\TextInput;
17-
use Illuminate\Database\Eloquent\Builder;
18-
use Illuminate\Database\Eloquent\SoftDeletingScope;
8+
use Filament\Forms\Components\Toggle;
9+
use Filament\Forms\Form;
10+
use Filament\Forms\Get;
1911
use Filament\Resources\RelationManagers\RelationManager;
12+
use Filament\Tables;
13+
use Filament\Tables\Columns\IconColumn;
14+
use Filament\Tables\Columns\TextColumn;
15+
use Filament\Tables\Table;
16+
use Tapp\FilamentForms\Enums\FilamentFieldTypeEnum;
2017

2118
class FilamentFormFieldsRelationManager extends RelationManager
2219
{

src/Filament/Resources/FilamentFormResource/RelationManagers/FilamentFormUsersRelationManager.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Tapp\FilamentForms\Filament\Resources\FilamentFormResource\RelationManagers;
44

55
use Filament\Forms;
6-
use Filament\Tables;
76
use Filament\Forms\Form;
7+
use Filament\Resources\RelationManagers\RelationManager;
8+
use Filament\Tables;
9+
use Filament\Tables\Actions\BulkAction;
810
use Filament\Tables\Table;
11+
use Illuminate\Database\Eloquent\Collection;
912
use Maatwebsite\Excel\Facades\Excel;
10-
use Filament\Tables\Actions\BulkAction;
1113
use Tapp\FilamentForms\Exports\FilamentFormUsersExport;
12-
use Illuminate\Database\Eloquent\Collection;
13-
use Filament\Resources\RelationManagers\RelationManager;
1414

1515
class FilamentFormUsersRelationManager extends RelationManager
1616
{
@@ -52,11 +52,10 @@ public function table(Table $table): Table
5252
Tables\Actions\BulkActionGroup::make([
5353
Tables\Actions\DeleteBulkAction::make(),
5454
BulkAction::make('Export Selected')
55-
->action(fn (Collection $records) =>
56-
Excel::download(
57-
new FilamentFormUsersExport($records),
58-
$this->getOwnerRecord()->name.'_form_entry_export'.now()->format('Y-m-dhis').'.csv')
59-
)
55+
->action(fn (Collection $records) => Excel::download(
56+
new FilamentFormUsersExport($records),
57+
$this->getOwnerRecord()->name.'_form_entry_export'.now()->format('Y-m-dhis').'.csv')
58+
)
6059
->icon('heroicon-o-document-chart-bar')
6160
->deselectRecordsAfterCompletion(),
6261
]),

src/Livewire/FilamentForm/show.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Tapp\FilamentForms\Livewire\FilamentForm;
44

5-
use Tapp\FilamentForms\Models\FilamentForm;
6-
use Tapp\FilamentForms\Models\FilamentFormField;
7-
use Tapp\FilamentForms\Models\FilamentFormUser;
85
use Filament\Forms\Components\Field;
96
use Filament\Forms\Concerns\InteractsWithForms;
107
use Filament\Forms\Contracts\HasForms;
118
use Filament\Forms\Form;
129
use Livewire\Component;
10+
use Tapp\FilamentForms\Models\FilamentForm;
11+
use Tapp\FilamentForms\Models\FilamentFormField;
12+
use Tapp\FilamentForms\Models\FilamentFormUser;
1313

1414
class DynamicForm extends Component implements HasForms
1515
{
@@ -108,7 +108,9 @@ public function create(): void
108108

109109
public function parseValue(FilamentFormField $field, ?string $value): string
110110
{
111-
if (!$value && !$field->type->isBool()) return '';
111+
if (! $value && ! $field->type->isBool()) {
112+
return '';
113+
}
112114

113115
$valueData = '';
114116

@@ -124,7 +126,7 @@ public function parseValue(FilamentFormField $field, ?string $value): string
124126
} elseif ($field->type->hasOptions() && ! is_array($value)) {
125127
$valueData = $field->options[$value];
126128
} elseif ($field->type->isBool()) {
127-
$valueData = (bool)$value ? 'true' : 'false';
129+
$valueData = (bool) $value ? 'true' : 'false';
128130
} else {
129131
$valueData = $value;
130132
}

src/Livewire/FilamentFormUser/show.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
namespace Tapp\FilamentForms\Livewire\FilamentFormUser;
44

5-
use Livewire\Component;
6-
use Tapp\FilamentForms\Models\FilamentFormUser;
7-
use Filament\Infolists\Infolist;
8-
use Filament\Forms\Contracts\HasForms;
9-
use Filament\Infolists\Components\TextEntry;
10-
use Filament\Infolists\Contracts\HasInfolists;
115
use Filament\Forms\Concerns\InteractsWithForms;
6+
use Filament\Forms\Contracts\HasForms;
127
use Filament\Infolists\Components\KeyValueEntry;
8+
use Filament\Infolists\Components\TextEntry;
139
use Filament\Infolists\Concerns\InteractsWithInfolists;
10+
use Filament\Infolists\Contracts\HasInfolists;
11+
use Filament\Infolists\Infolist;
12+
use Livewire\Component;
13+
use Tapp\FilamentForms\Models\FilamentFormUser;
1414

1515
class DynamicEntry extends Component implements HasForms, HasInfolists
1616
{
17-
use InteractsWithInfolists;
1817
use InteractsWithForms;
18+
use InteractsWithInfolists;
1919

2020
public FilamentFormUser $entry;
2121

src/Models/FilamentForm.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Tapp\FilamentForms\Models;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Database\Eloquent\Relations\HasMany;
5+
use App\Models\User;
76
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
9-
use Tapp\FilamentForms\Models\FilamentFormUser;
10-
use App\Models\User;
9+
use Illuminate\Database\Eloquent\Relations\HasMany;
1110

1211
class FilamentForm extends Model
1312
{

src/Models/FilamentFormField.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Tapp\FilamentForms\Models;
44

5-
use Tapp\FilamentForms\Enums\FilamentFieldTypeEnum;
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8-
use Illuminate\Database\Eloquent\Factories\HasFactory;
8+
use Tapp\FilamentForms\Enums\FilamentFieldTypeEnum;
99

1010
class FilamentFormField extends Model
1111
{

src/Models/FilamentFormUser.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Tapp\FilamentForms\Models;
44

5+
use App\Models\User;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
57
use Illuminate\Database\Eloquent\Model;
68
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7-
use Illuminate\Database\Eloquent\Factories\HasFactory;
8-
use Tapp\FilamentForms\Models\FilamentForm;
9-
use App\Models\User;
109

1110
class FilamentFormUser extends Model
1211
{

src/Traits/HasFilamentForms.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Tapp\FilamentForms\Traits;
44

5-
use Tapp\FilamentForms\Models\FilamentForm;
65
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
6+
use Tapp\FilamentForms\Models\FilamentForm;
77

88
trait HasFilamentForms
99
{

0 commit comments

Comments
 (0)