diff --git a/composer.json b/composer.json index fb0940d..43c5e4c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fantismic/dynamic-settings", - "version": "1.0.0", + "version": "1.0.1", "description": "This package creates custom dynamic settings controlled by the user.", "license": "MIT", "keywords": [ diff --git a/src/DynSettings.php b/src/DynSettings.php index c1f36a1..675b620 100644 --- a/src/DynSettings.php +++ b/src/DynSettings.php @@ -28,6 +28,16 @@ public function get($key) { return DynamicSetting::get($key); } + public function isKey($key) { + if (is_null($key) || empty($key)) return false; + + if ($this->getModel($key)) { + return true; + } else { + return false; + } + } + public function getModel($key=null) { return DynamicSetting::getModelByKey($key); } diff --git a/src/Livewire/DynamicSettingsComponent.php b/src/Livewire/DynamicSettingsComponent.php index 9a96477..be020c7 100644 --- a/src/Livewire/DynamicSettingsComponent.php +++ b/src/Livewire/DynamicSettingsComponent.php @@ -8,13 +8,17 @@ use Livewire\Attributes\Layout; use Livewire\Attributes\Validate; use Fantismic\DynSettings\Facades\DynSettings; +use WireUi\Traits\WireUiActions; class DynamicSettingsComponent extends Component { + use WireUiActions; + public $wire_ui = false; public $layout_mode; public $layout_path; + public $alert_array_format; public $settingsArr = []; public $settingsAll = []; @@ -49,6 +53,7 @@ public function mount() { $this->layout_mode = config('dynsettings.layout_mode', 'component'); $this->layout_path = config('dynsettings.layout_path', 'layouts.app'); + $this->alert_array_format = config('dynsettings.alert_array_format', true); switch (strtolower(config('dynsettings.component_blade'))) { case 'wireui': @@ -70,6 +75,17 @@ public function mount() { } + public function boot() + { + $this->withValidator(function ($validator) { + $validator->after(function ($validator) { + if (DynSettings::isKey($this->key)) { + $validator->errors()->add('key', __('A key already exists with this value')); + } + }); + }); + } + public function resetFields() { $this->allTypes = []; $this->allGroups = []; @@ -135,7 +151,12 @@ public function showAddModalBtn() { public function addSetting() { $this->validate(); - if (DynSettings::add($this->key,'empty',$this->type,$this->name,$this->group,$this->assoc,$this->description)) { + $value = 'n/v'; + if ($this->type == 'bool') { + $value = false; + } + + if (DynSettings::add($this->key,$value,$this->type,$this->name,$this->group,$this->assoc,$this->description)) { $this->message = 'Setting '.$this->name. ' has been created!'; $this->showMessage = true; $this->resetFields(); diff --git a/src/resources/views/livewire/dynamic-settings-wire_ui.blade.php b/src/resources/views/livewire/dynamic-settings-wire_ui.blade.php index 116fd3e..86d163c 100644 --- a/src/resources/views/livewire/dynamic-settings-wire_ui.blade.php +++ b/src/resources/views/livewire/dynamic-settings-wire_ui.blade.php @@ -1,5 +1,5 @@
-
+
{{-- Header --}}
{{-- Header title --}} @@ -39,18 +39,18 @@ {{-- Body --}} @foreach ($groups as $name => $group) {{-- Card body --}} -
+
{{-- Card Content --}} @foreach ($group as $name => $settings) {{-- Assoc card --}} - + {{-- Setting item --}}
@foreach ($settings as $setting) {{-- Setting item 1 --}} -
+
{{-- Setting first column --}}
@switch($setting['type']) @@ -65,11 +65,12 @@ @break @endswitch +
{{$setting['key']}}
{{-- End setting first column --}}
{{-- Setting second column --}}
- @if($setting['type'] == "array") + @if($setting['type'] == "array" && $alert_array_format) Always comma separated values!
@endif {{$setting['description']}} @@ -135,7 +136,7 @@ @@ -150,7 +151,7 @@ @@ -173,5 +174,4 @@ -
-{{--
--}} \ No newline at end of file + \ No newline at end of file diff --git a/src/resources/views/livewire/dynamic-settings.blade.php b/src/resources/views/livewire/dynamic-settings.blade.php index 7c8553d..93b3a9c 100644 --- a/src/resources/views/livewire/dynamic-settings.blade.php +++ b/src/resources/views/livewire/dynamic-settings.blade.php @@ -27,13 +27,13 @@ {{-- Buttons --}}
- - - {{-- End buttons --}} @@ -45,7 +45,7 @@ {{-- Body --}} @foreach ($groups as $name => $group) {{-- Card body --}} -
+
{{-- Card title --}}

{{ucFirst($name)}}

@@ -54,7 +54,7 @@
@foreach ($group as $name => $settings) {{-- Assoc card --}} -
+
{{-- Assoc card title --}}

{{ucFirst($name)}}

@@ -70,14 +70,14 @@ @case('array')
- +
@break @case('string') @case('int')
- +
@break @case('bool') @@ -90,11 +90,12 @@
@break @endswitch +
{{$setting['key']}}
{{-- End setting first column --}}
{{-- Setting second column --}}
- @if($setting['type'] == "array") + @if($setting['type'] == "array" && $alert_array_format) Always comma separated values!
@endif {{$setting['description']}}