From 97554bffc919f82600c7f9e7d7b0cf7a5955673b Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sun, 27 Apr 2025 18:53:24 +0200 Subject: [PATCH] add maquinista change user session --- ci4/app/Config/Routes.php | 5 ++- ci4/app/Controllers/Chat/ChatController.php | 36 +++++++++++++++++++ ci4/app/Controllers/Configuracion/Users.php | 32 ++++++++--------- .../Controllers/Produccion/Ordentrabajo.php | 4 +-- .../components/cards/tarea_card_actions.php | 2 +- .../vuexy/form/mensajes/mensajesView.php | 7 +++- .../viewMaquinistaCambioUserList.php | 27 ++++++++------ .../datatables/MessagesDatatable.js | 25 +++++++++++++ .../maquinista/maquinistaTareaView.js | 15 ++++++++ .../configuracion/messages/messagePage.js | 4 +++ 10 files changed, 126 insertions(+), 31 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 95ae5dbf..8aa63598 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -41,7 +41,7 @@ foreach (glob(APPPATH . 'Config/Routes/*Routes.php') as $routeFile) { $routes->group('users', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { $routes->get('', 'Users::index', ['as' => 'userList']); $routes->get('maquinista/change/user','Users::index_maquinista_change_user',['as' => 'maquinistaUserChangeList']); - $routes->get('maquinista/change/session/$1','Users::change_user_session/$1',['as' => 'maquinistaChangeUserSession']); + $routes->get('maquinista/change/session/(:num)','Users::change_user_session/$1',['as' => 'maquinistaChangeUserSession']); $routes->get('list', 'Users::index', ['as' => 'userList2']); $routes->get('add', 'Users::add', ['as' => 'newUser']); $routes->post('add', 'Users::add', ['as' => 'createUser']); @@ -644,6 +644,7 @@ $routes->group('messages', ['namespace' => 'App\Controllers\Chat'], function ($r $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->get('datatable/ots', 'ChatController::datatable_ot_messages', ['as' => 'getDatatableOtMessages']); $routes->post('direct', 'ChatController::store_new_direct_message', ['as' => 'storeNewDirectMessage']); $routes->post('direct/client', 'ChatController::store_new_direct_message_client', ['as' => 'storeNewDirectMessageClient']); @@ -654,6 +655,8 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route $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('ot/(:num)', 'ChatController::get_chat_ot_view/$1', ['as' => 'getChatOtView']); + $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']); diff --git a/ci4/app/Controllers/Chat/ChatController.php b/ci4/app/Controllers/Chat/ChatController.php index 71ee0d2d..1df0f469 100755 --- a/ci4/app/Controllers/Chat/ChatController.php +++ b/ci4/app/Controllers/Chat/ChatController.php @@ -222,6 +222,25 @@ class ChatController extends BaseController return view(static::$viewPath . 'messageChatInternal', $this->viewData); } } + public function get_chat_ot_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->orden_trabajo_id; + $this->viewData["type"] = "ot"; + $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) { @@ -502,6 +521,23 @@ class ChatController extends BaseController ->toJson(true); } + public function datatable_ot_messages() + { + $auth_user_id = auth()->user()->id; + $isAdmin = auth()->user()->inGroup('admin'); + $query = $this->chatModel->getQueryDatatableMessageOrdenTrabajo($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") : "") + ->edit("creator",fn($q) => $q->userId == $auth_user_id ? ''.lang("App.me").'' : $q->creator) + ->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId)) + ->add("action", fn($q) => ["type" => "ot", "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_message(int $chat_message_id) { $unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_message_id); diff --git a/ci4/app/Controllers/Configuracion/Users.php b/ci4/app/Controllers/Configuracion/Users.php index 82526665..923f0007 100755 --- a/ci4/app/Controllers/Configuracion/Users.php +++ b/ci4/app/Controllers/Configuracion/Users.php @@ -1,4 +1,6 @@ -sanitized($postData, true); - + $noException = true; // Obtener proveedor de usuarios @@ -118,11 +119,10 @@ class Users extends \App\Controllers\GoBaseController } // Email is not unique! else { - $this->viewData['errorMessage'] = "El correo '". $sanitizedData['email'] ."' ya está registrado en el sistema"; + $this->viewData['errorMessage'] = "El correo '" . $sanitizedData['email'] . "' ya está registrado en el sistema"; $this->session->setFlashdata('formErrors', $this->model->errors()); $successfulResult = false; // Hacked } - } catch (\Exception $e) { $noException = false; $this->viewData['errorMessage'] = $e->getMessage(); @@ -234,7 +234,6 @@ class Users extends \App\Controllers\GoBaseController } else { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } - } catch (\Exception $e) { $noException = false; $this->dealWithException($e); @@ -319,8 +318,6 @@ class Users extends \App\Controllers\GoBaseController $message = "Usuario eliminado correctamente"; return $this->redirect2listView('successMessage', $message); - - } // end function delete(...) @@ -374,9 +371,10 @@ class Users extends \App\Controllers\GoBaseController } } - public function datatable(){ + public function datatable() + { - if($this->request->isAJAX()){ + if ($this->request->isAJAX()) { $reqData = $this->request->getPost(); if (!isset($reqData['draw']) || !isset($reqData['columns'])) { @@ -405,7 +403,6 @@ class Users extends \App\Controllers\GoBaseController $this->model->getResource([])->countAllResults(), $this->model->getResource($searchValues)->countAllResults() )); - } else { return $this->failUnauthorized('Invalid request', 403); } @@ -453,18 +450,21 @@ class Users extends \App\Controllers\GoBaseController ['title' => lang("App.menu_change_session"), 'route' => route_to('maquinistaUserChangeList'), 'active' => true] ]; $maquinistas = []; - $users = auth()->getProvider()->findAll(); + $users = auth()->getProvider()->whereNotIn('id',[auth()->user()->id])->findAll(); foreach ($users as $key => $user) { - if($user->inGroup('maquina') && !$user->inGroup('admin','comercial','cliente-editor','cliente-admin')){ + if ($user->inGroup('maquina') && !$user->inGroup('admin', 'comercial', 'cliente-editor', 'cliente-admin')) { $maquinistas[] = $user; } } $this->viewData['maquinistas'] = $maquinistas; - return view('/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php',$this->viewData); + return view('/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php', $this->viewData); } public function change_user_session(int $user_id) { - return redirect_to("maquinistaUserChangeList"); + // Check the credentials + $user = auth()->getProvider()->findById($user_id); + auth()->logout(); + auth()->login($user); + return redirect("home"); } - } diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index efd40659..45aa3a7d 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -105,11 +105,11 @@ class Ordentrabajo extends BaseController public function update_orden_trabajo_tarea() { $bodyData = $this->request->getPost(); - return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "data" => $bodyData]); $validated = $this->validation->run($bodyData, "orden_trabajo_tarea"); if ($validated) { $r = $this->produccionService->updateOrdenTrabajoTarea($bodyData["orden_trabajo_tarea_id"], $bodyData); - return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $bodyData]); + $tareaEntity = $this->otTarea->find($bodyData["orden_trabajo_tarea_id"]); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r, "data" => $tareaEntity]); } else { return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); } diff --git a/ci4/app/Views/themes/vuexy/components/cards/tarea_card_actions.php b/ci4/app/Views/themes/vuexy/components/cards/tarea_card_actions.php index f29ca2f5..bd119b74 100644 --- a/ci4/app/Views/themes/vuexy/components/cards/tarea_card_actions.php +++ b/ci4/app/Views/themes/vuexy/components/cards/tarea_card_actions.php @@ -12,7 +12,7 @@

Clicks

-

click_tarea ?>

+

click_end - $ot_tarea->click_init ?>

diff --git a/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php b/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php index ef184ed5..f22cbaee 100755 --- a/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php +++ b/ci4/app/Views/themes/vuexy/form/mensajes/mensajesView.php @@ -26,6 +26,9 @@ use Config\App; +
@@ -41,7 +44,9 @@ use Config\App;
+ diff --git a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php index 094a2bd2..967b4be3 100644 --- a/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/maquinista/viewMaquinistaCambioUserList.php @@ -22,17 +22,24 @@ - $maquinista): ?> - - id ?> - first_name ?> - last_name ?> - getEmail() ?> - - id)?>" class="btn btn-lg btn-primary h-100 w-100">Mi turno - + 0): ?> + + $maquinista): ?> + + id ?> + first_name ?> + last_name ?> + getEmail() ?> + + id) ?>" class="btn btn-lg btn-primary h-100 w-100">Mi turno + + + + + + No hay usuarios para cambiar turno - + diff --git a/httpdocs/assets/js/safekat/components/datatables/MessagesDatatable.js b/httpdocs/assets/js/safekat/components/datatables/MessagesDatatable.js index 7b91f0c5..a150737f 100644 --- a/httpdocs/assets/js/safekat/components/datatables/MessagesDatatable.js +++ b/httpdocs/assets/js/safekat/components/datatables/MessagesDatatable.js @@ -7,6 +7,8 @@ class MessagesDatatable { this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages") this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages") this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages") + this.datatableOtMessageItem = this.item.find("#tableOtMessages") + this.focusTable = this.datatableItem this.columnDefs = [ ] @@ -131,6 +133,25 @@ class MessagesDatatable { columns: this.datatableColumns, ajax: '/messages/datatable/factura' }); + this.datatableOtMessage = this.datatableOtMessageItem.DataTable({ + processing: true, + order: [[1, 'desc']], + columnDefs : this.columnDefs, + orderCellsTop : 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/ots' + }); 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() @@ -143,6 +164,10 @@ class MessagesDatatable { let columnIndex = this.datatableColumns.findIndex((element) => element.data == $(event.currentTarget).attr("name")) this.datatableFacturaMessage.column(columnIndex).search($(event.currentTarget).val()).draw() }) + this.datatableOtMessageItem.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() + }) } diff --git a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js index 5ab8086d..b4e20735 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/maquinista/maquinistaTareaView.js @@ -79,10 +79,14 @@ class MaquinistaTareaView { } handleUpdateClickInputSucess(response) { popSuccessAlert(response.message) + this.updateContentClick(response.data.click_end - response.data.click_init) } handleUpdateClickInputError(error) { popErrorAlert(error) } + updateContentClick(clicks){ + this.item.find('#clicks-info').empty().html(clicks) + } handleDeleteTareaProgress() { let ajax = new Ajax('/produccion/ordentrabajo/tarea/progress/' + this.tareaId, null, @@ -194,6 +198,17 @@ class MaquinistaTareaView { } }) } + getTarea(tarea_id) { + return new Promise((resolve, reject) => { + let ajax = new Ajax(`/produccion/ordentrabajo/tarea/${tarea_id}`, null, null, (response) => { + resolve(response) + }, + (error) => { + resolve(error) + }) + ajax.get() + }) + } } diff --git a/httpdocs/assets/js/safekat/pages/configuracion/messages/messagePage.js b/httpdocs/assets/js/safekat/pages/configuracion/messages/messagePage.js index 97543c74..77f1dc54 100644 --- a/httpdocs/assets/js/safekat/pages/configuracion/messages/messagePage.js +++ b/httpdocs/assets/js/safekat/pages/configuracion/messages/messagePage.js @@ -54,6 +54,10 @@ class MessagePage { this.messageDatatable.datatableFacturaMessage.ajax.reload() this.messageDatatable.focusTable = this.messageDatatable.datatableFacturaMessageItem }) + $("#navs-top-align-ot-tab").on("click",()=>{ + this.messageDatatable.datatableOtMessage.ajax.reload() + this.messageDatatable.focusTable = this.messageDatatable.datatableOtMessageItem + }) } openNewMessageModal() {