maquinista view-basic

This commit is contained in:
amazuecos
2025-04-25 07:40:20 +02:00
parent 288a3f02eb
commit 52b3b1ae4d
28 changed files with 911 additions and 132 deletions

View File

@ -1,4 +1,92 @@
class MaquinistaTareaList{}
class MaquinistaTareaList {
constructor(domItem) {
this.item = domItem
this.maquinaId = this.item.data("id")
this.datatableItem = $("#maquinista-tarea-table")
this.btnTareasHoy = $("#btn-tareas-hoy")
this.todayDate = $('#today-date')
this.btnAllTareas = $("#btn-all-tareas")
this.datatableColumns = [
{ data: 'otId', searchable: false, sortable: false },
{ data: 'tareaName', searchable: false, sortable: false },
{ data: 'tareaEstado', searchable: false, sortable: false,render : this.renderStado.bind(this)},
{ data: 'presupuesto_titulo', searchable: false, sortable: false },
{ data: 'papel_impresion', searchable: false, sortable: false },
{ data: 'papel_gramaje', searchable: false, sortable: false },
{ data: 'fecha_impresion', searchable: false, sortable: false },
{ data: 'action', searchable: false, sortable: false, width: "20rem" },
]
this.urlAll = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/all/' + this.maquinaId
this.urlToday = '/produccion/ordentrabajo/maquinista/maquinas/tareas/datatable/today/' + this.maquinaId
this.initTable()
this.estadoClass = {
I : 'primary',
P : 'warning',
S : 'warning',
D : 'danger',
F : 'success'
}
this.estadoNames = {
I : 'Iniciada',
P : 'Pendiente',
S : 'Pausada',
D : 'Aplazada',
F : 'Finalizada'
}
}
init(){
this.btnTareasHoy.on('click',this.loadToday.bind(this))
this.btnAllTareas.on('click',this.loadAll.bind(this))
}
initTable() {
this.datatable = this.datatableItem.DataTable({
processing: true,
layout: {
topStart: 'pageLength',
topEnd: 'search',
bottomStart: 'info',
bottomEnd: 'paging'
},
serverSide: true,
pageLength: 25,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: this.datatableColumns,
ajax: this.urlToday
});
}
loadToday() {
this.btnTareasHoy.removeClass('active')
this.btnTareasHoy.removeAttr('aria-pressed')
this.btnAllTareas.removeClass('active')
this.btnAllTareas.removeAttr('aria-pressed')
this.todayDate.removeClass('d-none')
this.btnTareasHoy.addClass('active')
this.btnTareasHoy.attr('aria-pressed',true)
this.datatable.ajax.url(this.urlToday)
this.datatable.ajax.reload()
}
loadAll(){
this.btnTareasHoy.removeClass('active')
this.btnTareasHoy.removeAttr('aria-pressed')
this.todayDate.addClass('d-none')
this.btnAllTareas.addClass('active')
this.btnAllTareas.attr('aria-pressed',true)
this.datatable.ajax.url(this.urlAll)
this.datatable.ajax.reload()
}
renderStado(d){
return `<span class="badge text-bg-${this.estadoClass[d]}">${this.estadoNames[d]}</span>`
}
}
export default MaquinistaTareaList;

View File

