mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 07:20:58 +08:00
filament create&edit redirect
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Filament\Resources\System\AgentAllowResource;
|
||||
use App\Http\Resources\TagResource;
|
||||
use App\Models\AgentAllow;
|
||||
use App\Models\Attendance;
|
||||
use App\Models\Category;
|
||||
use App\Models\Exam;
|
||||
use App\Models\ExamProgress;
|
||||
use App\Models\ExamUser;
|
||||
@@ -91,15 +92,11 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Notification::make()
|
||||
// ->success()
|
||||
// ->title('Test Test')
|
||||
// ->send()
|
||||
// ;
|
||||
$key = 'sbsb';
|
||||
$r = session()->push($key, [1,2,3]);
|
||||
$r = session()->get($key);
|
||||
dd($r);
|
||||
$categoryTaxonomies = [
|
||||
'category' => ['table' => 'categories', 'model' => Category::class],
|
||||
];
|
||||
$categoryTaxonomies = array_merge($categoryTaxonomies, SearchBox::$taxonomies);
|
||||
dd($categoryTaxonomies);
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
app/Filament/CreateRedirectIndexTrait.php
Normal file
11
app/Filament/CreateRedirectIndexTrait.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament;
|
||||
|
||||
trait CreateRedirectIndexTrait
|
||||
{
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return static::$resource::getUrl('index');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament;
|
||||
|
||||
trait RedirectIndexTrait
|
||||
trait EditRedirectIndexTrait
|
||||
{
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\CreateRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\CategoryResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCategory extends CreateRecord
|
||||
{
|
||||
use CreateRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function afterCreate()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\EditRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\CategoryResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
@@ -9,6 +10,8 @@ use Nexus\Database\NexusDB;
|
||||
|
||||
class EditCategory extends EditRecord
|
||||
{
|
||||
use EditRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
||||
|
||||
use App\Filament\CreateRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\CodecResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCodec extends CreateRecord
|
||||
{
|
||||
use CreateRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = CodecResource::class;
|
||||
|
||||
public function afterCreate()
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
||||
|
||||
use App\Filament\RedirectIndexTrait;
|
||||
use App\Filament\EditRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\CodecResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCodec extends EditRecord
|
||||
{
|
||||
use RedirectIndexTrait;
|
||||
use EditRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = CodecResource::class;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Filament\Resources\Section;
|
||||
|
||||
use App\Filament\OptionsTrait;
|
||||
use App\Filament\RedirectIndexTrait;
|
||||
use App\Filament\EditRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\IconResource\Pages;
|
||||
use App\Filament\Resources\Section\IconResource\RelationManagers;
|
||||
use App\Models\Icon;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\IconResource\Pages;
|
||||
|
||||
use App\Filament\RedirectIndexTrait;
|
||||
use App\Filament\EditRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\IconResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditIcon extends EditRecord
|
||||
{
|
||||
use RedirectIndexTrait;
|
||||
use EditRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = IconResource::class;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Section\SecondIconResource\Pages;
|
||||
|
||||
use App\Filament\RedirectIndexTrait;
|
||||
use App\Filament\EditRedirectIndexTrait;
|
||||
use App\Filament\Resources\Section\SecondIconResource;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\SecondIcon;
|
||||
@@ -11,7 +11,7 @@ use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSecondIcon extends EditRecord
|
||||
{
|
||||
use RedirectIndexTrait;
|
||||
use EditRedirectIndexTrait;
|
||||
|
||||
protected static string $resource = SecondIconResource::class;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class EditExam extends EditRecord
|
||||
$examRep = new ExamRepository();
|
||||
try {
|
||||
$this->record = $examRep->update($data, $this->record->id);
|
||||
$this->notify('success', $this->getSavedNotificationMessage());
|
||||
$this->notify('success', $this->getSavedNotificationTitle());
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
|
||||
@@ -24,7 +24,7 @@ class EditSeedBoxRecord extends EditRecord
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
$this->record = $rep->update($data, $this->record->id);
|
||||
$this->notify('success', $this->getSavedNotificationMessage());
|
||||
$this->notify('success', $this->getSavedNotificationTitle());
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
|
||||
@@ -146,7 +146,7 @@ class SearchBox extends NexusModel
|
||||
$table = self::$taxonomies[$torrentField]['table'];
|
||||
return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
|
||||
return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
|
||||
})->get();
|
||||
})->orderBy('sort_index')->orderBy('id')->get();
|
||||
}
|
||||
|
||||
public static function listModeOptions(): array
|
||||
@@ -174,17 +174,27 @@ class SearchBox extends NexusModel
|
||||
}
|
||||
}
|
||||
|
||||
public static function isSpecialEnabled(): bool
|
||||
{
|
||||
return Setting::get('main.spsct') == 'yes';
|
||||
}
|
||||
|
||||
public static function getBrowseMode()
|
||||
{
|
||||
return Setting::get('main.browsecat');
|
||||
}
|
||||
|
||||
public static function getSpecialMode()
|
||||
{
|
||||
return Setting::get('main.specialcat');
|
||||
}
|
||||
|
||||
|
||||
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Category::class, 'mode');
|
||||
}
|
||||
|
||||
public function normal_fields(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(SearchBoxField::class, 'searchbox_id');
|
||||
}
|
||||
|
||||
public function taxonomy_source(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Source::class, 'mode');
|
||||
@@ -220,10 +230,5 @@ class SearchBox extends NexusModel
|
||||
return $this->hasMany(Processing::class, 'mode');
|
||||
}
|
||||
|
||||
public function taxonomies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Taxonomy::class, 'mode');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class SearchBoxField extends NexusModel
|
||||
{
|
||||
protected $table = 'searchbox_fields';
|
||||
|
||||
protected $fillable = ['searchbox_id', 'field_type', 'field_id', ];
|
||||
|
||||
const FIELD_TYPE_SOURCE = 'source';
|
||||
const FIELD_TYPE_MEDIUM = 'medium';
|
||||
const FIELD_TYPE_CODEC = 'codec';
|
||||
const FIELD_TYPE_AUDIO_CODEC = 'audio_codec';
|
||||
const FIELD_TYPE_STANDARD = 'standard';
|
||||
const FIELD_TYPE_PROCESSING = 'processing';
|
||||
const FIELD_TYPE_TEAM = 'team';
|
||||
const FIELD_TYPE_CUSTOM = 'custom';
|
||||
|
||||
public static $fieldTypes = [
|
||||
self::FIELD_TYPE_SOURCE => ['text' => 'Source', 'model' => Source::class],
|
||||
self::FIELD_TYPE_MEDIUM => ['text' => 'Medium', 'model' => Media::class],
|
||||
self::FIELD_TYPE_CODEC => ['text' => 'Codec', 'model' => Codec::class],
|
||||
self::FIELD_TYPE_AUDIO_CODEC => ['text' => 'Audio codec', 'model' => AudioCodec::class],
|
||||
self::FIELD_TYPE_STANDARD => ['text' => 'Standard', 'model' => Standard::class],
|
||||
self::FIELD_TYPE_PROCESSING => ['text' => 'Processing', 'model' => Processing::class],
|
||||
self::FIELD_TYPE_TEAM => ['text' => 'Team', 'model' => Team::class],
|
||||
self::FIELD_TYPE_CUSTOM => ['text' => 'Custom', ],
|
||||
];
|
||||
|
||||
|
||||
public function searchBox(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SearchBox::class, 'searchbox_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -56,44 +56,6 @@ class SearchBoxRepository extends BaseRepository
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function buildSearchBox($id)
|
||||
{
|
||||
$searchBox = SearchBox::query()->with(['categories', 'normal_fields'])->findOrFail($id);
|
||||
$fieldData = [];
|
||||
foreach ($searchBox->normal_fields as $normalField) {
|
||||
$fieldType = $normalField->field_type;
|
||||
$info = SearchBoxField::$fieldTypes[$fieldType] ?? null;
|
||||
if ($info) {
|
||||
/** @var NexusModel $model */
|
||||
$model = new $info[$fieldType]['model'];
|
||||
$fieldData[$fieldType] = $model::query()->get();
|
||||
}
|
||||
}
|
||||
$searchBox->setRelation('normal_fields_data', $fieldData);
|
||||
return $searchBox;
|
||||
}
|
||||
|
||||
public function initSearchBoxField($id)
|
||||
{
|
||||
$searchBox = SearchBox::query()->findOrFail($id);
|
||||
$logPrefix = "searchBox: $id";
|
||||
$result = $searchBox->normal_fields()->delete();
|
||||
do_log("$logPrefix, remove all normal fields: $result");
|
||||
foreach (SearchBoxField::$fieldTypes as $fieldType => $info) {
|
||||
if ($fieldType == SearchBoxField::FIELD_TYPE_CUSTOM) {
|
||||
continue;
|
||||
}
|
||||
$name = str_replace('_', '', "show{$fieldType}");
|
||||
$log = "$logPrefix, name: $name, fieldType: $fieldType";
|
||||
if ($searchBox->{$name}) {
|
||||
$searchBox->normal_fields()->create([
|
||||
'field_type' => $fieldType,
|
||||
]);
|
||||
do_log("$log, create.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function listIcon(array $idArr)
|
||||
{
|
||||
$searchBoxList = SearchBox::query()->with('categories')->find($idArr);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-11-28');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-12-01');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Nexus\Install;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Support\Str;
|
||||
use Nexus\Database\NexusDB;
|
||||
@@ -711,4 +712,11 @@ class Install
|
||||
return $this->steps[$step - 1] ?? '';
|
||||
}
|
||||
|
||||
public function migrateSearchBoxModeRelated()
|
||||
{
|
||||
$this->doLog("[migrateSearchBoxModeRelated]");
|
||||
$searchBoxRep = new SearchBoxRepository();
|
||||
$searchBoxRep->migrateToModeRelated();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -276,8 +276,7 @@ class Update extends Install
|
||||
$this->runMigrate('database/migrations/2022_09_05_230532_add_mode_to_section_related.php');
|
||||
$this->runMigrate('database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php');
|
||||
$this->runMigrate('database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php');
|
||||
$searchBoxRep = new SearchBoxRepository();
|
||||
$searchBoxRep->migrateToModeRelated();
|
||||
$this->migrateSearchBoxModeRelated();
|
||||
$this->doLog("[MIGRATE_TAXONOMY_TO_MODE_RELATED]");
|
||||
}
|
||||
$this->removeMenu(['catmanage.php']);
|
||||
|
||||
@@ -111,6 +111,7 @@ if ($currentStep == 4) {
|
||||
$install->createSymbolicLinks($symbolicLinks);
|
||||
$install->runDatabaseSeeder();
|
||||
$install->saveSettings($settings);
|
||||
$install->migrateSearchBoxModeRelated();
|
||||
$install->nextStep();
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
|
||||
Reference in New Issue
Block a user