mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-26 21:37:22 +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\Http\Resources\TagResource;
|
||||||
use App\Models\AgentAllow;
|
use App\Models\AgentAllow;
|
||||||
use App\Models\Attendance;
|
use App\Models\Attendance;
|
||||||
|
use App\Models\Category;
|
||||||
use App\Models\Exam;
|
use App\Models\Exam;
|
||||||
use App\Models\ExamProgress;
|
use App\Models\ExamProgress;
|
||||||
use App\Models\ExamUser;
|
use App\Models\ExamUser;
|
||||||
@@ -91,15 +92,11 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// Notification::make()
|
$categoryTaxonomies = [
|
||||||
// ->success()
|
'category' => ['table' => 'categories', 'model' => Category::class],
|
||||||
// ->title('Test Test')
|
];
|
||||||
// ->send()
|
$categoryTaxonomies = array_merge($categoryTaxonomies, SearchBox::$taxonomies);
|
||||||
// ;
|
dd($categoryTaxonomies);
|
||||||
$key = 'sbsb';
|
|
||||||
$r = session()->push($key, [1,2,3]);
|
|
||||||
$r = session()->get($key);
|
|
||||||
dd($r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
namespace App\Filament;
|
||||||
|
|
||||||
trait RedirectIndexTrait
|
trait EditRedirectIndexTrait
|
||||||
{
|
{
|
||||||
protected function getRedirectUrl(): ?string
|
protected function getRedirectUrl(): ?string
|
||||||
{
|
{
|
||||||
@@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\CreateRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\CategoryResource;
|
use App\Filament\Resources\Section\CategoryResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
class CreateCategory extends CreateRecord
|
class CreateCategory extends CreateRecord
|
||||||
{
|
{
|
||||||
|
use CreateRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = CategoryResource::class;
|
protected static string $resource = CategoryResource::class;
|
||||||
|
|
||||||
protected function afterCreate()
|
protected function afterCreate()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
namespace App\Filament\Resources\Section\CategoryResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\EditRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\CategoryResource;
|
use App\Filament\Resources\Section\CategoryResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
@@ -9,6 +10,8 @@ use Nexus\Database\NexusDB;
|
|||||||
|
|
||||||
class EditCategory extends EditRecord
|
class EditCategory extends EditRecord
|
||||||
{
|
{
|
||||||
|
use EditRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = CategoryResource::class;
|
protected static string $resource = CategoryResource::class;
|
||||||
|
|
||||||
protected function getActions(): array
|
protected function getActions(): array
|
||||||
|
|||||||
@@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\CreateRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\CodecResource;
|
use App\Filament\Resources\Section\CodecResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
class CreateCodec extends CreateRecord
|
class CreateCodec extends CreateRecord
|
||||||
{
|
{
|
||||||
|
use CreateRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = CodecResource::class;
|
protected static string $resource = CodecResource::class;
|
||||||
|
|
||||||
public function afterCreate()
|
public function afterCreate()
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
namespace App\Filament\Resources\Section\CodecResource\Pages;
|
||||||
|
|
||||||
use App\Filament\RedirectIndexTrait;
|
use App\Filament\EditRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\CodecResource;
|
use App\Filament\Resources\Section\CodecResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
class EditCodec extends EditRecord
|
class EditCodec extends EditRecord
|
||||||
{
|
{
|
||||||
use RedirectIndexTrait;
|
use EditRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = CodecResource::class;
|
protected static string $resource = CodecResource::class;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Filament\Resources\Section;
|
namespace App\Filament\Resources\Section;
|
||||||
|
|
||||||
use App\Filament\OptionsTrait;
|
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\Pages;
|
||||||
use App\Filament\Resources\Section\IconResource\RelationManagers;
|
use App\Filament\Resources\Section\IconResource\RelationManagers;
|
||||||
use App\Models\Icon;
|
use App\Models\Icon;
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\IconResource\Pages;
|
namespace App\Filament\Resources\Section\IconResource\Pages;
|
||||||
|
|
||||||
use App\Filament\RedirectIndexTrait;
|
use App\Filament\EditRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\IconResource;
|
use App\Filament\Resources\Section\IconResource;
|
||||||
use Filament\Pages\Actions;
|
use Filament\Pages\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
class EditIcon extends EditRecord
|
class EditIcon extends EditRecord
|
||||||
{
|
{
|
||||||
use RedirectIndexTrait;
|
use EditRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = IconResource::class;
|
protected static string $resource = IconResource::class;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Section\SecondIconResource\Pages;
|
namespace App\Filament\Resources\Section\SecondIconResource\Pages;
|
||||||
|
|
||||||
use App\Filament\RedirectIndexTrait;
|
use App\Filament\EditRedirectIndexTrait;
|
||||||
use App\Filament\Resources\Section\SecondIconResource;
|
use App\Filament\Resources\Section\SecondIconResource;
|
||||||
use App\Models\SearchBox;
|
use App\Models\SearchBox;
|
||||||
use App\Models\SecondIcon;
|
use App\Models\SecondIcon;
|
||||||
@@ -11,7 +11,7 @@ use Filament\Resources\Pages\EditRecord;
|
|||||||
|
|
||||||
class EditSecondIcon extends EditRecord
|
class EditSecondIcon extends EditRecord
|
||||||
{
|
{
|
||||||
use RedirectIndexTrait;
|
use EditRedirectIndexTrait;
|
||||||
|
|
||||||
protected static string $resource = SecondIconResource::class;
|
protected static string $resource = SecondIconResource::class;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class EditExam extends EditRecord
|
|||||||
$examRep = new ExamRepository();
|
$examRep = new ExamRepository();
|
||||||
try {
|
try {
|
||||||
$this->record = $examRep->update($data, $this->record->id);
|
$this->record = $examRep->update($data, $this->record->id);
|
||||||
$this->notify('success', $this->getSavedNotificationMessage());
|
$this->notify('success', $this->getSavedNotificationTitle());
|
||||||
$this->redirect($this->getResource()::getUrl('index'));
|
$this->redirect($this->getResource()::getUrl('index'));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->notify('danger', $exception->getMessage());
|
$this->notify('danger', $exception->getMessage());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class EditSeedBoxRecord extends EditRecord
|
|||||||
$rep = new SeedBoxRepository();
|
$rep = new SeedBoxRepository();
|
||||||
try {
|
try {
|
||||||
$this->record = $rep->update($data, $this->record->id);
|
$this->record = $rep->update($data, $this->record->id);
|
||||||
$this->notify('success', $this->getSavedNotificationMessage());
|
$this->notify('success', $this->getSavedNotificationTitle());
|
||||||
$this->redirect($this->getResource()::getUrl('index'));
|
$this->redirect($this->getResource()::getUrl('index'));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->notify('danger', $exception->getMessage());
|
$this->notify('danger', $exception->getMessage());
|
||||||
|
|||||||
+16
-11
@@ -146,7 +146,7 @@ class SearchBox extends NexusModel
|
|||||||
$table = self::$taxonomies[$torrentField]['table'];
|
$table = self::$taxonomies[$torrentField]['table'];
|
||||||
return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
|
return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
|
||||||
return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
|
return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
|
||||||
})->get();
|
})->orderBy('sort_index')->orderBy('id')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function listModeOptions(): array
|
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
|
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Category::class, 'mode');
|
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
|
public function taxonomy_source(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Source::class, 'mode');
|
return $this->hasMany(Source::class, 'mode');
|
||||||
@@ -220,10 +230,5 @@ class SearchBox extends NexusModel
|
|||||||
return $this->hasMany(Processing::class, 'mode');
|
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;
|
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)
|
public function listIcon(array $idArr)
|
||||||
{
|
{
|
||||||
$searchBoxList = SearchBox::query()->with('categories')->find($idArr);
|
$searchBoxList = SearchBox::query()->with('categories')->find($idArr);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
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('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Nexus\Install;
|
|||||||
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Repositories\SearchBoxRepository;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Nexus\Database\NexusDB;
|
use Nexus\Database\NexusDB;
|
||||||
@@ -711,4 +712,11 @@ class Install
|
|||||||
return $this->steps[$step - 1] ?? '';
|
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_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_004318_add_section_name_to_searchbox_table.php');
|
||||||
$this->runMigrate('database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php');
|
$this->runMigrate('database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php');
|
||||||
$searchBoxRep = new SearchBoxRepository();
|
$this->migrateSearchBoxModeRelated();
|
||||||
$searchBoxRep->migrateToModeRelated();
|
|
||||||
$this->doLog("[MIGRATE_TAXONOMY_TO_MODE_RELATED]");
|
$this->doLog("[MIGRATE_TAXONOMY_TO_MODE_RELATED]");
|
||||||
}
|
}
|
||||||
$this->removeMenu(['catmanage.php']);
|
$this->removeMenu(['catmanage.php']);
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ if ($currentStep == 4) {
|
|||||||
$install->createSymbolicLinks($symbolicLinks);
|
$install->createSymbolicLinks($symbolicLinks);
|
||||||
$install->runDatabaseSeeder();
|
$install->runDatabaseSeeder();
|
||||||
$install->saveSettings($settings);
|
$install->saveSettings($settings);
|
||||||
|
$install->migrateSearchBoxModeRelated();
|
||||||
$install->nextStep();
|
$install->nextStep();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user