diff --git a/demo/app/Sharp/Entities/PostBlockEntity.php b/demo/app/Sharp/Entities/PostBlockEntity.php index 2d5c3891a..668c1bdfc 100644 --- a/demo/app/Sharp/Entities/PostBlockEntity.php +++ b/demo/app/Sharp/Entities/PostBlockEntity.php @@ -15,12 +15,12 @@ class PostBlockEntity extends SharpEntity protected ?string $policy = PostBlockPolicy::class; protected string $label = 'Block'; - public function getMultiforms(): array - { - return [ - 'text' => [PostBlockTextForm::class, 'Text block'], - 'visuals' => [PostBlockVisualsForm::class, 'Visuals block'], - 'video' => [PostBlockVideoForm::class, 'Video block'], - ]; - } + // public function getMultiforms(): array + // { + // return [ + // 'text' => [PostBlockTextForm::class, 'Text block'], + // 'visuals' => [PostBlockVisualsForm::class, 'Visuals block'], + // 'video' => [PostBlockVideoForm::class, 'Video block'], + // ]; + // } } diff --git a/demo/app/Sharp/Entities/PostBlockTextEntity.php b/demo/app/Sharp/Entities/PostBlockTextEntity.php new file mode 100644 index 000000000..0eecbf49f --- /dev/null +++ b/demo/app/Sharp/Entities/PostBlockTextEntity.php @@ -0,0 +1,12 @@ +configureMultiformAttribute('type') + $this->configureEntityMap( + attribute: 'type', + entities: EntityListEntities::make() + ->addEntity('text', PostBlockTextEntity::class) + ->addEntity('video', PostBlockVideoEntity::class) + ->addEntity('visuals', PostBlockVisualsEntity::class), + ) ->configureReorderable(new SimpleEloquentReorderHandler(PostBlock::class)) ->configureQuickCreationForm(); } diff --git a/demo/app/Sharp/Posts/Blocks/PostBlockVisualsShow.php b/demo/app/Sharp/Posts/Blocks/PostBlockVisualsShow.php new file mode 100644 index 000000000..18e06f07c --- /dev/null +++ b/demo/app/Sharp/Posts/Blocks/PostBlockVisualsShow.php @@ -0,0 +1,62 @@ +addField( + SharpShowListField::make('files') + ->setLabel('Visuals') + ->addItemField( + SharpShowFileField::make('file') + ) + ->addItemField( + SharpShowTextField::make('legend') + ->setLabel('Legend') + ) + ); + } + + protected function buildShowLayout(ShowLayout $showLayout): void + { + $showLayout + ->addSection(function (ShowLayoutSection $section) { + $section + ->addColumn(12, function (ShowLayoutColumn $column) { + $column + ->withListField('files', function (ShowLayoutColumn $item) { + $item->withFields('file') + ->withField('legend'); + }); + }); + }); + } + + public function find(mixed $id): array + { + $postBlock = PostBlock::findOrFail($id); + + return $this + ->setCustomTransformer('files', new SharpUploadModelFormAttributeTransformer()) + ->transform($postBlock); + } + + public function delete(mixed $id): void + { + PostBlock::findOrFail($id)->delete(); + } +} diff --git a/resources/js/Layouts/Layout.vue b/resources/js/Layouts/Layout.vue index 8b48edf9c..abb9c0dd4 100644 --- a/resources/js/Layouts/Layout.vue +++ b/resources/js/Layouts/Layout.vue @@ -219,8 +219,8 @@ - - @@ -233,7 +233,7 @@
- + {{ __('sharp::menu.logout_label') }}
diff --git a/resources/js/Pages/Show/Show.vue b/resources/js/Pages/Show/Show.vue index 88a06ee60..703498790 100644 --- a/resources/js/Pages/Show/Show.vue +++ b/resources/js/Pages/Show/Show.vue @@ -335,7 +335,7 @@ :collapsable="section.collapsable" :entity-key="entityKey" :instance-id="instanceId" - :is-right-col="columnIndex === section.columns.length - 1" + :is-right-col="columnIndex > 0 && columnIndex === section.columns.length - 1" :row="row" @reordering="onEntityListReordering(fieldLayout.key, $event)" /> diff --git a/resources/js/entity-list/EntityList.ts b/resources/js/entity-list/EntityList.ts index 14d9ecfbb..25f55f146 100644 --- a/resources/js/entity-list/EntityList.ts +++ b/resources/js/entity-list/EntityList.ts @@ -6,7 +6,6 @@ import { EntityStateValueData, FilterData, } from "@/types"; -import { getAppendableParentUri, route } from "@/utils/url"; import { EntityListInstance, InstanceId } from "./types"; export class EntityList implements EntityListData { @@ -14,7 +13,7 @@ export class EntityList implements EntityListData { config: EntityListData['config']; data: EntityListData['data']; fields: EntityListData['fields']; - forms: EntityListData['forms']; + entities: EntityListData['entities']; meta: EntityListData['meta']; pageAlert: EntityListData['pageAlert']; query: EntityListData['query']; @@ -110,31 +109,6 @@ export class EntityList implements EntityListData { return instance[this.config.instanceIdAttribute]; } - instanceUrl(instance: EntityListInstance): string | null { - const entityKey = this.entityKey; - const instanceId = this.instanceId(instance); - - if(!this.authorizations.view.includes(instanceId)) { - return null; - } - - const multiform = this.forms && Object.values(this.forms).find(form => form.instances.includes(instanceId)); - - if(this.config.hasShowPage) { - return route('code16.sharp.show.show', { - parentUri: getAppendableParentUri(), - entityKey: multiform ? `${entityKey}:${multiform.key}` : entityKey, - instanceId, - }); - } - - return route('code16.sharp.form.edit', { - parentUri: getAppendableParentUri(), - entityKey: multiform ? `${entityKey}:${multiform.key}` : entityKey, - instanceId, - }); - } - instanceState(instance: EntityListInstance): string | number | null { return this.config.state ? instance[this.config.state.attribute] @@ -153,10 +127,7 @@ export class EntityList implements EntityListData { } instanceCanDelete(instance: EntityListInstance): boolean { - if(Array.isArray(this.authorizations.delete)) { - return this.authorizations.delete?.includes(this.instanceId(instance)); - } - return !!this.authorizations.delete; + return instance._meta.authorizations.delete; } instanceCommands(instance: EntityListInstance): Array> | undefined { diff --git a/resources/js/entity-list/components/EntityList.vue b/resources/js/entity-list/components/EntityList.vue index 2c858ff8c..805f85d31 100644 --- a/resources/js/entity-list/components/EntityList.vue +++ b/resources/js/entity-list/components/EntityList.vue @@ -3,9 +3,9 @@ import { FilterManager } from "@/filters/FilterManager"; import { EntityList } from "../EntityList"; import { - CommandData, EntityListFieldData, EntityListMultiformData, EntityListQueryParamsData, + CommandData, EntityListFieldData, EntityListQueryParamsData, EntityStateValueData, - FilterData + FilterData, EntityListEntityData } from "@/types"; import WithCommands from "@/commands/components/WithCommands.vue"; import { CommandManager } from "@/commands/CommandManager"; @@ -68,6 +68,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { useElementVisibility } from "@vueuse/core"; import StateBadge from "@/components/ui/StateBadge.vue"; + import Icon from "@/components/ui/Icon.vue"; // import StateBadgeTest from "@/components/dev/StateBadgeTest.vue"; const props = withDefaults(defineProps<{ @@ -175,7 +176,7 @@ }); } - async function onCreate(event: MouseEvent, form?: EntityListMultiformData) { + async function onCreate(event: MouseEvent, listEntity?: EntityListEntityData) { if(event.metaKey || event.ctrlKey || event.shiftKey) { return; } @@ -186,19 +187,18 @@ if(props.entityList.config.quickCreationForm) { await props.commands.send({ hasForm: true } as CommandData, { postCommand: route('code16.sharp.api.list.command.quick-creation-form.store', { - entityKey: form ? `${entityKey}:${form.key}` : entityKey, + entityKey, + formEntityKey: listEntity ? listEntity.entityKey : entityKey, }), getForm: route('code16.sharp.api.list.command.quick-creation-form.create', { - entityKey: form ? `${entityKey}:${form.key}` : entityKey, + entityKey, + formEntityKey: listEntity ? listEntity.entityKey : entityKey, }), query: props.entityList.query, - entityKey: form ? `${entityKey}:${form.key}` : entityKey, + entityKey: listEntity ? listEntity.entityKey : entityKey, }); } else { - router.visit(route('code16.sharp.form.create', { - parentUri: getAppendableParentUri(), - entityKey: form ? `${entityKey}:${form.key}` : entityKey, - })); + router.visit(listEntity ? listEntity.formCreateUrl : props.entityList.config.formCreateUrl); } } @@ -469,7 +469,7 @@