Skip to content

Commit

Permalink
Merge pull request #1273 from suraj-webkul/core-config
Browse files Browse the repository at this point in the history
Core system config enhancement.
  • Loading branch information
devansh-webkul authored Jul 19, 2024
2 parents 3b3692c + bb490ae commit 483cc18
Show file tree
Hide file tree
Showing 31 changed files with 1,052 additions and 762 deletions.
1 change: 0 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Kernel extends HttpKernel
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/Webkul/Admin/src/Config/core_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
'sort' => 1,
'fields' => [
[
'name' => 'locale',
'title' => 'admin::app.configuration.locale',
'type' => 'select',
'data_source' => 'Webkul\Core\Core@locales'
'name' => 'locale',
'title' => 'admin::app.configuration.locale',
'type' => 'select',
'validation' => 'required',
'options' => 'Webkul\Core\Core@locales'
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Webkul\Admin\Http\Controllers\Configuration;

use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Webkul\Core\Contracts\Validations\Code;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\ConfigurationForm;
use Webkul\Core\Repositories\CoreConfigRepository as ConfigurationRepository;

class ConfigurationController extends Controller
Expand All @@ -21,14 +23,12 @@ public function __construct(protected ConfigurationRepository $configurationRepo

/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
public function index(): RedirectResponse|View
{
$slugs = $this->getDefaultConfigSlugs();
$slugs = (array) $this->getDefaultConfigSlugs();

if (count($slugs)) {
if (! empty($slugs)) {
return redirect()->route('admin.configuration.index', $slugs);
}

Expand All @@ -37,32 +37,26 @@ public function index()

/**
* Returns slugs
*
* @return array
*/
public function getDefaultConfigSlugs()
public function getDefaultConfigSlugs(): array
{
if (! request()->route('slug')) {
$firstItem = current(app('core_config')->items);

$temp = explode('.', $firstItem['key']);
$slug = system_config()->getItems()->first()->getKey();

return ['slug' => current($temp)];
return ['slug' => $slug];
}

return [];
}

/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
public function store(ConfigurationForm $request): RedirectResponse
{
Event::dispatch('core.configuration.save.before');

$this->configurationRepository->create(request()->all());
$this->configurationRepository->create($request->all());

Event::dispatch('core.configuration.save.after');

Expand Down
43 changes: 43 additions & 0 deletions packages/Webkul/Admin/src/Http/Requests/ConfigurationForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Webkul\Admin\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ConfigurationForm extends FormRequest
{
/**
* Determine if the Configuration is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return collect(request()->input('keys', []))->mapWithKeys(function ($item) {
$data = json_decode($item, true);

return collect($data['fields'])->mapWithKeys(function ($field) use ($data) {
$key = $data['key'].'.'.$field['name'];

// Check delete key exist in the request
if (! $this->has($key.'.delete')) {
$validation = isset($field['validation']) && $field['validation'] ? $field['validation'] : 'nullable';

return [$key => $validation];
}

return [];
})->toArray();
})->toArray();
}
}
2 changes: 2 additions & 0 deletions packages/Webkul/Admin/src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@
Route::get('{slug?}', 'ConfigurationController@index')->name('admin.configuration.index');

Route::post('{slug?}', 'ConfigurationController@store')->name('admin.configuration.index.store');

Route::get('{slug}/{path}', 'ConfigurationController@download')->name('admin.configuration.download');
});
});
});
Expand Down
38 changes: 3 additions & 35 deletions packages/Webkul/Admin/src/Providers/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class AdminServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot(Router $router)
public function boot(Router $router): void
{
include __DIR__ . '/../Http/helpers.php';

Expand All @@ -37,10 +35,6 @@ public function boot(Router $router)

$router->aliasMiddleware('admin_locale', Locale::class);

// $this->publishes([
// __DIR__ . '/../../publishable/assets' => public_path('vendor/webkul/admin/assets'),
// ], 'public');

Relation::morphMap([
'leads' => 'Webkul\Lead\Models\Lead',
'products' => 'Webkul\Product\Models\Product',
Expand All @@ -63,16 +57,12 @@ public function register()
$this->registerFacades();

$this->registerConfig();

$this->registerCoreConfig();
}

/**
* Register Bouncer as a singleton.
*
* @return void
*/
protected function registerFacades()
protected function registerFacades(): void
{
$loader = AliasLoader::getInstance();

Expand All @@ -85,10 +75,8 @@ protected function registerFacades()

/**
* Register package config.
*
* @return void
*/
protected function registerConfig()
protected function registerConfig(): void
{
$this->mergeConfigFrom(dirname(__DIR__) . '/Config/acl.php', 'acl');

Expand All @@ -102,24 +90,4 @@ protected function registerConfig()

$this->mergeConfigFrom(dirname(__DIR__) . '/Config/attribute_entity_types.php', 'attribute_entity_types');
}

/**
* Register core config.
*
* @return void
*/
protected function registerCoreConfig()
{
$this->app->singleton('core_config', function () {
$tree = Tree::create();

foreach (config('core_config') as $item) {
$tree->add($item);
}

$tree->items = core()->sortItems($tree->items);

return $tree;
});
}
}
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ body {
margin-right: 5px;
}

.icon.download-icon {
.icon .download-icon {
position: absolute;
top: 40px;
right: 10px;
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
'timezone' => 'وحدة زمنية',
'date-time-formats' => 'تنسيقات التاريخ والوقت',
'save-message' => 'تم تحديث التهيئة بنجاح!',
'delete' => 'حذف',
"emails" => [
'email' => 'بريد الالكتروني',
'notification_label' => 'إشعارات',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@
'timezone' => 'Timezone',
'date-time-formats' => 'Date And Time Formats',
'save-message' => 'Configuration updated successfully!',
'delete' => 'Delete',
"emails" => [
'email' => 'Email',
'notification_label' => 'Notifications',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
'timezone' => 'Zona Horaria',
'date-time-formats' => 'Formato de Fecha y Hora',
'save-message' => 'Configuración actualizada con éxito!',
'delete' => 'Eliminar',
"emails" => [
'email' => 'Email',
'notification_label' => 'Notificaciones',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
'timezone' => 'منطقه زمانی',
'date-time-formats' => 'فرمت‌های تاریخ و زمان',
'save-message' => 'پیکربندی با موفقیت بروزرسانی شد!',
'delete' => 'حذف',
"emails" => [
'email' => 'ایمیل',
'notification_label' => 'اطلاعیه‌ها',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
'timezone' => 'Saat Dilimi',
'date-time-formats' => 'Tarih ve Saat Formatları',
'save-message' => 'Yapılandırma başarıyla güncellendi!',
'delete' => 'Sil',
"emails" => [
'email' => 'E-posta',
'notification_label' => 'Bildirimler',
Expand Down
Loading

0 comments on commit 483cc18

Please sign in to comment.