Laravel 11, Vuexy Admin 10.3, by admin@koneko.mx

This commit is contained in:
2025-01-25 04:23:40 -06:00
parent c3045b43b1
commit 64d505910f
1283 changed files with 140198 additions and 0 deletions

View File

@ -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');
}
}

View 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');
}
}

View 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');
}
}

View File

@ -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');
}
}

View 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');
}
}