#4316 module on/off options

This commit is contained in:
diashalabi 2021-07-12 16:56:40 +03:00
parent 256f52c5ac
commit 0c1fb51db0
5 changed files with 70 additions and 3 deletions

View File

@ -16,6 +16,7 @@ return [
'free_currencyconverterapi_key',
'hide_price_categories',
'tcmb_exchange_url',
'enabled_modules',
'enabled_currencies',
'disable_sentry',
'hide_ad_cat',

View File

@ -194,6 +194,22 @@ return [
},
],
],
'enabled_modules' => [
'type' => 'anomaly.field_type.checkboxes',
'config' => [
'mode' => 'tags',
'default_value' => function () {
$addons = app('module.collection')->enabled()->pluck('namespace')->all();
return $addons;
},
'options' => function () {
$addons = app('module.collection')->pluck('namespace', 'namespace');
return $addons;
},
],
],
'market_place' => [
'type' => 'anomaly.field_type.boolean',
'config' => [

View File

@ -125,6 +125,10 @@ return [
'enabled_currencies' => [
'name' => 'Enabled Currencies',
],
'enabled_modules' => [
'name' => 'Enabled Modules',
'warning' => 'Change at your own risk.',
],
'google_statistic_code' => [
'name' => 'Google Statistic Code',
],
@ -133,8 +137,8 @@ return [
],
'market_place' => [
'name' => 'Market Place',
'instructions' => 'If the marketplace is down, your site will act as ecommerce. For example,
some fields in the profile such as ads, dopings, messages, sale, packages and store are not visible and
'instructions' => 'If the marketplace is down, your site will act as ecommerce. For example,
some fields in the profile such as ads, dopings, messages, sale, packages and store are not visible and
removes corporate membership.'
],
'price_area_hidden' => [

View File

@ -2,11 +2,13 @@
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Navigation\Event\SortNavigation;
use Anomaly\Streams\Platform\Ui\Form\Event\FormWasSaved;
use Anomaly\Streams\Platform\Ui\Table\Event\TableIsQuerying;
use Illuminate\Pagination\AbstractPaginator;
use Visiosoft\DefaultadminTheme\Listener\AddGsmFilter;
use Visiosoft\DefaultadminTheme\Listener\AddViewAdsButton;
use Visiosoft\DefaultadminTheme\Listener\ApplySorting;
use Visiosoft\DefaultadminTheme\Listener\CheckEnabledModules;
/**
* Class DefaultadminThemeServiceProvider
@ -23,7 +25,10 @@ class DefaultadminThemeServiceProvider extends AddonServiceProvider
],
TableIsQuerying::class => [
AddGsmFilter::class,
AddViewAdsButton::class
AddViewAdsButton::class,
],
FormWasSaved::class => [
CheckEnabledModules::class,
],
];

View File

@ -0,0 +1,41 @@
<?php namespace Visiosoft\DefaultadminTheme\Listener;
use Anomaly\SettingsModule\Setting\Form\SettingFormBuilder;
use Anomaly\Streams\Platform\Addon\Module\Command\InstallModule;
use Anomaly\Streams\Platform\Addon\Module\Command\UninstallModule;
use Anomaly\Streams\Platform\Addon\Module\Contract\ModuleRepositoryInterface;
use Anomaly\Streams\Platform\Ui\Form\Event\FormWasSaved;
use Illuminate\Foundation\Bus\DispatchesJobs;
class CheckEnabledModules
{
use DispatchesJobs;
private $moduleRepository;
public function __construct(ModuleRepositoryInterface $moduleRepository)
{
$this->moduleRepository = $moduleRepository;
}
public function handle(FormWasSaved $event)
{
$builder = $event->getBuilder();
if (get_class($builder) == SettingFormBuilder::class) {
$value = $builder->getFormFields()->where('field', 'enabled_modules')->first()->getValue();
$disabledModules = app('module.collection')->whereNotIn('namespace', $value);
$enabledModules = app('module.collection')->whereIn('namespace', $value);
foreach ($disabledModules as $module) {
if ($module->isInstalled()) {
$this->dispatchNow(new UninstallModule($module, true));
}
}
foreach ($enabledModules as $module) {
if (!$module->isInstalled()) {
$this->dispatchNow(new InstallModule($module, true));
}
}
}
}
}