99use App \Sharp \Utils \Embeds \CodeEmbed ;
1010use App \Sharp \Utils \Embeds \RelatedPostEmbed ;
1111use App \Sharp \Utils \Embeds \TableOfContentsEmbed ;
12- use Carbon \Carbon ;
1312use Code16 \Sharp \Form \Eloquent \Uploads \Transformers \SharpUploadModelFormAttributeTransformer ;
1413use Code16 \Sharp \Form \Eloquent \WithSharpFormEloquentUpdater ;
1514use Code16 \Sharp \Form \Fields \Editor \Uploads \SharpFormEditorUpload ;
3029use Code16 \Sharp \Form \SharpForm ;
3130use Code16 \Sharp \Utils \Fields \FieldsContainer ;
3231use Illuminate \Support \Facades \Blade ;
33- use Illuminate \Support \Facades \Storage ;
3432
3533class PostForm extends SharpForm
3634{
@@ -110,7 +108,7 @@ public function buildFormFields(FieldsContainer $formFields): void
110108 )
111109 ->addField (
112110 SharpFormHtmlField::make ('publication_label ' )
113- ->setLiveRefresh (linkedFields: ['author_id ' , 'published_at ' ])
111+ ->setLiveRefresh (linkedFields: ['author_id ' , 'published_at ' , ' attachments ' ])
114112 ->setTemplate (function (array $ data ) {
115113 if (! isset ($ data ['published_at ' ])) {
116114 return '' ;
@@ -121,9 +119,13 @@ public function buildFormFields(FieldsContainer $formFields): void
121119 @if($author)
122120 by {{ $author->name }}.
123121 @endif
122+ <br>
123+ {{ count($linkAttachments) }} link attachments, {{ count($fileAttachments) }} file attachments.
124124 blade, [
125125 'published_at ' => \Carbon \Carbon::parse ($ data ['published_at ' ])->isoFormat ('LLLL ' ),
126126 'author ' => \App \Models \User::find ($ data ['author_id ' ]),
127+ 'linkAttachments ' => collect ($ data ['attachments ' ])->where ('is_link ' , true )->values (),
128+ 'fileAttachments ' => collect ($ data ['attachments ' ])->where ('is_link ' , false )->values (),
127129 ]);
128130 })
129131 )
@@ -155,23 +157,6 @@ public function buildFormFields(FieldsContainer $formFields): void
155157 ->setStorageBasePath ('data/posts/{id} ' )
156158 ->addConditionalDisplay ('!is_link ' ),
157159 )
158- ->addItemField (
159- SharpFormHtmlField::make ('document_infos ' )
160- ->setLiveRefresh (linkedFields: ['document ' ])
161- ->setTemplate (function (array $ data ) {
162- if (! isset ($ data ['document ' ]['file_name ' ])) {
163- return '' ;
164- }
165-
166- return sprintf (
167- 'File uploaded at : %s ' ,
168- Carbon::createFromTimestamp (
169- Storage::disk ($ data ['document ' ]['disk ' ])
170- ->lastModified ($ data ['document ' ]['file_name ' ])
171- )
172- );
173- })
174- ),
175160 )
176161 ->when (sharp ()->context ()->isUpdate (), fn ($ formFields ) => $ formFields ->addField (
177162 SharpFormAutocompleteRemoteField::make ('author_id ' )
@@ -211,9 +196,7 @@ public function buildFormLayout(FormLayout $formLayout): void
211196 ->withField ('publication_label ' )
212197 ->withListField ('attachments ' , function (FormLayoutColumn $ item ) {
213198 $ item ->withFields (title: 8 , is_link: 4 )
214- ->withField ('link_url ' )
215- ->withField ('document ' )
216- ->withField ('document_infos ' );
199+ ->withField ('link_url ' );
217200 });
218201 })
219202 ->addColumn (6 , function (FormLayoutColumn $ column ) {
0 commit comments