Laravel 11, Vuexy Admin 10.3, by admin@koneko.mx
This commit is contained in:
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\AdminSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Modules\Admin\App\Services\AdminSettingsService;
|
||||
use Modules\Admin\App\Services\AdminTemplateService;
|
||||
|
||||
class ApplicationSettings extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
private $targetNotify = "#application-settings-card .notification-container";
|
||||
|
||||
public $admin_app_name,
|
||||
$admin_image_logo,
|
||||
$admin_image_logo_dark;
|
||||
|
||||
public $upload_image_logo,
|
||||
$upload_image_logo_dark;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings($clearcache = false)
|
||||
{
|
||||
$this->upload_image_logo = null;
|
||||
$this->upload_image_logo_dark = null;
|
||||
|
||||
$adminTemplateService = app(AdminTemplateService::class);
|
||||
|
||||
if ($clearcache) {
|
||||
$adminTemplateService->clearAdminVarsCache();
|
||||
}
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $adminTemplateService->getAdminVars();
|
||||
|
||||
$this->admin_app_name = $settings['app_name'];
|
||||
$this->admin_image_logo = $settings['image_logo']['large'];
|
||||
$this->admin_image_logo_dark = $settings['image_logo']['large_dark'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'admin_app_name' => 'required|string|max:255',
|
||||
'upload_image_logo' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
'upload_image_logo_dark' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
]);
|
||||
|
||||
$adminSettingsService = app(AdminSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$adminSettingsService->updateSetting('admin_app_name', $this->admin_app_name);
|
||||
|
||||
// Procesar favicon si se ha cargado una imagen
|
||||
if ($this->upload_image_logo) {
|
||||
$adminSettingsService->processAndSaveImageLogo($this->upload_image_logo);
|
||||
}
|
||||
|
||||
if ($this->upload_image_logo_dark) {
|
||||
$adminSettingsService->processAndSaveImageLogo($this->upload_image_logo_dark, 'dark');
|
||||
}
|
||||
|
||||
$this->loadSettings(true);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.'
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.admin-settings.application-settings');
|
||||
}
|
||||
}
|
84
modules/Admin/App/Livewire/AdminSettings/GeneralSettings.php
Normal file
84
modules/Admin/App/Livewire/AdminSettings/GeneralSettings.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\AdminSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Modules\Admin\App\Services\AdminSettingsService;
|
||||
use Modules\Admin\App\Services\AdminTemplateService;
|
||||
|
||||
class GeneralSettings extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
private $targetNotify = "#general-settings-card .notification-container";
|
||||
|
||||
public $admin_title;
|
||||
public $admin_favicon_16x16,
|
||||
$admin_favicon_76x76,
|
||||
$admin_favicon_120x120,
|
||||
$admin_favicon_152x152,
|
||||
$admin_favicon_180x180,
|
||||
$admin_favicon_192x192;
|
||||
|
||||
public $upload_image_favicon;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings($clearcache = false)
|
||||
{
|
||||
$this->upload_image_favicon = null;
|
||||
|
||||
$adminTemplateService = app(AdminTemplateService::class);
|
||||
|
||||
if ($clearcache) {
|
||||
$adminTemplateService->clearAdminVarsCache();
|
||||
}
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $adminTemplateService->getAdminVars();
|
||||
|
||||
$this->admin_title = $settings['title'];
|
||||
$this->admin_favicon_16x16 = $settings['favicon']['16x16'];
|
||||
$this->admin_favicon_76x76 = $settings['favicon']['76x76'];
|
||||
$this->admin_favicon_120x120 = $settings['favicon']['120x120'];
|
||||
$this->admin_favicon_152x152 = $settings['favicon']['152x152'];
|
||||
$this->admin_favicon_180x180 = $settings['favicon']['180x180'];
|
||||
$this->admin_favicon_192x192 = $settings['favicon']['192x192'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'admin_title' => 'required|string|max:255',
|
||||
'upload_image_favicon' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
]);
|
||||
|
||||
$adminSettingsService = app(AdminSettingsService::class);
|
||||
|
||||
// Guardar título del sitio en configuraciones
|
||||
$adminSettingsService->updateSetting('admin_title', $this->admin_title);
|
||||
|
||||
// Procesar favicon si se ha cargado una imagen
|
||||
if ($this->upload_image_favicon) {
|
||||
$adminSettingsService->processAndSaveFavicon($this->upload_image_favicon);
|
||||
}
|
||||
|
||||
$this->loadSettings(true);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.'
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.admin-settings.general-settings');
|
||||
}
|
||||
}
|
118
modules/Admin/App/Livewire/AdminSettings/InterfaceSettings.php
Normal file
118
modules/Admin/App/Livewire/AdminSettings/InterfaceSettings.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\AdminSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\AdminTemplateService;
|
||||
use Modules\Admin\App\Services\GlobalSettingsService;
|
||||
|
||||
class InterfaceSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#interface-settings-card .notification-container";
|
||||
|
||||
public $vuexy_myLayout,
|
||||
$vuexy_myTheme,
|
||||
$vuexy_myStyle,
|
||||
$vuexy_hasCustomizer,
|
||||
$vuexy_displayCustomizer,
|
||||
$vuexy_contentLayout,
|
||||
$vuexy_navbarType,
|
||||
$vuexy_footerFixed,
|
||||
$vuexy_menuFixed,
|
||||
$vuexy_menuCollapsed,
|
||||
$vuexy_headerType,
|
||||
$vuexy_showDropdownOnHover,
|
||||
$vuexy_authViewMode,
|
||||
$vuexy_maxQuickLinks;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$adminTemplateService = app(AdminTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $adminTemplateService->getVuexyCustomizerVars();
|
||||
|
||||
$this->vuexy_myLayout = $settings['myLayout'];
|
||||
$this->vuexy_myTheme = $settings['myTheme'];
|
||||
$this->vuexy_myStyle = $settings['myStyle'];
|
||||
$this->vuexy_hasCustomizer = $settings['hasCustomizer'];
|
||||
$this->vuexy_displayCustomizer = $settings['displayCustomizer'];
|
||||
$this->vuexy_contentLayout = $settings['contentLayout'];
|
||||
$this->vuexy_navbarType = $settings['navbarType'];
|
||||
$this->vuexy_footerFixed = $settings['footerFixed'];
|
||||
$this->vuexy_menuFixed = $settings['menuFixed'];
|
||||
$this->vuexy_menuCollapsed = $settings['menuCollapsed'];
|
||||
$this->vuexy_headerType = $settings['headerType'];
|
||||
$this->vuexy_showDropdownOnHover = $settings['showDropdownOnHover'];
|
||||
$this->vuexy_authViewMode = $settings['authViewMode'];
|
||||
$this->vuexy_maxQuickLinks = $settings['maxQuickLinks'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'vuexy_maxQuickLinks' => 'required|integer|min:2|max:20',
|
||||
]);
|
||||
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
// Guardar configuraciones
|
||||
$globalSettingsService->updateSetting('config.custom.custom.myLayout', $this->vuexy_myLayout);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.myTheme', $this->vuexy_myTheme);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.myStyle', $this->vuexy_myStyle);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.hasCustomizer', $this->vuexy_hasCustomizer);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.displayCustomizer', $this->vuexy_displayCustomizer);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.contentLayout', $this->vuexy_contentLayout);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.navbarType', $this->vuexy_navbarType);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.footerFixed', $this->vuexy_footerFixed);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.menuFixed', $this->vuexy_menuFixed);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.menuCollapsed', $this->vuexy_menuCollapsed);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.headerType', $this->vuexy_headerType);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.showDropdownOnHover', $this->vuexy_showDropdownOnHover);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.authViewMode', $this->vuexy_authViewMode);
|
||||
$globalSettingsService->updateSetting('config.custom.custom.maxQuickLinks', $this->vuexy_maxQuickLinks);
|
||||
|
||||
$globalSettingsService->clearSystemConfigCache();
|
||||
|
||||
// Refrescar el componente actual
|
||||
$this->dispatch('clearLocalStoregeTemplateCustomizer');
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.',
|
||||
deferReload: true
|
||||
);
|
||||
}
|
||||
|
||||
public function clearCustomConfig()
|
||||
{
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
$globalSettingsService->clearVuexyCustomConfig();
|
||||
|
||||
// Refrescar el componente actual
|
||||
$this->dispatch('clearLocalStoregeTemplateCustomizer');
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.',
|
||||
deferReload: true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.admin-settings.interface-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\AdminSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\GlobalSettingsService;
|
||||
|
||||
class MailSenderResponseSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#mail-sender-response-settings-card .notification-container";
|
||||
|
||||
public $from_address,
|
||||
$from_name,
|
||||
$reply_to_method,
|
||||
$reply_to_email,
|
||||
$reply_to_name;
|
||||
|
||||
protected $listeners = ['saveMailSenderResponseSettings' => 'save'];
|
||||
|
||||
const REPLY_EMAIL_CREATOR = 1;
|
||||
const REPLY_EMAIL_SENDER = 2;
|
||||
const REPLY_EMAIL_CUSTOM = 3;
|
||||
|
||||
public $reply_email_options = [
|
||||
self::REPLY_EMAIL_CREATOR => 'Responder al creador del documento',
|
||||
self::REPLY_EMAIL_SENDER => 'Responder a quien envía el documento',
|
||||
self::REPLY_EMAIL_CUSTOM => 'Definir dirección de correo electrónico',
|
||||
];
|
||||
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $globalSettingsService->getMailSystemConfig();
|
||||
|
||||
$this->from_address = $settings['from']['address'];
|
||||
$this->from_name = $settings['from']['name'];
|
||||
$this->reply_to_method = $settings['reply_to']['method'];
|
||||
$this->reply_to_email = $settings['reply_to']['email'];
|
||||
$this->reply_to_name = $settings['reply_to']['name'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'from_address' => 'required|email',
|
||||
'from_name' => 'required|string|max:255',
|
||||
'reply_to_method' => 'required|string|max:255',
|
||||
], [
|
||||
'from_address.required' => 'El campo de correo electrónico es obligatorio.',
|
||||
'from_address.email' => 'El formato del correo electrónico no es válido.',
|
||||
'from_name.required' => 'El nombre es obligatorio.',
|
||||
'from_name.string' => 'El nombre debe ser una cadena de texto.',
|
||||
'from_name.max' => 'El nombre no puede tener más de 255 caracteres.',
|
||||
'reply_to_method.required' => 'El método de respuesta es obligatorio.',
|
||||
'reply_to_method.string' => 'El método de respuesta debe ser una cadena de texto.',
|
||||
'reply_to_method.max' => 'El método de respuesta no puede tener más de 255 caracteres.',
|
||||
]);
|
||||
|
||||
if ($this->reply_to_method == self::REPLY_EMAIL_CUSTOM) {
|
||||
$this->validate([
|
||||
'reply_to_email' => ['required', 'email'],
|
||||
'reply_to_name' => ['required', 'string', 'max:255'],
|
||||
], [
|
||||
'reply_to_email.required' => 'El correo de respuesta es obligatorio.',
|
||||
'reply_to_email.email' => 'El formato del correo de respuesta no es válido.',
|
||||
'reply_to_name.required' => 'El nombre de respuesta es obligatorio.',
|
||||
'reply_to_name.string' => 'El nombre de respuesta debe ser una cadena de texto.',
|
||||
'reply_to_name.max' => 'El nombre de respuesta no puede tener más de 255 caracteres.',
|
||||
]);
|
||||
}
|
||||
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$globalSettingsService->updateSetting('mail.from.address', $this->from_address);
|
||||
$globalSettingsService->updateSetting('mail.from.name', $this->from_name);
|
||||
$globalSettingsService->updateSetting('mail.reply_to.method', $this->reply_to_method);
|
||||
$globalSettingsService->updateSetting('mail.reply_to.email', $this->reply_to_method == self::REPLY_EMAIL_CUSTOM ? $this->reply_to_email : '');
|
||||
$globalSettingsService->updateSetting('mail.reply_to.name', $this->reply_to_method == self::REPLY_EMAIL_CUSTOM ? $this->reply_to_name : '');
|
||||
|
||||
$globalSettingsService->clearMailSystemConfigCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.',
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.admin-settings.mail-sender-response-settings');
|
||||
}
|
||||
}
|
175
modules/Admin/App/Livewire/AdminSettings/MailSmtpSettings.php
Normal file
175
modules/Admin/App/Livewire/AdminSettings/MailSmtpSettings.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\AdminSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Symfony\Component\Mailer\Transport;
|
||||
use Symfony\Component\Mailer\Mailer;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Modules\Admin\App\Services\GlobalSettingsService;
|
||||
|
||||
|
||||
class MailSmtpSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#mail-smtp-settings-card .notification-container";
|
||||
|
||||
public $change_smtp_settings,
|
||||
$host,
|
||||
$port,
|
||||
$encryption,
|
||||
$username,
|
||||
$password;
|
||||
|
||||
public $save_button_disabled;
|
||||
|
||||
protected $listeners = [
|
||||
'loadSettings',
|
||||
'testSmtpConnection',
|
||||
];
|
||||
|
||||
// the list of smtp_encryption values that can be stored in table
|
||||
const SMTP_ENCRYPTION_SSL = 'SSL';
|
||||
const SMTP_ENCRYPTION_TLS = 'TLS';
|
||||
const SMTP_ENCRYPTION_NONE = 'none';
|
||||
|
||||
public $encryption_options = [
|
||||
self::SMTP_ENCRYPTION_SSL => 'SSL (Secure Sockets Layer)',
|
||||
self::SMTP_ENCRYPTION_TLS => 'TLS (Transport Layer Security)',
|
||||
self::SMTP_ENCRYPTION_NONE => 'Sin encriptación (No recomendado)',
|
||||
];
|
||||
|
||||
public $rules = [
|
||||
[
|
||||
'host' => 'nullable|string|max:255',
|
||||
'port' => 'nullable|integer',
|
||||
'encryption' => 'nullable|string',
|
||||
'username' => 'nullable|string|max:255',
|
||||
'password' => 'nullable|string|max:255',
|
||||
],
|
||||
[
|
||||
'host.string' => 'El servidor SMTP debe ser una cadena de texto.',
|
||||
'host.max' => 'El servidor SMTP no puede exceder los 255 caracteres.',
|
||||
'port.integer' => 'El puerto SMTP debe ser un número entero.',
|
||||
'encryption.string' => 'El tipo de encriptación SMTP debe ser una cadena de texto.',
|
||||
'username.string' => 'El nombre de usuario SMTP debe ser una cadena de texto.',
|
||||
'username.max' => 'El nombre de usuario SMTP no puede exceder los 255 caracteres.',
|
||||
'password.string' => 'La contraseña SMTP debe ser una cadena de texto.',
|
||||
'password.max' => 'La contraseña SMTP no puede exceder los 255 caracteres.',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $globalSettingsService->getMailSystemConfig();
|
||||
|
||||
$this->change_smtp_settings = false;
|
||||
$this->save_button_disabled = true;
|
||||
|
||||
$this->host = $settings['mailers']['smtp']['host'];
|
||||
$this->port = $settings['mailers']['smtp']['port'];
|
||||
$this->encryption = $settings['mailers']['smtp']['encryption'];
|
||||
$this->username = $settings['mailers']['smtp']['username'];
|
||||
$this->password = null;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate($this->rules[0]);
|
||||
|
||||
$globalSettingsService = app(GlobalSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$globalSettingsService->updateSetting('mail.mailers.smtp.host', $this->host);
|
||||
$globalSettingsService->updateSetting('mail.mailers.smtp.port', $this->port);
|
||||
$globalSettingsService->updateSetting('mail.mailers.smtp.encryption', $this->encryption);
|
||||
$globalSettingsService->updateSetting('mail.mailers.smtp.username', $this->username);
|
||||
$globalSettingsService->updateSetting('mail.mailers.smtp.password', Crypt::encryptString($this->password));
|
||||
|
||||
$globalSettingsService->clearMailSystemConfigCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han guardado los cambios en las configuraciones.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSmtpConnection()
|
||||
{
|
||||
// Validar los datos del formulario
|
||||
$this->validate($this->rules[0]);
|
||||
|
||||
try {
|
||||
// Verificar la conexión SMTP
|
||||
if ($this->validateSMTPConnection()) {
|
||||
$this->save_button_disabled = false;
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Conexión SMTP exitosa, se guardó los cambios exitosamente.',
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Captura y maneja errores de conexión SMTP
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'danger',
|
||||
message: 'Error en la conexión SMTP: ' . $e->getMessage(),
|
||||
notificationTimeout: 15000 // Timeout personalizado
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSMTPConnection()
|
||||
{
|
||||
$dsn = sprintf(
|
||||
'smtp://%s:%s@%s:%s?encryption=%s',
|
||||
urlencode($this->username), // Codificar nombre de usuario
|
||||
urlencode($this->password), // Codificar contraseña
|
||||
$this->host, // Host SMTP
|
||||
$this->port, // Puerto SMTP
|
||||
$this->encryption // Encriptación (tls o ssl)
|
||||
);
|
||||
|
||||
// Crear el transportador usando el DSN
|
||||
$transport = Transport::fromDsn($dsn);
|
||||
|
||||
// Crear el mailer con el transportador personalizado
|
||||
$mailer = new Mailer($transport);
|
||||
|
||||
// Enviar un correo de prueba
|
||||
$email = (new Email())
|
||||
->from($this->username) // Dirección de correo del remitente
|
||||
->to(env('MAIL_SANDBOX')) // Dirección de correo de destino
|
||||
->subject(Config::get('app.name') . ' - Correo de prueba')
|
||||
->text('Este es un correo de prueba para verificar la conexión SMTP.');
|
||||
|
||||
// Enviar el correo
|
||||
$mailer->send($email);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.admin-settings.mail-smtp-settings');
|
||||
}
|
||||
}
|
212
modules/Admin/App/Livewire/Cache/CacheFunctions.php
Normal file
212
modules/Admin/App/Livewire/Cache/CacheFunctions.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Cache;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class CacheFunctions extends Component
|
||||
{
|
||||
private $targetNotify = "#cache-functions-card .notification-container";
|
||||
|
||||
public $cacheCounts = [
|
||||
'general' => 0,
|
||||
'config' => 0,
|
||||
'routes' => 0,
|
||||
'views' => 0,
|
||||
'events' => 0,
|
||||
];
|
||||
|
||||
protected $listeners = [
|
||||
'reloadCacheFunctionsStatsEvent' => 'reloadCacheStats',
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->reloadCacheStats(false);
|
||||
}
|
||||
|
||||
public function reloadCacheStats($notify = true)
|
||||
{
|
||||
$cacheDriver = config('cache.default'); // Obtiene el driver configurado para caché
|
||||
|
||||
// Caché General
|
||||
switch ($cacheDriver) {
|
||||
case 'memcached':
|
||||
try {
|
||||
$cacheStore = Cache::getStore()->getMemcached();
|
||||
$stats = $cacheStore->getStats();
|
||||
|
||||
$this->cacheCounts['general'] = array_sum(array_column($stats, 'curr_items')); // Total de claves en Memcached
|
||||
} catch (\Exception $e) {
|
||||
$this->cacheCounts['general'] = 'Error obteniendo datos de Memcached';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'redis':
|
||||
try {
|
||||
$prefix = config('cache.prefix'); // Asegúrate de agregar el sufijo correcto si es necesario
|
||||
$keys = Redis::connection('cache')->keys($prefix . '*');
|
||||
|
||||
$this->cacheCounts['general'] = count($keys); // Total de claves en Redis
|
||||
} catch (\Exception $e) {
|
||||
$this->cacheCounts['general'] = 'Error obteniendo datos de Redis';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'database':
|
||||
try {
|
||||
$this->cacheCounts['general'] = DB::table('cache')->count(); // Total de registros en la tabla de caché
|
||||
} catch (\Exception $e) {
|
||||
$this->cacheCounts['general'] = 'Error obteniendo datos de la base de datos';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'file':
|
||||
try {
|
||||
$cachePath = config('cache.stores.file.path');
|
||||
$files = glob($cachePath . '/*');
|
||||
|
||||
$this->cacheCounts['general'] = count($files);
|
||||
} catch (\Exception $e) {
|
||||
$this->cacheCounts['general'] = 'Error obteniendo datos de archivos';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->cacheCounts['general'] = 'Driver de caché no soportado';
|
||||
}
|
||||
|
||||
// Configuración
|
||||
$this->cacheCounts['config'] = file_exists(base_path('bootstrap/cache/config.php')) ? 1 : 0;
|
||||
|
||||
// Rutas
|
||||
$this->cacheCounts['routes'] = count(glob(base_path('bootstrap/cache/routes-*.php'))) > 0 ? 1 : 0;
|
||||
|
||||
// Vistas
|
||||
$this->cacheCounts['views'] = count(glob(storage_path('framework/views/*')));
|
||||
|
||||
// Configuración
|
||||
$this->cacheCounts['events'] = file_exists(base_path('bootstrap/cache/events.php')) ? 1 : 0;
|
||||
|
||||
if ($notify) {
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: 'success',
|
||||
message: 'Se han recargado los estadísticos de caché.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function clearLaravelCache()
|
||||
{
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->response('Se han limpiado las cachés de la aplicación.', 'warning');
|
||||
}
|
||||
|
||||
public function clearConfigCache()
|
||||
{
|
||||
Artisan::call('config:clear');
|
||||
|
||||
$this->response('Se ha limpiado la cache de la configuración de Laravel.', 'warning');
|
||||
}
|
||||
|
||||
public function configCache()
|
||||
{
|
||||
Artisan::call('config:cache');
|
||||
}
|
||||
|
||||
public function clearRouteCache()
|
||||
{
|
||||
Artisan::call('route:clear');
|
||||
|
||||
$this->response('Se han limpiado las rutas de Laravel.', 'warning');
|
||||
}
|
||||
|
||||
public function cacheRoutes()
|
||||
{
|
||||
Artisan::call('route:cache');
|
||||
}
|
||||
|
||||
public function clearViewCache()
|
||||
{
|
||||
Artisan::call('view:clear');
|
||||
|
||||
$this->response('Se han limpiado las vistas de Laravel.', 'warning');
|
||||
}
|
||||
|
||||
public function cacheViews()
|
||||
{
|
||||
Artisan::call('view:cache');
|
||||
|
||||
$this->response('Se han cacheado las vistas de Laravel.');
|
||||
}
|
||||
|
||||
public function clearEventCache()
|
||||
{
|
||||
Artisan::call('event:clear');
|
||||
|
||||
$this->response('Se han limpiado los eventos de Laravel.', 'warning');
|
||||
}
|
||||
|
||||
public function cacheEvents()
|
||||
{
|
||||
Artisan::call('event:cache');
|
||||
|
||||
$this->response('Se han cacheado los eventos de Laravel.');
|
||||
}
|
||||
|
||||
public function optimizeClear()
|
||||
{
|
||||
Artisan::call('optimize:clear');
|
||||
|
||||
$this->response('Se han optimizado todos los cachés de Laravel.');
|
||||
}
|
||||
|
||||
public function resetPermissionCache()
|
||||
{
|
||||
Artisan::call('permission:cache-reset');
|
||||
|
||||
$this->response('Se han limpiado los cachés de permisos.', 'warning');
|
||||
}
|
||||
|
||||
public function clearResetTokens()
|
||||
{
|
||||
Artisan::call('auth:clear-resets');
|
||||
|
||||
$this->response('Se han limpiado los tokens de reseteo de contraseña.', 'warning');
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera una respuesta estandarizada.
|
||||
*/
|
||||
private function response(string $message, string $type = 'success'): void
|
||||
{
|
||||
$this->reloadCacheStats(false);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $type,
|
||||
message: $message,
|
||||
);
|
||||
|
||||
$this->dispatch('reloadCacheStatsEvent', notify: false);
|
||||
$this->dispatch('reloadSessionStatsEvent', notify: false);
|
||||
$this->dispatch('reloadRedisStatsEvent', notify: false);
|
||||
$this->dispatch('reloadMemcachedStatsEvent', notify: false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.cache.cache-functions');
|
||||
}
|
||||
}
|
65
modules/Admin/App/Livewire/Cache/CacheStats.php
Normal file
65
modules/Admin/App/Livewire/Cache/CacheStats.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Cache;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\CacheConfigService;
|
||||
use Modules\Admin\App\Services\CacheManagerService;
|
||||
|
||||
class CacheStats extends Component
|
||||
{
|
||||
private $targetNotify = "#cache-stats-card .notification-container";
|
||||
|
||||
public $cacheConfig = [];
|
||||
public $cacheStats = [];
|
||||
|
||||
protected $listeners = ['reloadCacheStatsEvent' => 'reloadCacheStats'];
|
||||
|
||||
public function mount(CacheConfigService $cacheConfigService)
|
||||
{
|
||||
$this->cacheConfig = $cacheConfigService->getConfig();
|
||||
|
||||
$this->reloadCacheStats(false);
|
||||
}
|
||||
|
||||
public function reloadCacheStats($notify = true)
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService();
|
||||
|
||||
$this->cacheStats = $cacheManagerService->getCacheStats();
|
||||
|
||||
if ($notify) {
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $this->cacheStats['status'],
|
||||
message: $this->cacheStats['message']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService();
|
||||
|
||||
$message = $cacheManagerService->clearCache();
|
||||
|
||||
$this->reloadCacheStats(false);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $message['status'],
|
||||
message: $message['message'],
|
||||
);
|
||||
|
||||
$this->dispatch('reloadRedisStatsEvent', notify: false);
|
||||
$this->dispatch('reloadMemcachedStatsEvent', notify: false);
|
||||
$this->dispatch('reloadCacheFunctionsStatsEvent', notify: false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.cache.cache-stats');
|
||||
}
|
||||
}
|
64
modules/Admin/App/Livewire/Cache/MemcachedStats.php
Normal file
64
modules/Admin/App/Livewire/Cache/MemcachedStats.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Cache;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\CacheManagerService;
|
||||
|
||||
class MemcachedStats extends Component
|
||||
{
|
||||
private $driver = 'memcached';
|
||||
private $targetNotify = "#memcached-stats-card .notification-container";
|
||||
|
||||
public $memcachedStats = [];
|
||||
|
||||
protected $listeners = ['reloadMemcachedStatsEvent' => 'reloadCacheStats'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->reloadCacheStats(false);
|
||||
}
|
||||
|
||||
public function reloadCacheStats($notify = true)
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService($this->driver);
|
||||
|
||||
$memcachedStats = $cacheManagerService->getMemcachedStats();
|
||||
|
||||
$this->memcachedStats = $memcachedStats['info'];
|
||||
|
||||
if ($notify) {
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $memcachedStats['status'],
|
||||
message: $memcachedStats['message']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService($this->driver);
|
||||
|
||||
$message = $cacheManagerService->clearCache();
|
||||
|
||||
$this->reloadCacheStats(false);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $message['status'],
|
||||
message: $message['message'],
|
||||
);
|
||||
|
||||
$this->dispatch('reloadCacheStatsEvent', notify: false);
|
||||
$this->dispatch('reloadSessionStatsEvent', notify: false);
|
||||
$this->dispatch('reloadCacheFunctionsStatsEvent', notify: false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.cache.memcached-stats');
|
||||
}
|
||||
}
|
64
modules/Admin/App/Livewire/Cache/RedisStats.php
Normal file
64
modules/Admin/App/Livewire/Cache/RedisStats.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Cache;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\CacheManagerService;
|
||||
|
||||
class RedisStats extends Component
|
||||
{
|
||||
private $driver = 'redis';
|
||||
private $targetNotify = "#redis-stats-card .notification-container";
|
||||
|
||||
public $redisStats = [];
|
||||
|
||||
protected $listeners = ['reloadRedisStatsEvent' => 'reloadCacheStats'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->reloadCacheStats(false);
|
||||
}
|
||||
|
||||
public function reloadCacheStats($notify = true)
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService($this->driver);
|
||||
|
||||
$redisStats = $cacheManagerService->getRedisStats();
|
||||
|
||||
$this->redisStats = $redisStats['info'];
|
||||
|
||||
if ($notify) {
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $redisStats['status'],
|
||||
message: $redisStats['message']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
$cacheManagerService = new CacheManagerService($this->driver);
|
||||
|
||||
$message = $cacheManagerService->clearCache();
|
||||
|
||||
$this->reloadCacheStats(false);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $message['status'],
|
||||
message: $message['message'],
|
||||
);
|
||||
|
||||
$this->dispatch('reloadCacheStatsEvent', notify: false);
|
||||
$this->dispatch('reloadSessionStatsEvent', notify: false);
|
||||
$this->dispatch('reloadCacheFunctionsStatsEvent', notify: false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.cache.redis-stats');
|
||||
}
|
||||
}
|
63
modules/Admin/App/Livewire/Cache/SessionStats.php
Normal file
63
modules/Admin/App/Livewire/Cache/SessionStats.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Cache;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Admin\App\Services\CacheConfigService;
|
||||
use Modules\Admin\App\Services\SessionManagerService;
|
||||
|
||||
class SessionStats extends Component
|
||||
{
|
||||
private $targetNotify = "#session-stats-card .notification-container";
|
||||
|
||||
public $cacheConfig = [];
|
||||
public $sessionStats = [];
|
||||
|
||||
protected $listeners = ['reloadSessionStatsEvent' => 'reloadSessionStats'];
|
||||
|
||||
public function mount(CacheConfigService $cacheConfigService)
|
||||
{
|
||||
$this->cacheConfig = $cacheConfigService->getConfig();
|
||||
$this->reloadSessionStats(false);
|
||||
}
|
||||
|
||||
public function reloadSessionStats($notify = true)
|
||||
{
|
||||
$sessionManagerService = new SessionManagerService();
|
||||
|
||||
$this->sessionStats = $sessionManagerService->getSessionStats();
|
||||
|
||||
if ($notify) {
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $this->sessionStats['status'],
|
||||
message: $this->sessionStats['message']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function clearSessions()
|
||||
{
|
||||
$sessionManagerService = new SessionManagerService();
|
||||
|
||||
$message = $sessionManagerService->clearSessions();
|
||||
|
||||
$this->reloadSessionStats(false);
|
||||
|
||||
$this->dispatch(
|
||||
'notification',
|
||||
target: $this->targetNotify,
|
||||
type: $message['status'],
|
||||
message: $message['message'],
|
||||
);
|
||||
|
||||
$this->dispatch('reloadRedisStatsEvent', notify: false);
|
||||
$this->dispatch('reloadMemcachedStatsEvent', notify: false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.cache.session-stats');
|
||||
}
|
||||
}
|
28
modules/Admin/App/Livewire/Rbac/PermissionsIndex.php
Normal file
28
modules/Admin/App/Livewire/Rbac/PermissionsIndex.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Rbac;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class PermissionsIndex extends Component
|
||||
{
|
||||
public $roles_html_select;
|
||||
public $rows_roles;
|
||||
|
||||
public function render()
|
||||
{
|
||||
// Generamos Select y estilos HTML de roles
|
||||
$this->roles_html_select = "<select id=\"UserRole\" class=\"form-select text-capitalize\"><option value=\"\"> Selecciona un rol </option>";
|
||||
|
||||
foreach (Role::all() as $role) {
|
||||
$this->rows_roles[$role->name] = "<span class=\"badge bg-label-{$role->style} m-1\">{$role->name}</span>";
|
||||
$this->roles_html_select .= "<option value=\"{$role->name}\" class=\"text-capitalize\">{$role->name}</option>";
|
||||
}
|
||||
|
||||
$this->roles_html_select .= "</select>";
|
||||
|
||||
return view('admin::livewire.rbac.permissions-index');
|
||||
}
|
||||
}
|
182
modules/Admin/App/Livewire/Rbac/RoleCards.php
Normal file
182
modules/Admin/App/Livewire/Rbac/RoleCards.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Rbac;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class RoleCards extends Component
|
||||
{
|
||||
public $roles = [];
|
||||
public $permissions = [];
|
||||
public $roleId;
|
||||
public $name;
|
||||
public $style;
|
||||
public $title;
|
||||
public $btn_submit_text;
|
||||
public $permissionsInputs = [];
|
||||
public $destroyRoleId;
|
||||
|
||||
protected $listeners = ['saveRole', 'deleteRole'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadRolesAndPermissions();
|
||||
$this->dispatch('reloadForm');
|
||||
}
|
||||
|
||||
private function loadRolesAndPermissions()
|
||||
{
|
||||
$this->roles = Auth::user()->hasRole('SuperAdmin') ?
|
||||
Role::all() :
|
||||
Role::where('name', '!=', 'SuperAdmin')->get();
|
||||
|
||||
// Obtener todos los permisos
|
||||
$permissions = Permission::all()->map(function ($permission) {
|
||||
$name = $permission->name;
|
||||
$action = substr($name, strrpos($name, '.') + 1);
|
||||
|
||||
return [
|
||||
'group_name' => $permission->group_name,
|
||||
'sub_group_name' => $permission->sub_group_name,
|
||||
$action => $name // Agregar la acción directamente al array
|
||||
];
|
||||
})->groupBy('group_name'); // Agrupar los permisos por grupo
|
||||
|
||||
|
||||
// Procesar los permisos agrupados para cargarlos en el componente
|
||||
$permissionsInputs = [];
|
||||
|
||||
$this->permissions = $permissions->map(function ($groupPermissions) use (&$permissionsInputs) {
|
||||
$permission = [
|
||||
'group_name' => $groupPermissions[0]['group_name'], // Tomar el grupo del primer permiso del grupo
|
||||
'sub_group_name' => $groupPermissions[0]['sub_group_name'], // Tomar la descripción del primer permiso del grupo
|
||||
];
|
||||
|
||||
// Agregar todas las acciones al permissionsInputs y al permission
|
||||
foreach ($groupPermissions as $permissionData) {
|
||||
foreach ($permissionData as $key => $value) {
|
||||
if ($key !== 'sub_group_name' && $key !== 'group_name') {
|
||||
$permissionsInputs[str_replace('.', '_', $value)] = false;
|
||||
$permission[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $permission;
|
||||
});
|
||||
|
||||
$this->permissionsInputs = $permissionsInputs;
|
||||
}
|
||||
|
||||
public function loadRoleData($action, $roleId = false)
|
||||
{
|
||||
$this->resetForm();
|
||||
|
||||
$this->title = 'Agregar un nuevo rol';
|
||||
$this->btn_submit_text = 'Crear nuevo rol';
|
||||
|
||||
if ($roleId) {
|
||||
$role = Role::findOrFail($roleId);
|
||||
|
||||
switch ($action) {
|
||||
case 'view':
|
||||
$this->title = $role->name;
|
||||
$this->name = $role->name;
|
||||
$this->style = $role->style;
|
||||
$this->dispatch('deshabilitarFormulario');
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$this->title = 'Editar rol';
|
||||
$this->btn_submit_text = 'Guardar cambios';
|
||||
$this->roleId = $roleId;
|
||||
$this->name = $role->name;
|
||||
$this->style = $role->style;
|
||||
$this->dispatch('habilitarFormulario');
|
||||
break;
|
||||
|
||||
case 'clone':
|
||||
$this->style = $role->style;
|
||||
$this->dispatch('habilitarFormulario');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($role->permissions as $permission) {
|
||||
$this->permissionsInputs[str_replace('.', '_', $permission->name)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatch('reloadForm');
|
||||
}
|
||||
|
||||
public function loadDestroyRoleData() {}
|
||||
|
||||
public function saveRole()
|
||||
{
|
||||
$permissions = [];
|
||||
|
||||
foreach ($this->permissionsInputs as $permission => $value) {
|
||||
if ($value === true)
|
||||
$permissions[] = str_replace('_', '.', $permission);
|
||||
}
|
||||
|
||||
if ($this->roleId) {
|
||||
$role = Role::find($this->roleId);
|
||||
|
||||
$role->name = $this->name;
|
||||
$role->style = $this->style;
|
||||
|
||||
$role->save();
|
||||
|
||||
$role->syncPermissions($permissions);
|
||||
} else {
|
||||
$role = Role::create([
|
||||
'name' => $this->name,
|
||||
'style' => $this->style,
|
||||
]);
|
||||
|
||||
$role->syncPermissions($permissions);
|
||||
}
|
||||
|
||||
$this->loadRolesAndPermissions();
|
||||
|
||||
$this->dispatch('modalHide');
|
||||
$this->dispatch('reloadForm');
|
||||
}
|
||||
|
||||
public function deleteRole()
|
||||
{
|
||||
$role = Role::find($this->destroyRoleId);
|
||||
|
||||
if ($role)
|
||||
$role->delete();
|
||||
|
||||
$this->loadRolesAndPermissions();
|
||||
|
||||
$this->dispatch('modalDeleteHide');
|
||||
$this->dispatch('reloadForm');
|
||||
}
|
||||
|
||||
private function resetForm()
|
||||
{
|
||||
$this->roleId = '';
|
||||
$this->name = '';
|
||||
$this->style = '';
|
||||
|
||||
foreach ($this->permissionsInputs as $key => $permission) {
|
||||
$this->permissionsInputs[$key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.rbac.role-cards');
|
||||
}
|
||||
}
|
31
modules/Admin/App/Livewire/Users/UserCount.php
Normal file
31
modules/Admin/App/Livewire/Users/UserCount.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Users;
|
||||
|
||||
use Modules\Admin\App\Models\User;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class UserCount extends Component
|
||||
{
|
||||
public $total, $enabled, $disabled;
|
||||
|
||||
protected $listeners = ['refreshUserCount' => 'updateCounts'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->updateCounts();
|
||||
}
|
||||
|
||||
public function updateCounts()
|
||||
{
|
||||
$this->total = User::count();
|
||||
$this->enabled = User::where('status', User::STATUS_ENABLED)->count();
|
||||
$this->disabled = User::where('status', User::STATUS_DISABLED)->count();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.users.user-count');
|
||||
}
|
||||
}
|
115
modules/Admin/App/Livewire/Users/UserTable.php
Normal file
115
modules/Admin/App/Livewire/Users/UserTable.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\Users;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Admin\App\Models\User;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class UserTable extends Component
|
||||
{
|
||||
public $statuses;
|
||||
public $status_options;
|
||||
|
||||
public $rows_roles = [];
|
||||
public $roles_options = [];
|
||||
public $roles_html_select;
|
||||
|
||||
public $total, $enabled, $disabled;
|
||||
|
||||
public $indexAlert;
|
||||
|
||||
public $userId, $name, $email, $password, $roles, $status, $photo, $src_photo;
|
||||
public $modalTitle;
|
||||
public $btnSubmitTxt;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->modalTitle = 'Crear usuario nuevo';
|
||||
$this->btnSubmitTxt = 'Crear usuario';
|
||||
|
||||
$this->statuses = [
|
||||
User::STATUS_ENABLED => ['title' => 'Activo', 'class' => 'badge bg-label-' . User::$statusListClass[User::STATUS_ENABLED]],
|
||||
User::STATUS_DISABLED => ['title' => 'Deshabilitado', 'class' => 'badge bg-label-' . User::$statusListClass[User::STATUS_DISABLED]],
|
||||
User::STATUS_REMOVED => ['title' => 'Eliminado', 'class' => 'badge bg-label-' . User::$statusListClass[User::STATUS_REMOVED]],
|
||||
];
|
||||
|
||||
$roles = Role::whereNotIn('name', ['Patient', 'Doctor'])->get();
|
||||
|
||||
$this->roles_html_select = "<select id=\"UserRole\" class=\"form-select text-capitalize\"><option value=\"\"> Selecciona un rol </option>";
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$this->rows_roles[$role->name] = "<span class=\"badge bg-label-" . $role->style . " mx-1\">" . $role->name . "</span>";
|
||||
|
||||
if (Auth::user()->hasRole('SuperAdmin') || $role->name != 'SuperAdmin') {
|
||||
$this->roles_html_select .= "<option value=\"" . $role->name . "\" class=\"text-capitalize\">" . $role->name . "</option>";
|
||||
$this->roles_options[$role->name] = $role->name;
|
||||
}
|
||||
}
|
||||
|
||||
$this->roles_html_select .= "</select>";
|
||||
|
||||
$this->status_options = [
|
||||
User::STATUS_ENABLED => User::$statusList[User::STATUS_ENABLED],
|
||||
User::STATUS_DISABLED => User::$statusList[User::STATUS_DISABLED],
|
||||
];
|
||||
}
|
||||
|
||||
public function countUsers()
|
||||
{
|
||||
$this->total = User::count();
|
||||
$this->enabled = User::where('status', User::STATUS_ENABLED)->count();
|
||||
$this->disabled = User::where('status', User::STATUS_DISABLED)->count();
|
||||
}
|
||||
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$this->indexAlert = '';
|
||||
$this->modalTitle = 'Editar usuario: ' . $id;
|
||||
$this->btnSubmitTxt = 'Guardar cambios';
|
||||
|
||||
$this->userId = $user->id;
|
||||
$this->name = $user->name;
|
||||
$this->email = $user->email;
|
||||
$this->password = '';
|
||||
$this->roles = $user->roles->pluck('name')->toArray();
|
||||
$this->src_photo = $user->profile_photo_url;
|
||||
$this->status = $user->status;
|
||||
|
||||
$this->dispatch('openModal');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$user = User::find($id);
|
||||
|
||||
if ($user) {
|
||||
// Eliminar la imagen de perfil si existe
|
||||
if ($user->profile_photo_path)
|
||||
Storage::disk('public')->delete($user->profile_photo_path);
|
||||
|
||||
// Eliminar el usuario
|
||||
$user->delete();
|
||||
|
||||
$this->indexAlert = '<div class="alert alert-warning alert-dismissible" role="alert">Se eliminó correctamente el usuario.<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
||||
|
||||
$this->dispatch('refreshUserCount');
|
||||
$this->dispatch('afterDelete');
|
||||
} else {
|
||||
$this->indexAlert = '<div class="alert alert-danger alert-dismissible" role="alert">Usuario no encontrado.<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('admin::livewire.users.user-table', [
|
||||
'users' => User::paginate(10),
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class AnalyticsSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-analytics-settings-card .notification-container";
|
||||
|
||||
public $google_analytics_enabled,
|
||||
$google_analytics_id;
|
||||
|
||||
protected $listeners = ['saveAnalyticsSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$WebsiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $WebsiteTemplateService->getWebsiteVars('google');
|
||||
|
||||
$this->google_analytics_enabled = $settings['analytics']['enabled'];
|
||||
$this->google_analytics_id = $settings['analytics']['id'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if ($this->google_analytics_enabled) {
|
||||
$this->validate([
|
||||
'google_analytics_id' => 'required|string|min:12|max:30',
|
||||
]);
|
||||
}
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('google_analytics_enabled', $this->google_analytics_enabled);
|
||||
$websiteSettingsService->updateSetting('google_analytics_id', $this->google_analytics_id);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.analytics-settings');
|
||||
}
|
||||
}
|
68
modules/Admin/App/Livewire/WebsiteSettings/ChatSettings.php
Normal file
68
modules/Admin/App/Livewire/WebsiteSettings/ChatSettings.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class ChatSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-chat-settings-card .notification-container";
|
||||
|
||||
public $chat_provider,
|
||||
$chat_whatsapp_number,
|
||||
$chat_whatsapp_message;
|
||||
|
||||
protected $listeners = ['saveChatSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars('chat');
|
||||
|
||||
$this->chat_provider = $settings['provider'];
|
||||
$this->chat_whatsapp_number = $settings['whatsapp_number'];
|
||||
$this->chat_whatsapp_message = $settings['whatsapp_message'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if ($this->chat_provider == 'whatsapp') {
|
||||
$this->validate([
|
||||
'chat_whatsapp_number' => 'required|string|max:20',
|
||||
'chat_whatsapp_message' => 'required|string|max:255',
|
||||
]);
|
||||
}
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('chat_provider', $this->chat_provider);
|
||||
$websiteSettingsService->updateSetting('chat_whatsapp_number', preg_replace('/\D/', '', $this->chat_whatsapp_number));
|
||||
$websiteSettingsService->updateSetting('chat_whatsapp_message', $this->chat_whatsapp_message);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.chat-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class ContactFormSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-contact-form-settings-card .notification-container";
|
||||
|
||||
public $contact_form_email,
|
||||
$contact_form_email_cc,
|
||||
$contact_form_subject;
|
||||
|
||||
protected $listeners = ['saveContactFormSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->contact_form_email = $settings['contact']['form']['email'];
|
||||
$this->contact_form_email_cc = $settings['contact']['form']['email_cc'];
|
||||
$this->contact_form_subject = $settings['contact']['form']['subject'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'contact_form_email' => 'required|email',
|
||||
'contact_form_email_cc' => 'nullable|email',
|
||||
'contact_form_subject' => 'required|string'
|
||||
]);
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('contact_form_email', $this->contact_form_email);
|
||||
$websiteSettingsService->updateSetting('contact_form_email_cc', $this->contact_form_email_cc);
|
||||
$websiteSettingsService->updateSetting('contact_form_subject', $this->contact_form_subject);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.contact-form-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class ContactInfoSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-contact-info-settings-card .notification-container";
|
||||
|
||||
public $contact_phone_number,
|
||||
$contact_phone_number_ext,
|
||||
$contact_email;
|
||||
|
||||
protected $listeners = ['saveContactInfoSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->contact_phone_number = $settings['contact']['phone_number'];
|
||||
$this->contact_phone_number_ext = $settings['contact']['phone_number_ext'];
|
||||
$this->contact_email = $settings['contact']['email'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'contact_phone_number' => ['nullable', 'string', 'max:20'],
|
||||
'contact_phone_number_ext' => ['nullable', 'string', 'max:10'],
|
||||
'contact_email' => ['nullable', 'email']
|
||||
]);
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('contact_phone_number', $this->contact_phone_number);
|
||||
$websiteSettingsService->updateSetting('contact_phone_number_ext', $this->contact_phone_number_ext);
|
||||
$websiteSettingsService->updateSetting('contact_email', $this->contact_email);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.contact-info-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class FaviconSettings extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
private $targetNotify = "#website-favicon-settings-card .notification-container";
|
||||
|
||||
public $upload_image_favicon;
|
||||
public $website_favicon_16x16,
|
||||
$website_favicon_76x76,
|
||||
$website_favicon_120x120,
|
||||
$website_favicon_152x152,
|
||||
$website_favicon_180x180,
|
||||
$website_favicon_192x192;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
$this->upload_image_favicon = null;
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->website_favicon_16x16 = $settings['favicon']['16x16'];
|
||||
$this->website_favicon_76x76 = $settings['favicon']['76x76'];
|
||||
$this->website_favicon_120x120 = $settings['favicon']['120x120'];
|
||||
$this->website_favicon_152x152 = $settings['favicon']['152x152'];
|
||||
$this->website_favicon_180x180 = $settings['favicon']['180x180'];
|
||||
$this->website_favicon_192x192 = $settings['favicon']['192x192'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'upload_image_favicon' => 'required|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
]);
|
||||
|
||||
// Procesar favicon si se ha cargado una imagen
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
$websiteSettingsService->processAndSaveFavicon($this->upload_image_favicon);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.favicon-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class ImageLogoSettings extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
private $targetNotify = "#website-image-logo-settings-card .notification-container";
|
||||
|
||||
public $website_image_logo,
|
||||
$website_image_logo_dark;
|
||||
|
||||
public $upload_image_logo,
|
||||
$upload_image_logo_dark;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
$this->upload_image_logo = null;
|
||||
$this->upload_image_logo_dark = null;
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->website_image_logo = $settings['image_logo']['large'];
|
||||
$this->website_image_logo_dark = $settings['image_logo']['large_dark'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'upload_image_logo' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
'upload_image_logo_dark' => 'nullable|image|mimes:jpeg,png,jpg,svg,webp|max:20480',
|
||||
]);
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Procesar favicon si se ha cargado una imagen
|
||||
if ($this->upload_image_logo) {
|
||||
$websiteSettingsService->processAndSaveImageLogo($this->upload_image_logo);
|
||||
}
|
||||
|
||||
if ($this->upload_image_logo_dark) {
|
||||
$websiteSettingsService->processAndSaveImageLogo($this->upload_image_logo_dark, 'dark');
|
||||
}
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.image-logo-settings');
|
||||
}
|
||||
}
|
108
modules/Admin/App/Livewire/WebsiteSettings/LegalSettings.php
Normal file
108
modules/Admin/App/Livewire/WebsiteSettings/LegalSettings.php
Normal 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');
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class LocationSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-location-settings-card .notification-container";
|
||||
|
||||
public $contact_direccion,
|
||||
$contact_horario,
|
||||
$contact_location_lat,
|
||||
$contact_location_lng;
|
||||
|
||||
protected $listeners = ['saveLocationSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->contact_direccion = $settings['contact']['direccion'];
|
||||
$this->contact_horario = $settings['contact']['horario'];
|
||||
$this->contact_location_lat = $settings['contact']['location']['lat'];
|
||||
$this->contact_location_lng = $settings['contact']['location']['lng'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'contact_direccion' => ['nullable', 'string', 'max:255'],
|
||||
'contact_horario' => ['nullable', 'string', 'max:255'],
|
||||
'contact_location_lat' => ['nullable', 'numeric'],
|
||||
'contact_location_lng' => ['nullable', 'numeric'],
|
||||
]);
|
||||
|
||||
$websiteSettingsService = app(WebsiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('contact_direccion', $this->contact_direccion);
|
||||
$websiteSettingsService->updateSetting('contact_horario', $this->contact_horario);
|
||||
$websiteSettingsService->updateSetting('contact_location_lat', $this->contact_location_lat);
|
||||
$websiteSettingsService->updateSetting('contact_location_lng', $this->contact_location_lng);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.location-settings');
|
||||
}
|
||||
}
|
100
modules/Admin/App/Livewire/WebsiteSettings/SocialSettings.php
Normal file
100
modules/Admin/App/Livewire/WebsiteSettings/SocialSettings.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
use Modules\Admin\App\Services\WebsiteSettingsService;
|
||||
|
||||
class SocialSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-social-settings-card .notification-container";
|
||||
|
||||
public $social_whatsapp,
|
||||
$social_whatsapp_message,
|
||||
$social_facebook,
|
||||
$social_instagram,
|
||||
$social_linkedin,
|
||||
$social_tiktok,
|
||||
$social_x_twitter,
|
||||
$social_google,
|
||||
$social_pinterest,
|
||||
$social_youtube,
|
||||
$social_vimeo;
|
||||
|
||||
protected $listeners = ['saveSocialSettings' => 'save'];
|
||||
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getSocialVars();
|
||||
|
||||
$this->social_whatsapp = $settings['whatsapp'];
|
||||
$this->social_whatsapp_message = $settings['whatsapp_message'];
|
||||
$this->social_facebook = $settings['facebook'];
|
||||
$this->social_instagram = $settings['instagram'];
|
||||
$this->social_linkedin = $settings['linkedin'];
|
||||
$this->social_tiktok = $settings['tiktok'];
|
||||
$this->social_x_twitter = $settings['x_twitter'];
|
||||
$this->social_google = $settings['google'];
|
||||
$this->social_pinterest = $settings['pinterest'];
|
||||
$this->social_youtube = $settings['youtube'];
|
||||
$this->social_vimeo = $settings['vimeo'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'social_whatsapp' => 'string|max:20',
|
||||
'social_whatsapp_message' => 'string|max:255',
|
||||
'social_facebook' => 'url',
|
||||
'social_instagram' => 'url',
|
||||
'social_linkedin' => 'url',
|
||||
'social_tiktok' => 'url',
|
||||
'social_x_twitter' => 'url',
|
||||
'social_google' => 'url',
|
||||
'social_pinterest' => 'url',
|
||||
'social_youtube' => 'url',
|
||||
'social_vimeo' => 'url',
|
||||
]);
|
||||
|
||||
$websiteSettingsService = app(websiteSettingsService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteSettingsService->updateSetting('social_whatsapp', preg_replace('/\D/', '', $this->social_whatsapp));
|
||||
$websiteSettingsService->updateSetting('social_whatsapp_message', $this->social_whatsapp_message);
|
||||
$websiteSettingsService->updateSetting('social_facebook', $this->social_facebook);
|
||||
$websiteSettingsService->updateSetting('social_instagram', $this->social_instagram);
|
||||
$websiteSettingsService->updateSetting('social_linkedin', $this->social_linkedin);
|
||||
$websiteSettingsService->updateSetting('social_tiktok', $this->social_tiktok);
|
||||
$websiteSettingsService->updateSetting('social_x_twitter', $this->social_x_twitter);
|
||||
$websiteSettingsService->updateSetting('social_google', $this->social_google);
|
||||
$websiteSettingsService->updateSetting('social_pinterest', $this->social_pinterest);
|
||||
$websiteSettingsService->updateSetting('social_youtube', $this->social_youtube);
|
||||
$websiteSettingsService->updateSetting('social_vimeo', $this->social_vimeo);
|
||||
|
||||
app(WebsiteTemplateService::class)->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.social-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
|
||||
class TemplateSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-template-settings-card .notification-container";
|
||||
|
||||
public $website_tpl_style_switcher,
|
||||
$website_tpl_footer_text;
|
||||
|
||||
protected $listeners = ['saveTemplateSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->website_tpl_style_switcher = $settings['template']['style_switcher'];
|
||||
$this->website_tpl_footer_text = $settings['template']['footer_text'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'website_tpl_footer_text' => 'nullable|string|max:50',
|
||||
]);
|
||||
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteTemplateService->updateSetting('website_tpl_style_switcher', $this->website_tpl_style_switcher);
|
||||
$websiteTemplateService->updateSetting('website_tpl_footer_text', $this->website_tpl_footer_text);
|
||||
|
||||
$websiteTemplateService->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.template-settings');
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Livewire\WebsiteSettings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Services\WebsiteTemplateService;
|
||||
|
||||
class WebsiteSettings extends Component
|
||||
{
|
||||
private $targetNotify = "#website-settings-card .notification-container";
|
||||
|
||||
public $website_title,
|
||||
$website_description;
|
||||
|
||||
protected $listeners = ['saveWebsiteSettings' => 'save'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
public function loadSettings()
|
||||
{
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Obtener los valores de las configuraciones de la base de datos
|
||||
$settings = $websiteTemplateService->getWebsiteVars();
|
||||
|
||||
$this->website_title = $settings['title'];
|
||||
$this->website_description = $settings['description'];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'website_title' => 'string|required|max:50',
|
||||
'website_description' => 'string|max:160',
|
||||
]);
|
||||
|
||||
$websiteTemplateService = app(WebsiteTemplateService::class);
|
||||
|
||||
// Guardar título del App en configuraciones
|
||||
$websiteTemplateService->updateSetting('website_title', $this->website_title);
|
||||
$websiteTemplateService->updateSetting('website_description', $this->website_description);
|
||||
|
||||
$websiteTemplateService->clearWebsiteVarsCache();
|
||||
|
||||
$this->loadSettings();
|
||||
|
||||
$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.website-settings');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user