v2 up aoc9a9

This commit is contained in:
2018-12-12 22:39:12 +01:00
parent c7d1157a1a
commit 1517dbd7f0
4 changed files with 202 additions and 13 deletions

View File

@@ -1357,10 +1357,11 @@ class AutomaticDispose {
setTimeout(() => {
self.UpdateMissionsToDone(self.MissionID).then(async () => {
tellParent(`setTimeout(function(){console.log('ok:${window.name}:${self.MissionID}');},500);`);
if (window.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']").length > 0 && self.MissionConfig.share) {
if (window.$("#mission-form > div.pull-right > div:nth-child(1) > div > 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.$("a[title='Alarmieren, im Verband freigeben und nächsten Einsatz aufrufen']")[0].click();
window.$('#allianceShareText').val('Kein RD, die Patiernten gehören mir! Anonsten kann nach 2h geschlossen werden. Danke für die Aufmerksamkeit!')
window.$("#mission-form > div.pull-right > div:nth-child(1) > div > a.btn.btn-success.btn-sm.alert_notify_alliance").click();
} else {
window.$('#mission_alarm_btn').click();
}

View File

@@ -8,9 +8,9 @@
class WatchMissions {
constructor(){
constructor() {
let self = this;
self.DB = new Dexie('LSS_AutomaticDispo');
self.DB = new Dexie('LSS_WatchMissions');
self.DB.version(1).stores({
@@ -18,6 +18,7 @@ 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"
});
@@ -28,28 +29,214 @@ 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"
});
}
RegisterMissionPage() {
// 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);
}
}