mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
refactor isSeedBox judgement
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
|
||||
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
|
||||
use App\Exceptions\SeedBoxYesException;
|
||||
use App\Filament\PageList;
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource;
|
||||
use Filament\Pages\Actions;
|
||||
use App\Repositories\SeedBoxRepository;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class ListSeedBoxRecords extends PageList
|
||||
{
|
||||
protected static string $resource = SeedBoxRecordResource::class;
|
||||
|
||||
protected static ?array $checkResult = null;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
@@ -23,17 +26,40 @@ class ListSeedBoxRecords extends PageList
|
||||
Forms\Components\TextInput::make('uid')->required()->label('UID'),
|
||||
])
|
||||
->modalHeading(__('admin.resources.seed_box_record.check_modal_header'))
|
||||
->action(function ($data) {
|
||||
try {
|
||||
isIPSeedBox($data['ip'], $data['uid'], true, true);
|
||||
send_admin_success_notification(nexus_trans("seed-box.is_seed_box_no"));
|
||||
} catch (SeedBoxYesException $exception) {
|
||||
send_admin_fail_notification(nexus_trans("seed-box.is_seed_box_yes", ['id' => $exception->getId()]));
|
||||
} catch (\Throwable $throwable) {
|
||||
do_log($throwable->getMessage() . $throwable->getTraceAsString(), "error");
|
||||
send_admin_fail_notification($throwable->getMessage());
|
||||
}
|
||||
->action(function (array $data) {
|
||||
$result = SeedBoxRepository::isSeedBoxFromUserRecords($data['uid'], $data['ip']);
|
||||
self::$checkResult = $result;
|
||||
// return $result;
|
||||
// $this->replaceMountedAction("checkResult", ['result' => $result]);
|
||||
// if ($checkResult['result']) {
|
||||
// send_admin_success_notification(nexus_trans("seed-box.is_seed_box_yes", ['desc' => $checkResult['desc']]));
|
||||
// } else {
|
||||
// send_admin_fail_notification(nexus_trans("seed-box.is_seed_box_no", ['desc' => $checkResult['desc']]));
|
||||
// }
|
||||
})
|
||||
->registerModalActions([
|
||||
Actions\Action::make('checkResult')
|
||||
->modalHeading(function () {
|
||||
if (self::$checkResult !== null) {
|
||||
if (self::$checkResult['result']) {
|
||||
return nexus_trans("seed-box.is_seed_box_yes");
|
||||
} else {
|
||||
return nexus_trans("seed-box.is_seed_box_no");
|
||||
}
|
||||
}
|
||||
return 'Unknown';
|
||||
})
|
||||
->action(null)
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelAction(false)
|
||||
->modalDescription(fn () => new HtmlString(self::$checkResult['desc'] ?? ''))
|
||||
// ->modalContent(fn () => new HtmlString(self::$checkResult['desc'] ?? ''))
|
||||
])
|
||||
->after(function() {
|
||||
$this->mountAction("checkResult");
|
||||
})
|
||||
,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user