diff --git a/app/Filament/Resources/TorrentCustomFields/Pages/ListTorrentCustomFields.php b/app/Filament/Resources/TorrentCustomFields/Pages/ListTorrentCustomFields.php new file mode 100644 index 00000000..980981e2 --- /dev/null +++ b/app/Filament/Resources/TorrentCustomFields/Pages/ListTorrentCustomFields.php @@ -0,0 +1,19 @@ +components([ + TextInput::make('name') + ->label(__('label.field.name')) + ->helperText(__('label.field.name_help')) + ->alphaDash() + ->required(), + TextInput::make('label') + ->label(__('label.field.field_label')) + ->required(), + Select::make('type') + ->options((new Field())->getTypeRadioOptions()) + ->label(__('label.field.type')) + ->required(), + Checkbox::make('required') + ->label(__('label.field.required')), + Textarea::make('help') + ->label(__('label.field.help')) + ->rows(3), + Textarea::make('options') + ->label(__('label.field.options')) + ->rows(3) + ->hiddenJs("\$get('type') !== 'radio' && \$get('type') !== 'checkbox' && \$get('type') !== 'select'") + ->helperText(__('label.field.options_help')), + Checkbox::make('is_single_row') + ->label(__('label.field.is_single_row')), + TextInput::make('priority') + ->label(__('label.priority')) + ->numeric(), + Textarea::make('display') + ->label(__('label.field.display')) + ->rows(3) + ->helperText(__('label.search_box.custom_fields_display_help')), + + ]) + ->columns(1); + } +} diff --git a/app/Filament/Resources/TorrentCustomFields/Tables/TorrentCustomFieldsTable.php b/app/Filament/Resources/TorrentCustomFields/Tables/TorrentCustomFieldsTable.php new file mode 100644 index 00000000..9f32829b --- /dev/null +++ b/app/Filament/Resources/TorrentCustomFields/Tables/TorrentCustomFieldsTable.php @@ -0,0 +1,40 @@ +columns([ + TextColumn::make('id'), + TextColumn::make('name')->label(__('label.field.name')), + TextColumn::make('label')->label(__('label.field.field_label')), + TextColumn::make('type')->label(__('label.field.type')), + IconColumn::make('required')->boolean()->label(__('label.field.required')), + IconColumn::make('is_single_row')->boolean()->label(__('label.field.is_single_row')), + TextColumn::make('priority')->label(__('label.priority')), + ]) + ->filters([ + // + ]) + ->recordActions([ + EditAction::make(), + DeleteAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Filament/Resources/TorrentCustomFields/TorrentCustomFieldResource.php b/app/Filament/Resources/TorrentCustomFields/TorrentCustomFieldResource.php new file mode 100644 index 00000000..27d06b6b --- /dev/null +++ b/app/Filament/Resources/TorrentCustomFields/TorrentCustomFieldResource.php @@ -0,0 +1,59 @@ + ListTorrentCustomFields::route('/'), + ]; + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 3448477d..e007c51f 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -16,6 +16,7 @@ use App\Models\SecondIcon; use App\Models\Source; use App\Models\Standard; use App\Models\Team; +use App\Models\TorrentCustomField; use App\Models\User; use App\Policies\CodecPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; @@ -34,6 +35,7 @@ class AuthServiceProvider extends ServiceProvider Category::class => CodecPolicy::class, Icon::class => CodecPolicy::class, SecondIcon::class => CodecPolicy::class, + TorrentCustomField::class => CodecPolicy::class, Codec::class => CodecPolicy::class, AudioCodec::class => CodecPolicy::class, diff --git a/nexus/Field/Field.php b/nexus/Field/Field.php index 0f2e3ac3..fbf83555 100644 --- a/nexus/Field/Field.php +++ b/nexus/Field/Field.php @@ -55,14 +55,13 @@ class Field public function getTypeHuman($type) { - global $lang_fields; $map = [ - self::TYPE_TEXT => $lang_fields['field_type_text'], - self::TYPE_TEXTAREA => $lang_fields['field_type_textarea'], - self::TYPE_RADIO => $lang_fields['field_type_radio'], - self::TYPE_CHECKBOX => $lang_fields['field_type_checkbox'], - self::TYPE_SELECT => $lang_fields['field_type_select'], - self::TYPE_IMAGE => $lang_fields['field_type_image'], + self::TYPE_TEXT => nexus_trans('field.type.text'), + self::TYPE_TEXTAREA => nexus_trans('field.type.textarea'), + self::TYPE_RADIO => nexus_trans('field.type.radio'), + self::TYPE_CHECKBOX => nexus_trans('field.type.checkbox'), + self::TYPE_SELECT => nexus_trans('field.type.select'), + self::TYPE_IMAGE => nexus_trans('field.type.image'), ]; return $map[$type] ?? ''; } @@ -439,7 +438,7 @@ JS; $customFieldDisplay = $field['display']; $customFieldDisplay = str_replace("<%{$field['name']}.label%>", $field['label'], $customFieldDisplay); $customFieldDisplay = str_replace("<%{$field['name']}.value%>", $contentNotFormatted, $customFieldDisplay); - $rowByRowHtml .= tr($field['label'], format_comment($customFieldDisplay, false), 1); + $rowByRowHtml .= tr($field['label'], format_comment($customFieldDisplay), 1); } else { $contentFormatted = $this->formatCustomFieldValue($field, true); $rowByRowHtml .= tr($field['label'], $contentFormatted, 1); @@ -463,13 +462,13 @@ JS; switch ($customFieldWithValue['type']) { case self::TYPE_TEXT: case self::TYPE_TEXTAREA: - $result .= $doFormatComment ? format_comment($fieldValue, false) : $fieldValue; + $result .= $doFormatComment ? format_comment($fieldValue) : $fieldValue; break; case self::TYPE_IMAGE: if (substr($fieldValue, 0, 4) == 'http') { $result .= $doFormatComment ? formatImg($fieldValue, true, 700, 0, "attach{$customFieldWithValue['id']}") : $fieldValue; } else { - $result .= $doFormatComment ? format_comment($fieldValue, false) : $fieldValue; + $result .= $doFormatComment ? format_comment($fieldValue) : $fieldValue; } break; case self::TYPE_RADIO: diff --git a/public/fields.php b/public/fields.php index 6911a6ee..83a6f759 100644 --- a/public/fields.php +++ b/public/fields.php @@ -22,6 +22,7 @@ if ($action == 'view') { begin_main_frame(); echo $field->buildFieldForm(); } elseif ($action == 'submit') { + die("This method is deprecated! This method is no longer available in 1.10, it does not save data correctly, please go to the management system!"); try { $result = $field->save($_REQUEST); nexus_redirect('fields.php?action=view'); diff --git a/resources/lang/en/field.php b/resources/lang/en/field.php new file mode 100644 index 00000000..ede15af0 --- /dev/null +++ b/resources/lang/en/field.php @@ -0,0 +1,12 @@ + [ + 'text' => 'Short text', + 'textarea' => 'Long text', + 'radio' => 'Horizontal single select', + 'checkbox' => 'Horizontal multiple select', + 'select' => 'Vertical single select', + 'image' => 'Image', + ], +]; diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index 2a66aa19..def49dc2 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -456,4 +456,18 @@ Note: In 1.8, the 'searchbox_name' part can be omitted, i.e. the rule is 'pic/ca 'select_section' => 'Selections', 'select_section_help' => "If a selection is not defined, all options from the selection are allowed for the rule. At least one selection should be defined.", ], + 'field' => [ + 'label' => 'Custom field', + 'name' => 'Name', + 'name_help' => 'Only allow digit, alphabet, underline', + 'field_label' => 'Display label', + 'type' => 'Type', + 'required' => 'Required', + 'mod_only' => 'Mod only', + 'help' => 'Help text', + 'options' => 'Options', + 'options_help' => 'Required when type is radio, checkbox, select. One line, one option, format: value|display text', + 'is_single_row' => 'Display on a single row', + 'display' => 'Custom display', + ] ]; diff --git a/resources/lang/zh_CN/field.php b/resources/lang/zh_CN/field.php new file mode 100644 index 00000000..6e0d739d --- /dev/null +++ b/resources/lang/zh_CN/field.php @@ -0,0 +1,12 @@ + [ + 'text' => '短文本', + 'textarea' => '长文本', + 'radio' => '横向单选', + 'checkbox' => '横向多选', + 'select' => '下拉单选', + 'image' => '图片', + ], +]; diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 915d55d9..5cf33028 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -498,4 +498,18 @@ return [ 'select_section' => '选择', 'select_section_help' => "如果某个选择未指定,其所有选项都符合此规则。必须至少指定一个选择。", ], + 'field' => [ + 'label' => '自定义字段', + 'name' => '名称', + 'name_help' => '仅允许数字、字母、下划线', + 'field_label' => '显示标签', + 'type' => '类型', + 'required' => '不能为空', + 'mod_only' => '仅管理组可见', + 'help' => '辅助说明', + 'options' => '选项', + 'options_help' => '类型为单选、多选、下拉时必填,一行一个,格式:选项值|选项描述文本', + 'is_single_row' => '展示时单独一行', + 'display' => '自定义展示', + ] ];