@ -1,4 +1,201 @@
class MaquinistaTareaView{}
import Ajax from '../../../components/ajax.js'
import { alertConfirmAction } from '../../../components/alerts/sweetAlert.js'
class MaquinistaTareaView {
constructor(domItem) {
this.item = domItem
this.tareaId = this.item.data("id");
this.btnPlay = this.item.find("#btn-start-tarea")
this.btnPause = this.item.find("#btn-pause-tarea")
this.btnDelay = this.item.find("#btn-stop-tarea")
this.btnFinish = this.item.find("#btn-finish-tarea")
this.btnDeleteProgress = this.item.find("#btn-delete-tarea")
this.actionButtons = this.item.find('.action-btn')
this.tareaCardClass = '.tarea-card-action-block'
this.inputClick = $('.ot-tarea-click')
}
init() {
this.actionButtons.on('click', this.eventActionButton.bind(this))
this.btnDelay.on('click', this.delayEventActionButton.bind(this))
this.btnDeleteProgress.on('click', this.handleDeleteTareaProgress.bind(this))
this.handleGetTareaProgress();
this.inputClick.on('input', this.handleUpdateClickInput.bind(this))
}
eventActionButton(event) {
let statusClick = $(event.currentTarget).data('estado');
this.showBasedOnStatus(statusClick);
console.info(`Estado ${statusClick}`)
this.handleUpdateTareaProgress(statusClick)
this.handleGetTareaProgress()
}
delayEventActionButton(event) {
let statusClick = $(event.currentTarget).data('estado');
this.delayTarea()
}
actionLoader(status = true) {
if (status) {
Notiflix.Block.circle(this.tareaCardClass);
} else {
Notiflix.Block.remove(this.tareaCardClass);
}
}
showPlay() {
this.btnPause.addClass('d-none')
this.btnPlay.removeClass('d-none')
this.btnFinish.removeClass('d-none')
}
showPause() {
this.btnPlay.addClass('d-none')
this.btnFinish.addClass('d-none')
this.btnPause.removeClass('d-none')
}
disableButtons() {
this.actionButtons.attr('disabled', 'disabled')
}
enableButtons() {
this.actionButtons.removeAttr('disabled')
}
handleUpdateClickInput(event) {
let tareaId = $(event.currentTarget).data('id');
let name = $(event.currentTarget).attr('name')
let value = $(event.currentTarget).val()
let formData = {
orden_trabajo_tarea_id: tareaId
}
formData[name] = value;
let ajax = new Ajax('/produccion/ordentrabajo/update/tarea',
formData,
null,
this.handleUpdateClickInputSucess.bind(this),
this.handleGetTareaProgressError.bind(this)
)
if (value) {
ajax.post()
}
}
handleUpdateClickInputSucess(response) {
popSuccessAlert(response.message)
}
handleUpdateClickInputError(error) {
popErrorAlert(error)
}
handleDeleteTareaProgress() {
let ajax = new Ajax('/produccion/ordentrabajo/tarea/progress/' + this.tareaId,
null,
null,
this.handleDeleteTareaProgressSuccess.bind(this),
this.handleDeleteTareaProgressError.bind(this)
)
alertConfirmAction('Se borrará todo el progreso y se reiniciará el progreso')
.then(result => {
if (result.isConfirmed) {
this.actionLoader(true)
ajax.delete()
}
})
}
handleDeleteTareaProgressSuccess() {
window.location.reload()
}
handleDeleteTareaProgressError(error) {
popErrorAlert(error)
}
handleGetTareaProgress() {
this.actionLoader()
let ajax = new Ajax(`/produccion/ordentrabajo/tarea/progress/${this.tareaId}`, null, null,
this.handleGetTareaProgressSuccess.bind(this),
this.handleGetTareaProgressError.bind(this),
)
if (this.tareaId) {
ajax.get();
}
}
handleGetTareaProgressSuccess(response) {
if (response.progress_dates) {
let lastStatus = response.progress_dates.findLast(e => e.estado != null).estado
this.showBasedOnStatus(lastStatus)
}
if (response.tiempo_trabajado) {
this.item.find('#tiempo-real-info').html(response.tiempo_trabajado)
}
this.actionLoader(false)
}
handleGetTareaProgressError(error) {
this.actionLoader(false)
}
handleUpdateTareaProgress(status) {
this.actionLoader(true)
let ajax = new Ajax(`/produccion/ordentrabajo/update/tarea/progress`,
{
'ot_tarea_id': this.tareaId,
'estado': status
}, null,
this.handleUpdateTareaProgressSuccess.bind(this),
this.handleUpdateTareaProgressError.bind(this),
)
if (this.tareaId) {
ajax.post();
}
}
handleUpdateTareaProgressSuccess(response) {
if (response.data) {
if (response.data.estado == 'D') {
window.location.href = '/produccion/ordentrabajo/maquinista/maquinas/view'
}
this.showBasedOnStatus(response.data.status)
}
this.actionLoader(false)
}
handleUpdateTareaProgressError(error) {
popErrorAlert(error.error)
this.actionLoader(false)
}
showBasedOnStatus(status) {
if (['P', 'S'].includes(status)) {
this.enableButtons()
this.showPlay()
}
if (['F', 'E'].includes(status)) {
this.disableButtons()
this.showPlay()
}
if (status == 'I') {
this.enableButtons()
this.showPause()
}
if (status == 'D') {
window.href
}
}
eventUnloadWindow(event) {
// return confirm('¿Estás seguro de abandonar la página? La tarea se marcará como pausada')
alertConfirmAction('La tarea se marcará como pausada')
.then(result => {
if (result.isConfirmed) {
return ""
}
})
}
delayTarea() {
alertConfirmAction('La tarea se marcará como aplazada y podrás continuar después')
.then(result => {
if (result.isConfirmed) {
this.handleUpdateTareaProgress('D')
}
})
}
}
export default MaquinistaTareaView;

View File

@ -1,5 +1,7 @@
import maquinistaTareaList from "./maquinistaTareaList.js";
import MaquinistaTareaList from "./maquinistaTareaList.js";
$(() => {
console.info("MAQUINISTA TAREA LIST")
let maquinistaTareaList = new MaquinistaTareaList($("#viewMaquinistaMaquinaTareas"))
maquinistaTareaList.init();
})

View File

@ -2,4 +2,6 @@ import MaquinistaTareaView from "./maquinistaTareaView.js";
$(() => {
console.info("MAQUINISTA TAREA VIEW")
let mtv = new MaquinistaTareaView($("#viewMaquinistaMaquinaTarea"))
mtv.init();
})

View File

@ -1,4 +1,9 @@
.maquina-btn
{
height : 5rem;
width : 100%;
font-size : 20px;
}
.table-maquinista td{
height : 10rem;
}