tag add mode

This commit is contained in:
xiaomlove
2022-10-30 17:30:24 +08:00
parent 0fe7b2f76f
commit 87a079b392
39 changed files with 164 additions and 76 deletions
@@ -2,8 +2,8 @@
namespace App\Filament\Resources\Section;
use App\Filament\Resources\System\SectionResource\Pages;
use App\Filament\Resources\System\SectionResource\RelationManagers;
use App\Filament\Resources\Section\SectionResource\Pages;
use App\Filament\Resources\Section\SectionResource\RelationManagers;
use App\Http\Middleware\Locale;
use App\Models\Forum;
use App\Models\SearchBox;
@@ -1,6 +1,6 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
namespace App\Filament\Resources\Section\SectionResource\Pages;
use App\Filament\Resources\Section\SectionResource;
use App\Models\SearchBox;
@@ -1,6 +1,6 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
namespace App\Filament\Resources\Section\SectionResource\Pages;
use App\Filament\Resources\Section\SectionResource;
use App\Models\SearchBox;
@@ -1,6 +1,6 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
namespace App\Filament\Resources\Section\SectionResource\Pages;
use App\Filament\PageList;
use App\Filament\Resources\Section\SectionResource;
@@ -17,7 +17,7 @@ class CreateExam extends CreateRecord
$examRep = new ExamRepository();
try {
$this->record = $examRep->store($data);
$this->notify('success', $this->getCreatedNotificationMessage());
$this->notify('success', $this->getCreatedNotificationTitle());
if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->record::class);
@@ -22,7 +22,7 @@ class CreateSeedBoxRecord extends CreateRecord
$rep = new SeedBoxRepository();
try {
$this->record = $rep->store($data);
$this->notify('success', $this->getCreatedNotificationMessage());
$this->notify('success', $this->getCreatedNotificationTitle());
if ($another) {
// Ensure that the form record is anonymized so that relationships aren't loaded.
$this->form->model($this->record::class);
+21 -1
View File
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\Torrent;
use App\Filament\Resources\Torrent\TagResource\Pages;
use App\Filament\Resources\Torrent\TagResource\RelationManagers;
use App\Models\SearchBox;
use App\Models\Tag;
use Filament\Forms;
use Filament\Resources\Form;
@@ -45,6 +46,11 @@ class TagResource extends Resource
Forms\Components\TextInput::make('padding')->required()->label(__('label.tag.padding')),
Forms\Components\TextInput::make('border_radius')->required()->label(__('label.tag.border_radius')),
Forms\Components\TextInput::make('priority')->integer()->required()->label(__('label.priority'))->default(0),
Forms\Components\Select::make('mode')
->options(SearchBox::query()->pluck('name', 'id')->toArray())
->label(__('label.search_box.taxonomy.mode'))
->helperText(__('label.search_box.taxonomy.mode_help'))
,
]);
}
@@ -53,6 +59,10 @@ class TagResource extends Resource
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('search_box.name')
->label(__('label.search_box.label'))
->formatStateUsing(fn ($record) => $record->search_box->name ?? 'All')
,
Tables\Columns\TextColumn::make('name')->label(__('label.name'))->searchable(),
Tables\Columns\TextColumn::make('color')->label(__('label.tag.color')),
Tables\Columns\TextColumn::make('font_color')->label(__('label.tag.font_color')),
@@ -66,7 +76,17 @@ class TagResource extends Resource
])
->defaultSort('priority', 'desc')
->filters([
//
Tables\Filters\SelectFilter::make('mode')
->options(SearchBox::query()->pluck('name', 'id')->toArray())
->label(__('label.search_box.taxonomy.mode'))
->query(function (Builder $query, array $data) {
return $query->when($data['value'], function (Builder $query, $value) {
return $query->where(function (Builder $query) use ($value) {
return $query->where('mode', $value)->orWhere('mode', 0);
});
});
})
,
])
->actions(self::getActions())
->bulkActions([
@@ -20,7 +20,7 @@ class CreateUser extends CreateRecord
$this->record = $userRep->store($data);
$this->notify(
'success ',
$this->getCreatedNotificationMessage(),
$this->getCreatedNotificationTitle(),
);
$this->redirect($this->getRedirectUrl());
} catch (\Exception $exception) {
@@ -51,7 +51,12 @@ class AuthenticateController extends Controller
$user = User::query()->where('passkey', $passkey)->first(['id', 'passhash']);
if ($user) {
$ip = getip();
$passhash = md5($user->passhash . $ip);
/**
* Not IP related
* @since 1.8.0
*/
// $passhash = md5($user->passhash . $ip);
$passhash = md5($user->passhash);
do_log(sprintf('passhash: %s, ip: %s, md5: %s', $user->passhash, $ip, $passhash));
logincookie($user->id, $passhash,false, 0x7fffffff, true, true, true);
$user->last_login = now();
+1 -1
View File
@@ -7,7 +7,7 @@ class AudioCodec extends NexusModel
{
protected $table = 'audiocodecs';
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+1 -1
View File
@@ -7,7 +7,7 @@ class Codec extends NexusModel
{
protected $table = 'codecs';
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+1 -1
View File
@@ -7,7 +7,7 @@ class Media extends NexusModel
{
protected $table = 'media';
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+1 -1
View File
@@ -7,7 +7,7 @@ class Processing extends NexusModel
{
protected $table = 'processings';
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+1 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
class Source extends NexusModel
{
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+1 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
class Standard extends NexusModel
{
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+8 -1
View File
@@ -7,7 +7,9 @@ class Tag extends NexusModel
public $timestamps = true;
protected $fillable = [
'id', 'name', 'color', 'priority', 'created_at', 'updated_at', 'font_size', 'font_color', 'padding', 'margin', 'border_radius'
'id', 'name', 'color', 'priority', 'created_at', 'updated_at',
'font_size', 'font_color', 'padding', 'margin', 'border_radius',
'mode',
];
const DEFAULTS = [
@@ -66,6 +68,11 @@ class Tag extends NexusModel
return $this->hasMany(TorrentTag::class, 'tag_id');
}
public function search_box(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(SearchBox::class, 'mode', 'id');
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
class Team extends NexusModel
{
protected $fillable = ['name', 'sort_index'];
protected $fillable = ['name', 'sort_index', 'mode',];
public static function getLabelName()
{
+12 -9
View File
@@ -50,27 +50,27 @@ class TagRepository extends BaseRepository
return Tag::query()->orderBy('priority', 'desc')->orderBy('id', 'desc');
}
public function renderCheckbox(array $checked = [], $ignorePermission = false): string
public function renderCheckbox(int $searchBoxId, array $checked = [], $ignorePermission = false): string
{
$html = '';
$results = $this->listAll();
$results = $this->listAll($searchBoxId);
if (!$ignorePermission && !user_can('torrent-set-special-tag')) {
$specialTags = Tag::listSpecial();
$results = $results->filter(fn ($item) => !in_array($item->id, $specialTags));
}
foreach ($results as $value) {
$html .= sprintf(
'<label><input type="checkbox" name="tags[]" value="%s"%s />%s</label>',
$value->id, in_array($value->id, $checked) ? ' checked' : '', $value->name
'<label><input type="checkbox" name="tags[%s][]" value="%s"%s />%s</label>',
$searchBoxId, $value->id, in_array($value->id, $checked) ? ' checked' : '', $value->name
);
}
return $html;
}
public function renderSpan(array $renderIdArr = [], $withFilterLink = false): string
public function renderSpan(int $searchBoxId, array $renderIdArr = [], $withFilterLink = false): string
{
$html = '';
foreach ($this->listAll() as $value) {
foreach ($this->listAll($searchBoxId) as $value) {
if (in_array($value->id, $renderIdArr) || (isset($renderIdArr[0]) && $renderIdArr[0] == '*')) {
$tagId = $value->id;
if ($value) {
@@ -149,17 +149,20 @@ class TagRepository extends BaseRepository
return self::$orderByFieldIdString;
}
public function listAll()
public function listAll(int $searchBoxId = 0): \Illuminate\Database\Eloquent\Collection|array
{
if (empty(self::$allTags)) {
self::$allTags = self::createBasicQuery()->get();
}
if ($searchBoxId > 0) {
return self::$allTags->filter(fn ($d) => in_array($d->mode, [0, $searchBoxId]));
}
return self::$allTags;
}
public function buildSelect($name, $value): string
public function buildSelect(int $searchBoxId, $name, $value): string
{
$list = $this->listAll();
$list = $this->listAll($searchBoxId);
$select = sprintf('<select name="%s"><option value="">%s</option>', $name, nexus_trans('nexus.select_one_please'));
foreach ($list as $item) {
$selected = '';