message chat section

This commit is contained in:
amazuecos
2024-11-29 22:05:50 +01:00
parent c1aecb43f2
commit 2e767889ef
24 changed files with 615 additions and 105 deletions

View File

@ -763,12 +763,22 @@ $routes->group('mensajes', ['namespace' => 'App\Controllers\Mensajeria'], functi
});
$routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($routes) {
$routes->get('datatable', 'ChatController::datatable_messages', ['as' => 'getDatatableMessages']);
$routes->get('datatable/presupuesto', 'ChatController::datatable_presupuesto_messages', ['as' => 'getDatatablePresupuestoMessages']);
$routes->get('datatable/pedido', 'ChatController::datatable_pedido_messages', ['as' => 'getDatatablePedidoMessages']);
$routes->get('datatable/factura', 'ChatController::datatable_factura_messages', ['as' => 'getDatatableFacturaMessages']);
$routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']);
$routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']);
});
$routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($routes) {
$routes->get('direct/(:num)', 'ChatController::get_chat_direct_view/$1', ['as' => 'getChatDirectView']);
$routes->get('presupuesto/(:num)', 'ChatController::get_chat_presupuesto_view/$1', ['as' => 'getChatPresupuestoView']);
$routes->get('pedido/(:num)', 'ChatController::get_chat_pedido_view/$1', ['as' => 'getChatPedidoView']);
$routes->get('factura/(:num)', 'ChatController::get_chat_factura_view/$1', ['as' => 'getChatFacturaView']);
$routes->get('direct/conversation/(:num)', 'ChatController::get_chat_direct/$1', ['as' => 'getChatDirect']);
$routes->get('direct/users/select/(:num)', 'ChatController::get_chat_direct_select_users/$1', ['as' => 'getChatDirectSelectUsers']);
$routes->get('direct/users/(:num)', 'ChatController::get_chat_direct_users', ['as' => 'getChatDirectUsers']);
@ -779,6 +789,7 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
$routes->get('departments', 'ChatController::get_chat_departments', ['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']);

View File

@ -29,7 +29,7 @@ class ChatController extends BaseController
protected ClienteModel $clienteModel;
protected ChatUser $chatUserModel;
protected ChatNotification $chatNotificationModel;
protected array $viewData;
protected static $viewPath = 'themes/vuexy/form/mensajes/';
@ -57,6 +57,10 @@ class ChatController extends BaseController
$data = $this->chatDeparmentModel->getChatDepartments();
return $this->response->setJSON($data);
}
public function get_chat_department_select(){
$query = $this->chatDeparmentModel->getChatDepartmentSelect($this->request->getGet("q"));
return $this->response->setJSON($query->get()->getResultObject());
}
public function get_chat_presupuesto(int $chat_department_id, int $presupuesto_id)
{
@ -122,6 +126,62 @@ class ChatController extends BaseController
return view(static::$viewPath . 'messageChat', $this->viewData);
}
public function get_chat_presupuesto_view($chat_id)
{
$chat = $this->chatModel->find($chat_id);
$this->viewData['breadcrumb'] = [
['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false],
['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true]
];
$this->viewData["modelId"] = $chat->presupuesto_id;
$this->viewData["type"] = "presupuesto";
$auth_user = auth()->user();
$this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id);
$this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id);
if($chat->chat_department_id){
return view(static::$viewPath . 'messageChatPresupuesto', $this->viewData);
}else{
return view(static::$viewPath . 'messageChatInternal', $this->viewData);
}
}
public function get_chat_pedido_view($chat_id)
{
$chat = $this->chatModel->find($chat_id);
$this->viewData['breadcrumb'] = [
['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false],
['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true]
];
$this->viewData["modelId"] = $chat->pedido_id;
$this->viewData["type"] = "pedido";
$auth_user = auth()->user();
$this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id);
$this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id);
if($chat->chat_department_id ){
return view(static::$viewPath . 'messageChatPedido', $this->viewData);
}else{
return view(static::$viewPath . 'messageChatInternal', $this->viewData);
}
}
public function get_chat_factura_view($chat_id)
{
$chat = $this->chatModel->find($chat_id);
$this->viewData['breadcrumb'] = [
['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false],
['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true]
];
$this->viewData["modelId"] = $chat->factura_id;
$this->viewData["type"] = "factura";
$auth_user = auth()->user();
$this->chatModel->setAsViewedChatUserNotifications($chat_id, $auth_user->id);
$this->chatModel->setAsUnviewedChatUserMessages($chat_id, $auth_user->id);
if($chat->chat_department_id){
return view(static::$viewPath . 'messageChatFactura', $this->viewData);
}else{
return view(static::$viewPath . 'messageChatInternal', $this->viewData);
}
}
public function get_chat(int $chat_id)
{
@ -144,8 +204,8 @@ class ChatController extends BaseController
$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]);
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
@ -165,8 +225,8 @@ class ChatController extends BaseController
$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]);
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
@ -186,8 +246,8 @@ class ChatController extends BaseController
$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]);
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
@ -338,6 +398,7 @@ class ChatController extends BaseController
}
public function store_hebra_presupuesto()
{
$auth_user = auth()->user();
$bodyData = $this->request->getPost();
$chat_id = $this->chatModel->insert([
"presupuesto_id" => $bodyData["modelId"],
@ -346,9 +407,10 @@ class ChatController extends BaseController
$chatMessageId = $this->chatMessageModel->insert([
"chat_id" => $chat_id,
"message" => $bodyData["message"],
"sender_id" => auth()->user()->id
"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) {
@ -494,7 +556,45 @@ class ChatController extends BaseController
->edit('updated_at', fn($q) => 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) => $q->id)
->add("action", fn($q) => ["type" => "direct","modelId" => $q->id])
->toJson(true);
}
public function datatable_presupuesto_messages()
{
$auth_user_id = auth()->user()->id;
$query = $this->chatModel->getQueryDatatableMessagePresupuesto($auth_user_id);
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])
->toJson(true);
}
public function datatable_pedido_messages()
{
$auth_user_id = auth()->user()->id;
$query = $this->chatModel->getQueryDatatableMessagePedido($auth_user_id);
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])
->toJson(true);
}
public function datatable_factura_messages()
{
$auth_user_id = auth()->user()->id;
$query = $this->chatModel->getQueryDatatableMessageFactura($auth_user_id);
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])
->toJson(true);
}
public function store_new_direct_message()
@ -516,6 +616,28 @@ class ChatController extends BaseController
$this->chatModel->createNewDirectChat(...$bodyData);
return $this->response->setJSON(["message" => lang("Chat.new_message_ok"), "status" => true]);
}
public function store_new_direct_message_client()
{
$bodyData = $this->request->getPost();
$rules = [
"title" => "required|string",
"message" => "required|string",
"chat_department_id" => "required",
];
if (!$this->validate($rules)) {
return $this->response->setStatusCode(400)->setJSON([
'message' => lang('App.global_alert_save_error'),
'status' => 'error',
'errors' => $this->validator->getErrors(),
]);
}
$users = $this->chatDeparmentModel->getChatDepartmentUsers($bodyData["chat_department_id"]);
$bodyData["users"] = array_map(fn($q) => $q->id,$users);
dd(1);
$this->chatModel->createNewDirectChat(...$bodyData);
return $this->response->setJSON(["message" => lang("Chat.new_message_ok"), "status" => true]);
}
public function get_chat_direct($chat_id)
{
$chatData = $this->chatModel->getChatDirect($chat_id);
@ -570,9 +692,9 @@ class ChatController extends BaseController
$message = $this->chatMessageModel->get_chat_message($chat_message_id);
return $this->response->setJSON($message);
}
public function update_chat_direct_message_unread($chat_id){
$this->chatModel->setAsUnviewedChatUserNotifications($chat_id,auth()->user()->id);
public function update_chat_direct_message_unread($chat_id)
{
$this->chatModel->setAsUnviewedChatUserNotifications($chat_id, auth()->user()->id);
return $this->response->setJSON(["message" => "ok", "status" => true]);
}
}

View File

@ -3,6 +3,7 @@
return [
"chat" => "Mensajería",
"messages" => "Mensajes",
"message" => "Mensaje",
"modal" => [
"new_hebra" => "Nuevo hilo",
"title" => "Título",
@ -21,10 +22,11 @@ return [
],
"new_message_ok" => "Mensaje enviado correctamente",
"participants" => "Participantes",
"choose_department" => "Elige un departamento",
"new_participant" => "Añadir nuevos participantes",
"write_message_placeholder" => "Escriba aquí su mensaje...",
"add_notification" => "Notificación",
"check_as_unviewed" => "Marcar como no leídos",
"add_notification_message" => "Envía a los usuarios añadidos una notificación con los mensajes presentes en el chat."
"add_notification_message" => "Envía a los usuarios añadidos una notificación con los mensajes presentes en el chat.",
"chat_title_presupuesto" => 'Presupuesto[{title,string,0}][{id}]'
];

View File

@ -10,7 +10,7 @@ class ChatDeparmentModel extends Model
protected $table = 'chat_departments';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $returnType = 'object';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
@ -126,4 +126,21 @@ class ChatDeparmentModel extends Model
->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)
{
$q = $this->builder()->select([
"id",
"display as name",
"description"
]);
if($query){
$q->orLike("display",$query)
->orLike("name",$query);
}
return $q;
}
}

View File

@ -88,7 +88,11 @@ class ChatModel extends Model
public function createChatPresupuesto(int $chat_department_id, int $presupuesto_id): int
{
$model = model(PresupuestoModel::class);
$chatDeparmentModel = model(ChatDeparmentModel::class);
$presupuesto = $model->find($presupuesto_id);
return $this->insert([
"title" => $presupuesto->titulo."[".$chatDeparmentModel->getDisplay($chat_department_id)."]",
"presupuesto_id" => $presupuesto_id,
"chat_department_id" => $chat_department_id
]);
@ -96,7 +100,11 @@ class ChatModel extends Model
public function createChatPedido(int $chat_department_id, int $pedido_id): int
{
$model = model(PedidoModel::class);
$chatDeparmentModel = model(ChatDeparmentModel::class);
$pedido = $model->getPedidoClientePresupuesto($pedido_id);
return $this->insert([
"title" => "Pedido ".$pedido->titulo."[".$chatDeparmentModel->getDisplay($chat_department_id)."]",
"pedido_id" => $pedido_id,
"chat_department_id" => $chat_department_id
]);
@ -104,7 +112,12 @@ class ChatModel extends Model
public function createChatFactura(int $chat_department_id, int $factura_id): int
{
$model = model(FacturaModel::class);
$chatDeparmentModel = model(ChatDeparmentModel::class);
$factura = $model->find($factura_id);
return $this->insert([
"title" => "Factura ".$factura->numero."[".$chatDeparmentModel->getDisplay($chat_department_id)."]",
"factura_id" => $factura_id,
"chat_department_id" => $chat_department_id
]);
@ -370,6 +383,7 @@ class ChatModel extends Model
$q = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.chat_department_id as chatDepartmentId",
"chats.pedido_id as pedidoId",
"chats.presupuesto_id as presupuestoId",
"chats.factura_id as facturaId",
@ -390,10 +404,13 @@ class ChatModel extends Model
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId;
}else{
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId;
}
$row->title = $row->presupuestoId;
$row->chatDisplay = $row->model->titulo;
if($row->chatDepartmentId){
$row->chatDisplay = $row->model->titulo;
}else{
$row->chatDisplay .="[INTERNAL]";
}
$row->avatar = "PRE";
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
$rows_new[] = $row;
@ -401,6 +418,9 @@ class ChatModel extends Model
$row->model = $pedidoModel->find($row->pedidoId);
$row->uri = "/pedidos/edit/" . $row->pedidoId;
$row->title = $row->pedidoId;
if($row->chatDepartmentId){
$row->chatDisplay .= "[INTERNAL]";
}
$row->avatar = "P";
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
$rows_new[] = $row;
@ -408,6 +428,9 @@ class ChatModel extends Model
$row->model = $facturaModel->find($row->facturaId);
$row->uri = "/facturas/edit/" . $row->facturaId;
$row->avatar = "F";
if($row->chatDepartmentId){
$row->chatDisplay .= "[INTERNAL]";
}
$row->title = $row->facturaId;
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
$rows_new[] = $row;
@ -465,7 +488,8 @@ class ChatModel extends Model
->where("chats.presupuesto_id", $presupuesto_id);
$data["chatId"] = $chat_id;
$data["messages"] = $query->get()->getResultObject();
$data["chatTitle"] = $this->find($chat_id)->title;
$data["chatTitle"] = "Presupuesto"."[".$presupuesto_id."] - ";
$data["chatTitle"].= $this->find($chat_id)->title;
$data["users"] = $this->getChatUsers($chat_id);
return $data;
}
@ -485,7 +509,8 @@ class ChatModel extends Model
->where("chats.pedido_id", $pedido_id);
$data["chatId"] = $chat_id;
$data["messages"] = $query->get()->getResultObject();
$data["chatTitle"] = $this->find($chat_id)->title;
$data["chatTitle"] = "Pedido"."[".$pedido_id."] - ";
$data["chatTitle"].= $this->find($chat_id)->title;
$data["users"] = $this->getChatUsers($chat_id);
return $data;
}
@ -505,7 +530,8 @@ class ChatModel extends Model
->where("chats.factura_id", $factura_id);
$data["chatId"] = $chat_id;
$data["messages"] = $query->get()->getResultObject();
$data["chatTitle"] = $this->find($chat_id)->title;
$data["chatTitle"] = "Factura"."[".$factura_id."] - ";
$data["chatTitle"].= $this->find($chat_id)->title;
$data["users"] = $this->getChatUsers($chat_id);
return $data;
}
@ -680,9 +706,73 @@ class ChatModel extends Model
->where("pedido_id", null)
->where("presupuesto_id", null)
->where("factura_id", null)
->where("title is NOT NULL", NULL, FALSE)
->where("chat_users.user_id",$user_id)
->orderBy("created_at", "DESC");
->orderBy("created_at", "DESC")
->groupBy("chats.id");
return $query;
}
public function getQueryDatatableMessagePresupuesto(int $user_id): BaseBuilder
{
$query = $this->builder()
->select([
"chats.id",
"chats.created_at",
"chats.updated_at",
"chats.title",
])
->join("chat_users","chats.id = chat_users.chat_id","left")
->join("presupuestos","presupuestos.id = chats.presupuesto_id",'left')
->where("presupuesto_id is NOT NULL", NULL, FALSE)
->groupBy("chats.id");
if(auth()->user()->inGroup("admin") == false){
$query->where('presupuestos.cliente_id',auth()->user()->cliente_id)
->where("chat_department_id is NOT NULL",NULL,FALSE);
}
$query->orderBy("created_at", "DESC");
return $query;
}
public function getQueryDatatableMessagePedido(int $user_id): BaseBuilder
{
$query = $this->builder()
->select([
"chats.id",
"chats.created_at",
"chats.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("presupuestos","presupuestos.id = pedidos_linea.presupuesto_id",'left')
->where("chats.pedido_id is NOT NULL", NULL, FALSE)
->groupBy("chats.id");
if(auth()->user()->inGroup("admin") == false){
$query->where('presupuestos.cliente_id',auth()->user()->cliente_id)
->where("chat_department_id is NOT NULL",NULL,FALSE);
}
$query->orderBy("created_at", "DESC");
return $query;
}
public function getQueryDatatableMessageFactura(int $user_id): BaseBuilder
{
$query = $this->builder()
->select([
"chats.id",
"chats.created_at",
"chats.updated_at",
"chats.title",
])
->join("chat_users","chat_users.chat_id = chats.id","left")
->join("facturas","facturas.id = chats.factura_id","left")
->where("chats.factura_id is NOT NULL", NULL, FALSE)
->groupBy("chats.id");
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);
}
}
$query->orderBy("created_at", "DESC");
return $query;
}
public function createNewDirectChat(string $title, string $message, array $users)
@ -704,6 +794,7 @@ class ChatModel extends Model
$chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user_id]);
}
}
/**
* Obtain users and messages from `chat_id`
*

View File

@ -0,0 +1,14 @@
<?php
namespace App\Services;
use App\Models\Presupuestos\PresupuestoModel;
use CodeIgniter\Config\BaseService;
class MessageService extends BaseService
{
public static function get_chat_title_from_presupuesto(int $presuesto_id,?string $department_name = null) : string
{
}
}

View File

@ -31,17 +31,9 @@
<!-- Chats -->
<ul class="list-unstyled chat-contact-list" id="chat-list">
<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>
<div class="sk-wave-rect"></div>
<div class="sk-wave-rect"></div>
<div class="sk-wave-rect"></div>
</div>
</div>
<li class="chat-contact-list-item chat-list-item-0 d-none">
<h6 class="text-muted mb-0">No Chats Found</h6>
</li>
<!-- CHAT LIST -->
</ul>

View File

@ -32,9 +32,7 @@
<!-- Chats -->
<ul class="list-unstyled chat-contact-list" id="chat-list">
<li class="chat-contact-list-item chat-list-item-0 d-none">
<h6 class="text-muted mb-0">No Chats Found</h6>
</li>
<!-- CHAT LIST -->
</ul>

View File

@ -30,18 +30,8 @@
</div>
<!-- Chats -->
<ul class="list-unstyled chat-contact-list" id="chat-list">
<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>
<div class="sk-wave-rect"></div>
<div class="sk-wave-rect"></div>
<div class="sk-wave-rect"></div>
</div>
</div>
<li class="chat-contact-list-item chat-list-item-0 d-none">
<h6 class="text-muted mb-0">No Chats Found</h6>
</li>
<!-- CHAT LIST -->
</ul>

View File

@ -28,13 +28,19 @@
<option value="0"></option>
</select>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-label-secondary" data-bs-dismiss="modal"><?= lang('App.global_come_back') ?></button>
<button type="button" id="submit-new-direct-message" class="btn btn-primary"><?= lang('Chat.modal.btn_send') ?></button>
<?php if (auth()->user()->inGroup('admin')) { ?>
<button type="button" id="submit-new-direct-message" class="btn btn-primary"><?= lang('Chat.modal.btn_send') ?></button>
<?php } ?>
</div>
</div>
</div>

View File

@ -0,0 +1,15 @@
<table id="<?= $id ?>" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<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.creator') ?></th>
<th><?= lang('Chat.datatable_messages.viewed') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>

View File

@ -8,43 +8,48 @@
<!--Content Body-->
<div class="row">
<div class="col-md-12">
<div class="nav-tabs-shadow nav-align-top">
<ul class="nav nav-tabs" role="tablist">
<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 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>
</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>
</li>
<li class="nav-item">
<button type="button" class="nav-link" role="tab" id="navs-top-align-facturas-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-facturas">Facturas</button>
</li>
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?= lang('Chat.messages') ?></h3>
</div>
<!--//.card-header -->
<div class="card-body" id="messagesViewCard">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<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>
</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>
<table id="tableMessages" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<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.creator') ?></th>
<th><?= lang('Chat.datatable_messages.viewed') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
<div class="tab-pane fade show" 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">
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tablePedidoMessages"]) ?>
</tbody>
</table>
</div>
<!--//.card-body -->
<div class="card-footer">
</div>
<div class="tab-pane fade show" id="navs-top-align-facturas">
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableFacturaMessages"]) ?>
</div>
</div>
<!--//.card-footer -->
<!--//.card -->
</div>
<!--//.card -->
</div>
<!--//.col -->
</div>

View File

@ -0,0 +1,30 @@
<?= $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">
<?= view("themes/vuexy/components/chat_factura",["modelId" => $modelId]) ?>
</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/css/pages/app-chat.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>
<?= $this->endSection() ?>

View File

@ -0,0 +1,28 @@
<?= $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">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => $type]) ?>
</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/css/pages/app-chat.css') ?>">
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script type="module" src="<?= site_url("assets/js/safekat/pages/messages/internalMessagePage.js") ?>"></script>
<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>
<?= $this->endSection() ?>

View File

@ -0,0 +1,27 @@
<?= $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">
<?= view("themes/vuexy/components/chat_pedido",["modelId" => $modelId]) ?>
</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/css/pages/app-chat.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>
<?= $this->endSection() ?>

View File

@ -0,0 +1,27 @@
<?= $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">
<?= view("themes/vuexy/components/chat_presupuesto", ["modelId" => $modelId]) ?>
</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/css/pages/app-chat.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>
<?= $this->endSection() ?>

View File

@ -147,18 +147,6 @@ $picture = "/assets/img/default-user.png";
</div>
</li>
<!-- Notification -->
<li class="nav-item dropdown-notifications navbar-dropdown dropdown me-3 me-xl-1">
<a
class="nav-link dropdown-toggle hide-arrow"
href="javascript:void(0);"
data-bs-toggle="dropdown"
data-bs-auto-close="outside"
aria-expanded="false">
<i class="ti ti-bell ti-md"></i>
</a>
</li>
<!--/ Notification -->
<!-- Search Budgets -->
<li class="nav-item navbar-dropdown dropdown me-3 me-xl-1">

View File

@ -168,8 +168,6 @@ class Chat {
null,
this._handleGetChatListSuccess.bind(this),
this._handleGetChatListError.bind(this),
);
ajax.get();
}
@ -182,7 +180,7 @@ class Chat {
this.chatList.find(`#chat_${row.name}`).on("click", (event) => {
$(".chat-contact-list-item").removeClass("active")
$(event.currentTarget).parent().addClass("active")
this.chatHistoryBody.empty()
this.chatHistory.empty()
this.chatDeparmentId = this.chatList.find(`#chat_${row.name}`).data("id")
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)
@ -290,7 +288,7 @@ class Chat {
_getChatDepartmentMessageCountError() { }
_getChatMessage() {
this.chatHistory.empty()
this.domItem.find(".chat-loader").removeClass("d-none")
let ajax = new Ajax(
`/chat/department/${this.chatType}/${this.chatDeparmentId}/${this.modelId}`,
@ -305,7 +303,6 @@ class Chat {
}
_getChatMessageSuccess(data) {
this.domItem.find(".chat-loader").addClass("d-none")
this.chatHistory.empty()
this._setBtnDeparment()
if (data.messages) {
data.messages.map((m) => {

View File

@ -4,28 +4,34 @@ class MessagesDatatable {
constructor(domItem) {
this.item = domItem
this.datatableItem = this.item.find("#tableMessages")
this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages")
this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages")
this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages")
this.datatableColumns = [
{ data: 'created_at', searchable: true, sortable: true },
{ data: 'updated_at', searchable: true, sortable: true },
{ data: 'title', searchable: true, sortable: true },
{ data: 'creator', searchable: false, sortable: false },
{ data: 'viewed', searchable: false, sortable: false ,
render : (d,t) => {
{
data: 'viewed', searchable: false, sortable: false,
render: (d, t) => {
const iconClass = d == true ? "ti ti-sm ti-check" : "ti ti-sm ti-x"
return `<span class="${iconClass}"</span>`
}
},
},
{
data: 'action', sortable: false, searchable: false,
data: 'action', searchable: false, sortable: false,
render: (d, t) => {
return `
<div class="btn-group btn-group-sm">
<a href="/chat/direct/${d}" data-id="${d}" class="message-edit"><i class="ti ti-eye ti-sm mx-2"></i></a>
</div>
`
return `<div class="btn-group btn-group-sm">
<a href="/chat/${d.type}/${d.modelId}" class="message-edit"><i class="ti ti-eye ti-sm mx-2"></i></a>
</div>`
}
}
]
}
init() {
this.datatable = this.datatableItem.DataTable({
@ -45,6 +51,55 @@ class MessagesDatatable {
ajax: '/messages/datatable'
});
this.datatablePresupuestoMessage = this.datatablePresupuestoMessageItem.DataTable({
processing: true,
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: '/messages/datatable/presupuesto'
});
this.datatablePedidoMessage = this.datatablePedidoMessageItem.DataTable({
processing: true,
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: '/messages/datatable/pedido'
});
this.datatableFacturaMessage = this.datatableFacturaMessageItem.DataTable({
processing: true,
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: '/messages/datatable/factura'
});
}
}

View File

@ -5,18 +5,27 @@ import ClassSelect from "../../../components/select2.js";
import Alert from "../../../components/alerts/alert.js";
class MessagePage {
constructor() {
this.messageDatatable = new MessagesDatatable($("#messagesViewCard")) // mensajesView.php
this.messageDatatable = new MessagesDatatable($("#message-datatables-container")) // mensajesView.php
this.modalNewMessage = new Modal($("#modalNewDirectMessage"))
this.btnNewMessage = $("#btn-new-message")
this.btnSubmitNewDirectMessage = this.modalNewMessage.item.find("#submit-new-direct-message")
this.btnSubmitNewDirectMessageCliente = this.modalNewMessage.item.find("#submit-new-direct-message-client")
this.formNewDirectMessage = this.modalNewMessage.item.find("#formNewDirectMessage")
this.alert = new Alert($("#alertDirectMessage"))
this.selectUsers = $("#select-users")
this.selectUsers = $("#select-departments")
this.selectPlaceholder = {
id: '0',
text: "Seleccione un usuario"
}
this.selectDepartmentPlaceholder = {
id: '0',
text: "Seleccione un departamento"
}
this.selectMessageUsers = new ClassSelect(this.selectUsers, '/chat/users/all', this.selectPlaceholder, true)
this.selectChatDepartment = new ClassSelect(this.selectUsers, '/chat/department/select', this.selectDepartmentPlaceholder, true)
}
init() {
@ -27,6 +36,20 @@ class MessagePage {
// Open new message when click in btn-new-message
this.btnNewMessage.on("click", this.openNewMessageModal.bind(this))
this.btnSubmitNewDirectMessage.on("click", this.handleSubmitNewMessage.bind(this))
this.btnSubmitNewDirectMessageCliente.on("click", this.handleSubmitNewMessageClient.bind(this))
$("#navs-top-align-directos-tab").on("click",()=>{
this.messageDatatable.datatable.ajax.reload()
})
$("#navs-top-align-presupuestos-tab").on("click",()=>{
this.messageDatatable.datatablePresupuestoMessage.ajax.reload()
})
$("#navs-top-align-pedidos-tab").on("click",()=>{
this.messageDatatable.datatablePedidoMessage.ajax.reload()
})
$("#navs-top-align-facturas-tab").on("click",()=>{
this.messageDatatable.datatableFacturaMessage.ajax.reload()
})
}
openNewMessageModal() {
@ -60,6 +83,21 @@ class MessagePage {
this.alert.show()
this.alert.setAsError()
this.alert.setHeadingTitle(error.message)
}
handleSubmitNewMessageClient(){
this.btnNewMessage.addClass("loading")
const ajax = new Ajax("/messages/direct/client",
this.getNewMessageDataFormClient(),
null,
this.handleSubmitNewMessageSuccess.bind(this),
this.handleSubmitNewMessageError.bind(this))
ajax.post()
}
handleSubmitNewMessageClientSuccess(){
}
handleSubmitNewMessageClientError(){
}
getNewMessageDataForm() {
return {
@ -68,13 +106,24 @@ class MessagePage {
"users": this.selectMessageUsers.getVal()
}
}
getNewMessageDataFormClient() {
return {
"title": this.formNewDirectMessage.find("#new-direct-message-title").val(),
"message": this.formNewDirectMessage.find("#new-direct-message-text").val(),
"chat_department_id": this.selectChatDepartment.getVal()
}
}
hideForm() {
this.formNewDirectMessage.addClass("d-none")
this.btnSubmitNewDirectMessage.addClass("d-none")
this.btnSubmitNewDirectMessageCliente.addClass("d-none")
}
showForm() {
this.formNewDirectMessage.removeClass("d-none")
this.btnSubmitNewDirectMessage.removeClass("d-none")
this.btnSubmitNewDirectMessageCliente.addClass("d-none")
}
}

View File

@ -0,0 +1,9 @@
import Chat from "../../components/chat.js";
$(function(){
const chatDirectMessage = new Chat($("#chat-factura"))
chatDirectMessage.init()
chatDirectMessage.initFactura()
}
)

View File

@ -0,0 +1,10 @@
import InternalMessages from "../../components/internalMessagesSection.js";
$(function () {
if ($("#internal_messages_chat").length > 0) {
const internalMessages = new InternalMessages($("#internal_messages_chat"))
internalMessages.init()
}
}
)

View File

@ -0,0 +1,9 @@
import Chat from "../../components/chat.js";
$(function(){
const chatDirectMessage = new Chat($("#chat-pedido"))
chatDirectMessage.init()
chatDirectMessage.initPedido()
}
)

View File

@ -0,0 +1,18 @@
import Chat from "../../components/chat.js";
import InternalMessages from "../../components/internalMessagesSection.js";
$(function () {
if ($("#chat-presupuesto").length > 0) {
const chatDirectMessage = new Chat($("#chat-presupuesto"))
chatDirectMessage.init()
chatDirectMessage.initPresupuesto()
}
if ($("#internal_messages_chat").length > 0) {
const internalMessages = new InternalMessages($("#internal_messages_chat"))
internalMessages.init()
}
}
)