mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'feat/sk-31' into 'main'
Feat/sk 31 See merge request jjimenez/safekat!605
This commit is contained in:
@ -28,7 +28,7 @@ class Email extends BaseConfig
|
||||
/**
|
||||
* SMTP Server Hostname
|
||||
*/
|
||||
public string $SMTPHost = 'smtp.ionos.es';
|
||||
public string $SMTPHost = 'localhost';
|
||||
|
||||
/**
|
||||
* SMTP Username
|
||||
@ -38,7 +38,7 @@ class Email extends BaseConfig
|
||||
/**
|
||||
* SMTP Password
|
||||
*/
|
||||
public string $SMTPPass = 'H%5&qDkDkWnfLTGN';
|
||||
public string $SMTPPass = '';
|
||||
|
||||
/**
|
||||
* SMTP Port
|
||||
|
||||
@ -133,6 +133,9 @@ $routes->group('configuracion', ['namespace' => 'App\Controllers\Configuracion']
|
||||
$routes->get('edit/(:num)', 'MaquinaTarea::viewForm/$1', ['as' => 'maquinaTareaViewForm']);
|
||||
$routes->get('datatable', 'MaquinaTarea::datatable', ['as' => 'maquinaTareaDatatable']);
|
||||
});
|
||||
$routes->group("messages", ["namespace" => 'App\Controllers\Chat'], function ($routes) {
|
||||
$routes->get('', 'ChatController::config_view', ['as' => 'configMessagesIndex']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -903,18 +906,30 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
|
||||
$routes->post('direct/messages/unread/(:num)', 'ChatController::update_chat_direct_message_unread/$1', ['as' => 'updateChatDirectMessageUnread']);
|
||||
|
||||
|
||||
$routes->get('departments', 'ChatController::get_chat_departments', ['as' => 'getChatDepartments']);
|
||||
$routes->post('department', 'ChatController::store_chat_department', ['as' => 'storeChatDepartment']);
|
||||
$routes->delete('department/(:num)', 'ChatController::delete_chat_department/$1', ['as' => 'deleteChatDepartment']);
|
||||
$routes->post('department/update/(:num)', 'ChatController::update_chat_department/$1', ['as' => 'updateChatDepartment']);
|
||||
$routes->get('departments/(:alpha)/(:num)', 'ChatController::get_chat_departments/$1/$2', ['as' => 'getChatDepartments']);
|
||||
$routes->get('departments/select', 'ChatController::get_chat_department_select', ['as' => 'getChatDepartmentSelect']);
|
||||
$routes->get('department/presupuesto/(:num)/(:num)', 'ChatController::get_chat_presupuesto/$1/$2', ['as' => 'getChatPresupuesto']);
|
||||
$routes->get('department/pedido/(:num)/(:num)', 'ChatController::get_chat_pedido/$1/$2', ['as' => 'getChatPedido']);
|
||||
$routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']);
|
||||
$routes->get('department/(:num)/users', 'ChatController::get_chat_department_users/$1', ['as' => 'getChatDepartmentUsers']);
|
||||
$routes->get('department/users/presupuesto/(:num)/(:num)', 'ChatController::get_chat_department_presupuesto_users/$1/$2', ['as' => 'getPresupuestoChatDepartmentUsers']);
|
||||
$routes->get('department/datatable', 'ChatController::chat_department_datatable', ['as' => 'chatDepartmentDatatable']);
|
||||
$routes->get('department/edit/(:num)', 'ChatController::chat_department_edit/$1', ['as' => 'chatDepartmentEditView']);
|
||||
$routes->get('department/users/datatable/(:num)', 'ChatController::chat_department_user_datatable/$1', ['as' => 'chatDepartmentUsersDatatable']);
|
||||
$routes->get('department/users/pedido/(:num)/(:num)', 'ChatController::get_chat_department_pedido_users/$1/$2', ['as' => 'getPedidoChatDepartmentUsers']);
|
||||
$routes->get('department/users/factura/(:num)/(:num)', 'ChatController::get_chat_department_factura_users/$1/$2', ['as' => 'getFacturaChatDepartmentUsers']);
|
||||
$routes->get('department/users/select/add/(:num)', 'ChatController::select_users_not_in_chat_department/$1', ['as' => 'selectUsersNotInChatDepartment']);
|
||||
$routes->post('department/user', 'ChatController::subscribe_to_chat_deparment/$1', ['as' => 'subscribeToChatDepartment']);
|
||||
$routes->post('department/subscribe/admin/user', 'ChatController::subscribe_admin_to_department', ['as' => 'subscribeAdminToChatDepartment']);
|
||||
$routes->delete('department/user/(:num)', 'ChatController::delete_user_from_department/$1', ['as' => 'deleteUserFromDepartment']);
|
||||
$routes->delete('department/admin/user/(:num)/(:num)', 'ChatController::delete_user_admin_from_department/$1/$2', ['as' => 'deleteUserAdminFromDepartment']);
|
||||
|
||||
|
||||
$routes->get('(:num)', 'ChatController::get_chat/$1', ['as' => 'getChat']);
|
||||
$routes->post('message/error/presupuesto', 'ChatController::store_chat_error_message', ['as' => 'storeChatErrorMessage']);
|
||||
$routes->post('message/presupuesto', 'ChatController::store_chat_message_presupuesto', ['as' => 'storeChatMessagePresupuesto']);
|
||||
$routes->post('message/pedido', 'ChatController::store_chat_message_pedido', ['as' => 'storeChatMessagePedido']);
|
||||
$routes->post('message/factura', 'ChatController::store_chat_message_factura', ['as' => 'storeChatMessageFactura']);
|
||||
$routes->post('message/(:alpha)', 'ChatController::store_message/$1', ['as' => 'storeChatMessage']);
|
||||
$routes->post('message/internal', 'ChatController::store_chat_message_single', ['as' => 'storeChatMessageSingle']);
|
||||
$routes->get('contacts', 'ChatController::get_chat_internal_contacts', ['as' => 'getChatInternalContacts']);
|
||||
$routes->get('contacts/(:num)', 'ChatController::get_chat_internal_contact/$1', ['as' => 'getChatInternalContact']);
|
||||
@ -923,15 +938,11 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
|
||||
$routes->get('users/internal', 'ChatController::get_chat_users_internal', ['as' => 'getChatUsersInternal']);
|
||||
$routes->get('users/all', 'ChatController::get_chat_users_all', ['as' => 'getChatUsersAll']);
|
||||
|
||||
$routes->post('hebra/presupuesto', 'ChatController::store_hebra_presupuesto', ['as' => 'storeHebraPresupuesto']);
|
||||
$routes->post('hebra/pedido', 'ChatController::store_hebra_pedido', ['as' => 'storeHebraPedido']);
|
||||
$routes->post('hebra/factura', 'ChatController::store_hebra_factura', ['as' => 'storeHebraFactura']);
|
||||
$routes->post('hebra/(:alpha)', 'ChatController::store_hebra/$1', ['as' => 'storeHebra']);
|
||||
$routes->post('hebra/(:num)', 'ChatController::update_hebra/$1', ['as' => 'updateHebra']);
|
||||
$routes->get('hebra/presupuesto/(:num)', "ChatController::get_hebra_presupuesto/$1", ["as" => "getHebraPresupuesto"]);
|
||||
$routes->get('hebra/pedido/(:num)', "ChatController::get_hebra_pedido/$1", ["as" => "getHebraPedido"]);
|
||||
$routes->get('hebra/factura/(:num)', "ChatController::get_hebra_factura/$1", ["as" => "getHebraFactura"]);
|
||||
$routes->get('hebra/(:alpha)/(:num)', "ChatController::get_hebra/$1/$2", ["as" => "getHebra"]);
|
||||
|
||||
$routes->get('users/notifications-unviewed/(:num)','ChatController::get_notifications_not_viewed_from_chat/$1');
|
||||
$routes->get('users/message/notifications-unviewed/(:num)','ChatController::get_notifications_not_viewed_from_message/$1');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Config;
|
||||
|
||||
use App\Services\ChatService;
|
||||
use App\Services\FTPService;
|
||||
use App\Services\MaquinaService;
|
||||
use App\Services\MessageService;
|
||||
@ -9,6 +10,7 @@ use App\Services\PapelImpresionService;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use App\Services\ProductionService;
|
||||
use App\Services\TarifaMaquinaService;
|
||||
use CodeIgniter\Email\Email;
|
||||
|
||||
/**
|
||||
* Services Configuration file.
|
||||
@ -35,6 +37,7 @@ class Services extends BaseService
|
||||
* return new \CodeIgniter\Example();
|
||||
* }
|
||||
*/
|
||||
|
||||
public static function production(){
|
||||
return new ProductionService();
|
||||
}
|
||||
@ -53,4 +56,8 @@ class Services extends BaseService
|
||||
{
|
||||
return new MessageService();
|
||||
}
|
||||
public static function chat()
|
||||
{
|
||||
return new ChatService();
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,4 +162,15 @@ class Validation extends BaseConfig
|
||||
],
|
||||
|
||||
];
|
||||
public array $chat_department =
|
||||
[
|
||||
"display" => [
|
||||
"rules" => "required|string",
|
||||
"label" => "tarifa acabado",
|
||||
],
|
||||
"description" => [
|
||||
"rules" => "permit_empty",
|
||||
"label" => "maquina",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ use App\Models\Facturas\FacturaModel;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use App\Services\ChatService;
|
||||
use App\Services\MessageService;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
@ -21,6 +22,7 @@ use CodeIgniter\Log\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Hermawan\DataTables\DataTable;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use CodeIgniter\Validation\Validation;
|
||||
|
||||
class ChatController extends BaseController
|
||||
{
|
||||
@ -32,6 +34,8 @@ class ChatController extends BaseController
|
||||
protected ClienteModel $clienteModel;
|
||||
protected ChatUser $chatUserModel;
|
||||
protected ChatNotification $chatNotificationModel;
|
||||
protected Validation $validation;
|
||||
protected ChatService $chatService;
|
||||
protected array $viewData;
|
||||
protected static $viewPath = 'themes/vuexy/form/mensajes/';
|
||||
|
||||
@ -52,12 +56,16 @@ class ChatController extends BaseController
|
||||
$this->clienteModel = model(ClienteModel::class);
|
||||
$this->chatUserModel = model(ChatUser::class);
|
||||
$this->chatNotificationModel = model(ChatNotification::class);
|
||||
$this->validation = service("validation");
|
||||
$this->chatService = service("chat");
|
||||
|
||||
}
|
||||
public function index() {}
|
||||
public function get_chat_departments()
|
||||
public function get_chat_departments(string $model,int $modelId)
|
||||
{
|
||||
|
||||
$data = $this->chatDeparmentModel->getChatDepartments();
|
||||
$data = $this->chatService->getChatDepartments($model,$modelId);
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_select()
|
||||
@ -69,6 +77,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -77,6 +86,8 @@ class ChatController extends BaseController
|
||||
if ($chat) {
|
||||
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
|
||||
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
|
||||
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
|
||||
|
||||
$data["count"] = count($data["messages"]);
|
||||
}
|
||||
$data["chat"] = $chat;
|
||||
@ -86,6 +97,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -94,6 +106,8 @@ class ChatController extends BaseController
|
||||
if ($chat) {
|
||||
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
|
||||
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
|
||||
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
|
||||
|
||||
$data["count"] = count($data["messages"]);
|
||||
}
|
||||
$data["chat"] = $chat;
|
||||
@ -103,6 +117,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -111,6 +126,7 @@ class ChatController extends BaseController
|
||||
if ($chat) {
|
||||
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
|
||||
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
|
||||
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
|
||||
$data["count"] = count($data["messages"]);
|
||||
}
|
||||
$data["chat"] = $chat;
|
||||
@ -192,70 +208,15 @@ class ChatController extends BaseController
|
||||
$data = $this->chatModel->getChat($chat_id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function store_chat_message_presupuesto()
|
||||
public function store_message($model)
|
||||
{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
// $data = $this->chatModel->createChatPresupuesto();
|
||||
$existChat = $this->chatModel->existChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_pedido()
|
||||
{
|
||||
$chatMessageEntity = $this->chatService->storeChatMessage($data["chat_department_id"],$model,$data["model_id"],$data);
|
||||
return $this->response->setJSON($chatMessageEntity);
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$existChat = $this->chatModel->existChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_factura()
|
||||
{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$existChat = $this->chatModel->existChatFactura($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatFactura($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatFactura($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_single()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
@ -316,50 +277,23 @@ class ChatController extends BaseController
|
||||
public function get_chat_cliente()
|
||||
{
|
||||
$cliente_id = auth()->user()->cliente_id;
|
||||
$response = [];
|
||||
if ($cliente_id) {
|
||||
$data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
|
||||
$response["totalMessages"] = 0;
|
||||
$response["chatFacturas"] = $this->chatModel->getClienteChatFacturas($data["facturas"]);
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
|
||||
foreach ($response["chatFacturas"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["chatPresupuestos"] = $this->chatModel->getClienteChatPresupuestos($data["presupuestos"]);
|
||||
foreach ($response["chatPresupuestos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
foreach ($mensajes_directos as $value) {
|
||||
$response["internals"][] = $value;
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["chatPedidos"] = $this->chatModel->getClienteChatPedidos($data["pedidos"]);
|
||||
foreach ($response["chatPedidos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["data"] = $data;
|
||||
} else {
|
||||
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
|
||||
$internal_notifications = $this->chatModel->getChatInternalNotifications();
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
foreach ($internal_notifications as $value) {
|
||||
$response["internals"][] = $value;
|
||||
}
|
||||
foreach ($mensajes_directos as $value) {
|
||||
$response["internals"][] = $value;
|
||||
}
|
||||
$response["totalMessages"] = 0;
|
||||
foreach ($response["internals"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
}
|
||||
$response = $this->chatService->getAuthUserNotifications();
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function get_chat_department_users(int $chat_department_id)
|
||||
public function get_chat_department_presupuesto_users(int $chat_department_id, int $presupuesto_id)
|
||||
{
|
||||
$data = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($presupuesto_id, 'presupuesto');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_pedido_users(int $chat_department_id, $pedido_id)
|
||||
{
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($pedido_id, 'pedido');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_factura_users(int $chat_department_id, $factura_id)
|
||||
{
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($factura_id, 'factura');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_users_internal()
|
||||
@ -466,80 +400,14 @@ class ChatController extends BaseController
|
||||
|
||||
return $this->response->setJSON($query->get()->getResultObject());
|
||||
}
|
||||
public function store_hebra_presupuesto()
|
||||
public function store_hebra(string $model)
|
||||
{
|
||||
$auth_user = auth()->user();
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"presupuesto_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => $auth_user->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$bodyData["users"][] = $auth_user->id;
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
$status = $this->chatService->storeHebra($model,$bodyData['modelId'],$bodyData);
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => $status]);
|
||||
}
|
||||
|
||||
public function store_hebra_pedido()
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"pedido_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => auth()->user()->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
}
|
||||
|
||||
public function store_hebra_factura()
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"factura_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => auth()->user()->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
}
|
||||
public function update_hebra($chat_id)
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
@ -550,11 +418,7 @@ class ChatController extends BaseController
|
||||
]);
|
||||
$actualUsers = $this->chatUserModel->builder()->select("user_id")->where("chat_id", $chat_id)->get()->getResultArray();
|
||||
$actualUsersArray = array_map(fn($x) => $x["user_id"], $actualUsers);
|
||||
foreach ($actualUsersArray as $key => $user_id) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $user_id]
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($bodyData["users"])) {
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
if (in_array($userId, $actualUsersArray) == false) {
|
||||
@ -568,55 +432,13 @@ class ChatController extends BaseController
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra actualizada correctamente", "status" => true]);
|
||||
}
|
||||
public function get_hebra_presupuesto($presupuesto_id)
|
||||
public function get_hebra(string $model,int $modelId)
|
||||
{
|
||||
$data = $this->chatModel->getPresupuestoHebras($presupuesto_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.presupuesto_id", $presupuesto_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_hebra_pedido($pedido_id)
|
||||
{
|
||||
$data = $this->chatModel->getPedidoHebras($pedido_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.pedido_id", $pedido_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_hebra_factura($factura_id)
|
||||
{
|
||||
$data = $this->chatModel->getFacturaHebras($factura_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.factura_id", $factura_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
$data = $this->chatService->getHebras($model,$modelId);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
|
||||
|
||||
public function datatable_messages()
|
||||
{
|
||||
$auth_user_id = auth()->user()->id;
|
||||
@ -646,9 +468,9 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "presupuesto", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("action", fn($q) => ["type" => "presupuesto", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
@ -662,9 +484,9 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "pedido", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->add("action", fn($q) => ["type" => "pedido", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
@ -679,19 +501,28 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "factura", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->add("action", fn($q) => ["type" => "factura", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
|
||||
->toJson(true);
|
||||
}
|
||||
public function get_notifications_not_viewed_from_chat(int $chat_id)
|
||||
public function get_notifications_not_viewed_from_message(int $chat_message_id)
|
||||
{
|
||||
$data = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_id);
|
||||
return $this->response->setJSON(["data" => $data, "chat_id" => $chat_id]);
|
||||
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_message_id);
|
||||
// $viewedNotifications = $this->chatModel->getUsersNotificationViewedFromChat($chat_message_id);
|
||||
|
||||
return $this->response->setJSON(
|
||||
[
|
||||
"data" => [
|
||||
"notifications" => $unviewedNotifications,
|
||||
],
|
||||
"chat_message_id" => $chat_message_id
|
||||
]
|
||||
);
|
||||
}
|
||||
public function store_new_direct_message()
|
||||
{
|
||||
@ -800,4 +631,144 @@ class ChatController extends BaseController
|
||||
$r = $messageService->createErrorMessagePresupuesto("Error", $bodyData['presupuesto_id']);
|
||||
return $this->response->setJSON(["message" => "ok", "data" => $r]);
|
||||
}
|
||||
public function delete_user_from_department($chat_department_id)
|
||||
{
|
||||
$data = $this->request->getRawInput();
|
||||
$user_id = auth()->user()->id;
|
||||
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)
|
||||
->where('user_id', $user_id)
|
||||
->where('pedido_id', null)
|
||||
->where('factura_id', null)
|
||||
->where('presupuesto_id', null)->countAllResults();
|
||||
if ($adminExist) {
|
||||
return $this->response->setJSON(["message" => lang('Chat.exit_admin_chat_wrong'), "status" => false]);
|
||||
}
|
||||
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->where($data['model_fk'], $data['model_id_fk']);
|
||||
if ($chatDepartmentUserEntity->countAllResults() > 0) {
|
||||
$deleted = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->delete(purge: true);
|
||||
return $this->response->setJSON(["message" => lang('Chat.exit_chat_ok'), "status" => true]);
|
||||
} else {
|
||||
return $this->response->setJSON(["message" => lang('Chat.exit_chat_wrong'), "status" => false]);
|
||||
}
|
||||
}
|
||||
public function delete_user_admin_from_department($chat_department_id, $user_id)
|
||||
{
|
||||
$this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->delete();
|
||||
return $this->response->setJSON(["message" => lang('Chat.user_deleted_ok'), "status" => true]);
|
||||
}
|
||||
public function subscribe_to_chat_deparment()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$user_id = auth()->user()->id;
|
||||
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id', $data['chat_department_id'])
|
||||
->where('user_id', $user_id)
|
||||
->where('pedido_id', null)
|
||||
->where('factura_id', null)
|
||||
->where('presupuesto_id', null)->countAllResults();
|
||||
if ($adminExist) {
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'), "status" => false]);
|
||||
}
|
||||
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id', $data['chat_department_id'])->where('user_id', $user_id)->where($data['model_fk'], $data['model_id_fk']);
|
||||
if ($chatDepartmentUserEntity->countAllResults() > 0) {
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'), "status" => false]);
|
||||
} else {
|
||||
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"], "user_id" => $user_id, $data['model_fk'] => $data['model_id_fk']]);
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_ok'), "status" => true]);
|
||||
}
|
||||
}
|
||||
public function subscribe_admin_to_department()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
if ($data['user_id']) {
|
||||
|
||||
$this->chatDeparmentUserModel
|
||||
->insert(
|
||||
[
|
||||
"chat_department_id" => $data["chat_department_id"],
|
||||
"user_id" => $data["user_id"],
|
||||
]
|
||||
);
|
||||
return $this->response->setJSON(["message" => lang('Chat.subscribe_admin_chat_ok'), "status" => true]);
|
||||
} else {
|
||||
return $this->response->setStatusCode(422)->setJSON(["message" => lang('Chat.subscribe_admin_chat_wrong'), "status" => false]);
|
||||
}
|
||||
}
|
||||
public function config_view()
|
||||
{
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_configuration"), 'route' => 'javascript:void(0);', 'active' => false],
|
||||
['title' => lang("App.menu_config_messages"), 'route' => route_to("configMessagesIndex"), 'active' => true]
|
||||
];
|
||||
|
||||
return view('themes/vuexy/form/configuracion/messages/configView', $this->viewData);
|
||||
}
|
||||
public function chat_department_edit($chat_department_id)
|
||||
{
|
||||
$chatDepartment = $this->chatDeparmentModel->find($chat_department_id);
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_configuration"), 'route' => 'javascript:void(0);', 'active' => false],
|
||||
['title' => lang("App.menu_config_messages"), 'route' => route_to("configMessagesIndex"), 'active' => false],
|
||||
['title' => $chatDepartment->display, 'route' => route_to("chatDepartmentEditView", $chat_department_id), 'active' => true]
|
||||
|
||||
];
|
||||
$this->viewData["chat_department"] = $chatDepartment;
|
||||
return view('themes/vuexy/form/configuracion/messages/editChatDepartmentForm', $this->viewData);
|
||||
}
|
||||
public function chat_department_datatable()
|
||||
{
|
||||
$q = $this->chatDeparmentModel->datatableQuery();
|
||||
return DataTable::of($q)
|
||||
->add('action', fn($r) => $r->id)
|
||||
->toJson(true);
|
||||
}
|
||||
public function chat_department_user_datatable(int $chat_department_id)
|
||||
{
|
||||
$q = $this->chatDeparmentUserModel->datatableQuery($chat_department_id);
|
||||
$datatable = DataTable::of($q);
|
||||
if (auth()->user()->inGroup('admin')) {
|
||||
$datatable->add('action', fn($r) => $r->userId);
|
||||
}
|
||||
return $datatable->toJson(true);
|
||||
}
|
||||
public function select_users_not_in_chat_department(int $chat_department_id)
|
||||
{
|
||||
$paramQuery = $this->request->getGet("q");
|
||||
$data = $this->chatDeparmentUserModel->querySelectUsersNotInDepartment($chat_department_id, $paramQuery);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function store_chat_department()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$validated = $this->validation->run($data, 'chat_department');
|
||||
if ($validated) {
|
||||
$dataValidated = $this->validation->getValidated();
|
||||
$dataValidated['name'] = newUUID();
|
||||
$this->chatDeparmentModel->insert($dataValidated);
|
||||
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true, "data" => $dataValidated]);
|
||||
} else {
|
||||
return $this->response->setStatusCode(422)->setJSON(["message" => lang('App.global_alert_save_success'), "status" => false, "errors" => $this->validation->getErrors()]);
|
||||
}
|
||||
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true]);
|
||||
}
|
||||
public function update_chat_department(int $chat_department_id)
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$validated = $this->validation->run($data, 'chat_department');
|
||||
if ($validated) {
|
||||
$dataValidated = $this->validation->getValidated();
|
||||
$this->chatDeparmentModel->update($chat_department_id, $dataValidated);
|
||||
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true, "data" => $dataValidated]);
|
||||
} else {
|
||||
return $this->response->setStatusCode(422)->setJSON(["message" => lang('App.global_alert_save_success'), "status" => false, "errors" => $this->validation->getErrors()]);
|
||||
}
|
||||
}
|
||||
public function delete_chat_department($chat_department_id)
|
||||
{
|
||||
if (auth()->user()->inGroup('admin')) {
|
||||
$this->chatDeparmentModel->delete($chat_department_id);
|
||||
return $this->response->setJSON(["message" => lang('App.user_alert_delete'), "status" => true]);
|
||||
} else {
|
||||
return $this->response->setStatusCode(403)->setJSON(["message" => lang('App.user_alert_forbidden'), "status" => false]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class AddForeignChatDepartmentUsers extends Migration
|
||||
{
|
||||
protected array $COLUMNS = [
|
||||
"pedido_id" => [
|
||||
"type" => "INT",
|
||||
"constraint" => 16,
|
||||
"unsigned" => true,
|
||||
"null" => true
|
||||
],
|
||||
"presupuesto_id" => [
|
||||
"type" => "INT",
|
||||
"constraint" => 10,
|
||||
"unsigned" => true,
|
||||
"null" => true
|
||||
],
|
||||
"factura_id" => [
|
||||
"type" => "INT",
|
||||
"constraint" => 10,
|
||||
"unsigned" => true,
|
||||
"null" => true
|
||||
],
|
||||
];
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addColumn("chat_department_users",$this->COLUMNS);
|
||||
$this->forge->addForeignKey('pedido_id', 'pedidos', 'id');
|
||||
$this->forge->addForeignKey('factura_id', 'facturas', 'id');
|
||||
$this->forge->addForeignKey('presupuesto_id', 'presupuestos', 'id');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropForeignKey("chat_department_users","pedido_id");
|
||||
$this->forge->dropForeignKey("chat_department_users","factura_id");
|
||||
$this->forge->dropForeignKey("chat_department_users","presupuesto_id");
|
||||
$this->forge->dropColumn("chat_department_users",["pedido_id","factura_id","presupuesto_id"]);
|
||||
}
|
||||
}
|
||||
79
ci4/app/Entities/Chat/ChatDepartmentEntity.php
Normal file
79
ci4/app/Entities/Chat/ChatDepartmentEntity.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Models\Chat\ChatDeparmentUserModel;
|
||||
use App\Models\Chat\ChatModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
|
||||
class ChatDepartmentEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => null,
|
||||
"name" => null,
|
||||
"display" => null,
|
||||
"description" => null,
|
||||
"type" => null,
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"name" => "string",
|
||||
"display" => "string",
|
||||
"description" => "?string",
|
||||
"type" => "string",
|
||||
];
|
||||
|
||||
/**
|
||||
* Chat department users that are in department as administrador. These users belongs to department in all chats in any model associated and
|
||||
* will receive notifications always
|
||||
*
|
||||
* @return array<ChatDepartmentEntity>
|
||||
*/
|
||||
public function chatDepartmentAdminUsers(){
|
||||
$m = model(ChatDeparmentUserModel::class);
|
||||
$chatDepartmentUsers = $m->where('chat_department_id',$this->attributes['id'])
|
||||
->where('pedido_id',null)
|
||||
->where('factura_id',null)
|
||||
->where('presupuesto_id',null)->findAll();
|
||||
return $chatDepartmentUsers;
|
||||
}
|
||||
/**
|
||||
* Chat department users that has been associated to the department by sending a
|
||||
* message and users that are not as admin of the department that has written a message.
|
||||
*
|
||||
* @param integer $modelFkId Id from model associated
|
||||
* @param string $model Name of the model associated `['presupuesto','pedido','factura']`
|
||||
* @return array<ChatDepartmentEntity>
|
||||
*/
|
||||
public function chatDepartmentExternalUsers(int $modelFkId,string $model = "presupuesto") : array
|
||||
{
|
||||
$m = model(ChatDeparmentUserModel::class);
|
||||
$m->where('chat_department_id',$this->attributes['id']);
|
||||
|
||||
switch ($model) {
|
||||
case 'presupuesto':
|
||||
$m->where('presupuesto_id',$modelFkId);
|
||||
break;
|
||||
case 'pedido':
|
||||
$m->where('pedido_id',$modelFkId);
|
||||
break;
|
||||
case 'factura':
|
||||
$m->where('pedido_id',$modelFkId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $m->findAll() ?? [];
|
||||
|
||||
}
|
||||
public function withUsers(int $modelFkId,string $model = "presupuesto") : self
|
||||
{
|
||||
$externalUsers = $this->chatDepartmentExternalUsers($modelFkId,$model);
|
||||
$this->attributes["adminUsers"] = array_map(fn(ChatDepartmentUserEntity $du) => $du->user()->withAvatar() , $this->chatDepartmentAdminUsers());
|
||||
$this->attributes["externalUsers"] = array_map(fn(ChatDepartmentUserEntity $du) => $du->user()->withAvatar() , $externalUsers);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
60
ci4/app/Entities/Chat/ChatDepartmentUserEntity.php
Normal file
60
ci4/app/Entities/Chat/ChatDepartmentUserEntity.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Entities\Facturas\FacturaEntity;
|
||||
use App\Entities\Pedidos\PedidoEntity;
|
||||
use App\Entities\Presupuestos\PresupuestoEntity;
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatDeparmentModel;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class ChatDepartmentUserEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"chat_department_id" => null,
|
||||
"user_id" => null,
|
||||
"pedido_id" => null,
|
||||
"factura_id" => null,
|
||||
"presupuesto_id" => null,
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"chat_department_id" => "integer",
|
||||
"user_id" => "integer",
|
||||
"pedido_id" => "?integer",
|
||||
"factura_id" => "?integer",
|
||||
"presupuesto_id" => "?integer",
|
||||
];
|
||||
|
||||
public function user() : ?UserEntity
|
||||
{
|
||||
$m = model(UserModel::class);
|
||||
return $m->find($this->attributes['user_id']);
|
||||
}
|
||||
public function department() : ?ChatDepartmentEntity
|
||||
{
|
||||
$m = model(ChatDeparmentModel::class);
|
||||
return $m->find($this->attributes['chat_department_id']);
|
||||
}
|
||||
public function presupuesto() : ?PresupuestoEntity
|
||||
{
|
||||
$m = model(PresupuestoModel::class);
|
||||
return $m->find($this->attributes['presupuesto_id']);
|
||||
}
|
||||
public function pedido() : ?PedidoEntity
|
||||
{
|
||||
$m = model(PedidoModel::class);
|
||||
return $m->find($this->attributes['pedido_id']);
|
||||
}
|
||||
public function factura() : ?FacturaEntity
|
||||
{
|
||||
$m = model(FacturaEntity::class);
|
||||
return $m->find($this->attributes['factura_id']);
|
||||
}
|
||||
|
||||
}
|
||||
148
ci4/app/Entities/Chat/ChatEntity.php
Normal file
148
ci4/app/Entities/Chat/ChatEntity.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Entities\Facturas\FacturaEntity;
|
||||
use App\Entities\Pedidos\PedidoEntity;
|
||||
use App\Entities\Presupuestos\PresupuestoEntity;
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatDeparmentModel;
|
||||
use App\Models\Chat\ChatMessageModel;
|
||||
use App\Models\ChatUser;
|
||||
use App\Models\Facturas\FacturaModel;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
use CodeIgniter\Model;
|
||||
use stdClass;
|
||||
|
||||
class ChatEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => null,
|
||||
"chat_department_id" => null,
|
||||
"pedido_id" => null,
|
||||
"presupuesto_id" => null,
|
||||
"factura_id" => null,
|
||||
"title" => null
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"chat_department_id" => "?integer",
|
||||
"pedido_id" => "?integer",
|
||||
"presupuesto_id" => "?integer",
|
||||
"factura_id" => "?integer",
|
||||
"title" => "string"
|
||||
];
|
||||
|
||||
public function withMessages(): self
|
||||
{
|
||||
$auth_user = auth()->user();
|
||||
$messages = $this->messages();
|
||||
foreach ($messages as $key => $message) {
|
||||
if ($message->sender_id == $auth_user->id) {
|
||||
$message->pos = 'right';
|
||||
} else {
|
||||
$message->pos = 'left';
|
||||
}
|
||||
}
|
||||
$this->attributes["messages"] = $messages;
|
||||
return $this;
|
||||
}
|
||||
public function department(): ?ChatDepartmentEntity
|
||||
{
|
||||
$m = model(ChatDeparmentModel::class);
|
||||
return $m->find($this->attributes['chat_department_id']);
|
||||
}
|
||||
public function presupuesto(): ?PresupuestoEntity
|
||||
{
|
||||
$m = model(PresupuestoModel::class);
|
||||
return $m->find($this->attributes['presupuesto_id']);
|
||||
}
|
||||
public function pedido(): ?PedidoEntity
|
||||
{
|
||||
$m = model(PedidoModel::class);
|
||||
return $m->find($this->attributes['pedido_id']);
|
||||
}
|
||||
public function factura(): ?FacturaEntity
|
||||
{
|
||||
$m = model(FacturaEntity::class);
|
||||
return $m->find($this->attributes['factura_id']);
|
||||
}
|
||||
public function messages(): ?array
|
||||
{
|
||||
$m = model(ChatMessageModel::class);
|
||||
|
||||
$messages = $m->where('chat_id', $this->attributes["id"])->findAll();
|
||||
return array_map(fn(ChatMessageEntity $m) => $m->withUser(), $messages);
|
||||
}
|
||||
public function withHebra(): self
|
||||
{
|
||||
$this->attributes["messages"] = array_map(fn(ChatMessageEntity $m) => $m->withUser(), $this->messages());
|
||||
$this->attributes["internalUsers"] = array_map(fn(ChatUserEntity $u) => $u->user(), $this->internalUsers());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<ChatUserEntity>
|
||||
*/
|
||||
public function internalUsers(): array
|
||||
{
|
||||
$m = model(ChatUser::class);
|
||||
return $m->where('chat_id', $this->attributes["id"])->findAll() ?? [];
|
||||
}
|
||||
public function getModel(): ?Model
|
||||
{
|
||||
$model = null;
|
||||
$models = [
|
||||
"presupuesto_id" => model(PresupuestoModel::class),
|
||||
"pedido_id" => model(PedidoModel::class),
|
||||
"factura_id" => model(FacturaModel::class)
|
||||
];
|
||||
$fks = [
|
||||
"presupuesto_id" => $this->attributes["presupuesto_id"],
|
||||
"pedido_id" => $this->attributes["pedido_id"],
|
||||
"factura_id" => $this->attributes["factura_id"],
|
||||
];
|
||||
foreach ($fks as $key => $fk) {
|
||||
if ($fk) {
|
||||
$model = $models[$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
public function relatedFk(): array
|
||||
{
|
||||
$relatedFk = null;
|
||||
$relatedFkValue = null;
|
||||
$fks = [
|
||||
"presupuesto" => $this->attributes["presupuesto_id"],
|
||||
"pedido" => $this->attributes["pedido_id"],
|
||||
"factura" => $this->attributes["factura_id"],
|
||||
];
|
||||
foreach ($fks as $key => $fk) {
|
||||
if ($fk) {
|
||||
$relatedFk = $key;
|
||||
$relatedFkValue = $fk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [
|
||||
"relatedModel" => $relatedFk,
|
||||
"relatedFkValue" => $relatedFkValue
|
||||
];
|
||||
}
|
||||
public function withModel() : self
|
||||
{
|
||||
if($this->getModel()){
|
||||
$this->attributes["modelData"] = $this->getModel()->find($this->relatedFk()['relatedFkValue']);
|
||||
}else{
|
||||
$this->attributes["modelData"] = null;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
65
ci4/app/Entities/Chat/ChatMessageEntity.php
Normal file
65
ci4/app/Entities/Chat/ChatMessageEntity.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatModel;
|
||||
use App\Models\ChatNotification;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
use CodeIgniter\I18n\Time;
|
||||
|
||||
class ChatMessageEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => null,
|
||||
"message" => null,
|
||||
"chat_id" => null,
|
||||
"sender_id" => null,
|
||||
"receiver_id" => null,
|
||||
"viewed" => null,
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"message" => "string",
|
||||
"chat_id" => "integer",
|
||||
"sender_id" => "?integer",
|
||||
"receiver_id" => "?integer",
|
||||
"viewed" => "boolean",
|
||||
];
|
||||
protected $dates = [];
|
||||
|
||||
public function chat() : ?ChatEntity
|
||||
{
|
||||
$m = model(ChatModel::class);
|
||||
return $m->find($this->attributes['chat_id']);
|
||||
|
||||
}
|
||||
/**
|
||||
* Notifications related with this chat entity.
|
||||
*
|
||||
* @return array<ChatNotificationEntity>
|
||||
*/
|
||||
public function notifications() : array
|
||||
{
|
||||
$m = model(ChatNotification::class);
|
||||
return $m->asArray()->where('chat_id',$this->attributes['chat_id'])->findAll() ?? [];
|
||||
}
|
||||
public function sentBy() : ?UserEntity
|
||||
{
|
||||
$m = model(UserModel::class);
|
||||
return $m->find($this->attributes["sender_id"])->withAvatar();
|
||||
|
||||
}
|
||||
public function withUser() : self
|
||||
{
|
||||
$this->attributes["user"] = $this->sentBy();
|
||||
return $this;
|
||||
}
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return Time::createFromFormat("Y-m-d H:i:s",$this->attributes['created_at'])->format('d/m/Y H:i');
|
||||
|
||||
}
|
||||
}
|
||||
42
ci4/app/Entities/Chat/ChatNotificationEntity.php
Normal file
42
ci4/app/Entities/Chat/ChatNotificationEntity.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatMessageModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
use CodeIgniter\HTTP\Message;
|
||||
|
||||
class ChatNotificationEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => null,
|
||||
"chat_message_id" => null,
|
||||
"user_id" => null,
|
||||
"viewed" => null,
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"chat_message_id" => "integer",
|
||||
"user_id" => "integer",
|
||||
"viewed" => "boolean",
|
||||
];
|
||||
|
||||
public function message() : ?ChatMessageEntity
|
||||
{
|
||||
$m = model(ChatMessageModel::class);
|
||||
return $m->find($this->attributes['chat_message_id']);
|
||||
}
|
||||
public function user() : ?UserEntity
|
||||
{
|
||||
$m = model(UserModel::class);
|
||||
return $m->find($this->attributes['user_id']);
|
||||
}
|
||||
public function chat() : ?ChatEntity
|
||||
{
|
||||
return $this->message()->chat();
|
||||
}
|
||||
|
||||
}
|
||||
36
ci4/app/Entities/Chat/ChatUserEntity.php
Normal file
36
ci4/app/Entities/Chat/ChatUserEntity.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Chat;
|
||||
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class ChatUserEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"id" => null,
|
||||
"user_id" => null,
|
||||
"chat_id" => null,
|
||||
];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
"user_id" => "integer",
|
||||
"chat_id" => "integer",
|
||||
];
|
||||
|
||||
public function chat() : ?ChatEntity
|
||||
{
|
||||
$m = model(ChatModel::class);
|
||||
return $m->find($this->attributes['chat_id']);
|
||||
|
||||
}
|
||||
public function user() : ?UserEntity
|
||||
{
|
||||
$m = model(UserModel::class);
|
||||
return $m->find($this->attributes['user_id'])->withAvatar();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace App\Entities\Usuarios;
|
||||
|
||||
use App\Entities\Chat\ChatNotificationEntity;
|
||||
use App\Models\ChatNotification;
|
||||
use CodeIgniter\Entity;
|
||||
|
||||
class UserEntity extends \CodeIgniter\Entity\Entity
|
||||
@ -55,4 +57,20 @@ class UserEntity extends \CodeIgniter\Entity\Entity
|
||||
{
|
||||
return $this->getFullName();
|
||||
}
|
||||
public function withAvatar() : self
|
||||
{
|
||||
$users = auth()->getProvider();
|
||||
$this->attributes["avatar"] = md5($users->findById($this->attributes['id'])->getEmail());
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Return an array of ChatNotificationEntities that belongs to the user
|
||||
*
|
||||
* @return array<ChatNotificationEntity>
|
||||
*/
|
||||
public function chatNotifications() : array
|
||||
{
|
||||
$m = model(ChatNotification::class);
|
||||
return $m->where('user_id',$this->attributes['id'])->findAll() ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,10 @@ function getCurrentLanguageFlag(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getGravatarURL(int $size = 30)
|
||||
{
|
||||
return "https://gravatar.com/avatar/".md5(auth()->user()->getEmail())."?s=".$size;
|
||||
}
|
||||
function getAllClassFolder($folder = null){
|
||||
try {
|
||||
helper('filesystem');
|
||||
|
||||
61
ci4/app/Language/en/Chat.php
Normal file
61
ci4/app/Language/en/Chat.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"chat" => "Messages",
|
||||
"messages" => "Messages",
|
||||
"message" => "Message",
|
||||
"messages_internal" => "Internal messages",
|
||||
"message_internal" => "Internal message",
|
||||
"messages_client" => "Client messages",
|
||||
"message_client" => "Client message",
|
||||
"modal" => [
|
||||
"new_hebra" => "New thread",
|
||||
"title" => "Title",
|
||||
"new_message" => "New message",
|
||||
"new_receivers" => "New participants",
|
||||
"btn_send" => "Send",
|
||||
"btn_send_update" => "Send"
|
||||
],
|
||||
"datatable_messages" => [
|
||||
"created_at" => "Created at",
|
||||
"updated_at" => "Updated at",
|
||||
"title" => "Title",
|
||||
"creator" => "Created by",
|
||||
"viewed" => "Viewed",
|
||||
|
||||
],
|
||||
"datatable_departments" => [
|
||||
"name" => "Name",
|
||||
"description" => "Description",
|
||||
],
|
||||
"datatable_department_users" => [
|
||||
"name" => "Name",
|
||||
"user" => "User",
|
||||
],
|
||||
"new_message_ok" => "Message sent successfully",
|
||||
"participants" => "Participants",
|
||||
"choose_department" => "Choose a deparment",
|
||||
"new_participant" => "Add new participants",
|
||||
"write_message_placeholder" => "Type your message here ...",
|
||||
"add_notification" => "Notification",
|
||||
"check_as_unviewed" => "Check as not viewed",
|
||||
"add_notification_message" => "Add users present in this chat a notification",
|
||||
"chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]',
|
||||
"no_messages_notification" => 'There is no messages',
|
||||
"view_chat" => 'See chat',
|
||||
"view_by_alt_message" => 'Show users that has or not viewed the messages',
|
||||
"exit_chat" => 'Exit chat',
|
||||
"subscribe_chat" => 'Subscribe to chat',
|
||||
"exit_chat_ok" => "You have exit chat successfully. Notifications on this chat will no longer be received",
|
||||
"exit_chat_wrong" => "You can't exit the chat because you don't belong to it.",
|
||||
"subscribe_chat_ok" => "You've subscribed to chat successfully. Now on you'll receive notifications.",
|
||||
"subscribe_chat_wrong" => "You already belong to this chat.",
|
||||
"message_configuration" => "Messages configuration",
|
||||
"new_chat_department" => "New chat department",
|
||||
"user_deleted_ok" => "User deleted succesfully",
|
||||
"subscribe_admin_chat_ok" => "User added successfully",
|
||||
"subscribe_admin_chat_wrong" => "You must select a user",
|
||||
|
||||
|
||||
|
||||
];
|
||||
@ -226,6 +226,8 @@ return [
|
||||
"user_alert_add" => "¡Agregado exitosamente!",
|
||||
"user_alert_edit" => "¡Editado con éxito!",
|
||||
"user_alert_delete" => "¡Eliminado con éxito!",
|
||||
"user_alert_forbidden" => "No tienes permiso para realizar esta acción",
|
||||
|
||||
|
||||
// USER - form
|
||||
"user_add_title" => "Nuevo Usuario",
|
||||
@ -686,6 +688,7 @@ return [
|
||||
|
||||
"menu_configuration" => "Configuración",
|
||||
"menu_variables" => "Variables sistema",
|
||||
"menu_config_messages" => "Mensajería",
|
||||
"menu_error_presupuesto" => "Errores presupuesto",
|
||||
"menu_calendario" => "Calendario",
|
||||
"menu_paises" => "Paises",
|
||||
@ -824,6 +827,6 @@ return [
|
||||
"menu_soporte" => "Soporte",
|
||||
"menu_soporte_new_ticket" => "Crear ticket",
|
||||
"menu_soporte_ticket_list" => "Mis tickets",
|
||||
|
||||
"me" => "Yo",
|
||||
|
||||
];
|
||||
@ -20,10 +20,19 @@ return [
|
||||
"created_at" => "Fecha creación",
|
||||
"updated_at" => "Fecha actualización",
|
||||
"title" => "Título",
|
||||
"message" => "Mensaje",
|
||||
"creator" => "Creador",
|
||||
"viewed" => "Leído",
|
||||
|
||||
],
|
||||
"datatable_departments" => [
|
||||
"name" => "Nombre",
|
||||
"description" => "Descripción",
|
||||
],
|
||||
"datatable_department_users" => [
|
||||
"name" => "Nombre",
|
||||
"user" => "Usuario",
|
||||
],
|
||||
"new_message_ok" => "Mensaje enviado correctamente",
|
||||
"participants" => "Participantes",
|
||||
"choose_department" => "Elige un departamento",
|
||||
@ -35,5 +44,24 @@ return [
|
||||
"chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]',
|
||||
"no_messages_notification" => 'No hay mensajes que revisar por el momento',
|
||||
"view_chat" => 'Ver chat',
|
||||
"view_by_alt_message" => 'Muestra los usuarios que han leído o no los mensajes'
|
||||
"view_by_alt_message" => 'Muestra los usuarios que han leído o no los mensajes',
|
||||
"exit_chat" => 'Salir conversación',
|
||||
"subscribe_chat" => 'Subscribirse al chat',
|
||||
"exit_chat_ok" => "Ha salido de la conversación correctamente. No recibirá más notificaciones a no ser que sea añadido de nuevo.",
|
||||
"exit_chat_wrong" => "No puede salir de la conversación porque no pertenece a ella.",
|
||||
"exit_admin_chat_wrong" => "Perteneces como personal a este chat y no puedes salirte. Contacta administrador para ello.",
|
||||
"subscribe_chat_ok" => "Te has subscrito al chat correctamente. Ahora recibirás notificaciones cuando lleguen mensajes.",
|
||||
"subscribe_chat_wrong" => "Ya perteneces a este chat.",
|
||||
"message_configuration" => "Configuración mensajería",
|
||||
"new_chat_department" => "Nuevo departamento",
|
||||
"user_deleted_ok" => "Usuario eliminado con éxito",
|
||||
"department_users" => "Usuarios departamento",
|
||||
"subscribe_admin_chat_ok" => "Usuario añadido correctamente.",
|
||||
"subscribe_admin_chat_wrong" => "Tienes que seleccionar un usuario.",
|
||||
"help_select_chat_department_user" => "Solamente son listados los usuarios que pertenecen al personal. Los clientes no son listados, para añadirlos a la conversación se realiza desde la sección de mensajería de las diferentes secciones(presupuesto,pedido,factura ...)",
|
||||
"store_department" => "Crear departamento",
|
||||
"mail" => [
|
||||
"mail_subject" => "Nuevo mensaje"
|
||||
]
|
||||
|
||||
];
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Chat;
|
||||
|
||||
use App\Entities\Chat\ChatDepartmentEntity;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
@ -10,7 +11,7 @@ class ChatDeparmentModel extends Model
|
||||
protected $table = 'chat_departments';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'object';
|
||||
protected $returnType = ChatDepartmentEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
@ -89,7 +90,7 @@ class ChatDeparmentModel extends Model
|
||||
$departmentName = $row['name'];
|
||||
// If the department is not yet added to the array, initialize it
|
||||
if (!isset($departments[$departmentName])) {
|
||||
|
||||
|
||||
$departments[$departmentName] = [
|
||||
'id' => $row['id'],
|
||||
'name' => $row['name'],
|
||||
@ -105,9 +106,10 @@ class ChatDeparmentModel extends Model
|
||||
}
|
||||
return $departments;
|
||||
}
|
||||
public function getChatDepartmentUsers(int $chat_deparment_id)
|
||||
|
||||
public function getChatDeparmentUserQuery(int $chat_deparment_id)
|
||||
{
|
||||
$result = $this->builder()
|
||||
$query = $this
|
||||
->select(
|
||||
[
|
||||
"users.*"
|
||||
@ -122,27 +124,78 @@ class ChatDeparmentModel extends Model
|
||||
"users",
|
||||
"chat_department_users.user_id = users.id",
|
||||
'left'
|
||||
)->where("chat_departments.id", $chat_deparment_id)
|
||||
)
|
||||
->where("chat_department_users.chat_department_id", $chat_deparment_id)
|
||||
->where("chat_department_users.deleted_at",null)
|
||||
->where("users.deleted_at",null)
|
||||
->where("users.deleted_at",null);
|
||||
return $query;
|
||||
}
|
||||
public function getChatDepartmentUsers(int $chat_deparment_id)
|
||||
{
|
||||
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
|
||||
->where('chat_department_users.presupuesto_id',null)
|
||||
->where('chat_department_users.pedido_id',null)
|
||||
->where('chat_department_users.factura_id',null)
|
||||
->get();
|
||||
|
||||
return $result->getResultObject() ?: [];
|
||||
}
|
||||
public function getChatDeparmentPresupuestoUsers(int $chat_deparment_id, int $presupuesto_id)
|
||||
{
|
||||
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
|
||||
->where('chat_department_users.presupuesto_id', $presupuesto_id)
|
||||
->get()->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
public function getDisplay(int $chat_deparment_id) : string
|
||||
public function getChatDeparmentPedidoUsers(int $chat_deparment_id, int $pedido_id)
|
||||
{
|
||||
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
|
||||
->where('chat_department_users.pedido_id', $pedido_id)
|
||||
->get()->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
public function getChatDeparmentFacturaUsers(int $chat_deparment_id, int $factura_id)
|
||||
{
|
||||
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
|
||||
->where('chat_department_users.factura_id', $factura_id)
|
||||
->get()->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
public function getDisplay(int $chat_deparment_id): string
|
||||
{
|
||||
return $this->find($chat_deparment_id)->display;
|
||||
}
|
||||
public function getChatDepartmentSelect(string $query = null)
|
||||
public function getChatDepartmentSelect(?string $query)
|
||||
{
|
||||
$q = $this->builder()->select([
|
||||
"id",
|
||||
"display as name",
|
||||
"description"
|
||||
]);
|
||||
if($query){
|
||||
$q->orLike("display",$query)
|
||||
->orLike("name",$query);
|
||||
if ($query) {
|
||||
$q->orLike("display", $query)
|
||||
->orLike("name", $query);
|
||||
}
|
||||
return $q;
|
||||
}
|
||||
public function datatableQuery()
|
||||
{
|
||||
return $this->select(['id','display','description'])->where('deleted_at',null);
|
||||
}
|
||||
|
||||
public function getModelChatDepartments(string $modelFk,int $modelId) : array
|
||||
{
|
||||
$query = $this->builder()->select([
|
||||
'chat_departments.id',
|
||||
'chat_departments.name',
|
||||
'chat_departments.display',
|
||||
'COUNT(chat_messages.id) as countMessages'
|
||||
])
|
||||
->join('chats','chats.chat_department_id = chat_departments.id','left')
|
||||
->join('chat_messages','chat_messages.chat_id = chats.id','left')
|
||||
->where($modelFk,$modelId)
|
||||
->groupBy('chat_departments.name');
|
||||
return $query->get()->getResultArray() ?? [];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
|
||||
namespace App\Models\Chat;
|
||||
|
||||
|
||||
use App\Entities\Chat\ChatDepartmentUserEntity;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ChatDeparmentUserModel extends Model
|
||||
@ -10,12 +11,15 @@ class ChatDeparmentUserModel extends Model
|
||||
protected $table = 'chat_department_users';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $returnType = ChatDepartmentUserEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
"chat_department_id",
|
||||
"user_id"
|
||||
"user_id",
|
||||
"pedido_id",
|
||||
"factura_id",
|
||||
"presupuesto_id"
|
||||
];
|
||||
|
||||
protected bool $allowEmptyInserts = false;
|
||||
@ -47,14 +51,58 @@ class ChatDeparmentUserModel extends Model
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function getChatDepartmentUser(int $user_id)
|
||||
{
|
||||
return $this->db->table($this->table." t1")
|
||||
->select("chat_departments.*")
|
||||
->join("chat_departments","t1.chat_department_id = chat_departments.id","left")
|
||||
->where("t1.user_id",$user_id)
|
||||
->where("t1.deleted_at",null)
|
||||
->get()->getResultObject();
|
||||
|
||||
return $this->db->table($this->table . " t1")
|
||||
->select("chat_departments.*")
|
||||
->join("chat_departments", "t1.chat_department_id = chat_departments.id", "left")
|
||||
->where("t1.user_id", $user_id)
|
||||
->where("t1.deleted_at", null)
|
||||
->get()->getResultObject();
|
||||
}
|
||||
public function datatableQuery(int $chat_department_id)
|
||||
{
|
||||
return $this->builder()->select(
|
||||
[
|
||||
'users.id as userId',
|
||||
'CONCAT(users.first_name," ",users.last_name) as userFullName',
|
||||
'users.username'
|
||||
]
|
||||
)
|
||||
->join('users', 'users.id = chat_department_users.user_id', 'left')
|
||||
->join('chat_departments', 'chat_departments.id = chat_department_users.chat_department_id', 'left')
|
||||
->where('chat_departments.id', $chat_department_id)
|
||||
->where('chat_department_users.pedido_id', null)
|
||||
->where('chat_department_users.presupuesto_id', null)
|
||||
->where('chat_department_users.factura_id', null)
|
||||
->where('chat_department_users.deleted_at', null);
|
||||
}
|
||||
public function querySelectUsersNotInDepartment(int $chat_department_id, ?string $q): array
|
||||
{
|
||||
$query = $this->builder()->select([
|
||||
'users.id as userId',
|
||||
])
|
||||
->join('users', 'users.id = chat_department_users.user_id', 'left')
|
||||
->join('chat_departments', 'chat_departments.id = chat_department_users.chat_department_id', 'left')
|
||||
->where('chat_departments.id', $chat_department_id)
|
||||
->where('chat_department_users.deleted_at', null);
|
||||
|
||||
$usersInDepartment = array_map(fn($q) => $q->userId, $query->get()->getResultObject());
|
||||
$userModel = model(UserModel::class);
|
||||
$queryUser = $userModel->builder()->select([
|
||||
'id',
|
||||
'CONCAT(first_name," ",last_name) as name',
|
||||
'username as description',
|
||||
])
|
||||
->where('cliente_id',null)
|
||||
->where('deleted_at', null);
|
||||
if ($usersInDepartment) {
|
||||
$queryUser->whereNotIn("id", $usersInDepartment);
|
||||
}
|
||||
if ($q) {
|
||||
$queryUser->like('CONCAT(first_name," ",last_name)', $q);
|
||||
}
|
||||
return $queryUser->get()->getResultArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Chat;
|
||||
|
||||
use App\Entities\Chat\ChatMessageEntity;
|
||||
use App\Models\ChatNotification;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Model;
|
||||
@ -12,7 +13,7 @@ class ChatMessageModel extends Model
|
||||
protected $table = 'chat_messages';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'object';
|
||||
protected $returnType = ChatMessageEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
@ -45,7 +46,7 @@ class ChatMessageModel extends Model
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = [];
|
||||
protected $afterInsert = [];
|
||||
protected $afterInsert = ['callbackNewMessage'];
|
||||
protected $beforeUpdate = [];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
@ -82,7 +83,6 @@ class ChatMessageModel extends Model
|
||||
if ($auth_user->id == $message->sender_id) {
|
||||
$message->sender_first_name = $auth_user->first_name;
|
||||
$message->sender_last_name = $auth_user->last_name;
|
||||
|
||||
} else {
|
||||
$sender_user = $user->find($message->sender_id);
|
||||
$message->sender_first_name = $sender_user->first_name;
|
||||
@ -133,10 +133,10 @@ class ChatMessageModel extends Model
|
||||
->where("receiver_id", auth()->user()->id)->countAllResults();
|
||||
return $messagesFromReceiver;
|
||||
}
|
||||
public function get_chat_department_messages_count(int $chat_id) : int
|
||||
public function get_chat_department_messages_count(int $chat_id): int
|
||||
{
|
||||
$chatDepartmentMessagesCount = $this->builder()
|
||||
->where("id",$chat_id)
|
||||
->where("id", $chat_id)
|
||||
->countAllResults();
|
||||
return $chatDepartmentMessagesCount;
|
||||
}
|
||||
@ -194,4 +194,46 @@ class ChatMessageModel extends Model
|
||||
|
||||
return $messagesFromReceiver;
|
||||
}
|
||||
public function callbackNewMessage(array $data)
|
||||
{
|
||||
$authUser = auth()->user();
|
||||
$chatNotificationModel = model(ChatNotification::class);
|
||||
$chatMessageEntity = $this->find($data["id"]);
|
||||
$chatEntity = $chatMessageEntity->chat();
|
||||
if ($chatEntity->chat_department_id) {
|
||||
$chatDepartmentEntity = $chatEntity->department();
|
||||
$adminUsers = $chatDepartmentEntity->chatDepartmentAdminUsers();
|
||||
$modelFk = $chatEntity->relatedFk();
|
||||
$externalUsers = $chatDepartmentEntity->chatDepartmentExternalUsers($modelFk["relatedFkValue"], $modelFk["relatedModel"]);
|
||||
if ($modelFk["relatedModel"] && $modelFk["relatedFkValue"]) {
|
||||
|
||||
foreach ($adminUsers as $user) {
|
||||
if ($user->user_id != $authUser->id) {
|
||||
$chatNotificationModel->insert([
|
||||
"user_id" => $user->user_id,
|
||||
"chat_message_id" => $data["id"]
|
||||
]);
|
||||
}
|
||||
}
|
||||
foreach ($externalUsers as $user) {
|
||||
if ($user->user_id != $authUser->id) {
|
||||
$chatNotificationModel->insert([
|
||||
"user_id" => $user->user_id,
|
||||
"chat_message_id" => $data["id"]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($chatEntity->internalUsers() as $user) {
|
||||
if ($user->user_id != $authUser->id) {
|
||||
$chatNotificationModel->insert([
|
||||
"user_id" => $user->user_id,
|
||||
"chat_message_id" => $data["id"]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Chat;
|
||||
|
||||
use App\Entities\Chat\ChatEntity;
|
||||
use App\Models\ChatNotification;
|
||||
use App\Models\ChatUser;
|
||||
use App\Models\Facturas\FacturaModel;
|
||||
@ -16,7 +17,7 @@ class ChatModel extends Model
|
||||
protected $table = 'chats';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'object';
|
||||
protected $returnType = ChatEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
@ -315,12 +316,6 @@ class ChatModel extends Model
|
||||
}
|
||||
public function getChatDepartmentNotifications()
|
||||
{
|
||||
$chatDeparmentModel = model(ChatDeparmentModel::class);
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
$presupuestoModel = model(PresupuestoModel::class);
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
@ -329,53 +324,43 @@ class ChatModel extends Model
|
||||
"chats.presupuesto_id as presupuestoId",
|
||||
"chats.factura_id as facturaId",
|
||||
"chats.title as chatDisplay",
|
||||
"COUNT(chat_notifications.id) as unreadMessages"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->where("chat_notifications.viewed", false)
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE)
|
||||
->groupBy('chats.id');
|
||||
|
||||
$rows = $q->get()->getResultObject();
|
||||
$auth_user = auth()->user();
|
||||
$rows_new = [];
|
||||
foreach ($rows as $row) {
|
||||
$row->unreadMessages = 0;
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
// $row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if ($auth_user->cliente_id) {
|
||||
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId . "#accordionChatPresupuesto";
|
||||
} else {
|
||||
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId . "#accordionChatPresupuesto";
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay = $row->model->titulo;
|
||||
} else {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
|
||||
$row->avatar = "PRE";
|
||||
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
// $row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/pedidos/edit/" . $row->pedidoId . "#accordionChatPedido";
|
||||
$row->title = $row->pedidoId;
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
|
||||
$row->avatar = "P";
|
||||
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
// $row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/chat/factura/" . $row->facturaId . "#accordionChatFactura";
|
||||
$row->avatar = "F";
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
|
||||
$row->title = $row->facturaId;
|
||||
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
}
|
||||
@ -383,10 +368,6 @@ class ChatModel extends Model
|
||||
}
|
||||
public function getChatInternalNotifications()
|
||||
{
|
||||
$presupuestoModel = model(PresupuestoModel::class);
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
@ -395,52 +376,41 @@ class ChatModel extends Model
|
||||
"chats.presupuesto_id as presupuestoId",
|
||||
"chats.factura_id as facturaId",
|
||||
"chats.title as chatDisplay",
|
||||
"COUNT(chat_messages.id) as unreadMessages"
|
||||
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->where("chat_notifications.viewed", false)
|
||||
->where("chats.chat_department_id", null);
|
||||
->where("chats.chat_department_id", null)
|
||||
->groupBy('chats.id');
|
||||
|
||||
$auth_user = auth()->user();
|
||||
$rows = $q->get()->getResultObject();
|
||||
$rows_new = [];
|
||||
foreach ($rows as $row) {
|
||||
$row->unreadMessages = 0;
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if ($auth_user->cliente_id) {
|
||||
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId . "#accordionChatPresupuesto";
|
||||
} else {
|
||||
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId . "#accordionChatPresupuesto";
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay = $row->model->titulo;
|
||||
} else {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
$row->avatar = "PRE";
|
||||
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/pedidos/edit/" . $row->pedidoId . "#accordionChatFactura";
|
||||
$row->title = $row->pedidoId;
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
$row->avatar = "P";
|
||||
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/factura/edit/" . $row->facturaId . "#accordionChatFactura";
|
||||
$row->avatar = "F";
|
||||
if ($row->chatDepartmentId) {
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
$row->title = $row->facturaId;
|
||||
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
}
|
||||
@ -587,7 +557,7 @@ class ChatModel extends Model
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public function countUnreadMessagePresupuesto($presupuesto_id): int|string
|
||||
public function countUnreadMessagePresupuesto(int $presupuesto_id): int|string
|
||||
{
|
||||
return $this->builder()->select()
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
@ -676,6 +646,7 @@ class ChatModel extends Model
|
||||
->orderBy("chat_messages.created_at", 'ASC');
|
||||
return $q->get()->getFirstRow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all messages of a chat sent to an user have been viewed.
|
||||
*
|
||||
@ -683,13 +654,12 @@ class ChatModel extends Model
|
||||
* @param integer $user_id
|
||||
* @return boolean True : All messages readed
|
||||
*/
|
||||
public function isMessageChatViewed(int $chat_id, int $user_id): bool
|
||||
public function isMessageChatViewed(int $chat_message_id): bool
|
||||
{
|
||||
$q = $this->builder()->select(["chat_notifications.id"])
|
||||
$q = $this->builder()->select(["chat_notifications.id as cnId"])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", 'left')
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", 'left')
|
||||
->where("chats.id", $chat_id)
|
||||
// ->where("chat_notifications.user_id", $user_id)
|
||||
->where("chat_messages.id", $chat_message_id)
|
||||
->where("chat_notifications.viewed", false);
|
||||
$unread_messages_count = $q->countAllResults();
|
||||
if ($unread_messages_count > 0) {
|
||||
@ -705,26 +675,43 @@ class ChatModel extends Model
|
||||
* @param integer $chat_id
|
||||
* @return array True : All messages readed
|
||||
*/
|
||||
public function getUsersNotificationNotViewedFromChat(int $chat_id): array
|
||||
public function getUsersNotificationNotViewedFromChat(int $chat_message_id): array
|
||||
{
|
||||
$q = $this->builder()->distinct()->select(
|
||||
[
|
||||
"CONCAT(users.first_name,' ',users.last_name) as userFullName",
|
||||
"users.username as userName",
|
||||
"SUM(chat_notifications.viewed) as viewed_count",
|
||||
"COUNT(chat_notifications.id) as notification_count"
|
||||
|
||||
"chat_notifications.viewed"
|
||||
]
|
||||
|
||||
)
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", 'left')
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", 'left')
|
||||
->join("users", "users.id = chat_notifications.user_id", 'left')
|
||||
->where("chats.id", $chat_id)
|
||||
->where("chat_messages.id", $chat_message_id)
|
||||
->where("chat_notifications.deleted_at", null)
|
||||
->get()->getResultArray();
|
||||
return $q;
|
||||
}
|
||||
public function getUsersNotificationViewedFromChat(int $chat_message_id): array
|
||||
{
|
||||
$q = $this->builder()->distinct()->select(
|
||||
[
|
||||
"CONCAT(users.first_name,' ',users.last_name) as userFullName",
|
||||
"users.username as userName",
|
||||
"chat_notifications.viewed"
|
||||
]
|
||||
|
||||
)
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", 'left')
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", 'left')
|
||||
->join("users", "users.id = chat_notifications.user_id", 'left')
|
||||
->where("chat_messages.id", $chat_message_id)
|
||||
->where("chat_notifications.deleted_at", null)
|
||||
->where('chat_notifications.viewed', true)
|
||||
->get()->getResultArray();
|
||||
return $q;
|
||||
}
|
||||
public function getQueryDatatable(int $user_id): BaseBuilder
|
||||
{
|
||||
$query = $this->builder()
|
||||
@ -755,78 +742,93 @@ class ChatModel extends Model
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"chats.id",
|
||||
"cm.id as chatMessageId",
|
||||
"u.id as userId",
|
||||
"cm.message",
|
||||
"chats.created_at",
|
||||
"cm.updated_at",
|
||||
"chats.title",
|
||||
"
|
||||
(
|
||||
SELECT cm2.updated_at
|
||||
FROM chat_messages cm2
|
||||
WHERE cm2.chat_id = chats.id
|
||||
ORDER BY cm2.updated_at DESC LIMIT 1
|
||||
) as updated_at",
|
||||
"CONCAT(u.first_name,' ',u.last_name) as creator",
|
||||
"CONCAT('[',chats.title,']',' ',presupuestos.titulo) as title",
|
||||
])
|
||||
->join("chat_users", "chats.id = chat_users.chat_id", "left")
|
||||
->join("presupuestos", "presupuestos.id = chats.presupuesto_id", 'left')
|
||||
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->where("chats.presupuesto_id is NOT NULL", NULL, FALSE)
|
||||
->where("cm.updated_at = (
|
||||
SELECT cm2.updated_at
|
||||
FROM chat_messages cm2
|
||||
WHERE cm2.chat_id = chats.id
|
||||
ORDER BY cm2.updated_at DESC LIMIT 1
|
||||
)");
|
||||
->join("users u", "u.id = cm.sender_id", 'left')
|
||||
->where("chats.presupuesto_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("admin") == false) {
|
||||
$query->where('presupuestos.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chat_department_id is NOT NULL", NULL, FALSE);
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
return $query;
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function getQueryDatatableMessagePedido(int $user_id): BaseBuilder
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"chats.id",
|
||||
"cm.id as chatMessageId",
|
||||
"u.id as userId",
|
||||
"cm.message",
|
||||
"chats.created_at",
|
||||
"cm.updated_at",
|
||||
"chats.title",
|
||||
])
|
||||
->join("chat_users", "chat_users.chat_id = chats.id", "left")
|
||||
->join("pedidos_linea", "pedidos_linea.pedido_id = chats.pedido_id", 'left')
|
||||
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->join("presupuestos", "presupuestos.id = pedidos_linea.presupuesto_id", 'left')
|
||||
->where("chats.pedido_id is NOT NULL", NULL, FALSE)
|
||||
->where("cm.updated_at = (
|
||||
"
|
||||
(
|
||||
SELECT cm2.updated_at
|
||||
FROM chat_messages cm2
|
||||
WHERE cm2.chat_id = chats.id
|
||||
ORDER BY cm2.updated_at DESC LIMIT 1
|
||||
)");
|
||||
) as updated_at",
|
||||
"CONCAT(u.first_name,' ',u.last_name) as creator",
|
||||
"CONCAT('[',chats.title,']',' ',presupuestos.titulo) as title",
|
||||
])
|
||||
->join("pedidos_linea", "pedidos_linea.pedido_id = chats.pedido_id", 'left')
|
||||
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->join("users u", "u.id = cm.sender_id", 'left')
|
||||
->join("presupuestos", "presupuestos.id = pedidos_linea.presupuesto_id", 'left')
|
||||
->where("chats.pedido_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("admin") == false) {
|
||||
$query->where('presupuestos.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chat_department_id is NOT NULL", NULL, FALSE);
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
return $query;
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function getQueryDatatableMessageFactura(int $user_id): BaseBuilder
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select([
|
||||
"chats.id",
|
||||
"cm.id as chatMessageId",
|
||||
"u.id as userId",
|
||||
"cm.message",
|
||||
"chats.created_at",
|
||||
"cm.updated_at",
|
||||
"chats.title",
|
||||
])
|
||||
->join("chat_users", "chat_users.chat_id = chats.id", "left")
|
||||
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->join("facturas", "facturas.id = chats.factura_id", "left")
|
||||
->where("chats.factura_id is NOT NULL", NULL, FALSE)
|
||||
->where("cm.updated_at = (
|
||||
"
|
||||
(
|
||||
SELECT cm2.updated_at
|
||||
FROM chat_messages cm2
|
||||
WHERE cm2.chat_id = chats.id
|
||||
ORDER BY cm2.updated_at DESC LIMIT 1
|
||||
)");
|
||||
) as updated_at",
|
||||
"CONCAT(u.first_name,' ',u.last_name) as creator",
|
||||
"chats.title",
|
||||
])
|
||||
->join("chat_messages cm", "chats.id = cm.chat_id", "left")
|
||||
->join("users u", "u.id = cm.sender_id", 'left')
|
||||
->join("facturas", "facturas.id = chats.factura_id", "left")
|
||||
->where("chats.factura_id is NOT NULL", NULL, FALSE);
|
||||
|
||||
if (auth()->user()->inGroup("admin") == false) {
|
||||
if (auth()->user()->inGroup("admin") == false) {
|
||||
$query->where('facturas.cliente_id', auth()->user()->cliente_id)
|
||||
->where("chat_department_id is NOT NULL", NULL, FALSE);
|
||||
->where("chats.chat_department_id is NOT NULL", NULL, FALSE);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
return $query->groupBy('chatMessageId');
|
||||
}
|
||||
public function createNewDirectChat(string $title, string $message, array $users)
|
||||
{
|
||||
@ -903,16 +905,17 @@ class ChatModel extends Model
|
||||
public function setAsViewedChatUserNotifications(int $chat_id, int $user_id)
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select("chat_messages.id")
|
||||
->select("chat_notifications.id as notificationId")
|
||||
->join('chat_messages', 'chat_messages.chat_id = chats.id', 'left')
|
||||
->join('chat_notifications', 'chat_notifications.chat_message_id = chat_messages.id', 'left')
|
||||
->where('chat_notifications.user_id', $user_id)
|
||||
->where('chat_messages.chat_id', $chat_id)
|
||||
->get()->getResultObject();
|
||||
$chat_messages_ids = array_map(fn($q) => $q->id, $query);
|
||||
|
||||
$this->db->table("chat_notifications")
|
||||
->where("user_id", $user_id)
|
||||
->whereIn("chat_message_id", $chat_messages_ids)
|
||||
->update(["viewed" => true]);
|
||||
$chat_messages_ids = array_map(fn($q) => $q->notificationId, $query);
|
||||
$chatNotificationModel = model(ChatNotification::class);
|
||||
if ($chat_messages_ids) {
|
||||
$chatNotificationModel->setNotificationsAsViewed($chat_messages_ids);
|
||||
}
|
||||
}
|
||||
public function setAsViewedChatUserMessages(int $chat_id, int $user_id)
|
||||
{
|
||||
@ -924,16 +927,17 @@ class ChatModel extends Model
|
||||
public function setAsUnviewedChatUserNotifications(int $chat_id, int $user_id)
|
||||
{
|
||||
$query = $this->builder()
|
||||
->select("chat_messages.id")
|
||||
->select("chat_notifications.id as notificationId")
|
||||
->join('chat_messages', 'chat_messages.chat_id = chats.id', 'left')
|
||||
->join('chat_notifications', 'chat_notifications.chat_message_id = chat_messages.id', 'left')
|
||||
->where('chat_notifications.user_id', $user_id)
|
||||
->where('chat_messages.chat_id', $chat_id)
|
||||
->get()->getResultObject();
|
||||
$chat_messages_ids = array_map(fn($q) => $q->id, $query);
|
||||
|
||||
$this->db->table("chat_notifications")
|
||||
->where("user_id", $user_id)
|
||||
->whereIn("chat_message_id", $chat_messages_ids)
|
||||
->update(["viewed" => false]);
|
||||
$chat_messages_ids = array_map(fn($q) => $q->notificationId, $query);
|
||||
$chatNotificationModel = model(ChatNotification::class);
|
||||
if ($chat_messages_ids) {
|
||||
$chatNotificationModel->setNotificationsAsUnViewed($chat_messages_ids);
|
||||
}
|
||||
}
|
||||
|
||||
public function setAsUnviewedChatUserMessages(int $chat_id, int $user_id)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Entities\Chat\ChatNotificationEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ChatNotification extends Model
|
||||
@ -9,7 +10,7 @@ class ChatNotification extends Model
|
||||
protected $table = 'chat_notifications';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $returnType = ChatNotificationEntity::class;
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
@ -59,4 +60,12 @@ class ChatNotification extends Model
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
public function setNotificationsAsViewed(array $notificationIds) : bool
|
||||
{
|
||||
return $this->update($notificationIds,["viewed" => 1]);
|
||||
}
|
||||
public function setNotificationsAsUnViewed(array $notificationIds) : bool
|
||||
{
|
||||
return $this->update($notificationIds,["viewed" => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Entities\Chat\ChatUserEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ChatUser extends Model
|
||||
@ -9,7 +10,7 @@ class ChatUser extends Model
|
||||
protected $table = 'chat_users';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $returnType = ChatUserEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
|
||||
195
ci4/app/Services/ChatService.php
Normal file
195
ci4/app/Services/ChatService.php
Normal file
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Controllers\Configuracion\ConfigVariables;
|
||||
use App\Entities\Chat\ChatEntity;
|
||||
use App\Entities\Chat\ChatMessageEntity;
|
||||
use App\Entities\Chat\ChatNotificationEntity;
|
||||
use App\Entities\Usuarios\UserEntity;
|
||||
use App\Models\Chat\ChatDeparmentModel;
|
||||
use App\Models\Chat\ChatDeparmentUserModel;
|
||||
use App\Models\Chat\ChatMessageModel;
|
||||
use App\Models\Chat\ChatModel;
|
||||
use App\Models\ChatNotification;
|
||||
use App\Models\ChatUser;
|
||||
use App\Models\Configuracion\ConfigVariableModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\Email\Email;
|
||||
|
||||
class ChatService extends BaseService
|
||||
{
|
||||
protected ?ChatEntity $chatEntity;
|
||||
protected Email $emailService;
|
||||
protected UserModel $userModel;
|
||||
protected ChatModel $chatModel;
|
||||
protected ChatMessageModel $chatMessageModel;
|
||||
protected ChatUser $chatUserModel;
|
||||
protected ChatNotification $chatNotificationModel;
|
||||
protected PresupuestoModel $presupuestoModel;
|
||||
protected ChatDeparmentModel $chatDepartmentModel;
|
||||
protected ChatDeparmentUserModel $chatDepartmentUserModel;
|
||||
protected ConfigVariableModel $configVariables;
|
||||
protected array $modelFkMap = [
|
||||
"presupuesto" => "presupuesto_id",
|
||||
"pedido" => "pedido_id",
|
||||
"factura" => "factura_id",
|
||||
];
|
||||
protected array $modelClassMap;
|
||||
public function __construct()
|
||||
{
|
||||
$this->emailService = service('email');
|
||||
$this->userModel = model(UserModel::class);
|
||||
$this->chatModel = model(ChatModel::class);
|
||||
$this->chatMessageModel = model(ChatMessageModel::class);
|
||||
$this->chatNotificationModel = model(ChatNotification::class);
|
||||
$this->chatDepartmentUserModel = model(ChatDeparmentUserModel::class);
|
||||
$this->chatUserModel = model(ChatUser::class);
|
||||
$this->presupuestoModel = model(PresupuestoModel::class);
|
||||
$this->chatDepartmentModel = model(ChatDeparmentModel::class);
|
||||
$this->configVariables = model(ConfigVariableModel::class);
|
||||
}
|
||||
public function setChat($chatEntity): self
|
||||
{
|
||||
$this->chatEntity = $chatEntity;
|
||||
return $this;
|
||||
}
|
||||
public function storeChatMessage(string $chatDepartmentId, string $model, int $modelId, array $data): ?ChatMessageEntity
|
||||
{
|
||||
$this->chatEntity = $this->chatModel->where('chat_department_id', $chatDepartmentId)->where($this->modelFkMap[$model], $modelId)->first();
|
||||
if ($this->chatEntity == null) {
|
||||
$chatId = $this->createChat($chatDepartmentId, $model, $modelId);
|
||||
$this->chatEntity = $this->chatModel->find($chatId);
|
||||
}
|
||||
if ($data["client"]) {
|
||||
$cliente_in_department = $this->chatDepartmentUserModel
|
||||
->where('chat_department_id', $chatDepartmentId)
|
||||
->where('user_id', $data['client'])
|
||||
->where($this->modelFkMap[$model], $modelId)
|
||||
->first();
|
||||
if ($cliente_in_department == null) {
|
||||
$this->chatDepartmentUserModel->insert(['chat_department_id' => $chatDepartmentId, 'user_id' => $data['client'], $this->modelFkMap[$model] => $modelId]);
|
||||
}
|
||||
}
|
||||
$userAdminDepartment = $this->chatDepartmentUserModel
|
||||
->where('chat_department_id', $data["chat_department_id"])
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where("pedido_id", null)
|
||||
->where("factura_id", null)
|
||||
->where("presupuesto_id", null)
|
||||
->first();
|
||||
$userAlreadyInDepartment = $this->chatDepartmentUserModel
|
||||
->where('chat_department_id', $data["chat_department_id"])
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where($this->modelFkMap[$model], $modelId)
|
||||
->first();
|
||||
if ($userAdminDepartment == null && $userAlreadyInDepartment == null) {
|
||||
$this->chatDepartmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], $this->modelFkMap[$model] => $modelId, 'user_id' => auth()->user()->id]);
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $this->chatEntity->id, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$chatMessageEntity = $this->chatMessageModel->find($chat_message_id);
|
||||
if ($data["client"]) {
|
||||
$userClient = $this->userModel->find($data['client']);
|
||||
if ($userClient) {
|
||||
$this->sendMessageNotificationEmail($chatMessageEntity, $userClient);
|
||||
}
|
||||
}
|
||||
return $chatMessageEntity;
|
||||
}
|
||||
public function createChat(int $chatDepartmentId, string $model, int $modelId): bool|int|string
|
||||
{
|
||||
$r = false;
|
||||
switch ($model) {
|
||||
case 'presupuesto':
|
||||
$r = $this->chatModel->createChatPresupuesto($chatDepartmentId, $modelId);
|
||||
break;
|
||||
case 'pedido':
|
||||
$r = $this->chatModel->createChatPedido($chatDepartmentId, $modelId);
|
||||
break;
|
||||
case 'factura':
|
||||
$r = $this->chatModel->createChatFactura($chatDepartmentId, $modelId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function getChatDepartments(string $model, int $modelId): array
|
||||
{
|
||||
$chatDepartments = $this->chatDepartmentModel->getModelChatDepartments($this->modelFkMap[$model], $modelId);
|
||||
$departmentWithChat = array_map(fn($q) => $q["name"], $chatDepartments);
|
||||
if (count($departmentWithChat) > 0) {
|
||||
$departmentWithoutChat = $this->chatDepartmentModel->whereNotIn('name', $departmentWithChat)->findAll();
|
||||
} else {
|
||||
$departmentWithoutChat = $this->chatDepartmentModel->findAll();
|
||||
}
|
||||
foreach ($departmentWithoutChat as $value) {
|
||||
$d = [];
|
||||
$d["id"] = $value->id;
|
||||
$d["name"] = $value->name;
|
||||
$d["display"] = $value->display;
|
||||
$d["countMessages"] = "0";
|
||||
$chatDepartments[] = $d;
|
||||
}
|
||||
return $chatDepartments;
|
||||
}
|
||||
|
||||
public function storeHebra(string $model, int $modelId, array $data): bool
|
||||
{
|
||||
$auth_user = auth()->user();
|
||||
$chatId = $this->chatModel->insert([$this->modelFkMap[$model] => $modelId, 'title' => $data['title']]);
|
||||
|
||||
if (isset($data["users"])) {
|
||||
$data["users"][] = $auth_user->id;
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chatId], $data["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
}
|
||||
$this->chatMessageModel->insert(
|
||||
[
|
||||
'chat_id' => $chatId,
|
||||
'message' => $data['message'],
|
||||
'sender_id' => $auth_user->id
|
||||
]
|
||||
);
|
||||
return true;
|
||||
}
|
||||
public function getHebras(string $model, int $modelId): array
|
||||
{
|
||||
$chats = $this->chatModel->where('chat_department_id', null)
|
||||
->where($this->modelFkMap[$model], $modelId)
|
||||
->findAll();
|
||||
foreach ($chats as $c) {
|
||||
$this->chatModel->setAsViewedChatUserNotifications($c->id, auth()->user()->id);
|
||||
}
|
||||
$chatWithHebraData = array_map(fn(ChatEntity $c) => $c->withHebra(), $chats);
|
||||
return $chatWithHebraData ?? [];
|
||||
}
|
||||
public function getAuthUserNotifications(): array
|
||||
{
|
||||
$departmentNotifications = $this->chatModel->getChatDepartmentNotifications();
|
||||
$internalNotifications = $this->chatModel->getChatInternalNotifications();
|
||||
$totalMessages = 0;
|
||||
$countNotificiationDepartments = array_map(fn($n) => $n->unreadMessages, $departmentNotifications);
|
||||
$countNotificationInternal = array_map(fn($n) => $n->unreadMessages, $internalNotifications);
|
||||
$totalMessages = array_sum($countNotificiationDepartments) + array_sum($countNotificationInternal);
|
||||
|
||||
return [
|
||||
"departmentNotifications" => $departmentNotifications,
|
||||
"internalNotifications" => $internalNotifications,
|
||||
"totalMessages" => $totalMessages
|
||||
];
|
||||
}
|
||||
public function sendMessageNotificationEmail(ChatMessageEntity $chatMessageEntity, UserEntity $user): bool
|
||||
{
|
||||
$users = auth()->getProvider();
|
||||
$toEmail = $users->find($user->id)->getEmail();
|
||||
$this->emailService->setTo($toEmail);
|
||||
$subject = '[Safekat]' . lang('Chat.mail.mail_subject') . '-' . $chatMessageEntity->chat()->title;
|
||||
$this->emailService->setSubject($subject);
|
||||
$this->emailService->setMessage(view('themes/vuexy/mail/messageNotification', ["header" => lang('Chat.mail.mail_subject'), "data" => $chatMessageEntity->withUser()]));
|
||||
return $this->emailService->send();
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-factura" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden">
|
||||
<div class="row g-0">
|
||||
|
||||
@ -30,12 +26,17 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
<!-- Chats -->
|
||||
<ul class="list-unstyled chat-contact-list" id="chat-list">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
|
||||
</div>
|
||||
|
||||
@ -67,11 +68,27 @@
|
||||
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
@ -82,7 +99,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-history-body bg-body ">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="sk-wave sk-primary ">
|
||||
<div class="sk-wave-rect"></div>
|
||||
<div class="sk-wave-rect"></div>
|
||||
@ -101,19 +118,23 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment-client">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-pedido" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden">
|
||||
<div class="row g-0">
|
||||
|
||||
@ -30,13 +26,20 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<div class="chat-contact-list-item-title">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
<!-- Chats -->
|
||||
<ul class="list-unstyled chat-contact-list" id="chat-list">
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- CHAT LIST -->
|
||||
|
||||
</ul>
|
||||
@ -64,11 +67,26 @@
|
||||
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
@ -79,7 +97,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-history-body bg-body ">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="d-flex justify-content-center chat-loader">
|
||||
<div class="sk-wave sk-primary ">
|
||||
<div class="sk-wave-rect"></div>
|
||||
<div class="sk-wave-rect"></div>
|
||||
@ -98,19 +116,21 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment-client">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<div class="col-md-12" id="chat-presupuesto" data-id="<?= $modelId ?>">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="d-flex justify-content-start align-items-start gap-2 mb-3">
|
||||
<button class="btn btn-primary btn-md" id="direct-message-cliente"><i class="ti ti-xs ti-message"></i> Mensaje directo a cliente</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="app-chat card overflow-hidden border">
|
||||
<div class="row g-0">
|
||||
<!-- Chat & Contacts -->
|
||||
@ -29,6 +25,14 @@
|
||||
</div>
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
<div class="chat-contact-list-item-title">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<div class="mb-0 px-4 pt-3 pb-2">
|
||||
<select class="form-control chat-search-client"></select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
|
||||
</div>
|
||||
@ -63,15 +67,29 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-danger btn-sm exit-chat">
|
||||
<i class="ti ti-trash"></i>
|
||||
<?= lang('Chat.exit_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-2 px-2">
|
||||
<button type="button" class="btn btn-success btn-sm subscribe-chat">
|
||||
<i class="ti ti-plus"></i>
|
||||
<?= lang('Chat.subscribe_chat') ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
|
||||
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
|
||||
<i class="ti ti-users"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end" id="chat-header-users"
|
||||
<div class="dropdown-menu dropdown-menu-end mb-0 px-2 pt-3 pb-2" id="chat-header-users"
|
||||
aria-labelledby="chat-header-users">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -97,19 +115,22 @@
|
||||
<div
|
||||
class="form-send-message d-flex justify-content-between align-items-center">
|
||||
<input class="form-control message-input border-0 me-3 shadow-none"
|
||||
placeholder="<?=lang('Chat.write_message_placeholder')?>" />
|
||||
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
|
||||
<div class="message-actions d-flex align-items-center">
|
||||
<?php if (auth()->user()->inGroup('admin')): ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment" disabled>
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment-client">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<a class="btn btn-primary d-flex send-msg-btn" style="color:white"
|
||||
id="send-msg-btn-deparment">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block">Enviar</span>
|
||||
</a>
|
||||
<a class="btn btn-primary d-flex send-msg-btn"
|
||||
id="send-msg-btn-internal">
|
||||
<i class="ti ti-send me-md-1 me-0"></i>
|
||||
<span class="align-middle d-md-inline-block ">Enviar</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
<form id="<?=$id?>" data-id="<?= $entity->id ?>">
|
||||
<div class="row">
|
||||
<div class="col-md-12 mb-2">
|
||||
<label for="chat-department-display"><?= lang('Chat.datatable_departments.name') ?></label>
|
||||
<input type="text" name="display" id="chat-department-display" value="<?= $entity->display ?>" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-12 mb-2">
|
||||
<label for="chat-department-description"><?= lang('Chat.datatable_departments.description') ?></label>
|
||||
<textarea rows="5" cols="5" type="text" name="description" id="chat-department-description" class="form-control"><?= $entity->description ?></textarea>
|
||||
</div>
|
||||
<div class="col-md-12 mb-5">
|
||||
<button type="button" class="btn btn-primary w-100" id="btn-chat-department-update"><i class="ti icon-base ti-refresh me-2"></i>
|
||||
<?= lang("App.global_save") ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
|
||||
<div class="accordion accordion-bordered" id="accordionChatDepartmentUser">
|
||||
<div class="card accordion-item active">
|
||||
<h2 class="accordion-header">
|
||||
<button type="button" class="accordion-button" data-bs-toggle="collapse"
|
||||
data-bs-target="#accordionChatDepartmentUserTip" aria-expanded="false"
|
||||
aria-controls="accordionChatDepartmentUserTip">
|
||||
<h4><?= lang("Chat.department_users") ?></h4>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="accordionChatDepartmentUserTip" class="accordion-collapse"
|
||||
data-bs-parent="#accordionChatDepartment">
|
||||
<div class="accordion-body">
|
||||
<div class="col-md-12">
|
||||
<div class="row">
|
||||
<div class="col-md-10">
|
||||
<select id="selectChatDepartmentUser" class="select2 form-select" data-allow-clear="true"></select>
|
||||
<div id="floatingInputHelp" class="form-text"><?=lang('Chat.help_select_chat_department_user')?></div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-primary w-100" id="add-user-admin-chat-department"><i class="ti icon-base ti-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<?= view("themes/vuexy/components/tables/chat_department_users_table", ["id" => "tableChatDepartmentUsers", "entity" => $entity]) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -0,0 +1,12 @@
|
||||
<table id="<?= $id ?>" class="table table-striped table-hover" style="width: 100%;" data-id="<?= $entity->id ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('Chat.datatable_department_users.name') ?></th>
|
||||
<th><?= lang('Chat.datatable_department_users.user') ?></th>
|
||||
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
@ -0,0 +1,13 @@
|
||||
<table id="<?= $id ?>" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th><?= lang('Chat.datatable_departments.name') ?></th>
|
||||
<th><?= lang('Chat.datatable_departments.description') ?></th>
|
||||
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
@ -4,10 +4,20 @@
|
||||
<th><?= lang('Chat.datatable_messages.created_at') ?></th>
|
||||
<th><?= lang('Chat.datatable_messages.updated_at') ?></th>
|
||||
<th><?= lang('Chat.datatable_messages.title') ?></th>
|
||||
<th><?= lang('Chat.datatable_messages.message') ?></th>
|
||||
<th><?= lang('Chat.datatable_messages.creator') ?></th>
|
||||
<th><?= lang('Chat.datatable_messages.viewed') ?></th>
|
||||
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th><input type="text" class="form-control datatable-message-filter" name="title"></th>
|
||||
<th><input type="text" class="form-control datatable-message-filter" name="message"></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
|
||||
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
|
||||
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
|
||||
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||
|
||||
|
||||
<?= $this->section('content'); ?>
|
||||
<!--Content Body-->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= lang('Chat.message_configuration') ?></h3>
|
||||
</div>
|
||||
<!--//.card-header -->
|
||||
<div class="card-body">
|
||||
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
|
||||
<h4 class="card-title"><?= lang('Chat.store_department') ?></h4>
|
||||
<div class="row d-flex align-item-center">
|
||||
<div class="col-md-10 mb-2">
|
||||
<label for="chat-department-display"><?= lang('Chat.datatable_departments.name') ?></label>
|
||||
<input type="text" name="display" id="chat-department-display" class="form-control" placeholder="<?= lang('Chat.datatable_departments.name') ?>" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label for="btn-add-new-chat-department"> </label>
|
||||
<button type="button" class="btn btn-primary btn-sm w-100" id="btn-add-new-chat-department">
|
||||
<span class="icon-base ti ti-plus icon-xs me-1"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?= view("themes/vuexy/components/tables/chat_departments_table", ["id" => "tableChatDepartments"]) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/popper/popper.js') ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/configView.js') ?>"></script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@ -0,0 +1,38 @@
|
||||
<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
|
||||
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
|
||||
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
|
||||
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||
|
||||
|
||||
<?= $this->section('content'); ?>
|
||||
<!--Content Body-->
|
||||
<div class="row" id="chatDepartmentEditContainer">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><?= $chat_department->display ?></h3>
|
||||
</div>
|
||||
<!--//.card-header -->
|
||||
<div class="card-body">
|
||||
<?= view("themes/vuexy/components/forms/chat_department", ["id" => "chatDepartmentForm", "entity" => $chat_department]) ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/popper/popper.js') ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/editChatDepartmentView.js') ?>"></script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -10,11 +10,11 @@
|
||||
<div class="col-md-12">
|
||||
<div class="nav-tabs-shadow nav-align-top">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<!-- <li class="nav-item">
|
||||
<button type="button" class="nav-link active" role="tab" id="navs-top-align-directos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-directos">Directos</button>
|
||||
</li>
|
||||
</li> -->
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos">Presupuestos</button>
|
||||
<button type="button" class="nav-link active" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos">Presupuestos</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-pedidos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-pedidos">Pedidos</button>
|
||||
@ -25,18 +25,8 @@
|
||||
|
||||
</ul>
|
||||
<div class="tab-content" id="message-datatables-container">
|
||||
<div class="tab-pane fade show active" id="navs-top-align-directos">
|
||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
||||
<div class="row">
|
||||
<div class="col-md-12 d-flex justify-content-start">
|
||||
<button class="btn btn-primary" id="btn-new-message"><span class="ti ti-md ti-plus"></span>Nuevo mensaje</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableMessages"]) ?>
|
||||
</div>
|
||||
<div class="tab-pane fade show" id="navs-top-align-presupuestos">
|
||||
<div class="tab-pane fade show active" id="navs-top-align-presupuestos">
|
||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tablePresupuestoMessages"]) ?>
|
||||
</div>
|
||||
<div class="tab-pane fade show" id="navs-top-align-pedidos">
|
||||
@ -60,8 +50,7 @@
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
@ -70,5 +59,7 @@
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/index.js') ?>">
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -23,5 +23,7 @@
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -18,6 +18,8 @@
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
|
||||
|
||||
|
||||
@ -26,5 +28,7 @@
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -15,6 +15,8 @@
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
|
||||
|
||||
|
||||
@ -24,5 +26,5 @@
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
</script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
@ -15,13 +15,12 @@
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
</script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -15,13 +15,12 @@
|
||||
<?= $this->section('css') ?>
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
|
||||
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
</script>
|
||||
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
|
||||
<?= $this->endSection() ?>
|
||||
84
ci4/app/Views/themes/vuexy/mail/mail_layout.php
Normal file
84
ci4/app/Views/themes/vuexy/mail/mail_layout.php
Normal file
@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html
|
||||
class="h-100 light-style layout-navbar-fixed layout-menu-fixed"
|
||||
dir="ltr"
|
||||
data-theme="theme-default"
|
||||
data-assets-path="<?= site_url('themes/vuexy/') ?>"
|
||||
data-template="vertical-menu-template-no-customizer">
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
||||
|
||||
<meta name="description" content="" />
|
||||
<!-- Icons -->
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/fontawesome.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/tabler-icons.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/flag-icons.css') ?>" />
|
||||
|
||||
<!-- Core CSS -->
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/rtl/core.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/rtl/theme-semi-dark.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>" />
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/flatpickr/flatpickr.css') ?>" />
|
||||
|
||||
|
||||
|
||||
<!-- Vendors CSS -->
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/perfect-scrollbar/perfect-scrollbar.css') ?>" />
|
||||
|
||||
<!-- Page CSS -->
|
||||
<?= $this->renderSection('css') ?>
|
||||
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>" />
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="layout-container">
|
||||
<div class="layout-page">
|
||||
<div class="content-wrapper">
|
||||
<div class="container-fluid flex-grow-1 container-p-y">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card card-info">
|
||||
<div class="card-header">
|
||||
<div class="d-flex aling-items-center justify-content-between">
|
||||
<h3 class="card-title"><?= $header ?></h3>
|
||||
<span class="app-brand-logo">
|
||||
<img src="http://localhost:8000/themes/vuexy/img/safekat/logos/sk-logo.png" width="150px">
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!--//.card-header -->
|
||||
<div class="card-body">
|
||||
<?= $this->renderSection('content') ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="content-footer footer bg-footer-theme">
|
||||
<div class="container-fluid">
|
||||
<div class="footer-container d-flex align-items-center justify-content-center py-2 flex-md-row flex-column">
|
||||
<div>
|
||||
<a href="#" target="_blank" class="fw-semibold">Safekat</a> © <?= date('Y'); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
30
ci4/app/Views/themes/vuexy/mail/messageNotification.php
Normal file
30
ci4/app/Views/themes/vuexy/mail/messageNotification.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?= $this->extend('themes/vuexy/mail/mail_layout') ?>
|
||||
|
||||
<?= $this->section('content'); ?>
|
||||
|
||||
|
||||
<div class="card email-card-last mx-sm-4 mx-3 mt-4">
|
||||
<div class="card-header d-flex flex-wrap">
|
||||
<h6 class="m-0"><?= $data->chat()->title ?></h6>
|
||||
</div>
|
||||
<div class="card-header d-flex justify-content-between align-items-center flex-wrap">
|
||||
<div class="d-flex align-items-center mb-sm-0 mb-3">
|
||||
<img src="https://gravatar.com/avatar/<?= $data->user->avatar ?>s=40" alt="user-avatar" class="flex-shrink-0 rounded-circle me-3" height="30" width="30">
|
||||
<div class="flex-grow-1 ms-1">
|
||||
<h6 class="m-0"><?= $data->user->first_name . " " . $data->user->last_name ?></h6>
|
||||
<!-- <small class="text-muted"></small> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<p class="mb-0 me-3 text-muted"><?= $data->created_at ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="chat-message chat-message">
|
||||
<div class="chat-message-wrapper flex-grow-1">
|
||||
<p><?= $data->message ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
@ -250,7 +250,7 @@ $picture = "/assets/img/default-user.png";
|
||||
<a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);"
|
||||
data-bs-toggle="dropdown">
|
||||
<div class="avatar">
|
||||
<img src="<?= $picture ?? '' ?>" alt class="h-auto rounded-circle" />
|
||||
<img src="<?= getGravatarURL(50) ?? '' ?>" alt class="h-auto rounded-circle" />
|
||||
</div>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
@ -259,7 +259,7 @@ $picture = "/assets/img/default-user.png";
|
||||
<div class="d-flex">
|
||||
<div class="flex-shrink-0 me-3">
|
||||
<div class="avatar avatar">
|
||||
<img src="<?= $picture ?? '' ?>" alt class="h-auto rounded-circle" />
|
||||
<img src="<?= getGravatarURL() ?? '' ?>" alt class="h-auto rounded-circle" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
@ -346,7 +346,6 @@ $picture = "/assets/img/default-user.png";
|
||||
<!-- build:js assets/vendor/js/core.js -->
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/jquery/jquery.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/popper/popper.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/jquery/jquery.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/js/bootstrap.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/flatpickr/flatpickr.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/vendor/libs/perfect-scrollbar/perfect-scrollbar.js') ?>"></script>
|
||||
|
||||
@ -120,6 +120,13 @@ if (
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
|
||||
<li class="menu-item">
|
||||
<a href="<?= route_to('configMessagesIndex') ?>" class="menu-link">
|
||||
<?= lang("App.menu_config_messages") ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php } ?>
|
||||
@ -34,18 +34,19 @@ export const alertConfirmAction = (title, type = "primary") => {
|
||||
buttonsStyling: false
|
||||
})
|
||||
}
|
||||
export const alertSuccessMessage = (title, type = "primary") => {
|
||||
export const alertSuccessMessage = (title, type = "primary", options = {}) => {
|
||||
return Swal.fire({
|
||||
showCancelButton: false,
|
||||
showConfirmButton: false,
|
||||
title: title,
|
||||
text: title,
|
||||
icon: "success",
|
||||
timer: 2000
|
||||
timer: 2000,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const alertWarningMessage = (title, message, type = "primary") => {
|
||||
export const alertWarningMessage = (title, message, type = "primary",options = {}) => {
|
||||
return Swal.fire({
|
||||
title: title,
|
||||
text: message,
|
||||
@ -70,8 +71,8 @@ export const toastPresupuestoSummary = (value, target = 'body') => {
|
||||
popup: 'bg-primary text-white',
|
||||
},
|
||||
target: target,
|
||||
width : "200px",
|
||||
padding : '1px',
|
||||
width: "200px",
|
||||
padding: '1px',
|
||||
allowEscapeKey: false,
|
||||
showConfirmButton: false,
|
||||
timer: 0,
|
||||
@ -79,7 +80,7 @@ export const toastPresupuestoSummary = (value, target = 'body') => {
|
||||
stopKeydownPropagation: false,
|
||||
})
|
||||
}
|
||||
export const alertSuccess = (value, target = 'body') => {
|
||||
export const alertSuccess = (value, target = 'body',options = {}) => {
|
||||
return Swal.mixin({
|
||||
toast: true,
|
||||
position: 'bottom-end',
|
||||
@ -87,15 +88,16 @@ export const alertSuccess = (value, target = 'body') => {
|
||||
customClass: {
|
||||
popup: 'bg-success text-white',
|
||||
},
|
||||
icon : 'success',
|
||||
icon: 'success',
|
||||
iconColor: 'white',
|
||||
target: target,
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timer: 6000,
|
||||
timerProgressBar: true,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
export const alertError = (value, target = 'body') => {
|
||||
export const alertError = (value, target = 'body',options = {}) => {
|
||||
return Swal.mixin({
|
||||
toast: true,
|
||||
position: 'bottom-end',
|
||||
@ -103,15 +105,16 @@ export const alertError = (value, target = 'body') => {
|
||||
customClass: {
|
||||
popup: 'bg-danger text-white',
|
||||
},
|
||||
icon : 'error',
|
||||
icon: 'error',
|
||||
iconColor: 'white',
|
||||
target: target,
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timer: 6000,
|
||||
timerProgressBar: true,
|
||||
...options
|
||||
})
|
||||
}
|
||||
export const alertWarning = (value, target = 'body') => {
|
||||
export const alertWarning = (value, target = 'body',options = {}) => {
|
||||
return Swal.mixin({
|
||||
toast: true,
|
||||
position: 'bottom-end',
|
||||
@ -119,11 +122,12 @@ export const alertWarning = (value, target = 'body') => {
|
||||
customClass: {
|
||||
popup: 'bg-warning text-white',
|
||||
},
|
||||
icon : 'warning',
|
||||
icon: 'warning',
|
||||
iconColor: 'white',
|
||||
target: target,
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timer: 6000,
|
||||
timerProgressBar: true,
|
||||
...options
|
||||
})
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import Ajax from '../components/ajax.js'
|
||||
import Modal from './modal.js'
|
||||
import ClassSelect from './select2.js'
|
||||
|
||||
import { alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess } from "./alerts/sweetAlert.js"
|
||||
|
||||
|
||||
class Chat {
|
||||
@ -12,14 +12,18 @@ class Chat {
|
||||
this.modelId = this.domItem.data("id")
|
||||
this.chatHistoryBody = this.domItem.find(".chat-history-body")
|
||||
this.sendBtnMessageDepartment = this.domItem.find("#send-msg-btn-deparment")
|
||||
this.sendBtnMessageDepartmentClient = this.domItem.find("#send-msg-btn-deparment-client")
|
||||
this.sendBtnMessageInternal = this.domItem.find("#send-msg-btn-internal")
|
||||
this.chatSidebarLeftUserAbout = this.domItem.find('.chat-sidebar-left-user-about'),
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.sideBar = this.domItem.find(".sidebar-body")
|
||||
this.selectItem = this.domItem.find(".chat-search-client")
|
||||
this.btnExitChat = this.domItem.find(".exit-chat")
|
||||
this.btnSubscribeChat = this.domItem.find(".subscribe-chat")
|
||||
|
||||
this.chatDeparmentId = undefined
|
||||
this.searchInput = this.domItem.find(".chat-search-input")
|
||||
this.headers = {}
|
||||
|
||||
this.chatContactsBody = this.domItem.find('.app-chat-contacts .sidebar-body')
|
||||
this.chatContactListItems = [].slice.call(
|
||||
document.querySelectorAll('.chat-contact-list-item:not(.chat-contact-list-item-title)')
|
||||
@ -52,6 +56,9 @@ class Chat {
|
||||
}
|
||||
|
||||
this.sendBtnMessageDepartment.addClass("d-none")
|
||||
this.btnExitChat.on('click', this._handleExitChatDepartment.bind(this))
|
||||
this.btnSubscribeChat.on('click', this._handleSubscribeChatDepartment.bind(this))
|
||||
|
||||
this.sendBtnMessageInternal.addClass("d-none")
|
||||
if (this.chatContactsBody[0]) {
|
||||
this.scrollbarContacts = new PerfectScrollbar(this.chatContactsBody[0], {
|
||||
@ -69,6 +76,7 @@ class Chat {
|
||||
}
|
||||
}
|
||||
initDirectMessage() {
|
||||
|
||||
this.chatType = "direct"
|
||||
this.modalNewParticipant = new Modal(this.domItem.find("#modalAddNewChatParticipant"))
|
||||
this.selectPlaceholder = {
|
||||
@ -91,7 +99,7 @@ class Chat {
|
||||
this.selectParticipants.init()
|
||||
this.modalNewParticipant.toggle()
|
||||
})
|
||||
|
||||
|
||||
this.selectParticipants.item.on("change", () => {
|
||||
if (this.selectParticipants.getVal().length > 0) {
|
||||
this.btnAddParticipantSubmit.removeClass("d-none")
|
||||
@ -99,20 +107,39 @@ class Chat {
|
||||
this.btnAddParticipantSubmit.addClass("d-none")
|
||||
}
|
||||
})
|
||||
this.btnUpdateMessagesUnviewed.on("click",this._handleUpdateChatMessagesUnread.bind(this))
|
||||
this.btnUpdateMessagesUnviewed.on("click", this._handleUpdateChatMessagesUnread.bind(this))
|
||||
this._handleGetChatDirect()
|
||||
setInterval(this._handleReloadChatDirectMessages.bind(this),10000)
|
||||
setInterval(this._handleReloadChatDirectMessages.bind(this), 10000)
|
||||
}
|
||||
initSelectClient() {
|
||||
this.selectClientUser = new ClassSelect(this.selectItem, `/chat/direct/client/users/select/${this.chatType}/${this.modelId}`, "Seleccione contacto", true)
|
||||
this.selectClientUser.init()
|
||||
this.selectItem.on('change', () => {
|
||||
if (this.selectClientUser.getVal()) {
|
||||
this.sendBtnMessageDepartment.attr('disabled', null)
|
||||
} else {
|
||||
this.sendBtnMessageDepartment.attr('disabled', 'disabled')
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
initGeneral() {
|
||||
this.chatType = "general"
|
||||
this._handleGetChatList()
|
||||
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
|
||||
}
|
||||
initPresupuesto() {
|
||||
this.chatType = "presupuesto"
|
||||
this._handleGetChatList()
|
||||
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
this.initSelectClient()
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -120,15 +147,22 @@ class Chat {
|
||||
this.chatType = "pedido"
|
||||
this._handleGetChatList()
|
||||
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
this.initSelectClient()
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
|
||||
|
||||
|
||||
}
|
||||
initFactura() {
|
||||
this.chatType = "factura"
|
||||
this._handleGetChatList()
|
||||
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
|
||||
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
|
||||
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
|
||||
|
||||
this.initSelectClient()
|
||||
// setInterval(this._getChatMessage.bind(this), 10000)
|
||||
}
|
||||
initContacts() {
|
||||
this.chatType = "internal"
|
||||
@ -166,7 +200,7 @@ class Chat {
|
||||
_handleGetChatList(event) {
|
||||
this.domItem.find(".chat-loader").removeClass("d-none")
|
||||
let ajax = new Ajax(
|
||||
"/chat/departments",
|
||||
`/chat/departments/${this.chatType}/${this.modelId}`,
|
||||
null,
|
||||
null,
|
||||
this._handleGetChatListSuccess.bind(this),
|
||||
@ -179,7 +213,6 @@ class Chat {
|
||||
Object.values(data).map(row => {
|
||||
this.chatList.append(this._getContact(row))
|
||||
this.chatDeparmentId = row.id
|
||||
this._getChatTotalMessages(row.name)
|
||||
this.chatList.find(`#chat_${row.name}`).on("click", (event) => {
|
||||
$(".chat-contact-list-item").removeClass("active")
|
||||
$(event.currentTarget).parent().addClass("active")
|
||||
@ -188,12 +221,15 @@ class Chat {
|
||||
this.domItem.find(".chat-history-header div.chat-contact-info h6").text(row.display)
|
||||
this.domItem.find(".chat-history-header div.chat-contact-info small.user-status").text(row.display)
|
||||
this._getChatMessage()
|
||||
this._getChatTotalMessages(row.name)
|
||||
this._getChatDeparmentUsers()
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
this.chatList.find(`#chat__produccion`).trigger("click");
|
||||
if (Object.values(data)) {
|
||||
const firstDepartment = Object.values(data)[0]
|
||||
this.chatList.find(`#chat_${firstDepartment.name}`).trigger("click");
|
||||
}
|
||||
}
|
||||
_handleGetChatListError(error) {
|
||||
console.error(error)
|
||||
@ -202,7 +238,7 @@ class Chat {
|
||||
this.domItem.find("#chat-header-users").empty()
|
||||
this.domItem.find("#chat-header-dropdown-users").removeClass("d-none")
|
||||
let ajax = new Ajax(
|
||||
`/chat/department/${this.chatDeparmentId}/users`,
|
||||
`/chat/department/users/${this.chatType}/${this.chatDeparmentId}/${this.modelId}`,
|
||||
null,
|
||||
null,
|
||||
this._getChatDeparmentUsersSuccess.bind(this),
|
||||
@ -212,31 +248,32 @@ class Chat {
|
||||
ajax.get()
|
||||
}
|
||||
_getChatDeparmentUsersSuccess(deparmentUsers) {
|
||||
deparmentUsers.map((user) => {
|
||||
this.domItem.find("#chat-header-users").append(
|
||||
`
|
||||
<li class="chat-contact-list-item p-1">
|
||||
<a class="d-flex align-items-center py-1"
|
||||
id="chat-contact-list-item-${user.id}">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">
|
||||
${user?.first_name?.charAt(0) ?? "?"
|
||||
+ user?.last_name?.charAt(0) ?? "?"}</span>
|
||||
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
|
||||
user?.last_name ?? ""}</h6>
|
||||
<p class="chat-contact-status text-muted text-truncate mb-0">
|
||||
${user.username}
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
deparmentUsers.adminUsers.map(user => this.appendChatDepartmentUser(user))
|
||||
deparmentUsers.externalUsers.map(user => this.appendChatDepartmentUser(user, 'warning', 'user'))
|
||||
|
||||
}
|
||||
appendChatDepartmentUser(user, color = "primary", icon = "user") {
|
||||
this.domItem.find("#chat-header-users").append(
|
||||
`
|
||||
)
|
||||
})
|
||||
<li class="chat-contact-list-item p-1">
|
||||
<div class="d-flex align-items-center py-1"
|
||||
id="chat-contact-list-item-${user.id}">
|
||||
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
|
||||
user?.last_name ?? ""}</h6>
|
||||
<p class="chat-contact-status text-muted text-truncate mb-0">
|
||||
${user.username}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
`
|
||||
)
|
||||
}
|
||||
_getChatDeparmentUsersError(err) { }
|
||||
|
||||
@ -253,7 +290,7 @@ class Chat {
|
||||
${row.display}
|
||||
</p>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-secondary messages-unread-contact">${row.totalMessages ?? 0}</span>
|
||||
<span class="badge badge-center rounded-pill bg-secondary messages-unread-contact">${row.countMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
@ -265,7 +302,7 @@ class Chat {
|
||||
null,
|
||||
null,
|
||||
(data) => {
|
||||
this.chatList.find(`#chat_${row_name} .messages-unread-contact`).text(data.count)
|
||||
|
||||
},
|
||||
null
|
||||
|
||||
@ -307,6 +344,7 @@ class Chat {
|
||||
_getChatMessageSuccess(data) {
|
||||
this.domItem.find(".chat-loader").addClass("d-none")
|
||||
this._setBtnDeparment()
|
||||
this.chatList.find(`#chat_${data.department.name} .messages-unread-contact`).text(data.count ?? 0)
|
||||
if (data.messages) {
|
||||
data.messages.map((m) => {
|
||||
this._addChatMessage(m)
|
||||
@ -326,19 +364,18 @@ class Chat {
|
||||
<div class="chat-message-text">
|
||||
<p class="mb-0">${chatMessage?.message}</p>
|
||||
</div>
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<div class="text-${chatMessage?.pos == "left" ? "start" : "end"} text-muted mt-1">
|
||||
<i class="ti me-1"></i>
|
||||
<small>${chatMessage?.user?.first_name + " " + chatMessage?.user?.last_name}</small>
|
||||
</div>
|
||||
<i class="ti ${chatMessage?.viewed ? "ti-checks" : "ti-check"} ti-xs me-1 text-success"></i>
|
||||
<i class="ti ${chatMessage?.viewed == 1 ? "ti-checks" : "ti-check"} ti-xs me-1 text-success"></i>
|
||||
<small>${chatMessage.created_at}</small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="user-avatar flex-shrink-0 ms-3">
|
||||
<div class="avatar avatar-sm">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${chatMessage?.user?.first_name.charAt(0) + chatMessage?.user?.last_name.charAt(0)}</span>
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${chatMessage.user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -398,6 +435,7 @@ class Chat {
|
||||
message: messageText,
|
||||
chat_department_id: this.chatDeparmentId,
|
||||
user: this.userId,
|
||||
client: this.selectClientUser.getVal() ?? null,
|
||||
model_id: this.modelId
|
||||
}
|
||||
if (messageText) {
|
||||
@ -415,6 +453,7 @@ class Chat {
|
||||
_sendMessageSuccess(data) {
|
||||
this.messageInput.val("")
|
||||
this._getChatMessage(this.chatDeparmentId)
|
||||
this._getChatDeparmentUsers()
|
||||
}
|
||||
_sendMessageError(err) {
|
||||
console.error(err)
|
||||
@ -493,8 +532,6 @@ class Chat {
|
||||
}
|
||||
_handleGetSingleContactMessagesSuccess(data) {
|
||||
try {
|
||||
|
||||
|
||||
if (data) {
|
||||
data.map((m) => {
|
||||
this._addChatMessage(m)
|
||||
@ -647,7 +684,7 @@ class Chat {
|
||||
}
|
||||
_handleReloadChatDirectMessagesError(error) { }
|
||||
_handleStoreChatDirectUsers() {
|
||||
const data = { "users": this.selectParticipants.getVal() ,"notification" : this.checkboxNotificationMessage.prop("checked")}
|
||||
const data = { "users": this.selectParticipants.getVal(), "notification": this.checkboxNotificationMessage.prop("checked") }
|
||||
this.domItem.find(".chat-loader").removeClass("d-none")
|
||||
|
||||
const ajax = new Ajax(
|
||||
@ -689,7 +726,7 @@ class Chat {
|
||||
this._addChatDirectMessages(message)
|
||||
this.messageInput.val("")
|
||||
} catch (error) {
|
||||
|
||||
|
||||
} finally {
|
||||
this.scrollbarChatHistory.update()
|
||||
this.chatHistoryBody[0].scrollTop = this.scrollbarChatHistory.containerHeight
|
||||
@ -708,11 +745,73 @@ class Chat {
|
||||
)
|
||||
ajax.post()
|
||||
}
|
||||
_handleUpdateChatMessagesUnreadSuccess(){
|
||||
_handleUpdateChatMessagesUnreadSuccess() {
|
||||
this._handleReloadChatDirectMessages();
|
||||
}
|
||||
_handleUpdateChatMessagesUnreadError(){}
|
||||
_handleUpdateChatMessagesUnreadError() { }
|
||||
_handleRequestExitChatDeparment() {
|
||||
const ajax = new Ajax('/chat/department/user/' + this.chatDeparmentId,
|
||||
{
|
||||
model_fk: this.chatType + "_id",
|
||||
model_id_fk: this.modelId
|
||||
},
|
||||
null,
|
||||
(response) => {
|
||||
if (response.status) {
|
||||
alertSuccess(response.message).fire()
|
||||
this._getChatDeparmentUsers()
|
||||
} else {
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
alertError("Error")
|
||||
}
|
||||
|
||||
)
|
||||
ajax.delete();
|
||||
}
|
||||
_handleRequestSubscribeChatDeparment() {
|
||||
const ajax = new Ajax('/chat/department/user',
|
||||
{
|
||||
chat_department_id: this.chatDeparmentId,
|
||||
model_fk: this.chatType + "_id",
|
||||
model_id_fk: this.modelId
|
||||
},
|
||||
null,
|
||||
(response) => {
|
||||
if (response.status) {
|
||||
alertSuccess(response.message).fire()
|
||||
this._getChatDeparmentUsers()
|
||||
} else {
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
alertError("Error")
|
||||
}
|
||||
|
||||
)
|
||||
ajax.post();
|
||||
}
|
||||
_handleExitChatDepartment() {
|
||||
if (this.chatDeparmentId) {
|
||||
alertConfirmationDelete('¿Estás seguro de salir de la conversación?').then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this._handleRequestExitChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
_handleSubscribeChatDepartment() {
|
||||
if (this.chatDeparmentId) {
|
||||
alertConfirmAction('¿Estás seguro de subscribirte al chat?').then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this._handleRequestSubscribeChatDeparment()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -722,106 +821,73 @@ class Chat {
|
||||
|
||||
}
|
||||
|
||||
const addInternalNotification = (e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
$("#chat-notification-list").append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
}
|
||||
const addDepartmentNotification = (e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
$("#chat-notification-list").append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const showNotificationMessages = (dom) => {
|
||||
const addNotificationsToDom = (data) =>
|
||||
{
|
||||
$("#chat-notification-list").empty()
|
||||
if (data.totalMessages > 0) {
|
||||
$("#chat-message-notification-title").addClass("d-none")
|
||||
$("#chat-notification-number").removeClass("d-none")
|
||||
$("#chat-notification-number").text(data.totalMessages ?? 0)
|
||||
} else {
|
||||
$("#chat-message-notification-title").removeClass("d-none")
|
||||
$("#chat-notification-number").addClass("d-none")
|
||||
$("#chat-notification-number").text(0)
|
||||
}
|
||||
data.departmentNotifications?.map( e => {
|
||||
addDepartmentNotification(e)}
|
||||
)
|
||||
data.internalNotifications?.map(e => {
|
||||
addInternalNotification(e)}
|
||||
)
|
||||
|
||||
}
|
||||
export const showNotificationMessages = () => {
|
||||
let ajax = new Ajax(
|
||||
'/chat/notifications',
|
||||
null,
|
||||
null,
|
||||
(data) => {
|
||||
dom.empty()
|
||||
$("#chat-notification-number")
|
||||
if (data.totalMessages > 0) {
|
||||
$("#chat-message-notification-title").addClass("d-none")
|
||||
$("#chat-notification-number").removeClass("d-none")
|
||||
$("#chat-notification-number").text(data.totalMessages ?? 0)
|
||||
} else {
|
||||
$("#chat-message-notification-title").removeClass("d-none")
|
||||
$("#chat-notification-number").addClass("d-none")
|
||||
$("#chat-notification-number").text(0)
|
||||
}
|
||||
data?.internals?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="mb-2">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.avatar}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary p-1 m-2">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatPresupuestos?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.presupuestoId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatFacturas?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.facturaId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
data?.chatPedidos?.map((e) => {
|
||||
let numberOfMessages = e.unreadMessages
|
||||
if (numberOfMessages > 0) {
|
||||
dom.append(
|
||||
`
|
||||
<li class="">
|
||||
<a href="${e.uri}" class="d-flex align-items-center flex-grow">
|
||||
<div class="avatar d-block flex-shrink-0">
|
||||
<span class="avatar-initial rounded-circle bg-label-primary">${e.pedidoId}</span>
|
||||
</div>
|
||||
<div class="chat-contact-info flex-grow-1 ms-2">
|
||||
<h6 class="chat-contact-name text-truncate m-0">[${e.title}] ${e.chatDisplay}</h6>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-primary">${numberOfMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
addNotificationsToDom,
|
||||
(err) => { }
|
||||
)
|
||||
ajax.get()
|
||||
@ -829,104 +895,3 @@ export const showNotificationMessages = (dom) => {
|
||||
export default Chat
|
||||
|
||||
|
||||
// // Seleccionar elementos del DOM
|
||||
// const chatContactsBody = document.querySelector('.app-chat-contacts .sidebar-body'),
|
||||
// chatContactListItems = [].slice.call(
|
||||
// document.querySelectorAll('.chat-contact-list-item:not(.chat-contact-list-item-title)')
|
||||
// ),
|
||||
// chatHistoryBody = document.querySelector('.chat-history-body'),
|
||||
// chatSidebarLeftUserAbout = document.querySelector('.chat-sidebar-left-user-about'),
|
||||
// messageInput = document.querySelector('.message-input'),
|
||||
// searchInput = document.querySelector('.chat-search-input'),
|
||||
// sendMsgBtn = document.querySelector('.send-msg-btn'); // Seleccionar el botón de envío de mensaje
|
||||
|
||||
// // Inicializar PerfectScrollbar
|
||||
// if (chatContactsBody) {
|
||||
// new PerfectScrollbar(chatContactsBody, {
|
||||
// wheelPropagation: false,
|
||||
// suppressScrollX: true
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (chatHistoryBody) {
|
||||
// new PerfectScrollbar(chatHistoryBody, {
|
||||
// wheelPropagation: false,
|
||||
// suppressScrollX: true
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Función para desplazar el scroll al final
|
||||
// function scrollToBottom() {
|
||||
// if (chatHistoryBody) {
|
||||
// chatHistoryBody.scrollTo(0, chatHistoryBody.scrollHeight);
|
||||
// }
|
||||
// }
|
||||
// scrollToBottom();
|
||||
|
||||
// // Seleccionar chat o contacto
|
||||
|
||||
|
||||
// // Filtrar chats
|
||||
// if (searchInput) {
|
||||
// searchInput.addEventListener('keyup', e => {
|
||||
// const searchValue = e.currentTarget.value.toLowerCase(),
|
||||
// chatListItem0 = document.querySelector('.chat-list-item-0'),
|
||||
// contactListItem0 = document.querySelector('.contact-list-item-0'),
|
||||
// searchChatListItems = [].slice.call(
|
||||
// document.querySelectorAll('#chat-list li:not(.chat-contact-list-item-title)')
|
||||
// ),
|
||||
// searchContactListItems = [].slice.call(
|
||||
// document.querySelectorAll('#contact-list li:not(.chat-contact-list-item-title)')
|
||||
// );
|
||||
|
||||
// // Buscar en chats
|
||||
// const chatListItemsCount = searchChatContacts(searchChatListItems, searchValue);
|
||||
// // Mostrar u ocultar mensaje de "No se encontraron resultados" en chats
|
||||
// if (chatListItem0) {
|
||||
// chatListItem0.classList.toggle('d-none', chatListItemsCount !== 0);
|
||||
// }
|
||||
|
||||
// // Buscar en contactos
|
||||
// const contactListItemsCount = searchChatContacts(searchContactListItems, searchValue);
|
||||
// // Mostrar u ocultar mensaje de "No se encontraron resultados" en contactos
|
||||
// if (contactListItem0) {
|
||||
// contactListItem0.classList.toggle('d-none', contactListItemsCount !== 0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Función para buscar en chats y contactos
|
||||
// function searchChatContacts(searchListItems, searchValue) {
|
||||
// let searchListItemsCount = 0;
|
||||
// searchListItems.forEach(searchListItem => {
|
||||
// const searchListItemText = searchListItem.textContent.toLowerCase();
|
||||
// const matchesSearch = searchListItemText.indexOf(searchValue) !== -1;
|
||||
|
||||
// searchListItem.classList.toggle('d-flex', matchesSearch);
|
||||
// searchListItem.classList.toggle('d-none', !matchesSearch);
|
||||
|
||||
// if (matchesSearch) {
|
||||
// searchListItemsCount++;
|
||||
// }
|
||||
// });
|
||||
|
||||
// return searchListItemsCount;
|
||||
// }
|
||||
|
||||
// // // Enviar mensaje
|
||||
// // if (sendMsgBtn) {
|
||||
// // sendMsgBtn.addEventListener('click', e => {
|
||||
// // e.preventDefault();
|
||||
// // if (messageInput.value) {
|
||||
// // const renderMsg = document.createElement('div');
|
||||
// // renderMsg.className = 'chat-message-text mt-2';
|
||||
// // renderMsg.innerHTML = `<p class="mb-0">${messageInput.value}</p>`;
|
||||
// // const lastChatMessageWrapper = document.querySelector('li:last-child .chat-message-wrapper');
|
||||
// // if (lastChatMessageWrapper) {
|
||||
// // lastChatMessageWrapper.appendChild(renderMsg);
|
||||
// // }
|
||||
// // messageInput.value = '';
|
||||
// // scrollToBottom();
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
|
||||
@ -0,0 +1,160 @@
|
||||
import Ajax from "../ajax.js";
|
||||
import { alertConfirmationDelete, alertSuccess, alertError, alertConfirmAction } from '../alerts/sweetAlert.js'
|
||||
export class ChatDepartmentDatatable {
|
||||
constructor(domItem) {
|
||||
this.item = domItem
|
||||
this.chatDepartmentDisplay = $("#chat-department-display")
|
||||
this.btnStoreChatDepartment = $("#btn-add-new-chat-department")
|
||||
|
||||
this.datatableColumns = [
|
||||
{ data: 'id', searchable: false, sortable: true },
|
||||
{ data: 'display', searchable: true, sortable: true },
|
||||
{ data: 'description', searchable: true, sortable: true },
|
||||
{
|
||||
data: 'action', searchable: false, sortable: false,
|
||||
render: (d, t) => {
|
||||
return `<div class="btn-group btn-group-sm">
|
||||
<a href="/chat/department/edit/${d}" class="chat-department-edit" ><i class="ti ti-eye ti-sm mx-2"></i></a>
|
||||
<a href="javascript:void(0);" class="chat-department-delete" data-id="${d}" ><i class="ti ti-trash ti-sm mx-2"></i></a>
|
||||
</div>`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
init() {
|
||||
this.btnStoreChatDepartment.on('click', this.storeNewChatDepartment.bind(this))
|
||||
this.item.on('click', '.chat-department-delete', this.deleteChatDepartment.bind(this))
|
||||
|
||||
this.datatable = this.item.DataTable({
|
||||
processing: true,
|
||||
order: [[0, 'asc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
bottomStart: 'info',
|
||||
bottomEnd: 'paging'
|
||||
},
|
||||
serverSide: true,
|
||||
pageLength: 10,
|
||||
language: {
|
||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
},
|
||||
columns: this.datatableColumns,
|
||||
ajax: '/chat/department/datatable'
|
||||
});
|
||||
}
|
||||
deleteChatDepartment(event) {
|
||||
const ajax = new Ajax(
|
||||
`/chat/department/${$(event.currentTarget).data("id")}`,
|
||||
null,
|
||||
null,
|
||||
this.deleteChatDepartmentSuccess.bind(this),
|
||||
this.deleteChatDepartmentError.bind(this)
|
||||
)
|
||||
alertConfirmationDelete().then(result => {
|
||||
if (result.isConfirmed) {
|
||||
ajax.delete()
|
||||
}
|
||||
})
|
||||
}
|
||||
deleteChatDepartmentSuccess(response) {
|
||||
this.datatable.ajax.reload()
|
||||
alertSuccess(response.message).fire()
|
||||
}
|
||||
deleteChatDepartmentError(response) {
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
storeNewChatDepartment() {
|
||||
this.btnStoreChatDepartment.attr("disabled")
|
||||
const ajax = new Ajax("/chat/department", {
|
||||
display: this.chatDepartmentDisplay.val()
|
||||
},
|
||||
null,
|
||||
this.storeNewChatDepartmentSuccess.bind(this),
|
||||
this.storeNewChatDepartmentError.bind(this)
|
||||
)
|
||||
if (this.chatDepartmentDisplay.val()) {
|
||||
alertConfirmAction().then(result => {
|
||||
if (result.isConfirmed) {
|
||||
ajax.post()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.btnStoreChatDepartment.removeAttr("disabled")
|
||||
}
|
||||
}
|
||||
storeNewChatDepartmentSuccess(response) {
|
||||
this.datatable.ajax.reload()
|
||||
alertSuccess(response.message).fire()
|
||||
}
|
||||
storeNewChatDepartmentError(response) {
|
||||
console.log(response)
|
||||
alertError(response.message).fire()
|
||||
}
|
||||
|
||||
}
|
||||
export class ChatDepartmentUserDatatable {
|
||||
constructor(domItem) {
|
||||
this.item = domItem
|
||||
this.datatableColumns = [
|
||||
{ data: 'userFullName', searchable: true, sortable: true },
|
||||
{ data: 'username', searchable: true, sortable: true },
|
||||
{
|
||||
data: 'action', searchable: false, sortable: false,
|
||||
render: (d, t) => {
|
||||
return `<div class="btn-group btn-group-sm">
|
||||
<a type="button" href="javascript:void(0);" data-id="${d}" class="chat-department-user-delete"><i class="ti ti-trash ti-sm mx-2"></i></a>
|
||||
</div>`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
init() {
|
||||
this.actions()
|
||||
this.datatable = this.item.DataTable({
|
||||
processing: true,
|
||||
order: [[0, 'desc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
bottomStart: 'info',
|
||||
bottomEnd: 'paging'
|
||||
},
|
||||
serverSide: true,
|
||||
pageLength: 10,
|
||||
language: {
|
||||
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
|
||||
},
|
||||
columns: this.datatableColumns,
|
||||
ajax: '/chat/department/users/datatable/' + this.item.data('id')
|
||||
});
|
||||
}
|
||||
actions() {
|
||||
this.item.on("click", ".chat-department-user-delete", this.deleteRow.bind(this))
|
||||
}
|
||||
deleteRow(event) {
|
||||
const ajax = new Ajax(`/chat/department/admin/user/${this.item.data('id')}/${$(event.currentTarget).data("id")}`,
|
||||
null,
|
||||
null,
|
||||
this.deleteRowSuccess.bind(this),
|
||||
this.deleteRowError.bind(this),
|
||||
)
|
||||
alertConfirmationDelete().then(result => {
|
||||
if (result.isConfirmed) {
|
||||
ajax.delete()
|
||||
}
|
||||
})
|
||||
}
|
||||
deleteRowSuccess(response) {
|
||||
this.datatable.ajax.reload();
|
||||
alertSuccess(response.message).fire()
|
||||
}
|
||||
deleteRowError(response) {
|
||||
alertError(response?.message).fire()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -7,11 +7,13 @@ class MessagesDatatable {
|
||||
this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages")
|
||||
this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages")
|
||||
this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages")
|
||||
|
||||
this.columnDefs = [
|
||||
]
|
||||
this.datatableColumns = [
|
||||
{ data: 'created_at', searchable: true, sortable: true },
|
||||
{ data: 'updated_at', searchable: true, sortable: true },
|
||||
{ data: 'title', searchable: true, sortable: true },
|
||||
{ data: 'title', name:"chats.title",searchable: true, sortable: true },
|
||||
{ data: 'message', searchable: false, sortable: true },
|
||||
{ data: 'creator', searchable: false, sortable: false },
|
||||
{
|
||||
data: 'viewed', searchable: false, sortable: true,
|
||||
@ -27,10 +29,10 @@ class MessagesDatatable {
|
||||
<a href="/chat/${d.type}/${d.modelId}" class="message-edit" title="${d.lang.view_chat}"><i class="ti ti-eye ti-sm mx-2"></i></a>
|
||||
${d.isAdmin ?
|
||||
`<div class="btn-group dropstart btn-group-sm">
|
||||
<button data-id="${d.modelId}" type="button" title="${d.lang.view_by_alt_message}" class="btn btn-icon rounded-pill dropdown-toggle hide-arrow text-primary btn-notification-viewed" data-bs-toggle="dropdown">
|
||||
<button data-id="${d.chatMessageId}" type="button" title="${d.lang.view_by_alt_message}" class="btn btn-icon rounded-pill dropdown-toggle hide-arrow text-primary btn-notification-viewed" data-bs-toggle="dropdown">
|
||||
<i class="icon-base ti ti-messages"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu" id="dropdown-viewed-${d.modelId}">
|
||||
<ul class="dropdown-menu" id="dropdown-viewed-${d.chatMessageId}">
|
||||
</ul>
|
||||
</div>` : ""
|
||||
}
|
||||
@ -46,13 +48,16 @@ class MessagesDatatable {
|
||||
}
|
||||
init() {
|
||||
this.item.on('click', '.btn-notification-viewed', (event) => {
|
||||
const chatId = $(event.currentTarget).data('id')
|
||||
$(`#dropdown-viewed-${chatId}`).empty()
|
||||
this.handleDropUp(chatId)
|
||||
const chatMessageId = $(event.currentTarget).data('id')
|
||||
$(`#dropdown-viewed-${chatMessageId}`).empty()
|
||||
this.handleDropUp(chatMessageId)
|
||||
})
|
||||
|
||||
this.datatable = this.datatableItem.DataTable({
|
||||
processing: true,
|
||||
order: [[1, 'desc']],
|
||||
columnDefs : this.columnDefs,
|
||||
orderCellsTop : true,
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
@ -71,6 +76,8 @@ class MessagesDatatable {
|
||||
this.datatablePresupuestoMessage = this.datatablePresupuestoMessageItem.DataTable({
|
||||
processing: true,
|
||||
order: [[1, 'desc']],
|
||||
columnDefs : this.columnDefs,
|
||||
orderCellsTop : true,
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
topEnd: 'search',
|
||||
@ -87,6 +94,8 @@ class MessagesDatatable {
|
||||
});
|
||||
this.datatablePedidoMessage = this.datatablePedidoMessageItem.DataTable({
|
||||
processing: true,
|
||||
orderCellsTop : true,
|
||||
columnDefs : this.columnDefs,
|
||||
order: [[1, 'desc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
@ -104,6 +113,8 @@ class MessagesDatatable {
|
||||
});
|
||||
this.datatableFacturaMessage = this.datatableFacturaMessageItem.DataTable({
|
||||
processing: true,
|
||||
orderCellsTop : true,
|
||||
columnDefs : this.columnDefs,
|
||||
order: [[1, 'desc']],
|
||||
layout: {
|
||||
topStart: 'pageLength',
|
||||
@ -119,11 +130,23 @@ class MessagesDatatable {
|
||||
columns: this.datatableColumns,
|
||||
ajax: '/messages/datatable/factura'
|
||||
});
|
||||
this.datatablePresupuestoMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatablePresupuestoMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
this.datatablePedidoMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatablePedidoMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
this.datatableFacturaMessageItem.on("keyup", ".datatable-message-filter", (event) => {
|
||||
let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name"))
|
||||
this.datatableFacturaMessage.column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
handleDropUp(chatId) {
|
||||
let ajax = new Ajax('/chat/users/notifications-unviewed/' + chatId,
|
||||
handleDropUp(chatMessageId) {
|
||||
let ajax = new Ajax('/chat/users/message/notifications-unviewed/' + chatMessageId,
|
||||
null,
|
||||
null,
|
||||
this.handleDropUpSuccess.bind(this),
|
||||
@ -133,34 +156,49 @@ class MessagesDatatable {
|
||||
ajax.get();
|
||||
}
|
||||
handleDropUpSuccess(response) {
|
||||
const chatId = response.chat_id
|
||||
const users = response.data
|
||||
if (users.length > 0) {
|
||||
const chat_message_id = response.chat_message_id
|
||||
const notifications = response.data.notifications
|
||||
|
||||
users.forEach(user => {
|
||||
const viewed = (user.notification_count - user.viewed_count) == 0
|
||||
if (notifications.length > 0) {
|
||||
|
||||
notifications.forEach(user => {
|
||||
if (user.userFullName || user.userName) {
|
||||
|
||||
$(`#dropdown-viewed-${chatId}`)
|
||||
.append(`
|
||||
<li >
|
||||
<a class="d-flex flex-row justify-content-start align-items-center dropdown-item px-2 gap-2" href="javascript:void(0);" >
|
||||
<span> ${user.userFullName ?? user.userName} </span>
|
||||
<span class="badge badge-center rounded-pill text-bg-secondary">
|
||||
<i class="ti ti-xs ti-${viewed ? "eye-check" : "eye-off"} "></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
`)
|
||||
$(`#dropdown-viewed-${chat_message_id}`)
|
||||
.append(this.addDropUpItem(user))
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
$(`#dropdown-viewed-${chatId}`).append(`<li><a class="dropdown-item" href="javascript:void(0);" >Visto</a></li>`)
|
||||
}
|
||||
// if (viewedNotifications.length > 0) {
|
||||
|
||||
// viewedNotifications.forEach(user => {
|
||||
// if (user.userFullName || user.userName) {
|
||||
|
||||
// $(`#dropdown-viewed-${chat_message_id}`)
|
||||
// .append(this.addDropUpItem(user))
|
||||
// }
|
||||
|
||||
// });
|
||||
// }
|
||||
}
|
||||
handleDropUpError() { }
|
||||
|
||||
addDropUpItem(user)
|
||||
{
|
||||
return `
|
||||
<li >
|
||||
<a type="button" class="d-flex flex-row justify-content-between align-items-center dropdown-item px-2 gap-2" href="javascript:void(0);" >
|
||||
<span> ${user.userFullName ?? user.userName} </span>
|
||||
<span class="badge badge-center rounded-pill text-bg-${
|
||||
user.viewed == 1 ? 'success' : 'danger'
|
||||
}">
|
||||
<i class="ti ti-xs ti-${
|
||||
user.viewed == 1 ? 'eye-check' : 'eye-off'
|
||||
} "></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
import ClassSelect from "../select2.js"
|
||||
import { ChatDepartmentUserDatatable } from '../datatables/ChatDepartmentDatatable.js'
|
||||
import Ajax from "../ajax.js"
|
||||
import { alertConfirmAction, alertError, alertSuccess } from "../alerts/sweetAlert.js"
|
||||
|
||||
class ChatDepartmentForm {
|
||||
constructor(domItem) {
|
||||
this.item = domItem
|
||||
this.chatDepartmentId = this.item.data("id")
|
||||
this.btnAddUserToDepartment = this.item.find("#add-user-admin-chat-department")
|
||||
this.btnUpdate = this.item.find("#btn-chat-department-update")
|
||||
this.chatDepartmentUsersDatatable = new ChatDepartmentUserDatatable($("#tableChatDepartmentUsers"))
|
||||
this.seletChatDepartmentUserItem = this.item.find("#selectChatDepartmentUser")
|
||||
this.seletChatDepartmentUser = new ClassSelect(
|
||||
this.seletChatDepartmentUserItem,
|
||||
`/chat/department/users/select/add/${this.chatDepartmentId}`
|
||||
)
|
||||
}
|
||||
init() {
|
||||
this.seletChatDepartmentUser.init()
|
||||
this.chatDepartmentUsersDatatable.init()
|
||||
this.btnAddUserToDepartment.on('click', this._handleUserToDepartment.bind(this))
|
||||
this.btnUpdate.on("click", this._handleUpdateDepartment.bind(this))
|
||||
}
|
||||
getFormData() {
|
||||
return {
|
||||
display: this.item.find("#chat-department-display").val(),
|
||||
description: this.item.find("#chat-department-description").val()
|
||||
}
|
||||
}
|
||||
updateFormData(data) {
|
||||
this.item.find("#chat-department-display").val(data.display)
|
||||
this.item.find("#chat-department-description").val(data.description)
|
||||
}
|
||||
_handleUserToDepartment() {
|
||||
this.btnAddUserToDepartment.attr("disabled", "disabled")
|
||||
const ajax = new Ajax("/chat/department/subscribe/admin/user",
|
||||
{
|
||||
user_id: this.seletChatDepartmentUser.getVal(),
|
||||
chat_department_id: this.chatDepartmentId
|
||||
},
|
||||
null,
|
||||
this._handleUserToDepartmentSuccess.bind(this),
|
||||
this._handleUserToDepartmentError.bind(this)
|
||||
)
|
||||
if (this.seletChatDepartmentUser.getVal()) {
|
||||
ajax.post();
|
||||
} else {
|
||||
this.btnAddUserToDepartment.removeAttr("disabled")
|
||||
}
|
||||
}
|
||||
_handleUserToDepartmentSuccess(response) {
|
||||
this.btnAddUserToDepartment.removeAttr("disabled")
|
||||
this.chatDepartmentUsersDatatable.datatable.ajax.reload()
|
||||
alertSuccess(response.message).fire()
|
||||
this.seletChatDepartmentUser.reset()
|
||||
}
|
||||
_handleUserToDepartmentError(response) {
|
||||
alertError(response.message ?? "").fire()
|
||||
this.btnAddUserToDepartment.removeAttr("disabled")
|
||||
|
||||
}
|
||||
_handleUpdateDepartment() {
|
||||
this.btnUpdate.attr("disabled")
|
||||
const ajax = new Ajax("/chat/department/update/" + this.chatDepartmentId,
|
||||
this.getFormData(),
|
||||
null,
|
||||
this._handleUserToDepartmentSuccess.bind(this),
|
||||
this._handleUserToDepartmentError.bind(this)
|
||||
)
|
||||
if (this.getFormData()) {
|
||||
ajax.post();
|
||||
} else {
|
||||
this.btnUpdate.removeAttr("disabled")
|
||||
}
|
||||
}
|
||||
__handleUpdateDepartmentSuccess(response) {
|
||||
this.btnUpdate.removeAttr("disabled")
|
||||
alertSuccess(response.message).fire()
|
||||
this.updateFormData(response.data)
|
||||
}
|
||||
_handleUpdateDepartmentError(response) {
|
||||
this.btnUpdate.removeAttr("disabled")
|
||||
alertError(response.message ?? "").fire()
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default ChatDepartmentForm
|
||||
@ -5,8 +5,8 @@ import ClassSelect from "./select2.js"
|
||||
const getInitials = (name) => name.split(" ").map(e => e.charAt(0)).join("")
|
||||
const hebraList = (message) => `
|
||||
<div class="list-group-item list-group-item-action d-flex align-items-center cursor-pointer">
|
||||
<div class="avatar avatar-sm me-2">
|
||||
<span class="avatar-initial rounded-circle bg-primary" title="${message.senderFullName}">${getInitials(message.senderFullName)}</span>
|
||||
<div class="avatar avatar-md px-2 py-2">
|
||||
<img src="https://gravatar.com/avatar/${message.user?.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>
|
||||
<div class="w-100 px-4">
|
||||
<div class="d-flex flex-column">
|
||||
@ -18,7 +18,7 @@ const hebraList = (message) => `
|
||||
${message.created_at}
|
||||
</p>
|
||||
<h6>
|
||||
${message.senderFullName} (${message.senderUserName})
|
||||
${message.user.first_name} ${message.user.last_name} (${message.user.username})
|
||||
</h6>
|
||||
</div>
|
||||
<p class="text-start">${message.message}</p>
|
||||
@ -27,12 +27,10 @@ const hebraList = (message) => `
|
||||
</div>
|
||||
`
|
||||
const hebraUsersList = (user) => `
|
||||
<div class="avatar avatar-md px-2 py-2" title="${user.first_name + " " + user.last_name}">
|
||||
<img src="https://gravatar.com/avatar/${user.avatar}?s=40" class="rounded-circle"></img>
|
||||
</div>`
|
||||
|
||||
<div class="avatar avatar-sm me-2">
|
||||
<span class="avatar-initial rounded-circle bg-secondary" title="${user.userFullName}">${getInitials(user.userFullName)}</span>
|
||||
</div>
|
||||
|
||||
`
|
||||
class InternalMessages {
|
||||
constructor(domItem) {
|
||||
this.item = domItem
|
||||
@ -53,14 +51,14 @@ class InternalMessages {
|
||||
this.type = this.item.data("type")
|
||||
this.chatId = null
|
||||
|
||||
this.selectMessageUsers = new ClassSelect(this.selectUsers, '/chat/users/internal', "Seleccione un usuario",true)
|
||||
this.selectMessageUsers = new ClassSelect(this.selectUsers, '/chat/users/internal', "Seleccione un usuario", true)
|
||||
}
|
||||
init() {
|
||||
this.selectMessageUsers.init()
|
||||
this.item.on("click", ".btn-new-hebra", this.handleBtnNewHebra.bind(this))
|
||||
this.item.on("click", ".btn-new-hebra-message", this.handleBtnUpdateHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click","#submit_new_hebra",this.handlePostNewHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click","#submit_update_hebra",this.handleUpdateHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click", "#submit_new_hebra", this.handlePostNewHebra.bind(this))
|
||||
this.modalNewMessage.item.on("click", "#submit_update_hebra", this.handleUpdateHebra.bind(this))
|
||||
this.handleGetInternalMessages()
|
||||
|
||||
}
|
||||
@ -75,7 +73,7 @@ class InternalMessages {
|
||||
)
|
||||
ajax.get()
|
||||
}
|
||||
handlePostNewHebra(){
|
||||
handlePostNewHebra() {
|
||||
this._handleUpdateFormNewHebraValues()
|
||||
let ajax = new Ajax(
|
||||
`/chat/hebra/${this.type}`,
|
||||
@ -87,12 +85,12 @@ class InternalMessages {
|
||||
ajax.post()
|
||||
|
||||
}
|
||||
handlePostNewHebraSuccess(data){
|
||||
handlePostNewHebraSuccess(data) {
|
||||
this.modalNewMessage.toggle()
|
||||
this.handleGetInternalMessages()
|
||||
}
|
||||
handlePostNewHebraError(err){}
|
||||
handleUpdateHebra(){
|
||||
handlePostNewHebraError(err) { }
|
||||
handleUpdateHebra() {
|
||||
this._handleUpdateFormUpdateHebraValues()
|
||||
let ajax = new Ajax(
|
||||
`/chat/hebra/${this.chatId}`,
|
||||
@ -103,11 +101,11 @@ class InternalMessages {
|
||||
)
|
||||
ajax.post()
|
||||
}
|
||||
handleUpdateNewHebraSuccess(data){
|
||||
handleUpdateNewHebraSuccess(data) {
|
||||
this.modalNewMessage.toggle()
|
||||
this.handleGetInternalMessages()
|
||||
}
|
||||
handleUpdateNewHebraError(err){}
|
||||
handleUpdateNewHebraError(err) { }
|
||||
handleBtnNewHebra(e) {
|
||||
e.preventDefault()
|
||||
this.chatId = null
|
||||
@ -137,34 +135,34 @@ class InternalMessages {
|
||||
}
|
||||
_handleUpdateFormNewHebraValues() {
|
||||
this.formNewValues = {
|
||||
title : this.hebraTitle.val(),
|
||||
title: this.hebraTitle.val(),
|
||||
users: this.selectMessageUsers.getVal(),
|
||||
message: this.textAreaMessage.val(),
|
||||
modelId : this.modelId
|
||||
modelId: this.modelId
|
||||
}
|
||||
}
|
||||
_handleUpdateFormUpdateHebraValues() {
|
||||
this.formUpdateValues = {
|
||||
users: this.selectMessageUsers.getVal(),
|
||||
message: this.textAreaMessage.val(),
|
||||
modelId : this.modelId
|
||||
modelId: this.modelId
|
||||
}
|
||||
}
|
||||
_handleGetInternalMessagesSuccess(data){
|
||||
_handleGetInternalMessagesSuccess(data) {
|
||||
Object.values(data).map((k) => {
|
||||
this._addHebraDOM(k.chatId,k.chatTitle,k.messages,k.users)
|
||||
this._addHebraDOM(k.id, k.title, k.messages, k.internalUsers)
|
||||
})
|
||||
}
|
||||
_handleGetInternalMessagesError(err){}
|
||||
_handleGetInternalMessagesError(err) { }
|
||||
|
||||
_addHebraDOM(key,chatTitle,messages,users) {
|
||||
_addHebraDOM(key, chatTitle, messages, users) {
|
||||
const itemHebra = $(`<div id="hebra-item-${key}"></div>`).addClass("border border-container flex-grow-0 container-p-y mt-4 p-5")
|
||||
const headerHebra = $("<div></div>").addClass("d-flex justify-content-between align-items-center")
|
||||
const contentHeaderHebra = $("<h4></h4>").text(`${chatTitle}`)
|
||||
const btnNewHebra = $("<button></button>").attr("type", "button").addClass("btn btn-danger btn-sm btn-new-hebra")
|
||||
btnNewHebra.append('<span class="ti-xs ti ti-git-branch"></span>')
|
||||
btnNewHebra.append("Nuevo hilo")
|
||||
headerHebra.append(contentHeaderHebra,btnNewHebra)
|
||||
headerHebra.append(contentHeaderHebra, btnNewHebra)
|
||||
itemHebra.append(headerHebra)
|
||||
let itemMessagesHebraRow = $("<div></div>").addClass("row")
|
||||
let itemMessagesHebraCol = $("<div></div>").addClass("col")
|
||||
|
||||
@ -5,97 +5,96 @@
|
||||
* @param {String} placeholder
|
||||
*/
|
||||
let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}, dropdownParent = "", hideSearch = false) {
|
||||
this.url = url;
|
||||
this.item = domItem;
|
||||
this.params = params;
|
||||
this.dropdownParent = dropdownParent;
|
||||
this.hideSearch = hideSearch;
|
||||
this.url = url;
|
||||
this.item = domItem;
|
||||
this.params = params;
|
||||
this.dropdownParent = dropdownParent;
|
||||
this.hideSearch = hideSearch;
|
||||
|
||||
this.config = {
|
||||
placeholder: placeholder,
|
||||
allowClear: allowClear,
|
||||
dropdownParent: dropdownParent!=""?dropdownParent:domItem.parent(),
|
||||
language: "es",
|
||||
ajax: {
|
||||
url: () => {
|
||||
return this.url;
|
||||
},
|
||||
data: (params) => {
|
||||
let q = $.trim(params.term);
|
||||
let d = {
|
||||
q: q,
|
||||
page: params.page || 1,
|
||||
};
|
||||
|
||||
for (let key in this.params) {
|
||||
d[key] = this.params[key];
|
||||
}
|
||||
|
||||
return d;
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {
|
||||
results: $.map(data, function (obj) {
|
||||
return {
|
||||
id: obj.id,
|
||||
text: obj.nombre ?? obj.name,
|
||||
desc: obj.description,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
cache: true,
|
||||
this.config = {
|
||||
placeholder: placeholder,
|
||||
allowClear: allowClear,
|
||||
dropdownParent: dropdownParent != "" ? dropdownParent : domItem.parent(),
|
||||
language: "es",
|
||||
ajax: {
|
||||
url: () => {
|
||||
return this.url;
|
||||
},
|
||||
};
|
||||
this.init = function () {
|
||||
if (this.item.length) {
|
||||
data: (params) => {
|
||||
let q = $.trim(params.term);
|
||||
let d = {
|
||||
q: q,
|
||||
page: params.page || 1,
|
||||
};
|
||||
|
||||
if(this.hideSearch){
|
||||
this.config.minimumResultsForSearch = -1;
|
||||
for (let key in this.params) {
|
||||
d[key] = this.params[key];
|
||||
}
|
||||
|
||||
this.item = this.item.select2(this.config);
|
||||
// $.fn.modal.Constructor.prototype.enforceFocus = function () {};
|
||||
}
|
||||
};
|
||||
this.setOption = function (id, nombre) {
|
||||
var newOption = new Option(nombre , id, false, false);
|
||||
this.item.append(newOption);
|
||||
this.item.val(id).trigger("change");
|
||||
};
|
||||
this.reset = function () {
|
||||
this.item.val(null).trigger("change");
|
||||
};
|
||||
this.setParams = function(params){
|
||||
this.params = params;
|
||||
};
|
||||
this.getVal = function () {
|
||||
return this.item.val();
|
||||
};
|
||||
this.setVal = function (val) {
|
||||
return this.item.val(val).trigger("change");
|
||||
};
|
||||
this.empty = function () {
|
||||
return this.item.empty().trigger("change");
|
||||
};
|
||||
this.readOnly = function () {
|
||||
this.item.enable(false);
|
||||
};
|
||||
this.enable = () => {
|
||||
this.item.enable(true);
|
||||
};
|
||||
this.fixWithScroll = function () {};
|
||||
this.getText = () => {
|
||||
return this.item.find(":selected").text();
|
||||
};
|
||||
this.onChange = function(callback) {
|
||||
this.item.on('change', callback);
|
||||
};
|
||||
this.offChange = function() {
|
||||
this.item.off('change');
|
||||
};
|
||||
|
||||
return d;
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {
|
||||
results: $.map(data, function (obj) {
|
||||
return {
|
||||
id: obj.id,
|
||||
text: obj.nombre ?? obj.name,
|
||||
desc: obj.description,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
cache: true,
|
||||
},
|
||||
};
|
||||
|
||||
this.init = function () {
|
||||
if (this.item.length) {
|
||||
|
||||
if (this.hideSearch) {
|
||||
this.config.minimumResultsForSearch = -1;
|
||||
}
|
||||
|
||||
this.item = this.item.select2(this.config);
|
||||
// $.fn.modal.Constructor.prototype.enforceFocus = function () {};
|
||||
}
|
||||
};
|
||||
this.setOption = function (id, nombre) {
|
||||
var newOption = new Option(nombre, id, false, false);
|
||||
this.item.append(newOption);
|
||||
this.item.val(id).trigger("change");
|
||||
};
|
||||
this.reset = function () {
|
||||
this.item.val(null).trigger("change");
|
||||
};
|
||||
this.setParams = function (params) {
|
||||
this.params = params;
|
||||
};
|
||||
this.getVal = function () {
|
||||
return this.item.val();
|
||||
};
|
||||
this.setVal = function (val) {
|
||||
return this.item.val(val).trigger("change");
|
||||
};
|
||||
this.empty = function () {
|
||||
return this.item.empty().trigger("change");
|
||||
};
|
||||
this.readOnly = function () {
|
||||
this.item.enable(false);
|
||||
};
|
||||
this.enable = () => {
|
||||
this.item.enable(true);
|
||||
};
|
||||
this.fixWithScroll = function () { };
|
||||
this.getText = () => {
|
||||
return this.item.find(":selected").text();
|
||||
};
|
||||
this.onChange = function (callback) {
|
||||
this.item.on('change', callback);
|
||||
};
|
||||
this.offChange = function () {
|
||||
this.item.off('change');
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
export default ClassSelect;
|
||||
|
||||
@ -2,12 +2,12 @@ import { showNotificationMessages } from "../components/chat.js";
|
||||
|
||||
$(() => {
|
||||
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
const chatNotificationInterval = setInterval(() => {
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
}, 10000)
|
||||
$("#message-notification-dropdown").on("click", (e) => {
|
||||
showNotificationMessages($("#chat-notification-list"))
|
||||
showNotificationMessages()
|
||||
})
|
||||
$("#btn-log-out").on("click",() => {
|
||||
clearInterval(chatNotificationInterval)
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
import Ajax from '../../../components/ajax.js'
|
||||
import { ChatDepartmentDatatable } from '../../../components/datatables/ChatDepartmentDatatable.js'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$(() => {
|
||||
const chatDepartmentDatatable = new ChatDepartmentDatatable($("#tableChatDepartments"))
|
||||
chatDepartmentDatatable.init()
|
||||
})
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
|
||||
import ChatDepartmentForm from '../../../components/forms/chatDepartmentForm.js'
|
||||
|
||||
$(() => {
|
||||
|
||||
const chatDepartmentForm = new ChatDepartmentForm($("#chatDepartmentForm"))
|
||||
chatDepartmentForm.init()
|
||||
})
|
||||
Reference in New Issue
Block a user