feat: ✨ add field color to document_tags
This commit is contained in:
parent
ebefe52231
commit
5c486c73e5
7 changed files with 198 additions and 67 deletions
|
|
@ -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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('document_tags', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -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}
|
||||
/>
|
||||
<SimpleColorPicker
|
||||
name="color"
|
||||
label={str(
|
||||
useTrans("back.form_associate_to", {
|
||||
params: {
|
||||
attribute: useTrans(
|
||||
"validation.custom.color",
|
||||
),
|
||||
},
|
||||
choice: 1,
|
||||
}),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
setData={setData}
|
||||
value={data.color}
|
||||
required={true}
|
||||
/>
|
||||
</div>
|
||||
</FieldsetWrapper>
|
||||
<div className="text-center">
|
||||
<SubmitButton modelTrans={
|
||||
useTrans(`models.classes.${modelName}`, {
|
||||
<SubmitButton
|
||||
modelTrans={useTrans(`models.classes.${modelName}`, {
|
||||
choice: 1,
|
||||
})
|
||||
} />
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 } }) => (
|
||||
<DataTableFilterButton
|
||||
label={str(useTrans(`validation.attributes.${column.id}`)).ucFirst().value()}
|
||||
label={str(useTrans(`validation.attributes.${column.id}`))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
field={column.id}
|
||||
/>
|
||||
),
|
||||
cell: ({ row }: { row: Row<DocumentTagModel> }) => {
|
||||
return renderTranslationCell(
|
||||
row.getValue("name")
|
||||
)
|
||||
return renderTranslationCell(row.getValue("name"));
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "color",
|
||||
header: ({ column }: { column: { id: string } }) => (
|
||||
<DataTableFilterButton
|
||||
label={str(useTrans(`validation.custom.${column.id}`))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
field={column.id}
|
||||
/>
|
||||
),
|
||||
cell: ({ row }: { row: Row<DocumentTagModel> }) => {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<div
|
||||
className="w-8 h-8 rounded-md mx-auto border"
|
||||
style={{
|
||||
backgroundColor: row.getValue("color"),
|
||||
}}
|
||||
></div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{row.getValue("color")}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "documents",
|
||||
header: () => (
|
||||
<p className="w-full text-center">{str(useTrans(`validation.custom.documentTag.documents`)).ucFirst().value()}</p>
|
||||
<p className="w-full text-center">
|
||||
{str(useTrans(`validation.custom.documentTag.documents`))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
</p>
|
||||
),
|
||||
cell: ({ row }: { row: Row<DocumentTagModel> }) => (
|
||||
<div className="w-full flex justify-center">
|
||||
|
|
@ -75,7 +106,9 @@ export default function Index({
|
|||
accessorKey: "updated_at",
|
||||
header: ({ column }: { column: { id: string } }) => (
|
||||
<DataTableFilterButton
|
||||
label={str(useTrans(`validation.attributes.${column.id}`)).ucFirst().value()}
|
||||
label={str(useTrans(`validation.attributes.${column.id}`))
|
||||
.ucFirst()
|
||||
.value()}
|
||||
field={column.id}
|
||||
/>
|
||||
),
|
||||
|
|
@ -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 (
|
||||
<div className="flex justify-end items-center gap-x-1.5">
|
||||
{create && <BtnOptionnalLinkWithTooltip
|
||||
link={route(`back.${modelName}.create`)}
|
||||
content={<Plus />}
|
||||
tooltipContent={<p>{useTrans("back.crud_add_entry")}</p>}
|
||||
/>}
|
||||
{create && (
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
link={route(`back.${modelName}.create`)}
|
||||
content={<Plus />}
|
||||
tooltipContent={
|
||||
<p>{useTrans("back.crud_add_entry")}</p>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
title={transTitle}
|
||||
afterNode={afterNode()}
|
||||
>
|
||||
<AuthenticatedLayout title={transTitle} afterNode={afterNode()}>
|
||||
<DataTableSearch
|
||||
modelRoute={modelName}
|
||||
searchText={search}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { usePage } from "@inertiajs/react";
|
|||
import { route } from "ziggy-js";
|
||||
// * Components shadcn
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
// * Other
|
||||
import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout";
|
||||
import DetailsTable from "@/back/Components/Table/DetailsTable";
|
||||
|
|
@ -24,50 +25,87 @@ import { ArrowLeft } from "lucide-react";
|
|||
import AssociatedDocumentList from "@/back/Components/AssociatedDocumentList";
|
||||
import { renderTranslationCell } from "@/lib/translationCellFallback";
|
||||
|
||||
export default function Show({ data, modelName, documents }: { data: SingleResource, modelName: string, documents: Resource }) {
|
||||
export default function Show({
|
||||
data,
|
||||
modelName,
|
||||
documents,
|
||||
}: {
|
||||
data: SingleResource;
|
||||
modelName: string;
|
||||
documents: Resource;
|
||||
}) {
|
||||
const { auth, appEnv } = usePage().props as unknown as {
|
||||
auth: AuthProp;
|
||||
appEnv: AppEnv;
|
||||
};
|
||||
const { viewAny } = auth.policies.documentTags;
|
||||
const docsModel = data.data as DocumentTagModel;
|
||||
const actionModels = [
|
||||
Views.EDITION,
|
||||
Views.DELETION,
|
||||
];
|
||||
const actionModels = [Views.EDITION, Views.DELETION];
|
||||
const singularModelName = str(modelName).singular().value();
|
||||
const transTitle = useTrans("crud.helpers.visualization_model", {
|
||||
params: { model: useTrans(`models.classes.${singularModelName}`, { choice: 1 }) },
|
||||
params: {
|
||||
model: useTrans(`models.classes.${singularModelName}`, {
|
||||
choice: 1,
|
||||
}),
|
||||
},
|
||||
});
|
||||
const columns = [
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: str(useTrans("validation.attributes.name")).ucFirst().value(),
|
||||
header: str(useTrans("validation.attributes.name"))
|
||||
.ucFirst()
|
||||
.value(),
|
||||
cell: ({ value }: { value: TranslationField }) => {
|
||||
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]
|
||||
: (<p className="text-muted-foreground italic m-0">{useTrans('back.table_not_known')}</p>),
|
||||
cell: ({ value }: { value: TranslationField }) =>
|
||||
value[appEnv.locale] ? (
|
||||
value[appEnv.locale]
|
||||
) : (
|
||||
<p className="text-muted-foreground italic m-0">
|
||||
{useTrans("back.table_not_known")}
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "color",
|
||||
header: str(useTrans("validation.custom.color")).ucFirst().value(),
|
||||
cell: ({ value }: { value: string }) => {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<div
|
||||
className="w-8 h-8 rounded-md border"
|
||||
style={{
|
||||
backgroundColor: value,
|
||||
}}
|
||||
></div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{value}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
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 (
|
||||
<Badge variant="secondary">{useFormatedDate(value)}</Badge>
|
||||
)
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
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 }) => (
|
||||
<Badge variant="secondary">{useFormatedDate(value)}</Badge>
|
||||
),
|
||||
|
|
@ -75,22 +113,23 @@ export default function Show({ data, modelName, documents }: { data: SingleResou
|
|||
];
|
||||
|
||||
const beforeNode = () => {
|
||||
return viewAny && (
|
||||
<div className="flex justify-end items-center gap-x-1.5">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
link={route(`back.${modelName}.index`)}
|
||||
content={<ArrowLeft />}
|
||||
tooltipContent={<p>{useTrans("back.crud_back_to_list")}</p>}
|
||||
/>
|
||||
</div>
|
||||
return (
|
||||
viewAny && (
|
||||
<div className="flex justify-end items-center gap-x-1.5">
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
link={route(`back.${modelName}.index`)}
|
||||
content={<ArrowLeft />}
|
||||
tooltipContent={
|
||||
<p>{useTrans("back.crud_back_to_list")}</p>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
title={transTitle}
|
||||
beforeNode={beforeNode()}
|
||||
>
|
||||
<AuthenticatedLayout title={transTitle} beforeNode={beforeNode()}>
|
||||
<ModelActions
|
||||
actions={actionModels}
|
||||
modelRoute={modelName}
|
||||
|
|
|
|||
1
resources/ts/back/types/global.d.ts
vendored
1
resources/ts/back/types/global.d.ts
vendored
|
|
@ -210,6 +210,7 @@ type DocumentTagModel = {
|
|||
id: number;
|
||||
name: TranslationField;
|
||||
slug: TranslationField;
|
||||
color: string;
|
||||
documents_count?: number;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue