Refactor core config system

This commit is contained in:
jitendra 2018-12-07 12:35:34 +05:30
parent 14b619b747
commit 3515adeb03
10 changed files with 62 additions and 216 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js",
"/css/admin.css": "/css/admin.css"
}
"/js/admin.js": "/js/admin.js?id=c70dacdf945a32e04b77",
"/css/admin.css": "/css/admin.css?id=201f91bc553baa11139f"
}

View File

@ -1,37 +0,0 @@
<?php
namespace Webkul\Admin;
use Illuminate\Support\Facades\Config;
/**
* Facade for Configuartion.
*
* @author Rahul Shukla <rahulshukla.symfony517@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class Configuration {
/**
* ShippingMethods
*
* @var array
*/
protected $shippingMethods = [];
/**
* Collects shipping methods
*
* @return array
*/
public function getShippingMethod()
{
foreach(Config::get('carriers') as $shippingMethod) {
$object = new $shippingMethod['class'];
$shippingMethods[] = $object;
}
return $shippingMethods;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Webkul\Admin\Facades;
use Illuminate\Support\Facades\Facade;
class Configuration extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'configuration';
}
}

View File

@ -51,9 +51,7 @@ class ConfigurationController extends Controller
*/
public function index()
{
$shippingMethods = Configuration::getShippingMethod();
return view($this->_config['view'], compact('shippingMethods'));
return view($this->_config['view']);
}
/**
@ -65,70 +63,6 @@ class ConfigurationController extends Controller
{
$data = request()->all();
unset($data['_token']);
if($data['locale'] || $data['channel']){
$locale = $data['locale'];
$channel = $data['channel'];
unset($data['locale']);
unset($data['channel']);
}
foreach($data as $key => $value) {
$reomoveUnderScore = explode ("_", $key);
$key= implode(".",$reomoveUnderScore);
$fieldName = end($reomoveUnderScore);
array_pop($reomoveUnderScore);
$fieldCode = end($reomoveUnderScore);
foreach(Configuration::getShippingMethod() as $fields) {
$code = $fields->getCode();
if($code == $fieldCode) {
$field = $fields->getFieldDetails($fieldName);
}
}
$channel_based = false;
$locale_based = false;
if(isset($field['channel_based']) && $field['channel_based']) {
$channel_based = true;
}
if(isset($field['locale_based']) && $field['locale_based']) {
$locale_based = true;
}
$coreConfigValue = $this->coreConfig->findOneWhere([
'code' => $key,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
if(!$coreConfigValue) {
$this->coreConfig->create([
'code' => $key,
'value' => $value,
'locale_code' => $locale_based ? $locale : null,
'channel_code' => $channel_based ? $channel : null
]);
}else {
$updataData['code'] = $key;
$updataData['value'] = $value;
$updataData['locale_code'] = $locale_based ? $locale : null;
$updataData['channel_code'] = $channel_based ? $channel : null;
$this->coreConfig->update($updataData, $coreConfigValue->id);
}
}
session()->flash('success', 'Shipping Method is created successfully');
return redirect()->route($this->_config['redirect']);

View File

@ -41,16 +41,6 @@ class AdminServiceProvider extends ServiceProvider
);
}
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->registerFacades();
}
/**
* Bind the the data to the views
*
@ -102,19 +92,4 @@ class AdminServiceProvider extends ServiceProvider
$this->app['config']->set($key, array_merge($config, require $path));
}
/**
* Register Bouncer as a singleton.
*
* @return void
*/
protected function registerFacades()
{
$loader = AliasLoader::getInstance();
$loader->alias('configuration', ConfigurationFacade::class);
$this->app->singleton('configuration', function () {
return new Configuration();
});
}
}

View File

@ -1,6 +1,6 @@
<select v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $fieldDetail['name'] }}&quot;" >
<select v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;" >
@foreach($fieldDetail['options'] as $option)
@foreach($field['options'] as $option)
<?php
if($option['value']) {
@ -9,7 +9,7 @@
$value = 0;
}
$selectedOption = $configData['value'] ? $configData['value'] : '';
$selectedOption = core()->getConfigData($name) ?? '';
?>
<option value="{{ $value }}" {{ $value == $selectedOption ? 'selected' : ''}}>

