Skip to content

Commit deb5f6f

Browse files
Fixed: cms component issue
1 parent 5f7e85b commit deb5f6f

File tree

9 files changed

+74
-9
lines changed

9 files changed

+74
-9
lines changed

Http/Controllers/Backend/ContentTypesController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use VaahCms\Modules\Cms\Models\Content;
66
use VaahCms\Modules\Cms\Models\FieldType;
77
use VaahCms\Modules\Cms\Models\ContentType;
8+
use WebReinvent\VaahCms\Models\TaxonomyType;
89

910

1011
class ContentTypesController extends Controller
@@ -50,6 +51,12 @@ public function getAssets(Request $request)
5051
$data['field_types'] = FieldType::select('id', 'name', 'slug', 'meta')
5152
->get();
5253

54+
$data['content_relations'] = vh_content_relations();
55+
56+
$data['taxonomy_types'] = TaxonomyType::whereNotNull('is_active')
57+
->whereNull('parent_id')->with(['children'])
58+
->select('id', 'name', 'slug')->get();
59+
5360
$data['non_repeatable_fields'] = Content::getNonRepeatableFields();
5461

5562
$data['actions'] = [];

Http/Controllers/Backend/ContentsController.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,40 @@ public function itemAction(Request $request,$id,$action)
254254
}
255255
}
256256
//----------------------------------------------------------
257+
public function getRelationsInTree(Request $request)
258+
{
259+
$input = $request->all();
260+
261+
$list = [];
262+
263+
$relation = vh_content_relations_by_name($input['type']);
264+
265+
if(!isset($relation['display_column']) || !$relation['display_column']){
266+
$relation['display_column'] = 'name';
267+
}
268+
269+
$url = null;
270+
271+
if($relation && isset($relation['namespace'])){
272+
273+
$relation['filter_id'] = $input['filter_id'];
274+
275+
$list = Content::getListByVariables($relation);
276+
277+
if(isset($relation['add_url']) && $relation['add_url']){
278+
$url = $relation['add_url'];
279+
}
280+
}
281+
282+
283+
$response['success'] = true;
284+
$response['data']['list'] = $list;
285+
$response['data']['display_column'] = $relation['display_column'];
286+
$response['data']['add_url'] = $url;
287+
288+
return $response;
289+
}
290+
//----------------------------------------------------------
257291

258292

259293
}

Libraries/CmsSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ public static function createSampleField($theme_slug, $file_path, $content_type_
267267

268268
$content_type = ContentType::where('slug', $content_type_slug)
269269
->with(['groups.fields.type'])
270-
->first()->toArray();
270+
->first();
271271

272272
if(!$content_type)
273273
{
274274
return false;
275275
}
276276

277+
$content_type = $content_type->toArray();
277278

278279
foreach($list as $item)
279280
{

Models/ContentBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ public static function storeFormGroups(Content $content, $groups, $type = null)
891891
if(!$field['content']){
892892
$row_to_delete_ids = array_diff($relatable_ids, []);
893893
}else{
894-
$row_to_delete_ids = array_diff($relatable_ids, $field['content']);
894+
$row_to_delete_ids = array_diff($relatable_ids, [$field['content']]);
895895
}
896896

897897
if(count($row_to_delete_ids) > 0)
@@ -1330,7 +1330,7 @@ public static function getListByVariables($var)
13301330
$list->where($var['filter_by'],$var['filter_id']);
13311331
}
13321332

1333-
$list = $list->get();
1333+
$list = $list->select('id','id as key', $var['display_column'].' as label')->get();
13341334

13351335
return $list;
13361336

Models/FormGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static function syncWithFormFields(FormGroup $group, $fields_array)
224224

225225
if($stored_field){
226226

227-
if($stored_field->meta && isset($stored_field->meta->type)
227+
if(isset($field['id']) && $stored_field->meta && isset($stored_field->meta->type)
228228
&& $field['meta']['type'] != $stored_field->meta->type){
229229
$content_form_fields = ContentFormField::with(['contentFormRelations'])
230230
->where('vh_cms_form_field_id', $field['id'])->get();

Routes/backend/routes-contents.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function () {
3636
/**
3737
* Update List
3838
*/
39+
40+
Route::post('/getRelationsInTree', 'ContentsController@getRelationsInTree')
41+
->name('backend.cms.contents.getRelationsInTree');
42+
//---------------------------------------------------------
3943
Route::match(['put', 'patch'], '/', 'ContentsController@updateList')
4044
->name('vh.backend.cms.contents.list.update');
4145
/**

Vue/pages/contenttypes/ContentStructure.vue

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ const onSelectType = (field,data,group_index,field_index) => {
180180
</td>
181181
</tr>
182182

183-
<template v-if="element.meta">
184-
<tr v-for="(meta_item, meta_index) in element.meta"
185-
v-if="(meta_index !== 'container_opening_tag'
183+
<template v-if="element.meta" v-for="(meta_item, meta_index) in element.meta">
184+
<tr
185+
v-if="meta_index !== 'filter' && ((meta_index !== 'container_opening_tag'
186186
&& meta_index !== 'container_closing_tag')
187187
|| (store && store.assets && store.assets.non_repeatable_fields
188188
&& store.assets.non_repeatable_fields.includes(element.type.slug))
189-
|| element.is_repeatable"
189+
|| element.is_repeatable)"
190190
>
191191
<td v-if="meta_index !== 'filter_id'
192192
&& meta_index !== 'display_column'
@@ -228,9 +228,24 @@ const onSelectType = (field,data,group_index,field_index) => {
228228
<Dropdown v-model="element.meta[meta_index]"
229229
:options="store.assets.content_relations"
230230
optionLabel="name"
231+
optionValue="name"
231232
placeholder="Select"
232233
class="w-full md:w-14rem mt-3"
233234
/>
235+
236+
<TreeSelect v-if="element.meta[meta_index]
237+
&& useVaah.findInArrayByKey(
238+
store.assets.content_relations,'name', element.meta[meta_index])
239+
&& useVaah.findInArrayByKey(
240+
store.assets.content_relations,'name', element.meta[meta_index])['options']"
241+
class="w-full"
242+
v-model="element.meta['filter']"
243+
:metaKeySelection="false"
244+
@node-select="store.selectType($event,element)"
245+
:options="useVaah.findInArrayByKey(
246+
store.assets.content_relations,'name', element.meta[meta_index])['options']"
247+
placeholder="Select..."
248+
/>
234249
</template>
235250

236251
<template v-else>

Vue/stores/store-contenttypes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,10 @@ export const useContentTypeStore = defineStore({
993993
return item;
994994
},
995995
//---------------------------------------------------------------------
996+
async selectType(event,item) {
997+
item.meta['filter_id'] = event.id;
998+
},
999+
//---------------------------------------------------------------------
9961000
}
9971001
});
9981002

0 commit comments

Comments
 (0)