Prepare modules

This commit is contained in:
2025-03-22 12:41:56 -06:00
parent 04f5e973d7
commit 3916c62935
74 changed files with 4431 additions and 194 deletions

View File

@ -0,0 +1,217 @@
<?php
namespace Koneko\VuexyWebsiteAdmin\Livewire\LegalNotices;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;
use Koneko\VuexyAdmin\Livewire\Form\AbstractFormOffCanvasComponent;
use Koneko\VuexyContacts\Services\ContactCatalogService;
use Koneko\VuexyStoreManager\Services\StoreCatalogService;
use Koneko\VuexyWarehouse\Models\Warehouse;
/**
* Class LegalNoticeOffCanvasForm
*
* Componente Livewire para gestionar almacenes.
* Extiende la clase AbstractFormOffCanvasComponent e implementa validaciones dinámicas,
* manejo de formularios, eventos y actualizaciones en tiempo real.
*
* @package Koneko\VuexyWarehouse\Livewire\Warehouses
*/
class LegalNoticeOffCanvasForm extends AbstractFormOffCanvasComponent
{
/**
* Propiedades del formulario relacionadas con el almacén.
*/
public $id, $store_id, $work_center_id, $code, $name, $description,
$manager_id, $tel, $tel2, $priority, $status, $confirmDeletion;
/**
* Listas de opciones para selects en el formulario.
*/
public $store_options = [],
$work_center_options = [],
$manager_options = [];
/**
* Eventos de escucha de Livewire.
*
* @var array
*/
protected $listeners = [
'editWarehouse' => 'loadFormModel',
'confirmDeletionWarehouse' => 'loadFormModelForDeletion',
];
/**
* Definición de tipos de datos que se deben castear.
*
* @var array
*/
protected $casts = [
'status' => 'boolean',
];
/**
* Define el modelo Eloquent asociado con el formulario.
*
* @return string
*/
protected function model(): string
{
return Warehouse::class;
}
/**
* Define los campos del formulario.
*
* @return array<string, mixed>
*/
protected function fields(): array
{
return (new Warehouse())->getFillable();
}
/**
* Valores por defecto para el formulario.
*
* @return array
*/
protected function defaults(): array
{
return [
'priority' => 0,
'status' => true,
];
}
/**
* Campo que se debe enfocar cuando se abra el formulario.
*
* @return string
*/
protected function focusOnOpen(): string
{
return 'code';
}
/**
* Define reglas de validación dinámicas basadas en el modo actual.
*
* @param string $mode El modo actual del formulario ('create', 'edit', 'delete').
* @return array
*/
protected function dynamicRules(string $mode): array
{
switch ($mode) {
case 'create':
case 'edit':
return [
'store_id' => ['required', 'integer', 'exists:stores,id'],
'work_center_id' => ['nullable', 'integer', 'exists:store_work_centers,id'],
'code' => ['required', 'string', 'max:16', Rule::unique('warehouses', 'code')->ignore($this->id)],
'name' => ['required', 'string', 'max:96'],
'description' => ['nullable', 'string', 'max:1024'],
'manager_id' => ['nullable', 'integer', 'exists:users,id'],
'tel' => ['nullable', 'regex:/^[0-9+\-\s]+$/', 'max:20'],
'tel2' => ['nullable', 'regex:/^[0-9+\-\s]+$/', 'max:20'],
'priority' => ['nullable', 'numeric', 'between:0,99'],
'status' => ['nullable', 'boolean'],
];
case 'delete':
return [
'confirmDeletion' => 'accepted', // Asegura que el usuario confirme la eliminación
];
default:
return [];
}
}
// ===================== VALIDACIONES =====================
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
protected function attributes(): array
{
return [
'code' => 'código de almacén',
'name' => 'nombre del almacén',
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array<string, string>
*/
protected function messages(): array
{
return [
'store_id.required' => 'El almacén debe estar asociado a un negocio.',
'code.required' => 'El código del almacén es obligatorio.',
'code.unique' => 'Este código ya está en uso por otro almacén.',
'name.required' => 'El nombre del almacén es obligatorio.',
];
}
/**
* Carga el formulario con datos del almacén y actualiza las opciones dinámicas.
*
* @param int $id
*/
public function loadFormModel($id): void
{
parent::loadFormModel($id);
$this->work_center_options = DB::table('store_work_centers')
->where('store_id', $this->store_id)
->pluck('name', 'id')
->toArray();
}
/**
* Carga el formulario para eliminar un almacén, actualizando las opciones necesarias.
*
* @param int $id
*/
public function loadFormModelForDeletion($id): void
{
parent::loadFormModelForDeletion($id);
$this->work_center_options = DB::table('store_work_centers')
->where('store_id', $this->store_id)
->pluck('name', 'id')
->toArray();
}
/**
* Define las opciones de los selectores desplegables.
*
* @return array
*/
protected function options(): array
{
$storeCatalogService = app(StoreCatalogService::class);
$contactCatalogService = app(ContactCatalogService::class);
return [
'store_options' => $storeCatalogService->searchCatalog('stores', '', ['limit' => -1]),
'manager_options' => $contactCatalogService->searchCatalog('users', '', ['limit' => -1]),
];
}
/**
* Ruta de la vista asociada con este formulario.
*
* @return string
*/
protected function viewPath(): string
{
return 'vuexy-website-admin::livewire.legal-notices.offcanvas-form';
}
}

View File

@ -0,0 +1,109 @@
<?php
namespace Koneko\VuexyWebsiteAdmin\Livewire\LegalNotices;
use Livewire\Component;
use Koneko\VuexyAdmin\Rules\NotEmptyHtml;
use Koneko\VuexyAdmin\Services\SettingsService;
use Koneko\VuexyWebsiteAdmin\Services\WebsiteTemplateService;
class LegalNoticesIndex extends Component
{
private $targetNotify = "#website-legal-settings-card .notification-container";
public $legalVars = [];
public $currentSection = null;
protected $listeners = [
'saveLegalNotices' => 'save',
];
public function mount()
{
$this->loadSettings();
// Seleccionar la primera sección por defecto
$this->currentSection = array_key_first($this->legalVars);
}
function loadSettings()
{
$websiteTemplateService = app(WebsiteTemplateService::class);
switch ($this->currentSection) {
case 'legal_terminos_y_condiciones':
$this->legalVars['legal_terminos_y_condiciones'] = $websiteTemplateService->getLegalVars('legal_terminos_y_condiciones');
break;
case 'legal_aviso_de_privacidad':
$this->legalVars['legal_aviso_de_privacidad'] = $websiteTemplateService->getLegalVars('legal_aviso_de_privacidad');
break;
case 'legal_politica_de_devoluciones':
$this->legalVars['legal_politica_de_devoluciones'] = $websiteTemplateService->getLegalVars('legal_politica_de_devoluciones');
break;
case 'legal_politica_de_envios':
$this->legalVars['legal_politica_de_envios'] = $websiteTemplateService->getLegalVars('legal_politica_de_envios');
break;
case 'legal_politica_de_cookies':
$this->legalVars['legal_politica_de_cookies'] = $websiteTemplateService->getLegalVars('legal_politica_de_cookies');
break;
case 'legal_autorizaciones_y_licencias':
$this->legalVars['legal_autorizaciones_y_licencias'] = $websiteTemplateService->getLegalVars('legal_autorizaciones_y_licencias');
break;
case 'legal_informacion_comercial':
$this->legalVars['legal_informacion_comercial'] = $websiteTemplateService->getLegalVars('legal_informacion_comercial');
break;
case 'legal_consentimiento_para_el_login_de_terceros':
$this->legalVars['legal_consentimiento_para_el_login_de_terceros'] = $websiteTemplateService->getLegalVars('legal_consentimiento_para_el_login_de_terceros');
break;
case 'legal_leyendas_de_responsabilidad':
$this->legalVars['legal_leyendas_de_responsabilidad'] = $websiteTemplateService->getLegalVars('legal_leyendas_de_responsabilidad');
break;
default:
$this->legalVars = $websiteTemplateService->getLegalVars();
}
}
public function rules()
{
$rules = [];
if ($this->legalVars[$this->currentSection]['enabled']) {
$rules["legalVars.{$this->currentSection}.content"] = ['required', 'string', new NotEmptyHtml];
}
$rules["legalVars.{$this->currentSection}.enabled"] = 'boolean';
return $rules;
}
public function save()
{
$this->validate($this->rules());
$SettingsService = app(SettingsService::class);
$SettingsService->set($this->currentSection . '_enabled', $this->legalVars[$this->currentSection]['enabled'], null, 'vuexy-website-admin');
$SettingsService->set($this->currentSection . '_content', $this->legalVars[$this->currentSection]['content'], null, 'vuexy-website-admin');
$this->dispatch(
'notification',
target: $this->targetNotify,
type: 'success',
message: 'Se han guardado los cambios en las configuraciones.'
);
}
public function render()
{
return view('vuexy-website-admin::livewire.legal-notices.index');
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace Modules\Admin\App\Livewire\WebsiteSettings;
use Livewire\Component;
use App\Services\WebsiteTemplateService;
use Modules\Admin\App\Rules\NotEmptyHtml;
use Modules\Admin\App\Services\WebsiteSettingsService;
class LegalSettings extends Component
{
private $targetNotify = "#website-legal-settings-card .notification-container";
public $legalVars = [];
public $currentSection = null;
protected $listeners = [
'saveLegal' => 'save',
];
public function mount()
{
$this->loadSettings();
// Seleccionar la primera sección por defecto
$this->currentSection = array_key_first($this->legalVars);
}
function loadSettings()
{
$websiteTemplateService = app(WebsiteTemplateService::class);
switch ($this->currentSection) {
case 'legal_terminos_y_condiciones':
$this->legalVars['legal_terminos_y_condiciones'] = $websiteTemplateService->getLegalVars('legal_terminos_y_condiciones');
break;
case 'legal_aviso_de_privacidad':
$this->legalVars['legal_aviso_de_privacidad'] = $websiteTemplateService->getLegalVars('legal_aviso_de_privacidad');
break;
case 'legal_politica_de_devoluciones':
$this->legalVars['legal_politica_de_devoluciones'] = $websiteTemplateService->getLegalVars('legal_politica_de_devoluciones');
break;
case 'legal_politica_de_envios':
$this->legalVars['legal_politica_de_envios'] = $websiteTemplateService->getLegalVars('legal_politica_de_envios');
break;
case 'legal_politica_de_cookies':
$this->legalVars['legal_politica_de_cookies'] = $websiteTemplateService->getLegalVars('legal_politica_de_cookies');
break;
case 'legal_autorizaciones_y_licencias':
$this->legalVars['legal_autorizaciones_y_licencias'] = $websiteTemplateService->getLegalVars('legal_autorizaciones_y_licencias');
break;
case 'legal_informacion_comercial':
$this->legalVars['legal_informacion_comercial'] = $websiteTemplateService->getLegalVars('legal_informacion_comercial');
break;
case 'legal_consentimiento_para_el_login_de_terceros':
$this->legalVars['legal_consentimiento_para_el_login_de_terceros'] = $websiteTemplateService->getLegalVars('legal_consentimiento_para_el_login_de_terceros');
break;
case 'legal_leyendas_de_responsabilidad':
$this->legalVars['legal_leyendas_de_responsabilidad'] = $websiteTemplateService->getLegalVars('legal_leyendas_de_responsabilidad');
break;
default:
$this->legalVars = $websiteTemplateService->getLegalVars();
}
}
public function rules()
{
$rules = [];
if ($this->legalVars[$this->currentSection]['enabled']) {
$rules["legalVars.{$this->currentSection}.content"] = ['required', 'string', new NotEmptyHtml];
}
$rules["legalVars.{$this->currentSection}.enabled"] = 'boolean';
return $rules;
}
public function save()
{
$this->validate($this->rules());
$websiteSettingsService = app(WebsiteSettingsService::class);
$websiteSettingsService->updateSetting($this->currentSection . '_enabled', $this->legalVars[$this->currentSection]['enabled']);
$websiteSettingsService->updateSetting($this->currentSection . '_content', $this->legalVars[$this->currentSection]['content']);
$this->dispatch(
'notification',
target: $this->targetNotify,
type: 'success',
message: 'Se han guardado los cambios en las configuraciones.'
);
}
public function render()
{
return view('admin::livewire.website-settings.legal-settings');
}
}