Optimize manage list

This commit is contained in:
RubenPX 2022-04-28 15:32:35 +02:00
parent 770ab8ea8d
commit 8d8ce63402
1 changed files with 7 additions and 19 deletions

View File

@ -198,37 +198,25 @@ async function processSelectedDevices() {
* @param {Lot} lot lot id
* @param {Device[]} deviceList device id
*/
manage(event, lot, deviceList) {
manage(event, lot, deviceListID) {
event.preventDefault();
const lotID = lot.id;
const srcElement = event.srcElement.parentElement.children[0]
const {indeterminate} = srcElement;
const checked = !srcElement.checked;
const found = this.list.filter(list => list.lotID == lotID)[0];
const foundIndex = found != undefined ? this.list.findLastIndex(x => x.lotID == found.lotID) : -1;
const found = this.list.filter(list => list.lot.id == lotID)[0];
if (checked) {
if (found != undefined && found.type == "Remove") {
if (found.isFromIndeterminate == true) {
found.type = "Add";
this.list[foundIndex] = found;
} else {
this.list = this.list.filter(list => list.lotID != lotID);
}
if (found && found.type == "Remove") {
found.type = "Add";
} else {
this.list.push({ type: "Add", lot, devices: deviceList, isFromIndeterminate: indeterminate });
this.list.push({ type: "Add", lot, devices: deviceListID});
}
} else if (found != undefined && found.type == "Add") {
if (found.isFromIndeterminate == true) {
} else if (found && found.type == "Add") {
found.type = "Remove";
this.list[foundIndex] = found;
} else {
this.list = this.list.filter(list => list.lotID != lotID);
this.list.push({ type: "Remove", lot, devices: deviceListID});
}
} else {
this.list.push({ type: "Remove", lot, devices: deviceList, isFromIndeterminate: indeterminate });
}
if (this.list.length > 0) {
document.getElementById("ApplyDeviceLots").classList.remove("disabled");