Compare commits
3 Commits
e4fdd9521e
...
caeb0a5afd
| Author | SHA1 | Date | |
|---|---|---|---|
| caeb0a5afd | |||
|
|
0947408462 | ||
|
|
538f0961b4 |
@@ -102,10 +102,12 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail1')
|
Forms\Components\TextInput::make('mail1')
|
||||||
->label('E-Mail')
|
->label('Mail ID')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
|
->suffixIcon('heroicon-m-envelope')
|
||||||
|
->suffixIconColor('primary')
|
||||||
->email()
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
@@ -138,9 +140,11 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail2')
|
Forms\Components\TextInput::make('mail2')
|
||||||
->label('E-Mail')
|
->label('Mail ID')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->suffixIcon('heroicon-m-envelope')
|
||||||
|
->suffixIconColor('primary')
|
||||||
->email()
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
@@ -169,9 +173,11 @@ class CharacteristicApproverMasterResource extends Resource
|
|||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('mail3')
|
Forms\Components\TextInput::make('mail3')
|
||||||
->label('E-Mail')
|
->label('Mail ID')
|
||||||
->columnSpan(['default' => 1, 'sm' => 2])
|
->columnSpan(['default' => 1, 'sm' => 2])
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->suffixIcon('heroicon-m-envelope')
|
||||||
|
->suffixIconColor('primary')
|
||||||
->email()
|
->email()
|
||||||
->afterStateUpdated(function ($state, callable $set) {
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
|||||||
@@ -3,20 +3,20 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Resources\TestingTempResource\Pages;
|
use App\Filament\Resources\TestingTempResource\Pages;
|
||||||
use App\Filament\Resources\TestingTempResource\RelationManagers;
|
use App\Models\Plant;
|
||||||
use App\Models\TestingTemp;
|
use App\Models\TestingTemp;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
|
||||||
use Filament\Notifications\Notification;
|
|
||||||
use Storage;
|
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
|
use Storage;
|
||||||
|
|
||||||
class TestingTempResource extends Resource
|
class TestingTempResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -30,12 +30,69 @@ class TestingTempResource extends Resource
|
|||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
->schema([
|
->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')
|
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')
|
Forms\Components\Select::make('selected_file')
|
||||||
->label('Select Uploaded File')
|
->label('Select Uploaded File')
|
||||||
->options(function () {
|
->searchable()
|
||||||
return collect(Storage::disk('local')->files('uploads'))
|
->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) {
|
->mapWithKeys(function ($file) {
|
||||||
return [
|
return [
|
||||||
$file => basename($file), // value => label
|
$file => basename($file), // value => label
|
||||||
@@ -43,101 +100,157 @@ class TestingTempResource extends Resource
|
|||||||
})
|
})
|
||||||
->toArray();
|
->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(),
|
->reactive(),
|
||||||
|
// ->disabled(fn (callable $get) => ! $get('plant_id')),
|
||||||
Forms\Components\FileUpload::make('attachment')
|
Forms\Components\FileUpload::make('attachment')
|
||||||
->label('Upload')
|
->label('Choose File to Upload')
|
||||||
// ->acceptedFileTypes(['application/pdf'])
|
// ->acceptedFileTypes(['application/pdf'])
|
||||||
->storeFiles(false)
|
->storeFiles(false)
|
||||||
->disk('local')
|
->disk('local')
|
||||||
->directory('uploads/temp')
|
->directory(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
$plantCode = Plant::find($plantId)?->code ?? null;
|
||||||
|
|
||||||
|
return "uploads/temp/{$plantCode}";
|
||||||
|
})
|
||||||
->preserveFilenames()
|
->preserveFilenames()
|
||||||
->maxSize(20480)
|
->maxSize(20480) // 20 MB
|
||||||
->reactive(),
|
->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([
|
Forms\Components\Actions::make([
|
||||||
Action::make('uploadNow')
|
Action::make('uploadNow')
|
||||||
->label('File Upload')
|
->label('Upload File')
|
||||||
->color('success')
|
->color('success')
|
||||||
->action(function ($get) {
|
->requiresConfirmation(function (callable $get) {
|
||||||
|
$filePath = $get('attachment');
|
||||||
$uploadedFiles = $get('attachment');
|
if ($filePath) {
|
||||||
|
return true;
|
||||||
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
|
|
||||||
|
|
||||||
$uploaded = reset($uploadedFiles);
|
|
||||||
|
|
||||||
if ($uploaded instanceof TemporaryUploadedFile) {
|
|
||||||
|
|
||||||
$baseName = $get('name');
|
|
||||||
$extension = $uploaded->getClientOriginalExtension();
|
|
||||||
|
|
||||||
$finalFileName = $baseName . '.' . $extension;
|
|
||||||
|
|
||||||
$uploaded->storeAs(
|
|
||||||
'uploads',
|
|
||||||
$finalFileName,
|
|
||||||
'local'
|
|
||||||
);
|
|
||||||
|
|
||||||
Notification::make()
|
|
||||||
->title("File uploaded successfully: {$finalFileName}")
|
|
||||||
->success()
|
|
||||||
->send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
return false;
|
||||||
Notification::make()
|
})
|
||||||
->title('No file selected to upload')
|
->action(function (callable $get, callable $set) {
|
||||||
->warning()
|
|
||||||
->send();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Action::make('downloadAttachment')
|
$uploadedFiles = $get('attachment');
|
||||||
// ->label('Download File')
|
|
||||||
// ->action(function ($get) {
|
|
||||||
|
|
||||||
// $fileName = basename($get('selected_file'));
|
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
|
||||||
|
|
||||||
// //dd($fileName);
|
$uploaded = reset($uploadedFiles);
|
||||||
|
|
||||||
// // if (!$fileName) {
|
if ($uploaded instanceof TemporaryUploadedFile) {
|
||||||
// // Notification::make()
|
|
||||||
// // ->title('Enter file name to download')
|
|
||||||
// // ->danger()
|
|
||||||
// // ->send();
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// $files = Storage::disk('local')->files('uploads');
|
$baseName = $get('name');
|
||||||
|
$extension = $uploaded->getClientOriginalExtension();
|
||||||
|
|
||||||
// foreach ($files as $file) {
|
$finalFileName = $baseName.'.'.$extension;
|
||||||
|
|
||||||
// if (pathinfo($file, PATHINFO_FILENAME) === $fileName) {
|
$plantId = $get('plant_id');
|
||||||
// dd($fileName);
|
$plantCode = Plant::find($plantId)?->code ?? null;
|
||||||
// Notification::make()
|
|
||||||
// ->title("File downloaded successfully")
|
|
||||||
// ->success()
|
|
||||||
// ->send();
|
|
||||||
|
|
||||||
// return response()->download(
|
if (! $plantCode) {
|
||||||
// Storage::disk('local')->path($file)
|
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/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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
// // Notification::make()
|
|
||||||
// // ->title('File not found')
|
|
||||||
// // ->danger()
|
|
||||||
// // ->send();
|
|
||||||
// }),
|
|
||||||
Action::make('downloadAttachment')
|
Action::make('downloadAttachment')
|
||||||
->label('Download File')
|
->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
|
$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()
|
Notification::make()
|
||||||
->title('File not found')
|
->title('File not found')
|
||||||
->danger()
|
->danger()
|
||||||
@@ -146,6 +259,8 @@ class TestingTempResource extends Resource
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('File downloaded successfully')
|
->title('File downloaded successfully')
|
||||||
->success()
|
->success()
|
||||||
@@ -156,38 +271,65 @@ class TestingTempResource extends Resource
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Action::make('deleteAttachment')
|
Action::make('deleteAttachment')
|
||||||
->label('Delete File')
|
->label('Delete File')
|
||||||
->color('danger')
|
->color('danger')
|
||||||
->requiresConfirmation()
|
->requiresConfirmation(function (callable $get) {
|
||||||
->action(function ($get) {
|
$filePath = $get('selected_file');
|
||||||
|
|
||||||
|
if ($filePath) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
->action(function ($get, $set) {
|
||||||
|
|
||||||
$filePath = $get('selected_file'); // uploads/filename.pdf
|
$filePath = $get('selected_file'); // uploads/filename.pdf
|
||||||
|
|
||||||
if (!$filePath || !Storage::disk('local')->exists($filePath)) {
|
// if (! $get('plant_id')) {
|
||||||
Notification::make()
|
// Notification::make()
|
||||||
->title('File not found')
|
// ->title('Please select a plant first.')
|
||||||
->danger()
|
// ->warning()
|
||||||
->send();
|
// ->send();
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Storage::disk('local')->delete($filePath);
|
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// } else
|
||||||
|
if (! $filePath) {
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('File deleted successfully')
|
->title('Please select a file first.')
|
||||||
->success()
|
->warning()
|
||||||
->send();
|
->send();
|
||||||
}),
|
|
||||||
|
|
||||||
]),
|
return;
|
||||||
|
} elseif (! Storage::disk('local')->exists($filePath)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('File not found')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Storage::disk('local')->delete($filePath);
|
||||||
|
|
||||||
|
$set('selected_file', null);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('File deleted successfully')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
|
|
||||||
|
]),
|
||||||
Forms\Components\Hidden::make('created_by')
|
Forms\Components\Hidden::make('created_by')
|
||||||
->label('Created By')
|
->label('Created By')
|
||||||
->default(Filament::auth()->user()?->name),
|
->default(Filament::auth()->user()?->name)
|
||||||
|
->reactive(),
|
||||||
Forms\Components\Hidden::make('updated_by')
|
Forms\Components\Hidden::make('updated_by')
|
||||||
->label('Updated By')
|
->label('Updated By')
|
||||||
->default(Filament::auth()->user()?->name),
|
->default(Filament::auth()->user()?->name)
|
||||||
|
->reactive(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user