From 1517dbd7f0e1f8238a254402f01834ad801b026c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Fr=C3=B6hle?= Date: Wed, 12 Dec 2018 22:39:12 +0100 Subject: [PATCH] v2 up aoc9a9 --- dist/autoloader.js | 2 +- dist/autoloaderV2.js | 7 +- src/autoloaderV2.js | 5 +- src/watch_missions.js | 201 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 202 insertions(+), 13 deletions(-) diff --git a/dist/autoloader.js b/dist/autoloader.js index 7dded0c..74b647e 100755 --- a/dist/autoloader.js +++ b/dist/autoloader.js @@ -1,4 +1,4 @@ -/*Generated on:Tue Dec 11 2018 19:22:03 GMT+0100 (CET)*/ +/*Generated on:Wed Dec 12 2018 22:39:11 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(); diff --git a/dist/autoloaderV2.js b/dist/autoloaderV2.js index 59fdeba..6db2633 100644 --- a/dist/autoloaderV2.js +++ b/dist/autoloaderV2.js @@ -1,4 +1,4 @@ -/*Generated on:Tue Dec 11 2018 19:22:03 GMT+0100 (CET)*/ +/*Generated on:Wed Dec 12 2018 22:39:11 GMT+0100 (CET)*/ /* * Dexie.js - a minimalistic wrapper for IndexedDB * =============================================== @@ -18974,10 +18974,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(); } diff --git a/src/autoloaderV2.js b/src/autoloaderV2.js index 26efbb4..b93d9b8 100644 --- a/src/autoloaderV2.js +++ b/src/autoloaderV2.js @@ -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(); } diff --git a/src/watch_missions.js b/src/watch_missions.js index d310827..82e4dc9 100644 --- a/src/watch_missions.js +++ b/src/watch_missions.js @@ -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('
  • '); + $('#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$ = $(''); + for (var colIndex = 0; colIndex < columns.length; colIndex++) { + var cellValue = list[i][columns[colIndex]]; + + if (cellValue == null) { + cellValue = ""; + } + + if (cellValue.constructor === Array) { + $a = $(''); + row$.append($a); + self.addTable(cellValue, $a); + + } else if (cellValue.constructor === Object) { + + var array = $.map(cellValue, function (value, index) { + return [value]; + }); + + $a = $(''); + row$.append($a); + self.addObject(array, $a); + + } else { + row$.append($('').html(cellValue)); + } + } + appendObj.append(row$); + } + } + + + addObject(list, appendObj) { + const self = this; + for (var i = 0; i < list.length; i++) { + var row$ = $(''); + + var cellValue = list[i]; + + if (cellValue == null) { + cellValue = ""; + } + + if (cellValue.constructor === Array) { + $a = $(''); + row$.append($a); + self.addTable(cellValue, $a); + + } else if (cellValue.constructor === Object) { + + var array = $.map(cellValue, function (value, index) { + return [value]; + }); + + $a = $(''); + row$.append($a); + self.addObject(array, $a); + + } else { + row$.append($('').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$ = $(''); + + 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($('').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); } }