diff --git a/app/Http/Requests/Back/DocumentTag/StoreDocumentTagRequest.php b/app/Http/Requests/Back/DocumentTag/StoreDocumentTagRequest.php index e57787b6..0ed26bca 100644 --- a/app/Http/Requests/Back/DocumentTag/StoreDocumentTagRequest.php +++ b/app/Http/Requests/Back/DocumentTag/StoreDocumentTagRequest.php @@ -25,7 +25,8 @@ class StoreDocumentTagRequest extends FormRequest { return [ 'name' => 'required|string|between:3,255', - 'slug' => 'required|string|between:3,255' + 'slug' => 'required|string|between:3,255', + 'color' => 'required|string|hex_color', ]; } } diff --git a/app/Models/DocumentTag.php b/app/Models/DocumentTag.php index d11c5ef9..b4f3e160 100644 --- a/app/Models/DocumentTag.php +++ b/app/Models/DocumentTag.php @@ -2,13 +2,14 @@ namespace App\Models; -use App\Contracts\TranslatableModel; use App\Traits\Models\HasCache; +use Illuminate\Support\Facades\App; +use App\Contracts\TranslatableModel; use App\Traits\Models\HasTranslations; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Uwil\LaravelActivityLogs\Traits\ActivityLog; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class DocumentTag extends Model implements TranslatableModel { @@ -24,7 +25,8 @@ class DocumentTag extends Model implements TranslatableModel */ protected $fillable = [ 'name', - 'slug' + 'slug', + 'color' ]; /** diff --git a/database/migrations/2026_01_08_114841_alter_document_tags_table.php b/database/migrations/2026_01_08_114841_alter_document_tags_table.php new file mode 100644 index 00000000..448853e0 --- /dev/null +++ b/database/migrations/2026_01_08_114841_alter_document_tags_table.php @@ -0,0 +1,28 @@ +string('color')->default("#ff4e4e")->after('slug')->comment('Color of the news category.'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('document_tags', function (Blueprint $table) { + $table->dropColumn('color'); + }); + } +}; diff --git a/resources/ts/back/Pages/DocumentTag/Form.tsx b/resources/ts/back/Pages/DocumentTag/Form.tsx index 4ddf33b3..9308ca9b 100644 --- a/resources/ts/back/Pages/DocumentTag/Form.tsx +++ b/resources/ts/back/Pages/DocumentTag/Form.tsx @@ -11,6 +11,7 @@ import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import { useCrudSubmit } from "@/hooks/use-crud-submit"; import SubmitButton from "@/back/Components/SubmitButton"; +import SimpleColorPicker from "@/back/Components/Inputs/SimpleColorPicker"; import Slugifycator from "@/back/Components/Inputs/Slugifycator"; export default function Form({ @@ -28,12 +29,12 @@ export default function Form({ }) { const { locale } = usePage().props.appEnv as AppEnv; - /** Form section */ const { post, setData, data } = useForm({ - _method: method === Methods.POST ? 'post' : 'put', + _method: method === Methods.POST ? "post" : "put", name: model?.name ? model?.name[locale] : "", - slug: model?.slug ? model?.slug[locale] : "" + slug: model?.slug ? model?.slug[locale] : "", + color: model?.color ? model?.color : "", }); const submit = useCrudSubmit({ @@ -42,7 +43,7 @@ export default function Form({ modelName, action, model, - post + post, }); return ( @@ -59,11 +60,15 @@ export default function Form({ label={str( useTrans("back.form_associate_to", { params: { - attribute: useTrans("validation.attributes.name"), + attribute: useTrans( + "validation.attributes.name", + ), }, - choice: 1 + choice: 1, }), - ).ucFirst().value()} + ) + .ucFirst() + .value()} required={true} placeholder="ex: John Doe" value={data.name ?? ""} @@ -74,14 +79,32 @@ export default function Form({ targetValue={data.name} setData={setData} /> +
- + })} + />
); diff --git a/resources/ts/back/Pages/DocumentTag/Index.tsx b/resources/ts/back/Pages/DocumentTag/Index.tsx index 5ea8c8f9..a4318320 100644 --- a/resources/ts/back/Pages/DocumentTag/Index.tsx +++ b/resources/ts/back/Pages/DocumentTag/Index.tsx @@ -3,6 +3,11 @@ import { route } from "ziggy-js"; import { usePage } from "@inertiajs/react"; // * Components shadcn import { Badge } from "@/components/ui/badge"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; // * Other import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; import DataTable from "@/back/Components/Table/DataTable"; @@ -28,7 +33,7 @@ export default function Index({ documentTagModel, search, searchFields, - modelName + modelName, }: { documentTagModel: Resource; search: string; @@ -40,30 +45,56 @@ export default function Index({ appEnv: AppEnv; }; const { create } = auth.policies.documentTags; - const actionModels = [ - Views.VISUALIZATION, - Views.EDITION, - Views.DELETION, - ]; + const actionModels = [Views.VISUALIZATION, Views.EDITION, Views.DELETION]; const columns = [ { accessorKey: "name", header: ({ column }: { column: { id: string } }) => ( ), cell: ({ row }: { row: Row }) => { - return renderTranslationCell( - row.getValue("name") - ) + return renderTranslationCell(row.getValue("name")); + }, + }, + { + accessorKey: "color", + header: ({ column }: { column: { id: string } }) => ( + + ), + cell: ({ row }: { row: Row }) => { + return ( + + +
+
+ {row.getValue("color")} +
+ ); }, }, { accessorKey: "documents", header: () => ( -

{str(useTrans(`validation.custom.documentTag.documents`)).ucFirst().value()}

+

+ {str(useTrans(`validation.custom.documentTag.documents`)) + .ucFirst() + .value()} +

), cell: ({ row }: { row: Row }) => (
@@ -75,7 +106,9 @@ export default function Index({ accessorKey: "updated_at", header: ({ column }: { column: { id: string } }) => ( ), @@ -86,26 +119,30 @@ export default function Index({ ), }, ]; - const transModel = useTrans(`models.classes.${str(modelName).singular().value()}`, { choice: 2 }); + const transModel = useTrans( + `models.classes.${str(modelName).singular().value()}`, + { choice: 2 }, + ); const transTitle = str(transModel).ucFirst().value(); const afterNode = () => { return (
- {create && } - tooltipContent={

{useTrans("back.crud_add_entry")}

} - />} + {create && ( + } + tooltipContent={ +

{useTrans("back.crud_add_entry")}

+ } + /> + )}
); }; return ( - + { - return renderTranslationCell( - value - ) - } + return renderTranslationCell(value); + }, }, { accessorKey: "slug", header: str(useTrans("validation.custom.slug")).ucFirst().value(), - cell: ({ value }: { value: TranslationField }) => value[appEnv.locale] - ? value[appEnv.locale] - : (

{useTrans('back.table_not_known')}

), + cell: ({ value }: { value: TranslationField }) => + value[appEnv.locale] ? ( + value[appEnv.locale] + ) : ( +

+ {useTrans("back.table_not_known")} +

+ ), + }, + { + accessorKey: "color", + header: str(useTrans("validation.custom.color")).ucFirst().value(), + cell: ({ value }: { value: string }) => { + return ( + + +
+
+ {value} +
+ ); + }, }, { accessorKey: "created_at", - header: str(useTrans("validation.attributes.created_at")).ucFirst().value(), + header: str(useTrans("validation.attributes.created_at")) + .ucFirst() + .value(), cell: ({ value }: { value: string }) => { return ( {useFormatedDate(value)} - ) + ); }, }, { accessorKey: "updated_at", - header: str(useTrans("validation.attributes.updated_at")).ucFirst().value(), + header: str(useTrans("validation.attributes.updated_at")) + .ucFirst() + .value(), cell: ({ value }: { value: string }) => ( {useFormatedDate(value)} ), @@ -75,22 +113,23 @@ export default function Show({ data, modelName, documents }: { data: SingleResou ]; const beforeNode = () => { - return viewAny && ( -
- } - tooltipContent={

{useTrans("back.crud_back_to_list")}

} - /> -
+ return ( + viewAny && ( +
+ } + tooltipContent={ +

{useTrans("back.crud_back_to_list")}

+ } + /> +
+ ) ); }; return ( - +