Codacy JS eslint fix
This commit is contained in:
parent
aa0b45e563
commit
75bd786d2b
|
@ -1,20 +1,20 @@
|
|||
var GAME_LOADING_ERROR_MSG = 'Game loading failed, please retry later.';
|
||||
const GAME_LOADING_ERROR_MSG = "Game loading failed, please retry later.";
|
||||
|
||||
async function play(game){
|
||||
console.log("Opening game "+game+"...");
|
||||
async function play (game) {
|
||||
console.log("Opening game " + game + "...");
|
||||
try {
|
||||
await import(`./games/${game}/game.js`)
|
||||
.then(({default: Game}) => {
|
||||
var game = new Game();
|
||||
$("body").append('<div class="modal" id="modal_game" tabindex="-1" role="dialog" data-backdrop="static" style="display: none; min-width: 100%; margin: 0px;"><div class="modal-dialog" role="document" style="min-width: 100%; margin: 0;"><div class="modal-content" style="min-height: 100vh;" id="modal_game_content"></div></div></div>');
|
||||
$("#modal_game_content").append(`<div class="modal-header"><h5 class="modal-title" style="color: black">${game.title}</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body" id="modal_game_body"></div>`);
|
||||
$("#modal_game_body").append(`<div id="game_content" style="text-align: center"></div><p style="text-align: right; color: black;">Game by <a style="color: blue" target="_blank" href="${game.author_url}">${game.author}</a></p>`);
|
||||
$('#modal_game').modal('show');
|
||||
game.initialize($("#game_content"));
|
||||
});
|
||||
$('#modal_game').on('hidden.bs.modal', function (e) {
|
||||
.then(({ default: Game }) => {
|
||||
const game = new Game();
|
||||
$("body").append("<div class=\"modal\" id=\"modal_game\" tabindex=\"-1\" role=\"dialog\" data-backdrop=\"static\" style=\"display: none; min-width: 100%; margin: 0px;\"><div class=\"modal-dialog\" role=\"document\" style=\"min-width: 100%; margin: 0;\"><div class=\"modal-content\" style=\"min-height: 100vh;\" id=\"modal_game_content\"></div></div></div>");
|
||||
$("#modal_game_content").append(`<div class="modal-header"><h5 class="modal-title" style="color: black">${game.title}</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body" id="modal_game_body"></div>`);
|
||||
$("#modal_game_body").append(`<div id="game_content" style="text-align: center"></div><p style="text-align: right; color: black;">Game by <a style="color: blue" target="_blank" href="${game.author_url}">${game.author}</a></p>`);
|
||||
$("#modal_game").modal("show");
|
||||
game.initialize($("#game_content"));
|
||||
});
|
||||
$("#modal_game").on("hidden.bs.modal", function (e) {
|
||||
$("#modal_game").remove();
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toastr.error(GAME_LOADING_ERROR_MSG);
|
||||
|
@ -22,4 +22,4 @@ async function play(game){
|
|||
}
|
||||
|
||||
window.play = play;
|
||||
window.GAME_LOADING_ERROR_MSG = GAME_LOADING_ERROR_MSG;
|
||||
window.GAME_LOADING_ERROR_MSG = GAME_LOADING_ERROR_MSG;
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
import "bootstrap";
|
||||
import "bootstrap/dist/css/bootstrap.min.css";
|
||||
import "./main.css";
|
||||
import "./font-awesome.scss";
|
||||
import "bootstrap-datepicker";
|
||||
import "../node_modules/bootstrap-toggle/css/bootstrap-toggle.css";
|
||||
import "../node_modules/bootstrap-toggle/js/bootstrap-toggle.js";
|
||||
import "../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css";
|
||||
import "time-input-polyfill/auto";
|
||||
import "jquery-pjax";
|
||||
import toastr from "toastr";
|
||||
import "toastr/build/toastr.css";
|
||||
jQuery = $;
|
||||
window.$ = window.jQuery = $;
|
||||
import 'bootstrap';
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import './main.css';
|
||||
import './font-awesome.scss';
|
||||
import 'bootstrap-datepicker';
|
||||
import '../node_modules/bootstrap-toggle/css/bootstrap-toggle.css';
|
||||
import '../node_modules/bootstrap-toggle/js/bootstrap-toggle.js';
|
||||
import '../node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css';
|
||||
import 'time-input-polyfill/auto';
|
||||
import 'jquery-pjax';
|
||||
import toastr from 'toastr'
|
||||
import 'toastr/build/toastr.css';
|
||||
window.toastr = toastr;
|
||||
toastr.options = {
|
||||
"closeButton": false,
|
||||
"debug": false,
|
||||
"newestOnTop": false,
|
||||
"progressBar": true,
|
||||
"positionClass": "toast-bottom-right",
|
||||
"preventDuplicates": false,
|
||||
"onclick": null,
|
||||
"showDuration": "300",
|
||||
"hideDuration": "1000",
|
||||
"timeOut": "5000",
|
||||
"extendedTimeOut": "1000",
|
||||
"showEasing": "swing",
|
||||
"hideEasing": "linear",
|
||||
"showMethod": "fadeIn",
|
||||
"hideMethod": "fadeOut"
|
||||
}
|
||||
closeButton: false,
|
||||
debug: false,
|
||||
newestOnTop: false,
|
||||
progressBar: true,
|
||||
positionClass: "toast-bottom-right",
|
||||
preventDuplicates: false,
|
||||
onclick: null,
|
||||
showDuration: "300",
|
||||
hideDuration: "1000",
|
||||
timeOut: "5000",
|
||||
extendedTimeOut: "1000",
|
||||
showEasing: "swing",
|
||||
hideEasing: "linear",
|
||||
showMethod: "fadeIn",
|
||||
hideMethod: "fadeOut"
|
||||
};
|
||||
|
||||
$.fn.loading = function(action="start", options) {
|
||||
var opts = $.extend( {}, $.fn.loading.defaults, options );
|
||||
$.fn.loading = function (action = "start", options) {
|
||||
const opts = $.extend({}, $.fn.loading.defaults, options);
|
||||
|
||||
if(action === "show") {
|
||||
this.addClass("loading_blur");
|
||||
$( "body" ).append( "<div id='loading_div' class='loading_overlay'><p class=''><b>"+opts.message+"</b></p></div>" );
|
||||
} else if(action === "hide") {
|
||||
this.removeClass("loading_blur");
|
||||
this.addClass("loading_no_blur");
|
||||
setTimeout(() => {
|
||||
this.removeClass("loading_no_blur");
|
||||
}, 1000);
|
||||
$( "#loading_div" ).remove();
|
||||
if (action === "show") {
|
||||
this.addClass("loading_blur");
|
||||
$("body").append("<div id='loading_div' class='loading_overlay'><p class=''><b>" + opts.message + "</b></p></div>");
|
||||
} else if (action === "hide") {
|
||||
this.removeClass("loading_blur");
|
||||
this.addClass("loading_no_blur");
|
||||
setTimeout(() => {
|
||||
this.removeClass("loading_no_blur");
|
||||
}, 1000);
|
||||
$("#loading_div").remove();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -51,74 +51,74 @@ $.fn.loading.defaults = {
|
|||
message: "Loading..."
|
||||
};
|
||||
|
||||
console.log("Commit: "+process.env.GIT_VERSION);
|
||||
console.log("Date: "+process.env.GIT_AUTHOR_DATE);
|
||||
console.log("Bundle mode: "+process.env.BUNDLE_MODE);
|
||||
console.log("Bundle date: "+new Date(process.env.BUNDLE_DATE).toISOString());
|
||||
console.log("Commit: " + process.env.GIT_VERSION);
|
||||
console.log("Date: " + process.env.GIT_AUTHOR_DATE);
|
||||
console.log("Bundle mode: " + process.env.BUNDLE_MODE);
|
||||
console.log("Bundle date: " + new Date(process.env.BUNDLE_DATE).toISOString());
|
||||
|
||||
$(document).pjax('a:not(.pjax_disable)', '#content', {timeout: 100000});
|
||||
$(document).on('pjax:start', function() {
|
||||
if(document.getElementById("topNavBar") !== undefined){
|
||||
$(document).pjax("a:not(.pjax_disable)", "#content", { timeout: 100000 });
|
||||
$(document).on("pjax:start", function () {
|
||||
if (document.getElementById("topNavBar") !== undefined) {
|
||||
document.getElementById("topNavBar").className = "topnav";
|
||||
}
|
||||
old_data = "null";
|
||||
fillTable = undefined;
|
||||
table_engine = "datatables";
|
||||
if(window.loadTable_interval !== undefined){
|
||||
if (window.loadTable_interval !== undefined) {
|
||||
clearInterval(window.loadTable_interval);
|
||||
window.loadTable_interval = undefined;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Cookie functions from w3schools
|
||||
function setCookie(cname, cvalue, exdays) {
|
||||
var d = new Date();
|
||||
function setCookie (cname, cvalue, exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||
var expires = "expires=" + d.toUTCString();
|
||||
const expires = "expires=" + d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
}
|
||||
function getCookie(cname) {
|
||||
var name = cname + "=";
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var ca = decodedCookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) === 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
function getCookie (cname) {
|
||||
const name = cname + "=";
|
||||
const decodedCookie = decodeURIComponent(document.cookie);
|
||||
const ca = decodedCookie.split(";");
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === " ") {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) === 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
$( document ).ajaxError(function(event, xhr, settings, error) {
|
||||
console.error("Error requesting content: "+error+" - status code "+xhr.status);
|
||||
console.log(event);
|
||||
console.log(xhr);
|
||||
console.log(settings);
|
||||
$(document).ajaxError(function (event, xhr, settings, error) {
|
||||
console.error("Error requesting content: " + error + " - status code " + xhr.status);
|
||||
console.log(event);
|
||||
console.log(xhr);
|
||||
console.log(settings);
|
||||
});
|
||||
|
||||
if (getCookie("authenticated")) {
|
||||
var installServiceWorker = false;
|
||||
if(window.skipServiceWorkerInstallation !== undefined){ //if you want to disable SW for example via GreasyFork userscript
|
||||
if (window.skipServiceWorkerInstallation !== undefined) { // if you want to disable SW for example via GreasyFork userscript
|
||||
installServiceWorker = false;
|
||||
}
|
||||
if(getCookie("disableServiceWorkerInstallation")){
|
||||
if (getCookie("disableServiceWorkerInstallation")) {
|
||||
console.log("Skipping ServiceWorker installation because cookie 'disableServiceWorkerInstallation' exists");
|
||||
installServiceWorker = false;
|
||||
}
|
||||
if ('serviceWorker' in navigator) {
|
||||
if ('connection' in navigator && navigator.connection.saveData && !getCookie("forceServiceWorkerInstallation")) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
if ("connection" in navigator && navigator.connection.saveData && !getCookie("forceServiceWorkerInstallation")) {
|
||||
console.log("Skipping ServiceWorker installation because saveData is enabled");
|
||||
installServiceWorker = false;
|
||||
}
|
||||
if ('storage' in navigator && 'estimate' in navigator.storage && !getCookie("forceServiceWorkerInstallation")){
|
||||
if ("storage" in navigator && "estimate" in navigator.storage && !getCookie("forceServiceWorkerInstallation")) {
|
||||
navigator.storage.estimate().then((quota) => {
|
||||
const requiredMemory = 3 * 1e+6;
|
||||
if (quota < requiredMemory) {
|
||||
console.log("Skipping ServiceWorker installation because memory is low. memory="+quota);
|
||||
console.log("Skipping ServiceWorker installation because memory is low. memory=" + quota);
|
||||
installServiceWorker = false;
|
||||
}
|
||||
});
|
||||
|
@ -127,112 +127,116 @@ if (getCookie("authenticated")) {
|
|||
installServiceWorker = false;
|
||||
}
|
||||
}
|
||||
if(installServiceWorker){
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('sw.js').then((registration) => {
|
||||
console.log('SW registered: ', registration);
|
||||
if (installServiceWorker) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("sw.js").then((registration) => {
|
||||
console.log("SW registered: ", registration);
|
||||
}).catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
console.log("SW registration failed: ", registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$( document ).ready(function() {
|
||||
if($("#frontend_version") !== undefined){
|
||||
$("#frontend_version").append(process.env.GIT_VERSION+" aggiornamento "+new Date(process.env.BUNDLE_DATE).toLocaleString());
|
||||
$(document).ready(function () {
|
||||
if ($("#frontend_version") !== undefined) {
|
||||
$("#frontend_version").append(process.env.GIT_VERSION + " aggiornamento " + new Date(process.env.BUNDLE_DATE).toLocaleString());
|
||||
}
|
||||
});
|
||||
|
||||
var offline = false;
|
||||
var loadTable_interval = undefined;
|
||||
const offline = false;
|
||||
const loadTable_interval = undefined;
|
||||
var old_data = "null";
|
||||
var table_engine = "datatables";
|
||||
var fillTable = undefined;
|
||||
|
||||
async function loadTable({table_page, set_interval=true, interval=10000, onlineReload=false, use_custom_table_engine=false, callback=false}){
|
||||
if (typeof fillTable === "undefined"){
|
||||
if(use_custom_table_engine !== false){
|
||||
async function loadTable ({ table_page, set_interval = true, interval = 10000, onlineReload = false, use_custom_table_engine = false, callback = false }) {
|
||||
if (typeof fillTable === "undefined") {
|
||||
if (use_custom_table_engine !== false) {
|
||||
table_engine = use_custom_table_engine;
|
||||
} else if ('connection' in navigator && navigator.connection.saveData) {
|
||||
} else if ("connection" in navigator && navigator.connection.saveData) {
|
||||
table_engine = "default";
|
||||
}
|
||||
fillTable = await import(`./table_engine_${table_engine}.js`)
|
||||
.then(({default: _}) => {
|
||||
return _;
|
||||
});
|
||||
.then(({ default: _ }) => {
|
||||
return _;
|
||||
});
|
||||
}
|
||||
if ('getBattery' in navigator) {
|
||||
if ("getBattery" in navigator) {
|
||||
navigator.getBattery().then((level, charging) => {
|
||||
if (!charging && level < 0.2) {
|
||||
return;
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if ('deviceMemory' in navigator && navigator.deviceMemory < 0.2) {
|
||||
if ("deviceMemory" in navigator && navigator.deviceMemory < 0.2) {
|
||||
return;
|
||||
}
|
||||
let replaceLatLngWithMap = table_page == "services" || table_page == "trainings";
|
||||
$.getJSON({ url: "resources/ajax/ajax_"+table_page+".php", data: { "old_data": old_data }, success: function( data, status, xhr ) {
|
||||
old_data = xhr.getResponseHeader('data'); //TODO: refactoring and adding comments
|
||||
console.log(data);
|
||||
if(data.length > 0){
|
||||
fillTable({data, replaceLatLngWithMap, callback});
|
||||
var headers = new Headers();
|
||||
headers.append('date', Date.now());
|
||||
caches.open('tables-1').then((cache) => {
|
||||
cache.put('/table_'+table_page+'.json', new Response(xhr.responseText, {headers: headers}))
|
||||
});
|
||||
}
|
||||
if(window.offline){ // if xhr request successful, client is online
|
||||
console.log(onlineReload);
|
||||
if(onlineReload){
|
||||
location.reload(); //for offline page
|
||||
} else {
|
||||
$("#offline_alert").hide(400);
|
||||
window.offline = false;
|
||||
const replaceLatLngWithMap = table_page == "services" || table_page == "trainings";
|
||||
$.getJSON({
|
||||
url: "resources/ajax/ajax_" + table_page + ".php",
|
||||
data: { old_data: old_data },
|
||||
success: function (data, status, xhr) {
|
||||
old_data = xhr.getResponseHeader("data"); // TODO: refactoring and adding comments
|
||||
console.log(data);
|
||||
if (data.length > 0) {
|
||||
fillTable({ data, replaceLatLngWithMap, callback });
|
||||
const headers = new Headers();
|
||||
headers.append("date", Date.now());
|
||||
caches.open("tables-1").then((cache) => {
|
||||
cache.put("/table_" + table_page + ".json", new Response(xhr.responseText, { headers: headers }));
|
||||
});
|
||||
}
|
||||
if (window.offline) { // if xhr request successful, client is online
|
||||
console.log(onlineReload);
|
||||
if (onlineReload) {
|
||||
location.reload(); // for offline page
|
||||
} else {
|
||||
$("#offline_alert").hide(400);
|
||||
window.offline = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}).fail(function(data, status) {
|
||||
if(status == "parsererror"){
|
||||
if($("#table_body").children().length === 0) { //this is a server-side authentication error on some cheap hosting providers
|
||||
loadTable(table_page, set_interval, interval); //retry
|
||||
}).fail(function (data, status) {
|
||||
if (status == "parsererror") {
|
||||
if ($("#table_body").children().length === 0) { // this is a server-side authentication error on some cheap hosting providers
|
||||
loadTable(table_page, set_interval, interval); // retry
|
||||
} // else nothing
|
||||
} else {
|
||||
caches.open('tables-1').then(cache => {
|
||||
cache.match("/table_"+table_page+".json").then(response => {
|
||||
caches.open("tables-1").then(cache => {
|
||||
cache.match("/table_" + table_page + ".json").then(response => {
|
||||
response.json().then(data => {
|
||||
fillTable({data, replaceLatLngWithMap, callback});
|
||||
fillTable({ data, replaceLatLngWithMap, callback });
|
||||
console.log("Table loaded from cache");
|
||||
$("#offline_update").text(new Date(parseInt(response.headers.get("date"))).toLocaleString());
|
||||
});
|
||||
});
|
||||
});
|
||||
if(!window.offline){ // if xhr request fails, client is offline
|
||||
if (!window.offline) { // if xhr request fails, client is offline
|
||||
$("#offline_alert").show(400);
|
||||
window.offline = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if(set_interval){
|
||||
if ('connection' in navigator && navigator.connection.saveData) {
|
||||
if (set_interval) {
|
||||
if ("connection" in navigator && navigator.connection.saveData) {
|
||||
interval += 5000;
|
||||
}
|
||||
console.log("table_load interval "+interval);
|
||||
window.loadTable_interval = setInterval(function() {
|
||||
window.loadTable({table_page, set_interval: false, interval, onlineReload, use_custom_table_engine, callback: false});
|
||||
console.log("table_load interval " + interval);
|
||||
window.loadTable_interval = setInterval(function () {
|
||||
window.loadTable({ table_page, set_interval: false, interval, onlineReload, use_custom_table_engine, callback: false });
|
||||
}, interval);
|
||||
}
|
||||
}
|
||||
|
||||
function chat() {
|
||||
function chat () {
|
||||
setCookie("chat", "true", 1);
|
||||
location.reload();
|
||||
}
|
||||
|
||||
window.addEventListener('securitypolicyviolation',console.error.bind(console));
|
||||
window.addEventListener("securitypolicyviolation", console.error.bind(console));
|
||||
|
||||
function menu() {
|
||||
var topNavBar = document.getElementById("topNavBar");
|
||||
function menu () {
|
||||
const topNavBar = document.getElementById("topNavBar");
|
||||
if (topNavBar.className === "topnav") {
|
||||
topNavBar.className += " responsive";
|
||||
} else {
|
||||
|
@ -245,4 +249,4 @@ window.loadTable = loadTable;
|
|||
window.setCookie = setCookie;
|
||||
window.getCookie = getCookie;
|
||||
window.chat = chat;
|
||||
window.menu = menu;
|
||||
window.menu = menu;
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
import L from 'leaflet';
|
||||
import 'leaflet.locatecontrol';
|
||||
import '../node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css'
|
||||
import '../node_modules/leaflet/dist/leaflet.css';
|
||||
import './maps.css';
|
||||
import L from "leaflet";
|
||||
import "leaflet.locatecontrol";
|
||||
import "../node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css";
|
||||
import "../node_modules/leaflet/dist/leaflet.css";
|
||||
import "./maps.css";
|
||||
|
||||
const iconRetinaUrl = 'resources/dist/marker-icon-2x.png';
|
||||
const iconUrl = 'resources/dist/marker-icon.png';
|
||||
const shadowUrl = 'resources/dist/marker-shadow.png';
|
||||
const iconRetinaUrl = "resources/dist/marker-icon-2x.png";
|
||||
const iconUrl = "resources/dist/marker-icon.png";
|
||||
const shadowUrl = "resources/dist/marker-shadow.png";
|
||||
const iconDefault = new L.Icon({
|
||||
iconRetinaUrl,
|
||||
iconUrl,
|
||||
shadowUrl,
|
||||
iconSize: [25, 41],
|
||||
iconAnchor: [12, 41],
|
||||
popupAnchor: [1, -34],
|
||||
tooltipAnchor: [16, -28],
|
||||
shadowSize: [41, 41]
|
||||
iconRetinaUrl,
|
||||
iconUrl,
|
||||
shadowUrl,
|
||||
iconSize: [25, 41],
|
||||
iconAnchor: [12, 41],
|
||||
popupAnchor: [1, -34],
|
||||
tooltipAnchor: [16, -28],
|
||||
shadowSize: [41, 41]
|
||||
});
|
||||
|
||||
var marker;
|
||||
var feature;
|
||||
var map;
|
||||
let marker;
|
||||
let feature;
|
||||
let map;
|
||||
|
||||
function set_marker(LatLng){
|
||||
if(marker){
|
||||
console.log("Marker exists");
|
||||
//console.log(marker);
|
||||
marker.remove();
|
||||
}
|
||||
function set_marker (LatLng) {
|
||||
if (marker) {
|
||||
console.log("Marker exists");
|
||||
// console.log(marker);
|
||||
marker.remove();
|
||||
}
|
||||
console.log(LatLng);
|
||||
if($("input[name='place']").val() !== undefined){
|
||||
if ($("input[name='place']").val() !== undefined) {
|
||||
$("input[name='place']").val(LatLng.lat + ";" + LatLng.lng);
|
||||
}
|
||||
marker = L.marker(LatLng, {icon: iconDefault}).addTo(map);
|
||||
marker = L.marker(LatLng, { icon: iconDefault }).addTo(map);
|
||||
}
|
||||
|
||||
function load_map(lat=undefined, lng=undefined, selector_id=undefined, select=true) {
|
||||
if(lat == undefined && lng == undefined){
|
||||
lat = 45.5285; //TODO: replace hard-coded into cookie reading
|
||||
lng = 10.2956;
|
||||
}
|
||||
if(selector_id == undefined){
|
||||
selector_id = "map";
|
||||
}
|
||||
let zoom = select ? 10 : 17;
|
||||
let latLng = new L.LatLng(lat, lng);
|
||||
map = new L.Map(selector_id, {zoomControl: true});
|
||||
function load_map (lat = undefined, lng = undefined, selector_id = undefined, select = true) {
|
||||
if (lat == undefined && lng == undefined) {
|
||||
lat = 45.5285; // TODO: replace hard-coded into cookie reading
|
||||
lng = 10.2956;
|
||||
}
|
||||
if (selector_id == undefined) {
|
||||
selector_id = "map";
|
||||
}
|
||||
const zoom = select ? 10 : 17;
|
||||
const latLng = new L.LatLng(lat, lng);
|
||||
map = new L.Map(selector_id, { zoomControl: true });
|
||||
|
||||
let osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
osmAttribution = 'Map data © 2012 <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
|
||||
osm = new L.TileLayer(osmUrl, {maxZoom: 20, attribution: osmAttribution});
|
||||
const osmUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
|
||||
const osmAttribution = "Map data © 2012 <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors";
|
||||
const osm = new L.TileLayer(osmUrl, { maxZoom: 20, attribution: osmAttribution });
|
||||
|
||||
map.setView(latLng, zoom).addLayer(osm);
|
||||
map.setView(latLng, zoom).addLayer(osm);
|
||||
|
||||
if(select){
|
||||
map.on('click', function(e) {
|
||||
if (select) {
|
||||
map.on("click", function (e) {
|
||||
set_marker(e.latlng);
|
||||
});
|
||||
|
||||
L.Control.CustomLocate = L.Control.Locate.extend({
|
||||
_drawMarker: function() {
|
||||
_drawMarker: function () {
|
||||
set_marker(this._event.latlng);
|
||||
},
|
||||
_onDrag: function(){},
|
||||
_onZoom: function(){},
|
||||
_onZoomEnd: function(){},
|
||||
});
|
||||
_onDrag: function () {},
|
||||
_onZoom: function () {},
|
||||
_onZoomEnd: function () {}
|
||||
});
|
||||
|
||||
let lc = new L.Control.CustomLocate({
|
||||
const lc = new L.Control.CustomLocate({
|
||||
icon: "fa fa-map-marker",
|
||||
cacheLocation: false, //disabled for privacy reasons
|
||||
cacheLocation: false // disabled for privacy reasons
|
||||
}).addTo(map);
|
||||
|
||||
if($("#addr").val() !== undefined){
|
||||
document.getElementById("addr").addEventListener("keydown", function(event) {
|
||||
if ($("#addr").val() !== undefined) {
|
||||
document.getElementById("addr").addEventListener("keydown", function (event) {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
document.querySelector("#search > button").click();
|
||||
|
@ -81,130 +81,130 @@ function load_map(lat=undefined, lng=undefined, selector_id=undefined, select=tr
|
|||
});
|
||||
}
|
||||
|
||||
if(getCookie("experimental_read_clipboard")){
|
||||
window.addEventListener("focus", function(event) {
|
||||
if($("#addr").val() == ""){
|
||||
if (getCookie("experimental_read_clipboard")) {
|
||||
window.addEventListener("focus", function (event) {
|
||||
if ($("#addr").val() == "") {
|
||||
console.log("Loading location from clipboard");
|
||||
navigator.clipboard.readText().then(text => {
|
||||
$("#addr").val(text);
|
||||
if(!addr_search()){
|
||||
if (!addr_search()) {
|
||||
$("#addr").val("");
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('Failed to read clipboard contents: ', err);
|
||||
});
|
||||
console.error("Failed to read clipboard contents: ", err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
set_marker(latLng);
|
||||
}
|
||||
map.invalidateSize();
|
||||
} else {
|
||||
set_marker(latLng);
|
||||
}
|
||||
map.invalidateSize();
|
||||
}
|
||||
|
||||
// from unknown source in the Internet
|
||||
function chooseAddr(addr_lat, addr_lng, zoom=undefined, lat1=undefined, lng1=undefined, lat2=undefined, lng2=undefined, osm_type=undefined) {
|
||||
addr_lat = addr_lat.replace(",", ".");
|
||||
addr_lng = addr_lng.replace(",", ".");
|
||||
if(lat1 !== undefined && lng1 !== undefined && lat2 !== undefined && lng2 !== undefined && osm_type !== undefined){
|
||||
let loc1 = new L.LatLng(lat1, lng1);
|
||||
let loc2 = new L.LatLng(lat2, lng2);
|
||||
let bounds = new L.LatLngBounds(loc1, loc2);
|
||||
console.log(lat1, lng1, lat2, lng2, osm_type);
|
||||
set_marker(new L.LatLng(addr_lat, addr_lng));
|
||||
if (feature) {
|
||||
map.removeLayer(feature);
|
||||
}
|
||||
if (osm_type == "node") {
|
||||
map.fitBounds(bounds);
|
||||
map.setZoom(18);
|
||||
} else {
|
||||
let loc3 = new L.LatLng(lat1, lng2);
|
||||
let loc4 = new L.LatLng(lat2, lng1);
|
||||
feature = L.polyline( [loc1, loc4, loc2, loc3, loc1], {color: 'red'}).addTo(map);
|
||||
map.fitBounds(bounds);
|
||||
}
|
||||
} else if (addr_lat !== undefined && addr_lng !== undefined){
|
||||
let loc = new L.LatLng(addr_lat, addr_lng);
|
||||
console.log(loc);
|
||||
set_marker(loc);
|
||||
if(zoom !== undefined){
|
||||
map.setView(loc, zoom);
|
||||
} else {
|
||||
map.setView(loc);
|
||||
}
|
||||
}
|
||||
function chooseAddr (addr_lat, addr_lng, zoom = undefined, lat1 = undefined, lng1 = undefined, lat2 = undefined, lng2 = undefined, osm_type = undefined) {
|
||||
addr_lat = addr_lat.replace(",", ".");
|
||||
addr_lng = addr_lng.replace(",", ".");
|
||||
if (lat1 !== undefined && lng1 !== undefined && lat2 !== undefined && lng2 !== undefined && osm_type !== undefined) {
|
||||
const loc1 = new L.LatLng(lat1, lng1);
|
||||
const loc2 = new L.LatLng(lat2, lng2);
|
||||
const bounds = new L.LatLngBounds(loc1, loc2);
|
||||
console.log(lat1, lng1, lat2, lng2, osm_type);
|
||||
set_marker(new L.LatLng(addr_lat, addr_lng));
|
||||
if (feature) {
|
||||
map.removeLayer(feature);
|
||||
}
|
||||
if (osm_type == "node") {
|
||||
map.fitBounds(bounds);
|
||||
map.setZoom(18);
|
||||
} else {
|
||||
const loc3 = new L.LatLng(lat1, lng2);
|
||||
const loc4 = new L.LatLng(lat2, lng1);
|
||||
feature = L.polyline([loc1, loc4, loc2, loc3, loc1], { color: "red" }).addTo(map);
|
||||
map.fitBounds(bounds);
|
||||
}
|
||||
} else if (addr_lat !== undefined && addr_lng !== undefined) {
|
||||
const loc = new L.LatLng(addr_lat, addr_lng);
|
||||
console.log(loc);
|
||||
set_marker(loc);
|
||||
if (zoom !== undefined) {
|
||||
map.setView(loc, zoom);
|
||||
} else {
|
||||
map.setView(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// started from https://derickrethans.nl/leaflet-and-nominatim.html
|
||||
function addr_search(string_results_found=undefined, string_results_not_found=undefined) {
|
||||
function searchError(error, checkClipboard){
|
||||
if(!checkClipboard){
|
||||
$('<p>', { html: string_results_not_found }).appendTo('#results');
|
||||
console.error(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
let inp = document.getElementById("addr").value;
|
||||
//if translation strings are not defined, skip the nominatim step and don't log errors (no console.error)
|
||||
let checkClipboard = string_results_found==undefined && string_results_not_found==undefined;
|
||||
$('#results').empty();
|
||||
function addr_search (string_results_found = undefined, string_results_not_found = undefined) {
|
||||
function searchError (error, checkClipboard) {
|
||||
if (!checkClipboard) {
|
||||
$("<p>", { html: string_results_not_found }).appendTo("#results");
|
||||
console.error(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
let inp = document.getElementById("addr").value;
|
||||
// if translation strings are not defined, skip the nominatim step and don't log errors (no console.error)
|
||||
const checkClipboard = string_results_found == undefined && string_results_not_found == undefined;
|
||||
$("#results").empty();
|
||||
|
||||
if(inp.match("\@(-?[\d\.]*)")){ //Google Maps
|
||||
try {
|
||||
inp = inp.split("@")[1].split(",");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if(inp.includes("#map=")) { //OpenStreetMap website
|
||||
try {
|
||||
inp = inp.split("#map=")[1].split("/");
|
||||
chooseAddr(inp[1], inp[2], inp[0]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if(inp.match(/[0-9]+,\s[0-9]+/)) { //Bing
|
||||
try {
|
||||
inp = inp.split(", ");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if(inp.match(/[0-9]+;[0-9]+/)) { //DB dump
|
||||
try {
|
||||
inp = inp.split(";");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if(!checkClipboard) {
|
||||
$.getJSON('https://nominatim.openstreetmap.org/search?format=json&limit=5&q=' + inp, function(data) {
|
||||
let items = [];
|
||||
if (inp.match("\@(-?[\d\.]*)")) { // Google Maps
|
||||
try {
|
||||
inp = inp.split("@")[1].split(",");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if (inp.includes("#map=")) { // OpenStreetMap website
|
||||
try {
|
||||
inp = inp.split("#map=")[1].split("/");
|
||||
chooseAddr(inp[1], inp[2], inp[0]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if (inp.match(/[0-9]+,\s[0-9]+/)) { // Bing
|
||||
try {
|
||||
inp = inp.split(", ");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if (inp.match(/[0-9]+;[0-9]+/)) { // DB dump
|
||||
try {
|
||||
inp = inp.split(";");
|
||||
chooseAddr(inp[0], inp[1]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
searchError(error, checkClipboard);
|
||||
}
|
||||
} else if (!checkClipboard) {
|
||||
$.getJSON("https://nominatim.openstreetmap.org/search?format=json&limit=5&q=" + inp, function (data) {
|
||||
const items = [];
|
||||
|
||||
$.each(data, function(key, val) {
|
||||
items.push("<li><a href='' onclick='chooseAddr(\"" + val.lat + "\", \"" + val.lon + "\", undefined, " + val.boundingbox[0] + ", " + val.boundingbox[2] + ", " + val.boundingbox[1] + ", " + val.boundingbox[3] + ", \"" + val.osm_type + "\"); return false;'>" + val.display_name + '</a></li>');
|
||||
});
|
||||
$.each(data, function (key, val) {
|
||||
items.push("<li><a href='' onclick='chooseAddr(\"" + val.lat + "\", \"" + val.lon + "\", undefined, " + val.boundingbox[0] + ", " + val.boundingbox[2] + ", " + val.boundingbox[1] + ", " + val.boundingbox[3] + ", \"" + val.osm_type + "\"); return false;'>" + val.display_name + "</a></li>");
|
||||
});
|
||||
|
||||
if (items.length != 0) {
|
||||
$('<p>', { html: string_results_found+":" }).appendTo('#results');
|
||||
$('<ul/>', {
|
||||
'class': 'results-list',
|
||||
html: items.join('')
|
||||
}).appendTo('#results');
|
||||
} else {
|
||||
$('<p>', { html: string_results_not_found }).appendTo('#results');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (items.length != 0) {
|
||||
$("<p>", { html: string_results_found + ":" }).appendTo("#results");
|
||||
$("<ul/>", {
|
||||
class: "results-list",
|
||||
html: items.join("")
|
||||
}).appendTo("#results");
|
||||
} else {
|
||||
$("<p>", { html: string_results_not_found }).appendTo("#results");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
window.load_map = load_map;
|
||||
window.addr_search = addr_search;
|
||||
window.chooseAddr = chooseAddr;
|
||||
window.chooseAddr = chooseAddr;
|
||||
|
|
|
@ -1 +1 @@
|
|||
import {Howl, Howler} from 'howler';
|
||||
import { Howl, Howler } from "howler";
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import * as Sentry from "@sentry/browser";
|
||||
import { Integrations } from "@sentry/tracing";
|
||||
|
||||
if(process.env.config && process.env.config.sentry_enabled){
|
||||
if('connection' in navigator && navigator.connection.saveData){
|
||||
if (process.env.config && process.env.config.sentry_enabled) {
|
||||
if ("connection" in navigator && navigator.connection.saveData) {
|
||||
console.log("Skipping Sentry init because data save is enabled");
|
||||
} else {
|
||||
Sentry.init({
|
||||
dsn: process.env.config.sentry_dsn,
|
||||
integrations: [new Integrations.BrowserTracing()],
|
||||
tracesSampleRate: 0.6,
|
||||
release: "allerta-vvf-frontend@"+process.env.GIT_VERSION,
|
||||
release: "allerta-vvf-frontend@" + process.env.GIT_VERSION,
|
||||
environment: process.env.config.sentry_environment
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
const cacheVersion = process.env.BUNDLE_DATE;
|
||||
const cacheName = "static-"+cacheVersion;
|
||||
const expectedCaches = [cacheName, 'tables-1'];
|
||||
const cacheName = "static-" + cacheVersion;
|
||||
const expectedCaches = [cacheName, "tables-1"];
|
||||
|
||||
const urls = ['offline.php', 'manifest.webmanifest', 'resources/images/favicon.ico', 'resources/dist/marker-icon.png', 'resources/dist/layers.png', 'resources/dist/layers-2x.png', 'resources/images/android-chrome-192x192.png', 'resources/images/android-chrome-384x384.png', 'resources/images/black_helmet.png', 'resources/images/red_helmet.png', 'resources/images/wheel.png', 'resources/images/logo.png', 'resources/images/owner.png', 'resources/dist/fonts/fontawesome-webfont.woff2'];
|
||||
const urls = ["offline.php", "manifest.webmanifest", "resources/images/favicon.ico", "resources/dist/marker-icon.png", "resources/dist/layers.png", "resources/dist/layers-2x.png", "resources/images/android-chrome-192x192.png", "resources/images/android-chrome-384x384.png", "resources/images/black_helmet.png", "resources/images/red_helmet.png", "resources/images/wheel.png", "resources/images/logo.png", "resources/images/owner.png", "resources/dist/fonts/fontawesome-webfont.woff2"];
|
||||
|
||||
function fetchHandler(event, content_type, not_found_message){
|
||||
function fetchHandler (event, content_type, not_found_message) {
|
||||
// TODO: refactoring
|
||||
console.log(event);
|
||||
|
||||
// FROM https://googlechrome.github.io/samples/service-worker/custom-offline-page/
|
||||
// We only want to call event.respondWith() if this is a navigation request
|
||||
// for an HTML page.
|
||||
if (event.request.mode === 'navigate') {
|
||||
if (event.request.mode === "navigate") {
|
||||
event.respondWith((async () => {
|
||||
try {
|
||||
// First, try to use the navigation preload response if it's supported.
|
||||
|
@ -28,10 +28,10 @@ function fetchHandler(event, content_type, not_found_message){
|
|||
// due to a network error.
|
||||
// If fetch() returns a valid HTTP response with a response code in
|
||||
// the 4xx or 5xx range, the catch() will NOT be called.
|
||||
console.log('Fetch failed; returning offline page instead.', error);
|
||||
console.log("Fetch failed; returning offline page instead.", error);
|
||||
|
||||
const cache = await caches.open(cacheName);
|
||||
if(event.request.headers.get('Accept').includes('text/html')){
|
||||
if (event.request.headers.get("Accept").includes("text/html")) {
|
||||
cacheFileName = "offline.php";
|
||||
} else {
|
||||
cacheFileName = event.request.url;
|
||||
|
@ -49,16 +49,16 @@ function fetchHandler(event, content_type, not_found_message){
|
|||
// were no service worker involvement.
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
var request = event.request;
|
||||
self.addEventListener("fetch", function (event) {
|
||||
const request = event.request;
|
||||
|
||||
// https://stackoverflow.com/a/49719964
|
||||
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') return;
|
||||
if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") return;
|
||||
|
||||
if (request.headers.get('Accept').includes('text/html')) {
|
||||
if (request.headers.get("Accept").includes("text/html")) {
|
||||
fetchHandler(event, null, "offline.php");
|
||||
} else if (request.destination == "script") {
|
||||
fetchHandler(event, "application/javascript", "console.error('Script "+event.request.url+" not found');");
|
||||
fetchHandler(event, "application/javascript", "console.error('Script " + event.request.url + " not found');");
|
||||
} else if (request.destination == "image") {
|
||||
fetchHandler(event, null, "resources/images/logo.png");
|
||||
} else if (request.destination == "font") {
|
||||
|
@ -70,36 +70,36 @@ self.addEventListener('fetch', function (event) {
|
|||
}
|
||||
});
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
self.addEventListener("install", (event) => {
|
||||
self.skipWaiting();
|
||||
event.waitUntil(
|
||||
caches.open(cacheName).then((cache) => {
|
||||
cache.addAll(urls);
|
||||
fetch('resources/dist/manifest.json')
|
||||
fetch("resources/dist/manifest.json")
|
||||
.then((response) => response.json())
|
||||
.then((manifest) => {
|
||||
let scripts_required = ["main.js", "maps.js"];
|
||||
const scripts_required = ["main.js", "maps.js"];
|
||||
scripts_required.map((script_name) => {
|
||||
console.log(manifest);
|
||||
console.log(script_name);
|
||||
cache.add("resources/dist/"+manifest[script_name]);
|
||||
cache.add("resources/dist/" + manifest[script_name]);
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(
|
||||
keys.map((key) => {
|
||||
if (!expectedCaches.includes(key)) {
|
||||
console.log("Deleting cache "+key);
|
||||
console.log("Deleting cache " + key);
|
||||
return caches.delete(key);
|
||||
}
|
||||
})
|
||||
)).then(() => {
|
||||
console.log('Service worker now ready to handle fetches!');
|
||||
console.log("Service worker now ready to handle fetches!");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
import jsZip from 'jszip';
|
||||
window.JSZip = jsZip;
|
||||
import jsZip from "jszip";
|
||||
import pdfMake from "pdfmake/build/pdfmake";
|
||||
import pdfFonts from "pdfmake/build/vfs_fonts";
|
||||
import "datatables.net-bs4/js/dataTables.bootstrap4.min.js";
|
||||
import "datatables.net-bs4/css/dataTables.bootstrap4.min.css";
|
||||
import "datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js";
|
||||
import "datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css";
|
||||
import "datatables.net-buttons";
|
||||
import "datatables.net-buttons-bs4/js/buttons.bootstrap4.js";
|
||||
import "datatables.net-buttons-bs4/css/buttons.bootstrap4.css";
|
||||
import "datatables.net-buttons/js/buttons.html5.js";
|
||||
import "datatables.net-buttons/js/buttons.print.js";
|
||||
window.JSZip = jsZip;
|
||||
pdfMake.vfs = pdfFonts.pdfMake.vfs;
|
||||
import 'datatables.net-bs4/js/dataTables.bootstrap4.min.js';
|
||||
import 'datatables.net-bs4/css/dataTables.bootstrap4.min.css';
|
||||
import 'datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js';
|
||||
import 'datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css';
|
||||
import 'datatables.net-buttons';
|
||||
import 'datatables.net-buttons-bs4/js/buttons.bootstrap4.js';
|
||||
import 'datatables.net-buttons-bs4/css/buttons.bootstrap4.css';
|
||||
import 'datatables.net-buttons/js/buttons.html5.js';
|
||||
import 'datatables.net-buttons/js/buttons.print.js';
|
||||
|
||||
export default async function fillTable({data, replaceLatLngWithMap=false, callback=false}){
|
||||
export default async function fillTable ({ data, replaceLatLngWithMap = false, callback = false }) {
|
||||
$("#table_body").empty();
|
||||
$.each(data, function(row_num, item) {
|
||||
let row = document.createElement("tr");
|
||||
row.id = "row-"+row_num;
|
||||
$.each(item, function(cell_num, i) {
|
||||
if(i !== null){
|
||||
if(replaceLatLngWithMap && i.match(/[+-]?\d+([.]\d+)?[;][+-]?\d+([.]\d+)?/gm)){ /* credits to @visoom https://github.com/visoom */
|
||||
let lat = i.split(";")[0];
|
||||
let lng = i.split(";")[1];
|
||||
let mapDiv = document.createElement("div");
|
||||
$.each(data, function (row_num, item) {
|
||||
const row = document.createElement("tr");
|
||||
row.id = "row-" + row_num;
|
||||
$.each(item, function (cell_num, i) {
|
||||
if (i !== null) {
|
||||
if (replaceLatLngWithMap && i.match(/[+-]?\d+([.]\d+)?[;][+-]?\d+([.]\d+)?/gm)) { /* credits to @visoom https://github.com/visoom */
|
||||
const lat = i.split(";")[0];
|
||||
const lng = i.split(";")[1];
|
||||
const mapDiv = document.createElement("div");
|
||||
mapDiv.className = "map";
|
||||
mapDiv.id = "map-"+row_num;
|
||||
let mapScript = document.createElement("script");
|
||||
mapScript.appendChild(document.createTextNode("load_map("+lat+", "+lng+", \"map-"+row_num+"\", false)"));
|
||||
mapDiv.id = "map-" + row_num;
|
||||
const mapScript = document.createElement("script");
|
||||
mapScript.appendChild(document.createTextNode("load_map(" + lat + ", " + lng + ", \"map-" + row_num + "\", false)"));
|
||||
mapDiv.appendChild(mapScript);
|
||||
let cell = document.createElement("td");
|
||||
const cell = document.createElement("td");
|
||||
cell.appendChild(mapDiv);
|
||||
row.appendChild(cell);
|
||||
} else {
|
||||
let cell = document.createElement("td");
|
||||
const cell = document.createElement("td");
|
||||
cell.innerHTML = i;
|
||||
row.appendChild(cell);
|
||||
}
|
||||
|
@ -44,31 +44,31 @@ export default async function fillTable({data, replaceLatLngWithMap=false, callb
|
|||
let loadedLanguage = {};
|
||||
try {
|
||||
let language = navigator.language || navigator.userLanguage;
|
||||
language = language.toLowerCase().replace("_","-");
|
||||
language = language.toLowerCase().replace("_", "-");
|
||||
language = "it_it";
|
||||
loadedLanguage = await import(`datatables.net-plugins/i18n/${language}.json`)
|
||||
.then(({default: _}) => {
|
||||
return _;
|
||||
});
|
||||
.then(({ default: _ }) => {
|
||||
return _;
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error loading DataTables translation:");
|
||||
console.log(error);
|
||||
loadedLanguage = {};
|
||||
}
|
||||
if(! $.fn.DataTable.isDataTable( '#table' )){
|
||||
var table_dt = $('#table').DataTable({
|
||||
if (!$.fn.DataTable.isDataTable("#table")) {
|
||||
var table_dt = $("#table").DataTable({
|
||||
responsive: true,
|
||||
language: loadedLanguage,
|
||||
buttons: [ 'excel', 'pdf', 'csv' ]
|
||||
buttons: ["excel", "pdf", "csv"]
|
||||
});
|
||||
table_dt.buttons().container()
|
||||
.appendTo( '#table_wrapper :nth-child(1):eq(0)' );
|
||||
.appendTo("#table_wrapper :nth-child(1):eq(0)");
|
||||
|
||||
if(callback !== false){
|
||||
if (callback !== false) {
|
||||
callback(table_dt);
|
||||
}
|
||||
} else {
|
||||
table_dt.rows().invalidate();
|
||||
}
|
||||
window.table_dt = table_dt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
export default async function fillTable({data, replaceLatLngWithMap=false, callback=false}){
|
||||
export default async function fillTable ({ data, replaceLatLngWithMap = false, callback = false }) {
|
||||
$("#table_body").empty();
|
||||
$.each(data, function(row_num, item) {
|
||||
let row = document.createElement("tr");
|
||||
row.id = "row-"+row_num;
|
||||
$.each(item, function(cell_num, i) {
|
||||
if(i !== null){
|
||||
if(replaceLatLngWithMap && i.match(/[+-]?\d+([.]\d+)?[;][+-]?\d+([.]\d+)?/gm)){ /* credits to @visoom https://github.com/visoom */
|
||||
let lat = i.split(";")[0];
|
||||
let lng = i.split(";")[1];
|
||||
let mapDiv = document.createElement("div");
|
||||
$.each(data, function (row_num, item) {
|
||||
const row = document.createElement("tr");
|
||||
row.id = "row-" + row_num;
|
||||
$.each(item, function (cell_num, i) {
|
||||
if (i !== null) {
|
||||
if (replaceLatLngWithMap && i.match(/[+-]?\d+([.]\d+)?[;][+-]?\d+([.]\d+)?/gm)) { /* credits to @visoom https://github.com/visoom */
|
||||
const lat = i.split(";")[0];
|
||||
const lng = i.split(";")[1];
|
||||
const mapDiv = document.createElement("div");
|
||||
mapDiv.className = "map";
|
||||
mapDiv.id = "map-"+row_num;
|
||||
let mapScript = document.createElement("script");
|
||||
mapScript.appendChild(document.createTextNode("load_map("+lat+", "+lng+", \"map-"+row_num+"\", false)"));
|
||||
mapDiv.id = "map-" + row_num;
|
||||
const mapScript = document.createElement("script");
|
||||
mapScript.appendChild(document.createTextNode("load_map(" + lat + ", " + lng + ", \"map-" + row_num + "\", false)"));
|
||||
mapDiv.appendChild(mapScript);
|
||||
let cell = document.createElement("td");
|
||||
const cell = document.createElement("td");
|
||||
cell.appendChild(mapDiv);
|
||||
row.appendChild(cell);
|
||||
} else {
|
||||
let cell = document.createElement("td");
|
||||
const cell = document.createElement("td");
|
||||
cell.innerHTML = i;
|
||||
row.appendChild(cell);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export default async function fillTable({data, replaceLatLngWithMap=false, callb
|
|||
});
|
||||
document.getElementById("table_body").appendChild(row);
|
||||
});
|
||||
if(callback !== false){
|
||||
if (callback !== false) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue