- Refactor custom Filament actions into resource-specific subfolders (Cooperation, Proposal, Report).
- Standardize all action identifiers to snake_case for consistency.
- Move action identifiers directly into ::make('name') calls.
- Remove getDefaultName() from custom action classes to favor explicit naming.
- Update relation managers and resources to use the new namespaced action classes.
- Standardize closure syntax (fn) and string formatting across schemas and actions.
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Monitoring\MediaMonitorings\Actions;
|
|
|
|
use App\Models\Theme;
|
|
use App\Services\NewsCrawlerService;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
class CrawlNewsAction extends Action
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label('Crawl Berita')
|
|
->icon(Heroicon::MagnifyingGlass)
|
|
->color('info')
|
|
->schema([
|
|
TextInput::make('keyword')
|
|
->label('Kata Kunci')
|
|
->placeholder('Pendidikan, UMKM, Pariwisata')
|
|
->autofocus()
|
|
->autocomplete('off')
|
|
->required()
|
|
->helperText('Jika kata kunci nya lebih dari 1, pisahkan dengan koma.'),
|
|
|
|
Select::make('theme_id')
|
|
->label('Tema')
|
|
->required()
|
|
->options(Theme::active()->pluck('name', 'id'))
|
|
->searchable()
|
|
->multiple(),
|
|
|
|
TextInput::make('limit')
|
|
->label('Jumlah Berita')
|
|
->placeholder(10)
|
|
->numeric()
|
|
->required()
|
|
->default(10),
|
|
])
|
|
->action(function (array $data, NewsCrawlerService $service) {
|
|
$count = $service->crawlFromGoogleNews($data['keyword'], $data['limit'], $data['theme_id'] ?? []);
|
|
|
|
if ($count > 0) {
|
|
Notification::make()
|
|
->title('Crawl Selesai')
|
|
->body("Berhasil mengambil {$count} berita baru tentang '{$data['keyword']}' di Purwakarta.")
|
|
->success()
|
|
->send();
|
|
} else {
|
|
Notification::make()
|
|
->title('Tidak Ada Berita Baru')
|
|
->body("Tidak ditemukan berita baru untuk '{$data['keyword']}' yang belum ada di database.")
|
|
->info()
|
|
->send();
|
|
}
|
|
})
|
|
->modalWidth(Width::Large);
|
|
}
|
|
}
|