Skip to content

Commit

Permalink
Merge pull request #77 from bcgov/update-readme
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
kiiskila-bcgov authored Jan 10, 2025
2 parents e2de199 + 5ee4d1b commit 90eec6a
Show file tree
Hide file tree
Showing 31 changed files with 866 additions and 42 deletions.
140 changes: 140 additions & 0 deletions app/Filament/Fodig/Resources/SystemMessageResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

namespace App\Filament\Fodig\Resources;

use App\Filament\Fodig\Resources\SystemMessageResource\Pages;
use App\Filament\Fodig\Resources\SystemMessageResource\RelationManagers;
use App\Models\SystemMessage;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class SystemMessageResource extends Resource
{
protected static ?string $model = SystemMessage::class;

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

protected static ?string $navigationGroup = 'System Messages';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Textarea::make('error_code')
->required()
->columnSpanFull(),
Forms\Components\Textarea::make('error_message')
->required()
->columnSpanFull(),
Forms\Components\Textarea::make('icm_error_solution')
->label('ICM error solution')
->columnSpanFull(),
Forms\Components\Textarea::make('explanation')
->columnSpanFull(),
Forms\Components\Textarea::make('fix')
->columnSpanFull(),
Select::make('error_entity_id')
->relationship('errorEntity', 'name'),
Select::make('error_data_group_id')
->relationship('errorDataGroup', 'name'),
Select::make('error_integration_state_id')
->relationship('errorIntegrationState', 'name'),
Select::make('error_actor_id')
->relationship('errorActor', 'name'),
Select::make('error_source_id')
->relationship('errorSource', 'name'),
Forms\Components\Toggle::make('service_desk'),
Forms\Components\Toggle::make('limited_data'),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('error_code')
->searchable(),
Tables\Columns\TextColumn::make('errorEntity.name')
->label('Error Entity')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('errorDataGroup.name')
->label('Error Data Group')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('errorIntegrationState.name')
->label('Error Integration State')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('errorActor.name')
->label('Error Actor')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('errorSource.name')
->label('Error Source')
->sortable()
->searchable(),
Tables\Columns\IconColumn::make('service_desk')
->boolean(),
Tables\Columns\IconColumn::make('limited_data')
->boolean(),
])
->filters([
Tables\Filters\SelectFilter::make('error_entity_id')
->label('Error Entity')
->relationship('errorEntity', 'name'),
Tables\Filters\SelectFilter::make('error_data_group_id')
->label('Error Data Group')
->relationship('errorDataGroup', 'name'),
Tables\Filters\SelectFilter::make('error_integration_state_id')
->label('Error Integration State')
->relationship('errorIntegrationState', 'name'),
Tables\Filters\SelectFilter::make('error_actor_id')
->label('Error Actor')
->relationship('errorActor', 'name'),
Tables\Filters\SelectFilter::make('error_source_id')
->label('Error Source')
->relationship('errorSource', 'name'),
Tables\Filters\TernaryFilter::make('service_desk')
->label('Service Desk'),
Tables\Filters\TernaryFilter::make('limited_data')
->label('Limited Data'),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
//
])
->paginated([
10,
25,
50,
100,
]);;
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListSystemMessages::route('/'),
'create' => Pages\CreateSystemMessage::route('/create'),
'view' => Pages\ViewSystemMessage::route('/{record}'),
'edit' => Pages\EditSystemMessage::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Filament\Fodig\Resources\SystemMessageResource\Pages;

