Added module list file name
This commit is contained in:
@@ -38,6 +38,15 @@ class ModuleListResource extends Resource
|
|||||||
Forms\Components\TextInput::make('filter_name')
|
Forms\Components\TextInput::make('filter_name')
|
||||||
->label('Filter Name')
|
->label('Filter Name')
|
||||||
->required(),
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('file_name')
|
||||||
|
->label('File Name')
|
||||||
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->extraAttributes([
|
||||||
|
'x-data' => '{ value: "" }',
|
||||||
|
'x-model' => 'value',
|
||||||
|
'x-on:keydown.enter.prevent' => '$wire.process(value)',
|
||||||
|
]),
|
||||||
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),
|
||||||
@@ -45,7 +54,7 @@ class ModuleListResource extends Resource
|
|||||||
->label('Updated By')
|
->label('Updated By')
|
||||||
->default(Filament::auth()->user()?->name),
|
->default(Filament::auth()->user()?->name),
|
||||||
])
|
])
|
||||||
->columns(3),
|
->columns(4),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,73 @@
|
|||||||
namespace App\Filament\Resources\ModuleListResource\Pages;
|
namespace App\Filament\Resources\ModuleListResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\ModuleListResource;
|
use App\Filament\Resources\ModuleListResource;
|
||||||
|
use App\Models\ModuleList;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
use phpseclib3\Net\SFTP;
|
||||||
|
|
||||||
class CreateModuleList extends CreateRecord
|
class CreateModuleList extends CreateRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = ModuleListResource::class;
|
protected static string $resource = ModuleListResource::class;
|
||||||
|
|
||||||
|
public function process($fileName)
|
||||||
|
{
|
||||||
|
//$file = trim($fileName);
|
||||||
|
if (!$fileName)
|
||||||
|
{
|
||||||
|
Notification::make()
|
||||||
|
->title('File name is required!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ftpHost = env('SFTP_HOST');
|
||||||
|
$ftpUser = env('SFTP_USERNAME');
|
||||||
|
$ftpPass = env('SFTP_PASSWORD');
|
||||||
|
$remoteDir = env('SFTP_ROOT');
|
||||||
|
$port = env('SFTP_PORT');
|
||||||
|
|
||||||
|
$sftp = new SFTP($ftpHost, $port, 10);
|
||||||
|
if (! $sftp->login($ftpUser, $ftpPass)) {
|
||||||
|
Notification::make()->title('SFTP login failed')->danger()->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remoteFile = $remoteDir . '/' . $fileName . '.txt';
|
||||||
|
$content = $sftp->get($remoteFile);
|
||||||
|
|
||||||
|
if ($content == false) {
|
||||||
|
Notification::make()
|
||||||
|
->title("File {$remoteFile} not found")
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($content == false) {
|
||||||
|
Notification::make()
|
||||||
|
->title("Failed to read {$remoteDir} from SFTP")
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = array_map('trim', explode("\n", str_replace("\r", "", $content)));
|
||||||
|
|
||||||
|
ModuleList::create([
|
||||||
|
'module_name' => $lines[0] ?? '',
|
||||||
|
'dashboard_name' => $lines[1] ?? '',
|
||||||
|
'filter_name' => $lines[2] ?? '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title("File {$remoteDir} read and saved successfully!")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
|
||||||
protected function getRedirectUrl(): string
|
protected function getRedirectUrl(): string
|
||||||
{
|
{
|
||||||
return $this->getResource()::getUrl('create');
|
return $this->getResource()::getUrl('create');
|
||||||
|
|||||||
Reference in New Issue
Block a user