7 Commits

Author SHA1 Message Date
Jomaar 46efccd53a v2 uagf9a0guio 2018-12-17 21:04:54 +01:00
Jomaar 77fe05fc4b v2 up 9auf9u9 2018-12-17 21:03:06 +01:00
Jomaar 966d1ad67b v2 up 9agfiu09au 2018-12-17 21:02:11 +01:00
Jomaar 61357300e3 v2 update :ai 2018-12-17 20:57:15 +01:00
Jomaar 17c33e5bb3 v2 update maog9vcj 2018-12-17 20:46:51 +01:00
Jomaar 59b95b1807 v2 up a9g0a9u094ut98ujoijc 2018-12-17 20:13:23 +01:00
Jomaar b5cbdc236f v2 New Working & mission update 2018-12-17 20:07:30 +01:00
7 changed files with 363 additions and 602 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/*Generated on:Mon Dec 17 2018 20:00:28 GMT+0100 (CET)*/
/*Generated on:Mon Dec 17 2018 21:04:54 GMT+0100 (CET)*/
var AutomaticDispose_Branch = "master";
var AutomaticDispose_URL = "https://jf.git.rest/Jomaar/automatic-dispose/raw/branch/";
var da_lss_adis_time = new Date().getTime();
+177 -203
View File
@@ -1,4 +1,4 @@
/*Generated on:Mon Dec 17 2018 20:00:28 GMT+0100 (CET)*/
/*Generated on:Mon Dec 17 2018 21:04:54 GMT+0100 (CET)*/
/*
* Dexie.js - a minimalistic wrapper for IndexedDB
* ===============================================
@@ -17448,7 +17448,6 @@ class AutomaticDispose {
self.MaxVehicleID = 86
self.MissionType = null
self.MissionID = null
self.MissionData = null
self.MyRunner = null
self.MyRunnerSettings = null
self.OweSecure = false
@@ -17568,9 +17567,7 @@ class AutomaticDispose {
}, 500);
self.ADisSettings.runner.forEach((runner) => {
if(['kt','om'].indexOf(runner) !== -1) {
self.OpenNextMission(runner)
}
self.OpenNextMission(runner)
})
}
@@ -18534,7 +18531,7 @@ class AutomaticDispose {
// remove
console.log("Remove :", MyMission)
self.RemoveMissionsFromQueue(MyMission.missionID)
}
}
});
}
});
@@ -18542,7 +18539,6 @@ class AutomaticDispose {
});
});
const MyOwnObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
// console.log(mutation.target.id);
@@ -18570,11 +18566,11 @@ class AutomaticDispose {
ReadAndAddMissions(MissionID, Runner) {
const self = this;
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], async () => {
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
if (typeof MissionID != 'undefined') {
await self.AddMission(MissionID, Runner);
self.AddMission(MissionID, Runner);
} else {
await self.ADisSettings.runner_divs.forEach(async (RunnerX, index) => {
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);
@@ -18592,6 +18588,7 @@ class AutomaticDispose {
const runnerOpt = self.ADisSettings.runner[runnerID];
return self.ADSettings().then((setting) => {
if (setting[settingOpt] == 'true') {
let where = {
missionID: ID,
@@ -18600,106 +18597,78 @@ class AutomaticDispose {
return self.ADisDB.ADisMissions.where(where).limit(1)
}
}).then((Missions) => {
if (typeof Missions !== "undefined") {
return Missions.count((count) => {
if (count > 0) {
return Missions.each((MyMission) => {
var MissionElement = $("#mission_" + ID);
var _MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
if (MissionElement.length) {
return self.ADisDB.ADisAvailabelMissions.get({
type: _MissionType
}).then((available) => {
return self.UpdateMissions({
"missionID": MyMission.missionID,
"type": _MissionType,
"runner": MyMission.runner,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": "false",
"last_check": MyMission.last_check,
"next_check": MyMission.next_check
});
});
}
});
} else {
if (typeof Missions === "undefined") {
return;
}
return Missions.count((count) => {
if (count > 0) {
return Missions.each(() => {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var _MissionID = MissionElement.attr("mission_id");
var _MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
if (MissionElement.length) {
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.UpdateMissions({
"missionID": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": "false",
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"id": _MissionID,
"type": _MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined),
"done": false,
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
}
}
});
});
} else {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"missionID": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": 'false',
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
});
}
} else {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"id": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined),
"done": false,
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
});
}
});
});
}
AddMissionsToQueue(Mission) {
const self = this;
return self.ADisDB.ADisMissions.put({
missionID: Mission.missionID,
missionID: Mission.id,
type: Mission.type,
runner: Mission.runner,
name: Mission.name,
available: Mission.available,
done: Mission.done,
available: Mission.available ? 'true' : 'false',
done: Mission.done ? 'true' : 'false',
street: Mission.street,
village: Mission.village,
last_check: Mission.last_check,
@@ -18718,7 +18687,6 @@ class AutomaticDispose {
}
FreeIframe(Runner) {
// console.log('FreeIframe', Runner);
const self = this;
const runnerID = self.ADisSettings.runner.indexOf(Runner)
const runnerIframe = self.ADisSettings.runner_iframes[runnerID];
@@ -18731,7 +18699,7 @@ class AutomaticDispose {
const self = this;
return self.ADisDB.ADisMissions.update(MissionID, {
last_check: Math.floor(new Date().getTime() / 1000),
next_check: Math.floor(new Date().getTime() / 1000) + 120
next_check: Math.floor(new Date().getTime() / 1000) + 60
}).catch((err) => {
console.error(err)
})
@@ -18758,25 +18726,35 @@ class AutomaticDispose {
// runnerID: runnerID,
// runnerSettings: runnerSettings,
// runnerIframeName: runnerIframeName,
// runnerIframe: runnerIframe
// runnerIframe:runnerIframe
// })
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
self.ADSettings().then((setting) => {
if (setting[runnerSettings] == 'true') {
let coll = self.ADisDB.ADisMissions.where({
let where = {
runner: Runner,
available: 'true',
done: 'false'
})
//if (self.MyRunner != "kt") {
}
var coll = self.ADisDB.ADisMissions.where(where)
if (self.MyRunner != "kt") {
coll = coll.and(function (item) {
return item.next_check <= Math.floor(new Date().getTime() / 1000)
});
//}
}
return coll.toArray()
}
/*
if (setting[runnerSettings] == 'true') {
return self.ADisDB.ADisMissions.where({
runner: Runner,
available: 'true',
done: 'false'
}).and(function (item) {
return item.next_check <= Math.floor(new Date().getTime() / 1000)
}).toArray()
}*/
}).then((Wunsche) => {
if (typeof Wunsche === "undefined") {
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
@@ -18784,13 +18762,11 @@ class AutomaticDispose {
Wunsche.sort((a, b) => {
return a.next_check - b.next_check;
});
console.log("TIME:", Math.floor(new Date().getTime() / 1000))
//console.table(Wunsche);
// console.table(Wunsche);
if (Wunsche.length > 0) {
let myWunsch = Wunsche[0];
console.log("MYWUNSCH:")
console.table(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);
@@ -18804,7 +18780,6 @@ class AutomaticDispose {
} else {
// only while
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
self.UpdateMissionsToDone(MissionID)
}
}
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
@@ -18826,69 +18801,63 @@ class AutomaticDispose {
const runnerID = self.ADisSettings.runner_iframesName.indexOf(window.name);
self.MyRunner = self.ADisSettings.runner[runnerID];
self.MyRunnerSettings = self.ADisSettings.runner_settings[runnerID];
setTimeout(function () {
self.MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
var help_el = $('a#mission_help');
if (help_el.length > 0) {
self.MissionType = help_el[0].href.split("?")[0];
var re = /\d+$/i;
var found = self.MissionType.match(re);
self.MissionType = Number(found[0]);
} else {
self.MissionType = null;
}
// console.log("MissionID", self.MissionID);
// console.log("MissionType", self.MissionType);
// console.log("Window", window.name);
// console.log("self.MyRunner", self.MyRunner);
// console.log("self.MyRunnerSettings", self.MyRunnerSettings);
if (self.includesString($('#iframe-inside-container > div.missionNotFound > div.missionNotFoundText').text(), 'Der Einsatz wurde erfolgreich abgeschlossen.')) {
console.log("DONE: " + self.MissionID);
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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) => {
if (setting[self.MyRunnerSettings] === 'true') {
let where = {
missionID: self.MissionID,
runner: self.MyRunner,
done: 'false'
self.MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
var help_el = $('a#mission_help');
if (help_el.length > 0) {
self.MissionType = help_el[0].href.split("?")[0];
var re = /\d+$/i;
var found = self.MissionType.match(re);
self.MissionType = Number(found[0]);
} else {
self.MissionType = null;
}
// console.log("MissionID", self.MissionID);
// console.log("MissionType", self.MissionType);
// console.log("Window", window.name);
// console.log("self.MyRunner", self.MyRunner);
// console.log("self.MyRunnerSettings", self.MyRunnerSettings);
if (self.includesString($('#iframe-inside-container > div.missionNotFound > div.missionNotFoundText').text(), 'Der Einsatz wurde erfolgreich abgeschlossen.')) {
console.log("DONE: " + self.MissionID);
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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) => {
if (setting[self.MyRunnerSettings] === 'true') {
let where = {
missionID: self.MissionID,
runner: self.MyRunner,
done: 'false'
}
// console.log(where);
return self.ADisDB.ADisMissions.where(where).and(function (item) {
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) => {
return self.MainHandler()
});
} else {
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
return tellParent(`console.log('wunsch:1000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
})
}
// console.log(where);
return self.ADisDB.ADisMissions.where(where).and(function (item) {
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) => {
self.MissionData = mywunsch;
return self.UpdateMissionsToDone(self.MissionID).then(() => {
return self.MainHandler()
});
});
} else {
//return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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}');`);
})
}
})
});
} else {
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
return tellParent(`console.log('wunsch:2000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
})
}
})
}
}, 100);
})
}
}
@@ -18905,13 +18874,13 @@ class AutomaticDispose {
return tellParent(`console.log('handler:2000:update:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`); // update Mission here as updated or full
});
} else {
setTimeout(function () {
if (['adis-ownmissions', 'adis-plannedeventss', 'adis-krankentransporte'].indexOf(window.name) != -1) {
self.CheckMissionAutomatic();
} else if (['adis-verbandmission', 'adis-verbandmission-event'].indexOf(window.name) != -1) {
self.WorkVerbandMission();
}
}, 250);
}
}
@@ -19011,10 +18980,7 @@ class AutomaticDispose {
if (self.MyRunner == 'os') {
self.OweSecure = true;
}
Mission.done = "true";
self.UpdateMissions(Mission).then(()=>{
self.GetMissionConfiguration(Mission.type);
})
self.GetMissionConfiguration(Mission.type);
}
});
}
@@ -19028,15 +18994,16 @@ class AutomaticDispose {
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType.toString()
}).then((availableMission) => {
if (availableMission != undefined) {
if (availableMission.jsondata) {
self.MissionConfig = availableMission.jsondata;
// console.log('MissionConfig: ', MissionType.toString(), JSON.stringify(self.MissionConfig, null, 2))
self.StartAlarmProcess();
} else {
self.UpdateMissionsToDone(self.MissionID);
return tellParent(`console.log('handler:2000:update:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`); // update Mission here as updated or full
}
if (availableMission != undefined && availableMission.jsondata) {
self.MissionConfig = availableMission.jsondata;
// console.log('MissionConfig: ', MissionType.toString(), JSON.stringify(self.MissionConfig, null, 2))
self.StartAlarmProcess();
} else {
var updateData = {
available: false,
next_check: CurrentTime + 60
};
self.UpdateOwnMissionsToDone(self.MissionID, updateData);
}
});
});
@@ -19090,27 +19057,33 @@ class AutomaticDispose {
}
}
console.log("Clicked Vehicles:"+self.MissionID+":"+self.MissionConfig.type+" ", $('#vehicle_show_table_all input[type="checkbox"]:checked').length, $('#vehicle_show_table_all input[type="checkbox"]:checked'));
console.table(self.MissionData)
self.UpdateMissionsToDone(self.MissionID).then(async () => {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');},2500);`);
//if (window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").length > 0 && self.MissionConfig.share) {
// window.$('input[type=checkbox]').prop('checked', false);
// await self.WorkVerbandMission(true);
// window.$('#allianceShareText').val('Kein RD, die Patiernten gehören mir! Anonsten kann nach 2h geschlossen werden. Danke für die Aufmerksamkeit!')
// window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").click();
//} else {
if ($('#vehicle_show_table_all input[type="checkbox"]:checked').length){
console.log('send now')
window.$('#mission_alarm_btn').click();
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
} else {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
}
//}
});
console.log("Clicked Vehicles:" + self.MissionID + ":" + self.MissionConfig.type + " ", $('#vehicle_show_table_all input[type="checkbox"]:checked').length, $('#vehicle_show_table_all input[type="checkbox"]:checked'));
console.table(self.MissionData)
self.UpdateMissionsToDone(self.MissionID).then(async () => {
//tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},2500);`);
//if (window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").length > 0 && self.MissionConfig.share) {
// window.$('input[type=checkbox]').prop('checked', false);
// await self.WorkVerbandMission(true);
// window.$('#allianceShareText').val('Kein RD, die Patiernten gehören mir! Anonsten kann nach 2h geschlossen werden. Danke für die Aufmerksamkeit!')
// window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").click();
//} else {
if ($('#vehicle_show_table_all input[type="checkbox"]:checked').length) {
console.log('send now')
if (window.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']").length > 0 && self.MissionConfig.share) {
window.$('input[type=checkbox]').prop('checked', false);
await self.WorkVerbandMission(true);
window.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']")[0].click();
} else {
window.$('#mission_alarm_btn').click();
}
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
} else {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
}
//}
});
})
}
@@ -19142,6 +19115,7 @@ class AutomaticDispose {
}
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// -
// - Collect Involved Vehicles & Patients
+1 -1
View File
@@ -10,7 +10,7 @@
<title>LEITSTELLENSPIEL.DE - baue deine eigene Leitstelle, in deiner Stadt!</title>
<meta content="authenticity_token" name="csrf-param" />
<meta content="TjGsiG+tPyL8SPR51dhx6sasfS4wF1Rh9n4qtzZ+rMw=" name="csrf-token" />
<meta content="cvOny8TDgPA/eJthVo45f8+Vh/ExGdKnenC3q0Fr0sk=" name="csrf-token" />
<script src="/assets/application-a789289a71061d030b76a864e1d16075.js" type="text/javascript"></script>
+1 -1
View File
@@ -10,7 +10,7 @@
<title>LEITSTELLENSPIEL.DE - baue deine eigene Leitstelle, in deiner Stadt!</title>
<meta content="authenticity_token" name="csrf-param" />
<meta content="hJglNqkHsn0i29Jl1jR6BKjpRCfjK8cVTvRYHW9X3mQ=" name="csrf-token" />
<meta content="/1vfZbjIof1sP0Gy1juDZhzIKL3GHnKnAPVcFhmrmLU=" name="csrf-token" />
<script src="/assets/application-a789289a71061d030b76a864e1d16075.js" type="text/javascript"></script>
+1 -1
View File
@@ -10,7 +10,7 @@
<title>LEITSTELLENSPIEL.DE - baue deine eigene Leitstelle, in deiner Stadt!</title>
<meta content="authenticity_token" name="csrf-param" />
<meta content="A7oqOPApiZ55rSDeWfOI6Tk/D0I8Dd/wMWOGGAJr+xw=" name="csrf-token" />
<meta content="ftiiGYcaqxTBxvpRVtzy+XpuEqIE9is8LacbnV7bmNo=" name="csrf-token" />
<script src="/assets/application-a789289a71061d030b76a864e1d16075.js" type="text/javascript"></script>
+176 -202
View File
@@ -22,7 +22,6 @@ class AutomaticDispose {
self.MaxVehicleID = 86
self.MissionType = null
self.MissionID = null
self.MissionData = null
self.MyRunner = null
self.MyRunnerSettings = null
self.OweSecure = false
@@ -142,9 +141,7 @@ class AutomaticDispose {
}, 500);
self.ADisSettings.runner.forEach((runner) => {
if(['kt','om'].indexOf(runner) !== -1) {
self.OpenNextMission(runner)
}
self.OpenNextMission(runner)
})
}
@@ -874,7 +871,7 @@ class AutomaticDispose {
// remove
console.log("Remove :", MyMission)
self.RemoveMissionsFromQueue(MyMission.missionID)
}
}
});
}
});
@@ -882,7 +879,6 @@ class AutomaticDispose {
});
});
const MyOwnObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
// console.log(mutation.target.id);
@@ -910,11 +906,11 @@ class AutomaticDispose {
ReadAndAddMissions(MissionID, Runner) {
const self = this;
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], async () => {
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
if (typeof MissionID != 'undefined') {
await self.AddMission(MissionID, Runner);
self.AddMission(MissionID, Runner);
} else {
await self.ADisSettings.runner_divs.forEach(async (RunnerX, index) => {
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);
@@ -932,6 +928,7 @@ class AutomaticDispose {
const runnerOpt = self.ADisSettings.runner[runnerID];
return self.ADSettings().then((setting) => {
if (setting[settingOpt] == 'true') {
let where = {
missionID: ID,
@@ -940,106 +937,78 @@ class AutomaticDispose {
return self.ADisDB.ADisMissions.where(where).limit(1)
}
}).then((Missions) => {
if (typeof Missions !== "undefined") {
return Missions.count((count) => {
if (count > 0) {
return Missions.each((MyMission) => {
var MissionElement = $("#mission_" + ID);
var _MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
if (MissionElement.length) {
return self.ADisDB.ADisAvailabelMissions.get({
type: _MissionType
}).then((available) => {
return self.UpdateMissions({
"missionID": MyMission.missionID,
"type": _MissionType,
"runner": MyMission.runner,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": "false",
"last_check": MyMission.last_check,
"next_check": MyMission.next_check
});
});
}
});
} else {
if (typeof Missions === "undefined") {
return;
}
return Missions.count((count) => {
if (count > 0) {
return Missions.each(() => {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var _MissionID = MissionElement.attr("mission_id");
var _MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
if (MissionElement.length) {
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.UpdateMissions({
"missionID": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": "false",
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"id": _MissionID,
"type": _MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined),
"done": false,
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
}
}
});
});
} else {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"missionID": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined)?'true':'false',
"done": 'false',
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
});
}
} else {
var MissionElement = $("#mission_" + ID);
var MissionID = MissionElement.attr("mission_id");
var MissionType = MissionElement.attr("mission_type_id");
var addr = MissionElement.find(".map_position_mover").text().split(",")
var MissionName = addr[0];
var MissionStreet = addr[1];
var MissionVillage = addr[2];
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType
}).then((available) => {
return self.AddMissionsToQueue({
"id": MissionID,
"type": MissionType,
"runner": runnerOpt,
"name": MissionName,
"street": MissionStreet,
"village": MissionVillage,
"available": (available !== undefined),
"done": false,
"last_check": Math.floor(new Date().getTime() / 1000),
"next_check": Math.floor(new Date().getTime() / 1000) + 1
});
});
}
});
});
}
AddMissionsToQueue(Mission) {
const self = this;
return self.ADisDB.ADisMissions.put({
missionID: Mission.missionID,
missionID: Mission.id,
type: Mission.type,
runner: Mission.runner,
name: Mission.name,
available: Mission.available,
done: Mission.done,
available: Mission.available ? 'true' : 'false',
done: Mission.done ? 'true' : 'false',
street: Mission.street,
village: Mission.village,
last_check: Mission.last_check,
@@ -1058,7 +1027,6 @@ class AutomaticDispose {
}
FreeIframe(Runner) {
// console.log('FreeIframe', Runner);
const self = this;
const runnerID = self.ADisSettings.runner.indexOf(Runner)
const runnerIframe = self.ADisSettings.runner_iframes[runnerID];
@@ -1071,7 +1039,7 @@ class AutomaticDispose {
const self = this;
return self.ADisDB.ADisMissions.update(MissionID, {
last_check: Math.floor(new Date().getTime() / 1000),
next_check: Math.floor(new Date().getTime() / 1000) + 120
next_check: Math.floor(new Date().getTime() / 1000) + 60
}).catch((err) => {
console.error(err)
})
@@ -1098,25 +1066,35 @@ class AutomaticDispose {
// runnerID: runnerID,
// runnerSettings: runnerSettings,
// runnerIframeName: runnerIframeName,
// runnerIframe: runnerIframe
// runnerIframe:runnerIframe
// })
return self.ADisDB.transaction('rw', [self.ADisDB.ADisMissions, self.ADisDB.ADisAvailabelMissions], () => {
self.ADSettings().then((setting) => {
if (setting[runnerSettings] == 'true') {
let coll = self.ADisDB.ADisMissions.where({
let where = {
runner: Runner,
available: 'true',
done: 'false'
})
//if (self.MyRunner != "kt") {
}
var coll = self.ADisDB.ADisMissions.where(where)
if (self.MyRunner != "kt") {
coll = coll.and(function (item) {
return item.next_check <= Math.floor(new Date().getTime() / 1000)
});
//}
}
return coll.toArray()
}
/*
if (setting[runnerSettings] == 'true') {
return self.ADisDB.ADisMissions.where({
runner: Runner,
available: 'true',
done: 'false'
}).and(function (item) {
return item.next_check <= Math.floor(new Date().getTime() / 1000)
}).toArray()
}*/
}).then((Wunsche) => {
if (typeof Wunsche === "undefined") {
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
@@ -1124,13 +1102,11 @@ class AutomaticDispose {
Wunsche.sort((a, b) => {
return a.next_check - b.next_check;
});
console.log("TIME:", Math.floor(new Date().getTime() / 1000))
//console.table(Wunsche);
// console.table(Wunsche);
if (Wunsche.length > 0) {
let myWunsch = Wunsche[0];
console.log("MYWUNSCH:")
console.table(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);
@@ -1144,7 +1120,6 @@ class AutomaticDispose {
} else {
// only while
// setTimeout(self.OpenNextMission.bind(self), 5000, Runner);
self.UpdateMissionsToDone(MissionID)
}
}
return setTimeout(self.OpenNextMission.bind(self), 1000, Runner);
@@ -1166,69 +1141,63 @@ class AutomaticDispose {
const runnerID = self.ADisSettings.runner_iframesName.indexOf(window.name);
self.MyRunner = self.ADisSettings.runner[runnerID];
self.MyRunnerSettings = self.ADisSettings.runner_settings[runnerID];
setTimeout(function () {
self.MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
var help_el = $('a#mission_help');
if (help_el.length > 0) {
self.MissionType = help_el[0].href.split("?")[0];
var re = /\d+$/i;
var found = self.MissionType.match(re);
self.MissionType = Number(found[0]);
} else {
self.MissionType = null;
}
// console.log("MissionID", self.MissionID);
// console.log("MissionType", self.MissionType);
// console.log("Window", window.name);
// console.log("self.MyRunner", self.MyRunner);
// console.log("self.MyRunnerSettings", self.MyRunnerSettings);
if (self.includesString($('#iframe-inside-container > div.missionNotFound > div.missionNotFoundText').text(), 'Der Einsatz wurde erfolgreich abgeschlossen.')) {
console.log("DONE: " + self.MissionID);
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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) => {
if (setting[self.MyRunnerSettings] === 'true') {
let where = {
missionID: self.MissionID,
runner: self.MyRunner,
done: 'false'
self.MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
var help_el = $('a#mission_help');
if (help_el.length > 0) {
self.MissionType = help_el[0].href.split("?")[0];
var re = /\d+$/i;
var found = self.MissionType.match(re);
self.MissionType = Number(found[0]);
} else {
self.MissionType = null;
}
// console.log("MissionID", self.MissionID);
// console.log("MissionType", self.MissionType);
// console.log("Window", window.name);
// console.log("self.MyRunner", self.MyRunner);
// console.log("self.MyRunnerSettings", self.MyRunnerSettings);
if (self.includesString($('#iframe-inside-container > div.missionNotFound > div.missionNotFoundText').text(), 'Der Einsatz wurde erfolgreich abgeschlossen.')) {
console.log("DONE: " + self.MissionID);
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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) => {
if (setting[self.MyRunnerSettings] === 'true') {
let where = {
missionID: self.MissionID,
runner: self.MyRunner,
done: 'false'
}
// console.log(where);
return self.ADisDB.ADisMissions.where(where).and(function (item) {
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) => {
return self.MainHandler()
});
} else {
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
return tellParent(`console.log('wunsch:1000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
})
}
// console.log(where);
return self.ADisDB.ADisMissions.where(where).and(function (item) {
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) => {
self.MissionData = mywunsch;
return self.UpdateMissionsToDone(self.MissionID).then(() => {
return self.MainHandler()
});
});
} else {
//return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
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}');`);
})
}
})
});
} else {
return self.RemoveMissionsFromQueue(self.MissionID).then(() => {
return tellParent(`console.log('wunsch:2000:done:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`);
})
}
})
}
}, 100);
})
}
}
@@ -1245,13 +1214,13 @@ class AutomaticDispose {
return tellParent(`console.log('handler:2000:update:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`); // update Mission here as updated or full
});
} else {
setTimeout(function () {
if (['adis-ownmissions', 'adis-plannedeventss', 'adis-krankentransporte'].indexOf(window.name) != -1) {
self.CheckMissionAutomatic();
} else if (['adis-verbandmission', 'adis-verbandmission-event'].indexOf(window.name) != -1) {
self.WorkVerbandMission();
}
}, 250);
}
}
@@ -1351,10 +1320,7 @@ class AutomaticDispose {
if (self.MyRunner == 'os') {
self.OweSecure = true;
}
Mission.done = "true";
self.UpdateMissions(Mission).then(()=>{
self.GetMissionConfiguration(Mission.type);
})
self.GetMissionConfiguration(Mission.type);
}
});
}
@@ -1368,15 +1334,16 @@ class AutomaticDispose {
return self.ADisDB.ADisAvailabelMissions.get({
type: MissionType.toString()
}).then((availableMission) => {
if (availableMission != undefined) {
if (availableMission.jsondata) {
self.MissionConfig = availableMission.jsondata;
// console.log('MissionConfig: ', MissionType.toString(), JSON.stringify(self.MissionConfig, null, 2))
self.StartAlarmProcess();
} else {
self.UpdateMissionsToDone(self.MissionID);
return tellParent(`console.log('handler:2000:update:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');`); // update Mission here as updated or full
}
if (availableMission != undefined && availableMission.jsondata) {
self.MissionConfig = availableMission.jsondata;
// console.log('MissionConfig: ', MissionType.toString(), JSON.stringify(self.MissionConfig, null, 2))
self.StartAlarmProcess();
} else {
var updateData = {
available: false,
next_check: CurrentTime + 60
};
self.UpdateOwnMissionsToDone(self.MissionID, updateData);
}
});
});
@@ -1430,27 +1397,33 @@ class AutomaticDispose {
}
}
console.log("Clicked Vehicles:"+self.MissionID+":"+self.MissionConfig.type+" ", $('#vehicle_show_table_all input[type="checkbox"]:checked').length, $('#vehicle_show_table_all input[type="checkbox"]:checked'));
console.table(self.MissionData)
self.UpdateMissionsToDone(self.MissionID).then(async () => {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');},2500);`);
//if (window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").length > 0 && self.MissionConfig.share) {
// window.$('input[type=checkbox]').prop('checked', false);
// await self.WorkVerbandMission(true);
// window.$('#allianceShareText').val('Kein RD, die Patiernten gehören mir! Anonsten kann nach 2h geschlossen werden. Danke für die Aufmerksamkeit!')
// window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").click();
//} else {
if ($('#vehicle_show_table_all input[type="checkbox"]:checked').length){
console.log('send now')
window.$('#mission_alarm_btn').click();
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
} else {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
}
//}
});
console.log("Clicked Vehicles:" + self.MissionID + ":" + self.MissionConfig.type + " ", $('#vehicle_show_table_all input[type="checkbox"]:checked').length, $('#vehicle_show_table_all input[type="checkbox"]:checked'));
console.table(self.MissionData)
self.UpdateMissionsToDone(self.MissionID).then(async () => {
//tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},2500);`);
//if (window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").length > 0 && self.MissionConfig.share) {
// window.$('input[type=checkbox]').prop('checked', false);
// await self.WorkVerbandMission(true);
// window.$('#allianceShareText').val('Kein RD, die Patiernten gehören mir! Anonsten kann nach 2h geschlossen werden. Danke für die Aufmerksamkeit!')
// window.$("a.btn.btn-success.btn-sm.alert_notify_alliance").click();
//} else {
if ($('#vehicle_show_table_all input[type="checkbox"]:checked').length) {
console.log('send now')
if (window.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']").length > 0 && self.MissionConfig.share) {
window.$('input[type=checkbox]').prop('checked', false);
await self.WorkVerbandMission(true);
window.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']")[0].click();
} else {
window.$('#mission_alarm_btn').click();
}
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
} else {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');window.AutomaticDisposeCall.FreeIframe('${self.MyRunner}');},500);`);
}
//}
});
})
}
@@ -1482,6 +1455,7 @@ class AutomaticDispose {
}
// - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// -
// - Collect Involved Vehicles & Patients
+6 -193
View File
@@ -8,9 +8,9 @@
class WatchMissions {
constructor() {
constructor(){
let self = this;
self.DB = new Dexie('LSS_WatchMissions');
self.DB = new Dexie('LSS_AutomaticDispo');
self.DB.version(1).stores({
@@ -18,7 +18,6 @@ class WatchMissions {
* Missions to Watch
* - missionID - Mission ID that should be watched.
* - limit - If the Mission turns green more than 6 times, no more requests will be sent.
* - data - {name, datetime, onsite{ username:{ cars: [ {name, type} ] } } }
*/
Missions: "++missionID"
});
@@ -29,214 +28,28 @@ class WatchMissions {
// index page
if (window.location.pathname === "/" || window.location.pathname === "/#" || window.location.pathname === "/#_=_") {
self.RegisterIndexPage();
}
}
// mission page
else if (window.location.pathname.indexOf("/missions/") !== -1 && window.name == 'watchMission') {
self.RegisterMissionPage();
}
})
}
get RandomTime() {
const max = 6;
const min = 1;
return Math.floor((Math.random() * (max - min + 1) + min) * 1000);
return Math.floor((Math.random()*(max-min+1)+min)*1000);
}
RegisterIndexPage() {
let self = this;
// -
// - Google Font
// -
var styleElement = document.createElement("link");
styleElement.rel = "stylesheet";
styleElement.href = "https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700";
this.ADis_MyHead.appendChild(styleElement);
// -
// - FontAwesome 5
// -
var scriptElement = document.createElement("script");
scriptElement.type = "text/javascript";
scriptElement.src = "https://use.fontawesome.com/releases/v5.5.0/js/all.js";
this.ADis_MyHead.appendChild(scriptElement);
// -
// - Navbar Dashboard
// -
var styleElement = document.createElement("link");
styleElement.rel = "stylesheet";
styleElement.type = "text/css";
styleElement.media = "screen";
styleElement.href = this.ADisSettings.url + this.ADisSettings.branch + "/style/interface.css";
this.ADis_MyHead.appendChild(styleElement);
// Create Dashboard
$('#news_li').before('<li id="adis-nav-item"></li>');
$('#adis-nav-item').html(`/***ADis_Navbar***/0`)
$("#adis-dashboard").css({
display: "none",
opacity: "0"
});
}
// Generate HTML Table
// Builds the HTML Table out of myList json data from Ivy restful service.
buildHtmlTable() {
const self = this;
self.addTable(myList, $("#excelDataTable"));
}
addTable(list, appendObj) {
const self = this;
appendObj.html('');
var columns = self.addAllColumnHeaders(list, appendObj);
for (var i = 0; i < list.length; i++) {
var row$ = $('<tr/>');
for (var colIndex = 0; colIndex < columns.length; colIndex++) {
var cellValue = list[i][columns[colIndex]];
if (cellValue == null) {
cellValue = "";
}
if (cellValue.constructor === Array) {
$a = $('<td/>');
row$.append($a);
self.addTable(cellValue, $a);
} else if (cellValue.constructor === Object) {
var array = $.map(cellValue, function (value, index) {
return [value];
});
$a = $('<td/>');
row$.append($a);
self.addObject(array, $a);
} else {
row$.append($('<td/>').html(cellValue));
}
}
appendObj.append(row$);
}
}
addObject(list, appendObj) {
const self = this;
for (var i = 0; i < list.length; i++) {
var row$ = $('<tr/>');
var cellValue = list[i];
if (cellValue == null) {
cellValue = "";
}
if (cellValue.constructor === Array) {
$a = $('<td/>');
row$.append($a);
self.addTable(cellValue, $a);
} else if (cellValue.constructor === Object) {
var array = $.map(cellValue, function (value, index) {
return [value];
});
$a = $('<td/>');
row$.append($a);
self.addObject(array, $a);
} else {
row$.append($('<td/>').html(cellValue));
}
appendObj.append(row$);
}
}
// Adds a header row to the table and returns the set of columns.
// Need to do union of keys from all records as some records may not contain
// all records
addAllColumnHeaders(list, appendObj) {
var columnSet = [];
var headerTr$ = $('<tr/>');
for (var i = 0; i < list.length; i++) {
var rowHash = list[i];
for (var key in rowHash) {
if ($.inArray(key, columnSet) == -1) {
columnSet.push(key);
headerTr$.append($('<th/>').html(key));
}
}
}
appendObj.append(headerTr$);
return columnSet;
}
// Mission Page
RegisterMissionPage() {
let MissionType = null;
let MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
let help_el = $('a#mission_help');
if (help_el.length > 0) {
MissionType = help_el[0].href.split("?")[0];
var re = /\d+$/i;
var found = MissionType.match(re);
MissionType = Number(found[0]);
}
var myRows = [];
var $headers = $("table#mission_vehicle_driving th");
var $rows = $("table#mission_vehicle_driving tbody tr").each(function (index) {
$cells = $(this).find("td");
myRows[index] = {};
$cells.each(function (cellIndex) {
let mcoai = '';
if (cellIndex == 1) {
mcoai = ($($(this).find("a")[0]).text().trim() + ' ' + $($(this).find("small")[0]).text().trim()).replace(/(\r\n\t|\n|\r\t|\s{2,})/gm, "");
} else {
mcoai = ($(this).text().trim()).replace(/(\r\n\t|\n|\r\t|\s{2,})/gm, "");
}
console.log(cellIndex, mcoai, $($headers[cellIndex]).text().trim());
if ($($headers[cellIndex]).text().trim() != '') {
myRows[index][$($headers[cellIndex]).text().trim()] = mcoai
}
});
});
// Let's put this in the object like you want and convert to JSON (Note: jQuery will also do this for you on the Ajax request)
var myObj = {};
myObj.Anfahrt = myRows.filter(value => Object.keys(value).length !== 0);
myRows = [];
$headers = $("table#mission_vehicle_at_mission th");
$rows = $("table#mission_vehicle_at_mission tbody tr").each(function (index) {
$cells = $(this).find("td");
myRows[index] = {};
$cells.each(function (cellIndex) {
let mcoai = '';
if (cellIndex == 1) {
mcoai = ($($(this).find("a")[0]).text().trim() + ' ' + $($(this).find("small")[0]).text().trim()).replace(/(\r\n\t|\n|\r\t|\s{2,})/gm, "");
} else {
mcoai = ($(this).text().trim()).replace(/(\r\n\t|\n|\r\t|\s{2,})/gm, "");
}
console.log(cellIndex, mcoai, $($headers[cellIndex]).text().trim());
if ($($headers[cellIndex]).text().trim() != '') {
myRows[index][$($headers[cellIndex]).text().trim()] = mcoai
}
});
});
// Let's put this in the object like you want and convert to JSON (Note: jQuery will also do this for you on the Ajax request)
myObj.VorOrt = myRows.filter(value => Object.keys(value).length !== 0);
console.log(myObj);
}
}