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,36 +198,24 @@ 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) {
if (found && found.type == "Remove") {
found.type = "Add";
this.list[foundIndex] = found;
} else {
this.list = this.list.filter(list => list.lotID != lotID);
this.list.push({ type: "Add", lot, devices: deviceListID});
}
} else {
this.list.push({ type: "Add", lot, devices: deviceList, isFromIndeterminate: indeterminate });
}
} 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);
}
} else {
this.list.push({ type: "Remove", lot, devices: deviceList, isFromIndeterminate: indeterminate });
this.list.push({ type: "Remove", lot, devices: deviceListID});
}
if (this.list.length > 0) {