Merge pull request #815 from openclassify/vedat

admin panel ads table refactor
This commit is contained in:
Muammer Top 2020-11-24 17:56:55 +03:00 committed by GitHub
commit 546b29deb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 196 additions and 168 deletions

View File

@ -20,6 +20,11 @@ var promiseForCategory = new Promise(function (resolve) {
});
promiseForCategory.then(function (categories_list) {
categories_list = $.grep(Object.values(categories_list), function (e) {
return (e.length > 0) ? e : '';
});
level = 0;
$.each(categories_list, function (index, value) {
level++;

View File

@ -36,7 +36,7 @@ return [
'new_productoption' => 'New Productoption',
'new_productoptions_value' => 'New Product option value',
'new_options_configuration' => 'New Option configuration',
'new_option_configuration' => 'New Option configuration',
'new_option_configuration' => 'New Option configuration',
'create_configurations' => 'Create Configurations',
'replicate' => 'Replicate',
];

View File

@ -390,4 +390,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
{
return $this->product_options_value;
}
public function status()
{
return $this->status;
}
}

View File

@ -83,4 +83,6 @@ interface AdvInterface extends EntryInterface
public function expired();
public function getProductOptionsValues();
public function status();
}

View File

@ -1,16 +1,8 @@
<?php namespace Visiosoft\AdvsModule\Adv\Table;
use Anomaly\Streams\Platform\Model\Users\UsersUsersEntryModel;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
use Anomaly\UsersModule\UsersModule;
use Illuminate\Database\Eloquent\Builder;
use Visiosoft\AdvsModule\Adv\Table\Filter\NameDescFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Filter\UserFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Handler\AdvHandler;
use Visiosoft\AdvsModule\Adv\Table\Views\All;
use Visiosoft\AdvsModule\Adv\Table\Views\unfinished;
use Visiosoft\AdvsModule\Category\CategoryModel;
use Visiosoft\PackagesModule\User\UserModel;
class AdvTableBuilder extends TableBuilder
{
@ -34,24 +26,6 @@ class AdvTableBuilder extends TableBuilder
];
/**
* The table filters.
*
* @var array|string
*/
protected $filters = [
'search' => [
'filter' => 'input',
'placeholder' => 'visiosoft.module.advs::field.search',
'query' => NameDescFilterQuery::class,
],
'country',
'id' => [
'heading' => 'ID',
'filter' => 'input'
],
];
/**
* The table columns.
*

View File

@ -0,0 +1,56 @@
<?php namespace Visiosoft\AdvsModule\Adv\Table;
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
use Anomaly\Streams\Platform\Entry\EntryModel;
class AdvTableButtons
{
public function handle(AdvTableBuilder $builder)
{
$builder->setButtons([
'status' => [
'text' => function (EntryInterface $entry) {
$text_type = ($entry->status() == 'approved') ? 'decline' : 'approve';
return "<font class='hidden-xs-down'>" . trans('visiosoft.module.advs::button.' . $text_type) . "</font>";
},
'icon' => function (EntryInterface $entry) {
return ($entry->status() == 'approved') ? "fa fa-eye-slash" : "fa fa-eye";
},
'href' => function (EntryInterface $entry) {
$action_type = ($entry->status() == 'approved') ? 'declined' : 'approved';
return "/admin/class/actions/{entry.id}/" . $action_type;
},
'type' => function (EntryInterface $entry) {
return ($entry->status() == 'approved') ? "danger" : "success";
},
],
'edit' => [
'href' => function (EntryModel $entry) {
return route('visiosoft.module.advs::edit_adv', ['id' => $entry->getId()]);
},
'text' => "<font class='hidden-xs-down'>" . trans('streams::button.edit') . "</font>"
],
'settings' => [
'text' => false,
'href' => false,
'dropdown' => [
'change_owner' => [
'data-toggle' => 'modal',
'data-target' => '#modal',
'text' => trans('visiosoft.module.advs::button.change_owner'),
'href' => 'admin/advs-users/choose/{entry.id}'
],
'replicate' => [
'text' => 'visiosoft.module.advs::button.replicate'
],
'create_configration' => [
'text' => trans('visiosoft.module.advs::button.create_configurations'),
'href' => route('visiosoft.module.advs::configrations.create') . "?ad={entry.id}"]
]
]
]);
}
}

View File

@ -0,0 +1,58 @@
<?php namespace Visiosoft\AdvsModule\Adv\Table;
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
use Visiosoft\CatsModule\Category\CategoryModel;
class AdvTableColumns
{
public function handle(AdvTableBuilder $builder)
{
$builder->setColumns([
'cover_photo' => [
'value' => function (EntryInterface $entry) {
return "<img width='80px' src='" . $entry->AddAdsDefaultCoverImage($entry)->cover_photo . "' >";
},
],
'name' => [
'sort_column' => 'slug',
'wrapper' => '
<strong><span class="text-muted">#{value.id}</span>{value.name}</strong>
<br>
<small class="text-muted">{value.finish_at}</small>
<br>
<span>{value.category}</span>',
'value' => [
'id' => 'entry.id',
'finish_at' => 'entry.finish_at',
'name' => function (EntryInterface $entry) {
if ($entry->getTitle()) {
$value = "<a href='" . $entry->getAdvDetailLinkByModel($entry, 'list') . "' > {entry.name}</a > ";
} else {
$value = "<font color='red'>" . trans("visiosoft.module.advs::view.unfinished") . "</font>";
}
return $value;
},
'category' => function (EntryInterface $entry, CategoryModel $categoryModel) {
$category = $categoryModel->getCat($entry->cat1);
if (!is_null($category))
return $category->name;
}
],
],
'price' => [
'wrapper' => '{{currency_format("{entry.price}","{entry.currency}")}}',
'class' => 'advs-price',
],
'country' => [
'class' => 'advs-country',
],
'created_by' => [
'value' => 'entry.created_by.name',
],
]);
}
}

View File

@ -0,0 +1,64 @@
<?php namespace Visiosoft\AdvsModule\Adv\Table;
use Visiosoft\AdvsModule\Adv\Table\Filter\CategoryFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Filter\CityFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Filter\NameDescFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Filter\StatusFilterQuery;
use Visiosoft\AdvsModule\Adv\Table\Filter\UserFilterQuery;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
class AdvTableFilters
{
public function handle(AdvTableBuilder $builder, CategoryRepositoryInterface $categoryRepository, CityRepositoryInterface $cityRepository)
{
$cities = $cityRepository->all()->pluck('name', 'id')->all();
$categories = $categoryRepository->all()->mainCategories()->pluck('name', 'id')->all();
$builder->setFilters(
[
'search' => [
'filter' => 'input',
'placeholder' => 'visiosoft.module.advs::field.search',
'query' => NameDescFilterQuery::class,
],
'country',
'id' => [
'heading' => 'ID',
'filter' => 'input'
],
'City' => [
'exact' => true,
'filter' => 'select',
'query' => CityFilterQuery::class,
'options' => $cities,
],
'Category' => [
'exact' => true,
'filter' => 'select',
'query' => CategoryFilterQuery::class,
'options' => $categories,
],
'User' => [
'exact' => true,
'filter' => 'select',
'query' => UserFilterQuery::class,
],
'status' => [
'filter' => 'select',
'query' => StatusFilterQuery::class,
'options' => [
'approved' => 'visiosoft.module.advs::field.status.option.approved',
'expired' => 'visiosoft.module.advs::field.status.option.expired',
'unpublished' => 'visiosoft.module.advs::field.status.option.unpublished',
'pending_admin' => 'visiosoft.module.advs::field.status.option.pending_admin',
'pending_user' => 'visiosoft.module.advs::field.status.option.pending_user',
],
]
]
);
}
}

View File

@ -52,67 +52,11 @@ class AdvsController extends AdminController
* @param AdvTableBuilder $table
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index(AdvTableBuilder $table, \Anomaly\UsersModule\User\UserModel $userModel, CityModel $cityModel, CatsCategoryEntryModel $categoryModel)
public function index(AdvTableBuilder $table)
{
$table->addAsset("styles.css", "visiosoft.module.advs::css/custom.css");
$table->addAsset('scripts.js', 'visiosoft.module.advs::js/list.js');
$table->addButtons([
'status' => [
'text' => function (EntryInterface $entry) {
if ($entry->status == 'approved') {
return "<font class='hidden-xs-down'>" . trans('visiosoft.module.advs::button.decline') . "</font>";
} else {
return "<font class='hidden-xs-down'>" . trans('visiosoft.module.advs::button.approve') . "</font>";
}
},
'icon' => function (EntryInterface $entry) {
if ($entry->status == 'approved') {
return "fa fa-eye-slash";
} else {
return "fa fa-eye";
}
},
'href' => function (EntryInterface $entry) {
if ($entry->status == 'approved') {
return "/admin/class/actions/{entry.id}/declined";
} else {
return "/admin/class/actions/{entry.id}/approved";
}
},
'type' => function (EntryInterface $entry) {
if ($entry->status == 'approved') {
return "danger";
} else {
return "success";
}
},
],
'edit' => [
'href' => '/advs/edit_advs/{entry.id}',
'text' => "<font class='hidden-xs-down'>" . trans('streams::button.edit') . "</font>",
],
'settings' => [
'text' => false,
'href' => false,
'dropdown' => [
'change_owner' => [
'data-toggle' => 'modal',
'data-target' => '#modal',
'text' => trans('visiosoft.module.advs::button.change_owner'),
'href' => 'admin/advs-users/choose/{entry.id}',
],
'replicate' => [
'text' => 'Replicate',
],
'create_configration' => [
'text' => trans('visiosoft.module.advs::button.create_configurations'),
'href' => route('visiosoft.module.advs::configrations.create')."?ad={entry.id}"
],
],
],
]);
if ($this->model->is_enabled('recommendedads')) {
$table->addButton('add_recommended', [
'type' => 'default',
@ -122,87 +66,6 @@ class AdvsController extends AdminController
]);
}
$table->setColumns([
'cover_photo' => [
'value' => function (EntryInterface $entry) {
return "<img width='80px' src='" . $this->model->AddAdsDefaultCoverImage($entry)->cover_photo . "' >";
},
],
'entry.id',
'name' => [
'class' => 'advs-name',
'sort_column' => 'slug',
'value' => function (EntryInterface $entry) {
return (!is_null($entry->name)) ? "<a href='" . $this->model->getAdvDetailLinkByModel($entry, 'list') . "' > " . $entry->name . "</a > " : "<font color='red'>" . trans("visiosoft.module.advs::view.unfinished") . "</font>";
},
],
'price' => [
'class' => 'advs-price',
],
'currency' => [
'class' => 'advs-currency',
],
'country' => [
'class' => 'advs-country',
],
'created_by' => [
'value' => function (EntryInterface $entry, UserModel $userModel) {
$user = $userModel->find($entry->created_by_id);
if (!is_null($user))
return $user->first_name . " " . $user->last_name;
}
],
'category' => [
'sort_column' => 'cat1',
'value' => function (EntryInterface $entry, CategoryModel $categoryModel) {
$category = $categoryModel->getCat($entry->cat1);
if (!is_null($category))
return $category->name;
}
],
'finish_at',
]);
$cities = $cityModel->all()->pluck('name', 'id')->all();
$categories = $categoryModel::query()->where('parent_category_id', null)
->leftJoin('cats_category_translations', 'cats_category.id', '=', 'cats_category_translations.entry_id')
->where('locale', config('app.locale'))
->select('cats_category.*', 'cats_category_translations.name')
->pluck('t1.name', 'id')->all();
$table->setFilters(array_merge($table->getFilters(),
[
'City' => [
'exact' => true,
'filter' => 'select',
'query' => CityFilterQuery::class,
'options' => $cities,
],
'Category' => [
'exact' => true,
'filter' => 'select',
'query' => CategoryFilterQuery::class,
'options' => $categories,
],
'User' => [
'exact' => true,
'filter' => 'select',
'query' => UserFilterQuery::class,
],
'status' => [
'filter' => 'select',
'query' => StatusFilterQuery::class,
'options' => [
'approved' => 'visiosoft.module.advs::field.status.option.approved',
'expired' => 'visiosoft.module.advs::field.status.option.expired',
'unpublished' => 'visiosoft.module.advs::field.status.option.unpublished',
'pending_admin' => 'visiosoft.module.advs::field.status.option.pending_admin',
'pending_user' => 'visiosoft.module.advs::field.status.option.pending_user',
],
]
])
);
return $table->render();
}
@ -342,7 +205,8 @@ class AdvsController extends AdminController
}
public function exportAdvs(){
return Excel::download(new AdvsExport(), 'advs-' . time() . '.xlsx');
}
public function exportAdvs()
{
return Excel::download(new AdvsExport(), 'advs-' . time() . '.xlsx');
}
}