improvement sending variables data through methods
This commit is contained in:
parent
bb284008cc
commit
770ab8ea8d
|
@ -194,12 +194,13 @@ async function processSelectedDevices() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage the actions that will be performed when applying the changes
|
* Manage the actions that will be performed when applying the changes
|
||||||
* @param {*} ev event (Should be a checkbox type)
|
* @param {EventSource} ev event (Should be a checkbox type)
|
||||||
* @param {string} lotID lot id
|
* @param {Lot} lot lot id
|
||||||
* @param {number} deviceID device id
|
* @param {Device[]} deviceList device id
|
||||||
*/
|
*/
|
||||||
manage(event, lotID, deviceListID) {
|
manage(event, lot, deviceList) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const lotID = lot.id;
|
||||||
const srcElement = event.srcElement.parentElement.children[0]
|
const srcElement = event.srcElement.parentElement.children[0]
|
||||||
const {indeterminate} = srcElement;
|
const {indeterminate} = srcElement;
|
||||||
const checked = !srcElement.checked;
|
const checked = !srcElement.checked;
|
||||||
|
@ -216,7 +217,7 @@ async function processSelectedDevices() {
|
||||||
this.list = this.list.filter(list => list.lotID != lotID);
|
this.list = this.list.filter(list => list.lotID != lotID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.list.push({ type: "Add", lotID, devices: deviceListID, isFromIndeterminate: indeterminate });
|
this.list.push({ type: "Add", lot, devices: deviceList, isFromIndeterminate: indeterminate });
|
||||||
}
|
}
|
||||||
} else if (found != undefined && found.type == "Add") {
|
} else if (found != undefined && found.type == "Add") {
|
||||||
if (found.isFromIndeterminate == true) {
|
if (found.isFromIndeterminate == true) {
|
||||||
|
@ -226,7 +227,7 @@ async function processSelectedDevices() {
|
||||||
this.list = this.list.filter(list => list.lotID != lotID);
|
this.list = this.list.filter(list => list.lotID != lotID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.list.push({ type: "Remove", lotID, devices: deviceListID, isFromIndeterminate: indeterminate });
|
this.list.push({ type: "Remove", lot, devices: deviceList, isFromIndeterminate: indeterminate });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.list.length > 0) {
|
if (this.list.length > 0) {
|
||||||
|
@ -268,14 +269,14 @@ async function processSelectedDevices() {
|
||||||
this.list.forEach(async action => {
|
this.list.forEach(async action => {
|
||||||
if (action.type == "Add") {
|
if (action.type == "Add") {
|
||||||
try {
|
try {
|
||||||
await Api.devices_add(action.lotID, action.devices);
|
await Api.devices_add(action.lot.id, action.devices.map(dev => dev.data));
|
||||||
this.notifyUser("Devices sucefully aded to selected lot/s", "", false);
|
this.notifyUser("Devices sucefully aded to selected lot/s", "", false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.notifyUser("Failed to add devices to selected lot/s", error.responseJSON.message, true);
|
this.notifyUser("Failed to add devices to selected lot/s", error.responseJSON.message, true);
|
||||||
}
|
}
|
||||||
} else if (action.type == "Remove") {
|
} else if (action.type == "Remove") {
|
||||||
try {
|
try {
|
||||||
await Api.devices_remove(action.lotID, action.devices);
|
await Api.devices_remove(action.lot.id, action.devices.map(dev => dev.data));
|
||||||
this.notifyUser("Devices sucefully removed from selected lot/s", "", false);
|
this.notifyUser("Devices sucefully removed from selected lot/s", "", false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.notifyUser("Fail to remove devices from selected lot/s", error.responseJSON.message, true);
|
this.notifyUser("Fail to remove devices from selected lot/s", error.responseJSON.message, true);
|
||||||
|
@ -343,16 +344,22 @@ async function processSelectedDevices() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.children[0].addEventListener("mouseup", (ev) => actions.manage(ev, id, selectedDevicesIDs));
|
doc.children[0].addEventListener("mouseup", (ev) => actions.manage(ev, lot, selectedDevices));
|
||||||
doc.children[1].addEventListener("mouseup", (ev) => actions.manage(ev, id, selectedDevicesIDs));
|
doc.children[1].addEventListener("mouseup", (ev) => actions.manage(ev, lot, selectedDevices));
|
||||||
elementTarget.append(doc);
|
elementTarget.append(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
const listHTML = $("#LotsSelector")
|
const listHTML = $("#LotsSelector")
|
||||||
|
|
||||||
// Get selected devices
|
// Get selected devices
|
||||||
const selectedDevicesIDs = $.map($(".deviceSelect").filter(":checked"), (x) => parseInt($(x).attr("data")));
|
const selectedDevices = table.rows().dt.activeRows.filter(item => item.querySelector("input").checked).map(item => {
|
||||||
if (selectedDevicesIDs.length <= 0) {
|
const child = item.childNodes[0].children[0]
|
||||||
|
const info = {}
|
||||||
|
Object.values(child.attributes).forEach(attrib => { info[attrib.nodeName] = attrib.nodeValue })
|
||||||
|
return info
|
||||||
|
})
|
||||||
|
|
||||||
|
if (selectedDevices.length <= 0) {
|
||||||
listHTML.html("<li style=\"color: red; text-align: center\">No devices selected</li>");
|
listHTML.html("<li style=\"color: red; text-align: center\">No devices selected</li>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -367,7 +374,7 @@ async function processSelectedDevices() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
listHTML.html("<li style=\"text-align: center\"><div class=\"spinner-border text-info\" style=\"margin: auto\" role=\"status\"></div></li>")
|
listHTML.html("<li style=\"text-align: center\"><div class=\"spinner-border text-info\" style=\"margin: auto\" role=\"status\"></div></li>")
|
||||||
const devices = await Api.get_devices(selectedDevicesIDs);
|
const devices = await Api.get_devices(selectedDevices.map(dev => dev.data));
|
||||||
let lots = await Api.get_lots();
|
let lots = await Api.get_lots();
|
||||||
|
|
||||||
lots = lots.map(lot => {
|
lots = lots.map(lot => {
|
||||||
|
@ -379,7 +386,7 @@ async function processSelectedDevices() {
|
||||||
case 0:
|
case 0:
|
||||||
lot.state = "false";
|
lot.state = "false";
|
||||||
break;
|
break;
|
||||||
case selectedDevicesIDs.length:
|
case selectedDevices.length:
|
||||||
lot.state = "true";
|
lot.state = "true";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Reference in New Issue