Skip to content

Commit

Permalink
Merge pull request #91 from balajidharma/2.x-Changes
Browse files Browse the repository at this point in the history
Added comment and forum thread
  • Loading branch information
balajidharma authored Nov 23, 2024
2 parents b810cb9 + 7a7e44f commit ec4510b
Show file tree
Hide file tree
Showing 20 changed files with 638 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode

**/caddy
frankenphp
frankenphp-worker.php
10 changes: 9 additions & 1 deletion app/Grid/Admin/CategoryItemGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public function columns()
[
'attribute' => 'description',
'label' => __('Description'),
'list' => false,
],
[
'attribute' => 'enabled',
'label' => __('Enabled'),
'type' => 'checkbox',
'value' => function ($model) {
return $model->enabled ? 'Yes' : 'No';
},
'form_options' => function ($model) {
return [
'value' => 1,
Expand All @@ -70,6 +74,7 @@ public function columns()
],
];
},
'list' => false,
],
[
'attribute' => 'weight',
Expand All @@ -80,15 +85,18 @@ public function columns()
'wrapper' => ['class' => 'form-control py-2 w-40'],
];
},
'list' => false,
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
'list' => false,
],
[
'attribute' => 'updated_at',
'sortable' => true,
'list' => false,
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Grid/Admin/CategoryTypeGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function columns()
];
},
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
148 changes: 148 additions & 0 deletions app/Grid/Admin/CommentGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

namespace App\Grid\Admin;

use BalajiDharma\LaravelComment\Models\Comment;
use BalajiDharma\LaravelCrud\CrudBuilder;
use Config;

class CommentGrid extends CrudBuilder
{
public $title = 'Comments';

public $description = 'Manage Comments';

public $model = Comment::class;

public $route = 'admin.comment';

public function columns()
{
return [
[
'attribute' => 'id',
'label' => __('ID'),
'sortable' => true,
'searchable' => true,
'list' => [
'class' => 'BalajiDharma\LaravelCrud\Column\LinkColumn',
'route' => 'admin.comment.show',
'route_params' => ['comment' => 'id'],
'attr' => ['class' => 'link link-primary'],
],
],
[
'attribute' => 'content',
'label' => __('Content'),
'searchable' => true,
'list' => [
'class' => 'BalajiDharma\LaravelCrud\Column\LinkColumn',
'route' => 'admin.comment.show',
'route_params' => ['comment' => 'id'],
'attr' => ['class' => 'link link-primary'],
],
'form_options' => function ($model) {
return [
'field_type' => 'textarea',
'attr' => [
'rows' => 5
]
];
},
],
[
'attribute' => 'commenter_type',
'label' => __('Commenter Type'),
'type' => 'select',
'list' => true,
'show' => true,
'form_options' => function ($model) {
$commenter_type = [
'App\Models\User' => __('User'),
];

return [
'choices' => $commenter_type,
'empty_value' => __('Select an option'),
'default_value' => $model ? $model->commenter_type : null,
];
},
],
[
'attribute' => 'commenter_id',
'label' => __('Commenter ID'),
'list' => false,
'show' => false,
],
[
'attribute' => 'commenter',
'label' => __('Commenter'),
'value' => function ($model) {
return $model->commenter ? $model->commenter->name : null;
},
'create' => false,
'edit' => false,
'sortable' => true,
],
[
'attribute' => 'commentable_type',
'label' => __('Commentable Type'),
'type' => 'select',
'list' => false,
'form_options' => function ($model) {
$commentable_type = [
'Balajidharma\LaravelForum\Models\Thread' => __('Thread'),
];

return [
'choices' => $commentable_type,
'empty_value' => __('Select an option'),
'default_value' => $model ? $model->commentable_type : null,
];
},
],
[
'attribute' => 'commentable_id',
'label' => __('Commentable ID'),
'list' => false,
],
[
'attribute' => 'parent_id',
'label' => __('Parent ID'),
'list' => false,
'form_options' => function ($model) {
return [
'field_type' => 'text',
];
},
],
[
'attribute' => 'status',
'label' => __('Status'),
'type' => 'select',
'value' => function ($model) {
return __(array_flip(config('comment.status'))[$model->status]);
},
'form_options' => function ($model) {
$status = [];
foreach (config('comment.status') as $key => $value) {
$status[$value] = __($key);
};

return [
'choices' => $status,
'default_value' => $model ? $model->status : null,
];
},
],
[
'attribute' => 'created_at',
'sortable' => true,
],
[
'attribute' => 'updated_at',
'sortable' => true,
],
];
}
}
43 changes: 43 additions & 0 deletions app/Grid/Admin/GridHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Grid\Admin;

use BalajiDharma\LaravelCategory\Models\CategoryType;

class GridHelper
{
public static function getTagsField($attribute, $tagName)
{
return [
'attribute' => $attribute,
'label' => __('Tags'),
'list' => false,
'fillable' => true,
'value' => function ($model) use ($tagName) {
return collect($model->getCategoriesByType($tagName)->get())->pluck('name')->implode(', ');
},
'form_options' => function ($model) use ($attribute, $tagName) {
if (old($attribute)) {
if (json_decode(old($attribute))) {
$value = collect(json_decode(old($attribute)))->pluck('value')->implode(',');
} else {
$value = old($attribute);
}
} else {
$value = $model ? collect($model->getCategoriesByType($tagName)->get())->pluck('name')->implode(', ') : '';
}

return [
'field_type' => 'text',
'value' => $value,
'attr' => [
'data-tagify' => 1,
'placeholder' => 'Enter tag',
'data-tagify-maxTags' => 5,
'data-tagify-url' => route('admin.category.type.item.index', CategoryType::where('machine_name', $tagName)->first()->id),
],
];
},
];
}
}
2 changes: 1 addition & 1 deletion app/Grid/Admin/MediaGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function columns()
return '<div class="avatar"><div class="w-32 rounded">'.$file.'</div><div>';
},
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
2 changes: 1 addition & 1 deletion app/Grid/Admin/MenuGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function columns()
];
},
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
2 changes: 1 addition & 1 deletion app/Grid/Admin/MenuItemGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function columns()
];
},
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
2 changes: 1 addition & 1 deletion app/Grid/Admin/PermissionGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function columns()
'attr' => ['class' => 'link link-primary'],
],
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
2 changes: 1 addition & 1 deletion app/Grid/Admin/RoleGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function columns()
];
},
],
include 'includes/tags.php',
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
[
'attribute' => 'created_at',
'sortable' => true,
Expand Down
Loading

0 comments on commit ec4510b

Please sign in to comment.