transactions
This commit is contained in:
@@ -885,39 +885,38 @@ class AutomaticDispose {
|
||||
ReadAndAddMissions(MissionID, Runner) {
|
||||
const self = this;
|
||||
|
||||
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
|
||||
|
||||
self.ADSettings().then(() => {
|
||||
return self.ADisDB.transaction('r', [self.ADisDB.ADisMissions], async () => {
|
||||
return self.ADSettings().then(async () => {
|
||||
return self.ADisDB.ADisMissions.toCollection()
|
||||
}).then((Missions) => {
|
||||
if (typeof Missions !== "undefined") {
|
||||
return Missions.count((count) => {
|
||||
if (count > 0) {
|
||||
return Missions.each((MyMission) => {
|
||||
var MissionElement = $("#mission_" + MyMission.missionID);
|
||||
if (MissionElement.length == 0 || $('#mission_panel_' + MyMission.missionID).hasClass('mission_panel_green')) {
|
||||
// remove
|
||||
console.log("Remove :", MyMission)
|
||||
self.RemoveMissionsFromQueue(MyMission.missionID)
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}).then(() => {
|
||||
|
||||
if (typeof MissionID != 'undefined') {
|
||||
return self.AddMission(MissionID, Runner);
|
||||
} else {
|
||||
return self.ADisSettings.runner_divs.forEach(async (RunnerX, index) => {
|
||||
await $("#" + RunnerX).find(".missionSideBarEntry").each(async (index, elem) => {
|
||||
MissionID = $(elem).attr("mission_id");
|
||||
await self.AddMission(MissionID, RunnerX);
|
||||
})
|
||||
}).then((Missions) => {
|
||||
if (typeof Missions !== "undefined") {
|
||||
return Missions.count((count) => {
|
||||
if (count > 0) {
|
||||
return Missions.each((MyMission) => {
|
||||
var MissionElement = $("#mission_" + MyMission.missionID);
|
||||
if (MissionElement.length == 0 || $('#mission_panel_' + MyMission.missionID).hasClass('mission_panel_green')) {
|
||||
// remove
|
||||
console.log("Remove :", MyMission)
|
||||
self.RemoveMissionsFromQueue(MyMission.missionID)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}).then(() => {
|
||||
|
||||
if (typeof MissionID != 'undefined') {
|
||||
return self.AddMission(MissionID, Runner);
|
||||
} else {
|
||||
return self.ADisSettings.runner_divs.forEach(async (RunnerX, index) => {
|
||||
await $("#" + RunnerX).find(".missionSideBarEntry").each(async (index, elem) => {
|
||||
MissionID = $(elem).attr("mission_id");
|
||||
await self.AddMission(MissionID, RunnerX);
|
||||
});
|
||||
})
|
||||
}
|
||||
});;
|
||||
}
|
||||
|
||||
AddMission(ID, Runner) {
|
||||
@@ -1065,10 +1064,12 @@ class AutomaticDispose {
|
||||
|
||||
RemoveMissionsFromQueue(MissionID) {
|
||||
const self = this;
|
||||
return self.ADisDB.ADisMissions.where({
|
||||
missionID: MissionID
|
||||
}).delete().catch((err) => {
|
||||
console.error(err)
|
||||
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions], async () => {
|
||||
return self.ADisDB.ADisMissions.where({
|
||||
missionID: MissionID
|
||||
}).delete().catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1088,7 +1089,7 @@ class AutomaticDispose {
|
||||
// })
|
||||
|
||||
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
|
||||
self.ADSettings().then((setting) => {
|
||||
return self.ADSettings().then((setting) => {
|
||||
if (setting[runnerSettings] == 'true') {
|
||||
return self.ADisDB.ADisMissions.where({
|
||||
runner: Runner,
|
||||
@@ -1098,36 +1099,36 @@ class AutomaticDispose {
|
||||
return item.next_check <= Math.floor(new Date().getTime() / 1000)
|
||||
}).limit(1)
|
||||
}
|
||||
}).then((Wunsch) => {
|
||||
// console.table(Wunsch);
|
||||
if (Wunsch !== undefined) {
|
||||
return Wunsch.count(function (count) {
|
||||
if (count > 0) {
|
||||
return Wunsch.each((myWunsch) => {
|
||||
// console.log("MYWUNSCH:")
|
||||
// console.table(myWunsch);
|
||||
let MissionID = myWunsch.missionID;
|
||||
if ($('#' + runnerIframe).attr("mission_id") == "empty") {
|
||||
$('#' + runnerIframe).attr("src", "https://www.leitstellenspiel.de/missions/" + MissionID);
|
||||
$('#' + runnerIframe).attr("mission_id", MissionID);
|
||||
// self.UpdateMissionsToDone(MissionID).then(() => {
|
||||
// // console.log('done.... ' + Runner);
|
||||
// $('#' + runnerIframe).attr("src", '');
|
||||
// $('#' + runnerIframe).attr("mission_id", 'empty');
|
||||
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
|
||||
// })
|
||||
} else {
|
||||
// only while
|
||||
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
|
||||
}
|
||||
});
|
||||
}
|
||||
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
|
||||
});
|
||||
})
|
||||
}).then((Wunsch) => {
|
||||
// console.table(Wunsch);
|
||||
if (Wunsch !== undefined) {
|
||||
return Wunsch.count(function (count) {
|
||||
if (count > 0) {
|
||||
return Wunsch.each((myWunsch) => {
|
||||
// console.log("MYWUNSCH:")
|
||||
// console.table(myWunsch);
|
||||
let MissionID = myWunsch.missionID;
|
||||
if ($('#' + runnerIframe).attr("mission_id") == "empty") {
|
||||
$('#' + runnerIframe).attr("src", "https://www.leitstellenspiel.de/missions/" + MissionID);
|
||||
$('#' + runnerIframe).attr("mission_id", MissionID);
|
||||
// self.UpdateMissionsToDone(MissionID).then(() => {
|
||||
// // console.log('done.... ' + Runner);
|
||||
// $('#' + runnerIframe).attr("src", '');
|
||||
// $('#' + runnerIframe).attr("mission_id", 'empty');
|
||||
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
|
||||
// })
|
||||
} else {
|
||||
// only while
|
||||
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
|
||||
}
|
||||
});
|
||||
}
|
||||
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1168,8 +1169,8 @@ class AutomaticDispose {
|
||||
// return tellParent(`console.log('handler:1000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`); // delete Mission here as completed
|
||||
// })
|
||||
// } else {
|
||||
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions], () => {
|
||||
self.ADSettings().then((setting) => {
|
||||
return self.ADisDB.transaction('r', [self.ADisDB.ADisMissions], () => {
|
||||
return self.ADSettings().then((setting) => {
|
||||
if (setting[self.MyRunnerSettings] === 'true') {
|
||||
|
||||
let where = {
|
||||
@@ -1182,26 +1183,26 @@ class AutomaticDispose {
|
||||
return item.next_check <= Math.floor(new Date().getTime() / 1000)
|
||||
}).limit(1)
|
||||
}
|
||||
}).then((Wunsch) => {
|
||||
if (Wunsch !== undefined) {
|
||||
return Wunsch.count(function (count) {
|
||||
if (count > 0) {
|
||||
return Wunsch.each((mywunsch) => {
|
||||
console.table(mywunsch);
|
||||
return self.MainHandler()
|
||||
});
|
||||
} else {
|
||||
return self.UpdateMissionsToDone(self.MissionID).then(() => {
|
||||
return tellParent(`console.log('wunsch:1000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
|
||||
})
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
|
||||
return tellParent(`console.log('wunsch:2000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
|
||||
})
|
||||
}
|
||||
})
|
||||
}).then((Wunsch) => {
|
||||
if (Wunsch !== undefined) {
|
||||
return Wunsch.count(function (count) {
|
||||
if (count > 0) {
|
||||
return Wunsch.each((mywunsch) => {
|
||||
console.table(mywunsch);
|
||||
return self.MainHandler()
|
||||
});
|
||||
} else {
|
||||
return self.UpdateMissionsToDone(self.MissionID).then(() => {
|
||||
return tellParent(`console.log('wunsch:1000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
|
||||
})
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
|
||||
return tellParent(`console.log('wunsch:2000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
|
||||
})
|
||||
}
|
||||
})
|
||||
// }
|
||||
}, 500);
|
||||
|
||||
Reference in New Issue
Block a user