ranjith-dev #290

Merged
jothi merged 2 commits from ranjith-dev into master 2026-02-03 05:51:13 +00:00
2 changed files with 248 additions and 100 deletions

View File

@@ -102,10 +102,12 @@ class CharacteristicApproverMasterResource extends Resource
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('mail1')
->label('E-Mail')
->label('Mail ID')
->columnSpan(['default' => 1, 'sm' => 2])
->reactive()
->required()
->suffixIcon('heroicon-m-envelope')
->suffixIconColor('primary')
->email()
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
@@ -138,9 +140,11 @@ class CharacteristicApproverMasterResource extends Resource
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('mail2')
->label('E-Mail')
->label('Mail ID')
->columnSpan(['default' => 1, 'sm' => 2])
->reactive()
->suffixIcon('heroicon-m-envelope')
->suffixIconColor('primary')
->email()
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
@@ -169,9 +173,11 @@ class CharacteristicApproverMasterResource extends Resource
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('mail3')
->label('E-Mail')
->label('Mail ID')
->columnSpan(['default' => 1, 'sm' => 2])
->reactive()
->suffixIcon('heroicon-m-envelope')
->suffixIconColor('primary')
->email()
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);

View File

@@ -3,20 +3,20 @@
namespace App\Filament\Resources;
use App\Filament\Resources\TestingTempResource\Pages;
use App\Filament\Resources\TestingTempResource\RelationManagers;
use App\Models\Plant;
use App\Models\TestingTemp;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Storage;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Storage;
class TestingTempResource extends Resource
{
@@ -30,12 +30,69 @@ class TestingTempResource extends Resource
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant Name')
->relationship('plant', 'name')
->required()
->searchable()
// ->preload()
// ->nullable(),
->reactive()
->columnSpan(1)
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('ivPlantError', null);
$set('name', null);
$set('selected_file', null);
$set('attachment', null);
if (! $plantId) {
$set('ivPlantError', 'Please select a plant first.');
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('ivPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('ivPlantError') ? $get('ivPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->label('File Name'),
->label('File Name')
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$fileNam = $get('name');
// $set('selected_file', null);
if (! $plantId) {
$set('name', null);
} elseif (! $fileNam) {
$set('attachment', null);
}
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('selected_file')
->label('Select Uploaded File')
->options(function () {
return collect(Storage::disk('local')->files('uploads'))
->searchable()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (! $plantId) {
return collect(Storage::disk('local')->files('uploads/temp'))
->mapWithKeys(function ($file) {
return [
$file => basename($file), // value => label
];
})
->toArray();
}
$plantCode = Plant::find($plantId)?->code ?? null;
return collect(Storage::disk('local')->files("uploads/temp/{$plantCode}"))
->mapWithKeys(function ($file) {
return [
$file => basename($file), // value => label
@@ -43,22 +100,59 @@ class TestingTempResource extends Resource
})
->toArray();
})
->searchable()
->afterStateUpdated(function ($state, callable $set, callable $get) {
// $plantId = $get('plant_id');
// if (! $plantId) {
// $set('selected_file', null);
// }
$set('updated_by', Filament::auth()->user()?->name);
})
->reactive(),
// ->disabled(fn (callable $get) => ! $get('plant_id')),
Forms\Components\FileUpload::make('attachment')
->label('Upload')
->label('Choose File to Upload')
// ->acceptedFileTypes(['application/pdf'])
->storeFiles(false)
->disk('local')
->directory('uploads/temp')
->directory(function (callable $get) {
$plantId = $get('plant_id');
$plantCode = Plant::find($plantId)?->code ?? null;
return "uploads/temp/{$plantCode}";
})
->preserveFilenames()
->maxSize(20480)
->reactive(),
->maxSize(20480) // 20 MB
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (! $plantId) {
$set('attachment', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->required(function (callable $get) {
$selFile = $get('selected_file');
$selAtt = $get('attachment');
if (! $selAtt && ! $selFile) {
return true;
}
return false;
})
->reactive()
->disabled(fn (callable $get) => ! $get('plant_id') || ! $get('name')),
Forms\Components\Actions::make([
Action::make('uploadNow')
->label('File Upload')
->label('Upload File')
->color('success')
->action(function ($get) {
->requiresConfirmation(function (callable $get) {
$filePath = $get('attachment');
if ($filePath) {
return true;
}
return false;
})
->action(function (callable $get, callable $set) {
$uploadedFiles = $get('attachment');
@@ -73,71 +167,90 @@ class TestingTempResource extends Resource
$finalFileName = $baseName.'.'.$extension;
$plantId = $get('plant_id');
$plantCode = Plant::find($plantId)?->code ?? null;
if (! $plantCode) {
Notification::make()
->title('Please select a plant first.')
->warning()
->send();
return;
} elseif (! $baseName) {
Notification::make()
->title('Please enter a file name first.')
->warning()
->send();
return;
}
// return "uploads/temp/{$plantCode}";
$uploaded->storeAs(
'uploads',
"uploads/temp/{$plantCode}",
$finalFileName,
'local'
);
$set('updated_by', Filament::auth()->user()?->name);
Notification::make()
->title("File uploaded successfully: {$finalFileName}")
->success()
->send();
}
} else {
if (! $get('plant_id')) {
Notification::make()
->title('Please select a plant first.')
->warning()
->send();
} elseif (! $get('name')) {
Notification::make()
->title('Please enter a file name first.')
->warning()
->send();
} else {
Notification::make()
->title('No file selected to upload')
->warning()
->send();
}
}
}),
// Action::make('downloadAttachment')
// ->label('Download File')
// ->action(function ($get) {
// $fileName = basename($get('selected_file'));
// //dd($fileName);
// // if (!$fileName) {
// // Notification::make()
// // ->title('Enter file name to download')
// // ->danger()
// // ->send();
// // return;
// // }
// $files = Storage::disk('local')->files('uploads');
// foreach ($files as $file) {
// if (pathinfo($file, PATHINFO_FILENAME) === $fileName) {
// dd($fileName);
// Notification::make()
// ->title("File downloaded successfully")
// ->success()
// ->send();
// return response()->download(
// Storage::disk('local')->path($file)
// );
// }
// }
// // Notification::make()
// // ->title('File not found')
// // ->danger()
// // ->send();
// }),
Action::make('downloadAttachment')
->label('Download File')
->action(function ($get) {
->color('warning')
->requiresConfirmation(function (callable $get) {
$filePath = $get('selected_file');
if ($filePath) {
return true;
}
return false;
})
->action(function (callable $get, callable $set) {
$filePath = $get('selected_file'); // uploads/filename.pdf
if (!$filePath || !Storage::disk('local')->exists($filePath)) {
// if (! $get('plant_id')) {
// Notification::make()
// ->title('Please select a plant first.')
// ->warning()
// ->send();
// return;
// } else
if (! $filePath) {
Notification::make()
->title('Please select a file first.')
->warning()
->send();
return;
} elseif (! Storage::disk('local')->exists($filePath)) {
Notification::make()
->title('File not found')
->danger()
@@ -146,6 +259,8 @@ class TestingTempResource extends Resource
return;
}
$set('updated_by', Filament::auth()->user()?->name);
Notification::make()
->title('File downloaded successfully')
->success()
@@ -159,12 +274,35 @@ class TestingTempResource extends Resource
Action::make('deleteAttachment')
->label('Delete File')
->color('danger')
->requiresConfirmation()
->action(function ($get) {
->requiresConfirmation(function (callable $get) {
$filePath = $get('selected_file');
if ($filePath) {
return true;
}
return false;
})
->action(function ($get, $set) {
$filePath = $get('selected_file'); // uploads/filename.pdf
if (!$filePath || !Storage::disk('local')->exists($filePath)) {
// if (! $get('plant_id')) {
// Notification::make()
// ->title('Please select a plant first.')
// ->warning()
// ->send();
// return;
// } else
if (! $filePath) {
Notification::make()
->title('Please select a file first.')
->warning()
->send();
return;
} elseif (! Storage::disk('local')->exists($filePath)) {
Notification::make()
->title('File not found')
->danger()
@@ -175,6 +313,8 @@ class TestingTempResource extends Resource
Storage::disk('local')->delete($filePath);
$set('selected_file', null);
Notification::make()
->title('File deleted successfully')
->success()
@@ -184,10 +324,12 @@ class TestingTempResource extends Resource
]),
Forms\Components\Hidden::make('created_by')
->label('Created By')
->default(Filament::auth()->user()?->name),
->default(Filament::auth()->user()?->name)
->reactive(),
Forms\Components\Hidden::make('updated_by')
->label('Updated By')
->default(Filament::auth()->user()?->name),
->default(Filament::auth()->user()?->name)
->reactive(),
]);
}