#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', 'free_currencyconverterapi_key',
'hide_price_categories', 'hide_price_categories',
'tcmb_exchange_url', 'tcmb_exchange_url',
'enabled_modules',
'enabled_currencies', 'enabled_currencies',
'disable_sentry', 'disable_sentry',
'hide_ad_cat', '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' => [ 'market_place' => [
'type' => 'anomaly.field_type.boolean', 'type' => 'anomaly.field_type.boolean',
'config' => [ 'config' => [

View File

@ -125,6 +125,10 @@ return [
'enabled_currencies' => [ 'enabled_currencies' => [
'name' => 'Enabled Currencies', 'name' => 'Enabled Currencies',
], ],
'enabled_modules' => [
'name' => 'Enabled Modules',
'warning' => 'Change at your own risk.',
],
'google_statistic_code' => [ 'google_statistic_code' => [
'name' => 'Google Statistic Code', 'name' => 'Google Statistic Code',
], ],

View File

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