View File

@ -1,4 +1,4 @@
<input type="text" v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($fieldDetail['name']) ?: $configData['value'] }}" data-vv-as="&quot;{{ $fieldDetail['name'] }}&quot;">
<input type="text" v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">

View File

@ -1 +1 @@
<textarea v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $fieldDetail['name'] }}&quot;">{{ old($fieldDetail['name']) ?: $configData['value'] }}</textarea>
<textarea v-validate="'{{$validations}}'" class="control" id="{{ $name }}" name="{{ $name }}" data-vv-as="&quot;{{ $field['name'] }}&quot;">{{ old($name) ?: core()->getConfigData($name) }}</textarea>

View File

@ -54,73 +54,69 @@
<div class="form-container">
@csrf()
@foreach($shippingMethods as $fields)
<?php
$methodFields = $fields->getConfigFields();
$code = $fields->getCode();
?>
<accordian :active="true">
<div slot="body">
@foreach($methodFields as $fieldDetail)
<?php
$validations = [];
$disabled = false;
if(isset($fieldDetail['validation'])) {
array_push($validations, $fieldDetail['validation']);
}else {
$disabled = true;
}
$validations = implode('|', array_filter($validations));
?>
@if(view()->exists($typeView = 'admin::configuration.sales.field-types.' . $fieldDetail['type']))
@foreach (config('core.carriers') as $method => $carrier)
<accordian :title="'{{ __(config('carriers.' . $method . '.title')) }}'" :active="true">
<div slot="body">
@foreach ($carrier as $field)
<?php
$name = 'carrires'.'.'.$code.'.'.$fieldDetail['name'];
$validations = [];
$disabled = false;
if (isset($field['validation'])) {
array_push($validations, $field['validation']);
} else {
$disabled = true;
}
$validations = implode('|', array_filter($validations));
?>
<div class="control-group {{ $fieldDetail['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<label for="{{ $name }}" {{ $disabled == false ? 'class=required' : '' }}>
{{ $fieldDetail['title'] }}
<?php
$channel_locale = [];
if(isset($fieldDetail['channel_based']) && $fieldDetail['channel_based'])
{
array_push($channel_locale, $channel);
}
if(isset($fieldDetail['locale_based']) && $fieldDetail['locale_based']) {
array_push($channel_locale, $locale);
}
?>
@if(count($channel_locale))
<span class="locale">[{{ implode(' - ', $channel_locale) }}]</span>
@endif
</label>
@if (view()->exists($typeView = 'admin::configuration.sales.field-types.' . $field['type']))
<?php
$configData = core()->getConfigData($name, current($channel_locale), next($channel_locale));
$name = 'carriers' . '.' . $method . '.' . $field['name'];
?>
@include ($typeView)
<div class="control-group {{ $field['type'] }}" :class="[errors.has('{{ $name }}') ? 'has-error' : '']">
<label for="{{ $name }}" {{ $disabled == false ? 'class=required' : '' }}>
<span class="control-error" v-if="errors.has('{{ $name }}')">@{{ errors.first('{!! $name !!}') }}</span>
{{ $field['title'] }}
</div>
<?php
$channel_locale = [];
@endif
@endforeach
</div>
</accordian>
if(isset($field['channel_based']) && $field['channel_based'])
{
array_push($channel_locale, $channel);
}
if(isset($field['locale_based']) && $field['locale_based']) {
array_push($channel_locale, $locale);
}
?>
@if(count($channel_locale))
<span class="locale">[{{ implode(' - ', $channel_locale) }}]</span>
@endif
</label>
<?php
$configData = core()->getConfigData($name, current($channel_locale), next($channel_locale));
?>
@include ($typeView)
<span class="control-error" v-if="errors.has('{{ $name }}')">@{{ errors.first('{!! $name !!}') }}</span>
</div>
@endif
@endforeach
</div>
</accordian>
@endforeach