use App\Filament\Fodig\Resources\SystemMessageResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateSystemMessage extends CreateRecord
{
protected static string $resource = SystemMessageResource::class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Filament\Fodig\Resources\SystemMessageResource\Pages;

use App\Filament\Fodig\Resources\SystemMessageResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditSystemMessage extends EditRecord
{
protected static string $resource = SystemMessageResource::class;

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Fodig\Resources\SystemMessageResource\Pages;

use App\Filament\Fodig\Resources\SystemMessageResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListSystemMessages extends ListRecords
{
protected static string $resource = SystemMessageResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Fodig\Resources\SystemMessageResource\Pages;

use App\Filament\Fodig\Resources\SystemMessageResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewSystemMessage extends ViewRecord
{
protected static string $resource = SystemMessageResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
5 changes: 2 additions & 3 deletions app/Filament/Forms/Resources/FieldGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public static function form(Form $form): Form
return $form
->schema([
TextInput::make('name')
->unique()
->required(),
TextInput::make('label')
->unique(ignoreRecord: true)
->required(),
TextInput::make('label'),
Textarea::make('description')
->columnSpanFull(),
Textarea::make('internal_description')
Expand Down
36 changes: 16 additions & 20 deletions app/Filament/Forms/Resources/FormFieldResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,25 @@ public static function form(Form $form): Form
return $form
->schema([
Forms\Components\TextInput::make('name')
->unique()
->unique(ignoreRecord: true)
->required(),
Forms\Components\TextInput::make('label')
->required(),
Forms\Components\Select::make('data_type_id')
->relationship('dataType', 'name')
->required()
->live(),
Forms\Components\Select::make('selectOptions')
->label('Select Options')
->relationship('selectOptions', 'label')
->multiple()
->preload()
->live()
->visible(function ($get) {
$dataTypeId = $get('data_type_id');
$dataType = \App\Models\DataType::find($dataTypeId);
return $dataType && in_array($dataType->name, ['radio', 'dropdown']);
}),
Forms\Components\Select::make('data_binding_path')
->label('Field data source')
->options(FormDataSource::pluck('name', 'name')),
Expand All @@ -71,10 +86,6 @@ public static function form(Form $form): Form
->collapsed(),
Forms\Components\Textarea::make('help_text')
->columnSpanFull(),
Forms\Components\Select::make('data_type_id')
->relationship('dataType', 'name')
->required()
->live(),
Forms\Components\Textarea::make('value')
->label('Field Value')
->visible(function (callable $get) {
Expand All @@ -89,21 +100,6 @@ public static function form(Form $form): Form
->multiple()
->preload()
->relationship('fieldGroups', 'name'),
Forms\Components\Repeater::make('selectOptions')
->label('Select Options')
->relationship('selectOptions')
->columnSpanFull()
->visible(function ($get) {
$dataTypeId = $get('data_type_id');
$dataType = \App\Models\DataType::find($dataTypeId);
return $dataType && in_array($dataType->name, ['radio', 'dropdown']);
})
->schema([
Forms\Components\TextInput::make('name')->required(),
Forms\Components\TextInput::make('label'),
Forms\Components\TextInput::make('value'),
Forms\Components\Textarea::make('description'),
]),
]);
}

Expand Down
11 changes: 9 additions & 2 deletions app/Filament/Forms/Resources/SelectOptionsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Filament\Forms\Resources\SelectOptionsResource\Pages;
use App\Filament\Forms\Resources\SelectOptionsResource\RelationManagers;
use App\Filament\Imports\SelectOptionsImporter;
use App\Models\SelectOptions;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
Expand All @@ -25,9 +27,10 @@ public static function form(Form $form): Form
return $form
->schema([
Forms\Components\TextInput::make('name')
->unique()
->unique(ignoreRecord: true)
->required(),
Forms\Components\TextInput::make('label')
->required(),
Forms\Components\TextInput::make('label'),
Forms\Components\TextInput::make('value'),
Forms\Components\Textarea::make('description')
->columnSpanFull(),
Expand Down Expand Up @@ -75,6 +78,10 @@ public static function table(Table $table): Table
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->headerActions([
ImportAction::make('Import CSV')
->importer(SelectOptionsImporter::class)
])
->bulkActions([
//
])
Expand Down
51 changes: 51 additions & 0 deletions app/Filament/Imports/SelectOptionsImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Filament\Imports;

use App\Models\SelectOptions;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Illuminate\Support\Str;

class SelectOptionsImporter extends Importer
{
protected static ?string $model = SelectOptions::class;

public static function getColumns(): array
{
return [
ImportColumn::make('name')
->requiredMapping()
->rules(['required'])
->example('eye_color_brown'),
ImportColumn::make('label')
->example('Brown'),
ImportColumn::make('value')
->example('1'),
ImportColumn::make('description')
->example('This option is used for...'),
];
}

public function resolveRecord(): ?SelectOptions
{
return SelectOptions::firstOrNew([
// Update existing records, matching them by `$this->data['column_name']`
'name' => $this->data['name'],
]);

return new SelectOptions();
}

public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your select options import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';

if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
}

return $body;
}
}
4 changes: 2 additions & 2 deletions app/Helpers/FormTemplateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected static function formatField($fieldInstance, $index)
"direction" => "bottom",
"size" => "md",
"helperText" => "Choose one from the list",
"listItems" => SelectOptions::where('form_field_id', $field->id)
"listItems" => $field->selectOptions()
->get()
->map(function ($selectOption) {
return ["text" => $selectOption->label];
Expand All @@ -164,7 +164,7 @@ protected static function formatField($fieldInstance, $index)
case "radio":
return array_merge($base, [
"helperText" => "Choose one option",
"listItems" => SelectOptions::where('form_field_id', $field->id)
"listItems" => $field->selectOptions()
->get()
->map(function ($selectOption) {
return ["text" => $selectOption->label];
Expand Down
Loading

0 comments on commit 90eec6a

Please sign in to comment.