RA-#16 Updated Dev Buttons

This commit is contained in:
ostertun
2020-10-01 23:25:48 +02:00
parent cacee5a54a
commit 2533c3d66a
3 changed files with 110 additions and 95 deletions

View File

@@ -161,19 +161,19 @@ function dbGetResultCalculated(regatta) {
return new Promise(async function(resolve) { return new Promise(async function(resolve) {
var results = await dbGetDataIndex('results', 'regatta', regatta.id); var results = await dbGetDataIndex('results', 'regatta', regatta.id);
if (results.length > 0) { if (results.length > 0) {
var gemeldet = results.length; var gemeldet = results.length;
for (id in results) { for (id in results) {
results[id]['finished'] = false; results[id]['finished'] = false;
results[id]['values'] = []; results[id]['values'] = [];
results[id]['values_all'] = []; results[id]['values_all'] = [];
results[id]['texts'] = []; results[id]['texts'] = [];
var copy = []; var copy = [];
for (var i = 0; i < regatta['races']; i ++) { for (var i = 0; i < regatta['races']; i ++) {
var race = results[id]['race' + (i + 1)].replace(',', '.'); var race = results[id]['race' + (i + 1)].replace(',', '.');
if (!isNaN(race)) { if (!isNaN(race)) {
copy[i] = results[id]['values'][i] = parseFloat(race); copy[i] = results[id]['values'][i] = parseFloat(race);
results[id]['texts'][i] = race; results[id]['texts'][i] = race;
@@ -198,7 +198,7 @@ function dbGetResultCalculated(regatta) {
// Unbekannt // Unbekannt
default: results[id]['values'][i] = 0; copy[i] = 0; break; default: results[id]['values'][i] = 0; copy[i] = 0; break;
} }
if (results[id]['values'][i] != 0) { if (results[id]['values'][i] != 0) {
results[id]['texts'][i] = race + ' (' + results[id]['values'][i] + ')'; results[id]['texts'][i] = race + ' (' + results[id]['values'][i] + ')';
} else { } else {
@@ -206,7 +206,7 @@ function dbGetResultCalculated(regatta) {
} }
} }
} }
results[id]['values_all'] = [...results[id]['values']]; results[id]['values_all'] = [...results[id]['values']];
for (var s = 0; s < regatta['streicher']; s ++) { for (var s = 0; s < regatta['streicher']; s ++) {
var max = Math.max(...copy); var max = Math.max(...copy);
@@ -217,7 +217,7 @@ function dbGetResultCalculated(regatta) {
} }
} }
} }
var brutto = 0; var brutto = 0;
var netto = 0; var netto = 0;
for (var i = 0; i < regatta['races']; i ++) { for (var i = 0; i < regatta['races']; i ++) {
@@ -233,11 +233,11 @@ function dbGetResultCalculated(regatta) {
results[id]['brutto'] = brutto; results[id]['brutto'] = brutto;
results[id]['netto'] = netto; results[id]['netto'] = netto;
} }
compareResultsRaceCount = regatta['races']; compareResultsRaceCount = regatta['races'];
results.sort(compareResults); results.sort(compareResults);
var place = 1; var place = 1;
for (id in results) { for (id in results) {
if ((id > 0) && (compareResults(results[id], results[id - 1]) == 0)) { if ((id > 0) && (compareResults(results[id], results[id - 1]) == 0)) {
@@ -247,9 +247,9 @@ function dbGetResultCalculated(regatta) {
} }
place ++; place ++;
} }
resolve(results); resolve(results);
} else { } else {
resolve([]); resolve([]);
} }
@@ -259,26 +259,26 @@ function dbGetResultCalculated(regatta) {
function dbGetRanking(minDate, maxDate, jugend, jugstrict) { function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
return new Promise(async function(resolve) { return new Promise(async function(resolve) {
var rankNoResults = []; var rankNoResults = [];
var sailors = await dbGetData('sailors'); var sailors = await dbGetData('sailors');
var regattas = await dbGetRegattasRange(minDate, maxDate); var regattas = await dbGetRegattasRange(minDate, maxDate);
var sailorIds = {}; var sailorIds = {};
for (s in sailors) { for (s in sailors) {
sailorIds[sailors[s].id] = s; sailorIds[sailors[s].id] = s;
} }
for (var i in sailors) { for (var i in sailors) {
sailors[i].regattas = {}; sailors[i].regattas = {};
sailors[i].tmp_rlp = []; sailors[i].tmp_rlp = [];
} }
for (var i in regattas) { for (var i in regattas) {
var regatta = regattas[i]; var regatta = regattas[i];
// regatta has to be min. 2 days to be ranking regatta // regatta has to be min. 2 days to be ranking regatta
if (regatta.length < 2) continue; if (regatta.length < 2) continue;
var results = await dbGetDataIndex('results', 'regatta', regatta.id); var results = await dbGetDataIndex('results', 'regatta', regatta.id);
if (results.length <= 0) { if (results.length <= 0) {
if (regatta.dateTo <= getToday()) { if (regatta.dateTo <= getToday()) {
@@ -288,7 +288,7 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
} }
continue; continue;
} }
// in one race there must be at least 10 boats started // in one race there must be at least 10 boats started
var ok = false; var ok = false;
for (var j = 1; j <= regatta.races; j ++) { for (var j = 1; j <= regatta.races; j ++) {
@@ -304,9 +304,9 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
} }
} }
if (!ok) continue; if (!ok) continue;
var fb = regatta.finishedBoats; var fb = regatta.finishedBoats;
// calc m // calc m
var m; var m;
if (regatta.m > 0) { if (regatta.m > 0) {
@@ -320,16 +320,16 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
m = 4; m = 4;
} }
} }
// add regatta to each sailor // add regatta to each sailor
for (var r in results) { for (var r in results) {
var result = results[r]; var result = results[r];
if (result.rlp == 0) continue; if (result.rlp == 0) continue;
// check if crew is youth // check if crew is youth
// TODO: not used // TODO: not used
sailors[sailorIds[result.steuermann]].regattas[regatta.id] = { sailors[sailorIds[result.steuermann]].regattas[regatta.id] = {
regatta: regatta.id, regatta: regatta.id,
boat: result.boat, boat: result.boat,
@@ -345,7 +345,7 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
} }
} }
} }
// remove not german or not youth sailors // remove not german or not youth sailors
for (var i = sailors.length - 1; i >= 0; i --) { for (var i = sailors.length - 1; i >= 0; i --) {
if (sailors[i].german == '0') { if (sailors[i].german == '0') {
@@ -357,13 +357,13 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
} }
} }
} }
for (var i = sailors.length - 1; i >= 0; i --) { for (var i = sailors.length - 1; i >= 0; i --) {
// sort rlps desc // sort rlps desc
sailors[i].tmp_rlp.sort(function (a,b) { sailors[i].tmp_rlp.sort(function (a,b) {
return b[1] - a[1]; return b[1] - a[1];
}); });
// calc mean rlp // calc mean rlp
var sum = 0; var sum = 0;
var cnt = 0; var cnt = 0;
@@ -383,16 +383,16 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
sailors.splice(i, 1); sailors.splice(i, 1);
} }
} }
sailors.sort(function (a,b) { sailors.sort(function (a,b) {
if (a.m != b.m) return b.m - a.m; if (a.m != b.m) return b.m - a.m;
return b.rlp - a.rlp; return b.rlp - a.rlp;
}); });
for (var i = 0; i < sailors.length; i ++) { for (var i = 0; i < sailors.length; i ++) {
sailors[i].rank = (i + 1); sailors[i].rank = (i + 1);
} }
resolve([sailors, rankNoResults]); resolve([sailors, rankNoResults]);
}); });
} }
@@ -424,7 +424,7 @@ async function updateSyncStatus() { // TODO
// var now = new Date(); // var now = new Date();
// var diff = Math.round((now - lastSync) / 1000); // var diff = Math.round((now - lastSync) / 1000);
// var txt = ''; // var txt = '';
// //
// if (diff < 30) { // 30 sec // if (diff < 30) { // 30 sec
// txt = 'jetzt'; // txt = 'jetzt';
// } else if (diff < 3600) { // 60 min // } else if (diff < 3600) { // 60 min
@@ -437,7 +437,7 @@ async function updateSyncStatus() { // TODO
// diff = Math.round(diff / 86400); // diff = Math.round(diff / 86400);
// txt = 'vor ' + diff + ' ' + (diff == 1 ? 'Tag' : 'Tagen'); // txt = 'vor ' + diff + ' ' + (diff == 1 ? 'Tag' : 'Tagen');
// } // }
// //
// var btn = '<a href="#" onclick="setLoading(true); sync(); return false;"><i class="fas fa-sync"></i> Sync</a>'; // var btn = '<a href="#" onclick="setLoading(true); sync(); return false;"><i class="fas fa-sync"></i> Sync</a>';
// syncStatus.innerHTML = 'Zuletzt aktualisiert: ' + txt + btn; // syncStatus.innerHTML = 'Zuletzt aktualisiert: ' + txt + btn;
} }
@@ -453,7 +453,7 @@ async function runPageScript() {
} }
}; };
updateSyncStatus(); updateSyncStatus();
if (isLoggedIn()) { if (isLoggedIn()) {
var plannings = await dbGetDataIndex('plannings', 'user', USER_ID); var plannings = await dbGetDataIndex('plannings', 'user', USER_ID);
plannings = plannings.map(function (e) { return e.regatta; }); plannings = plannings.map(function (e) { return e.regatta; });
@@ -471,7 +471,7 @@ async function runPageScript() {
} }
// syncStatus.style.display = 'block'; // syncStatus.style.display = 'block';
} }
if (typeof siteScript === 'function') { if (typeof siteScript === 'function') {
siteScript(); siteScript();
} else { } else {
@@ -482,20 +482,20 @@ async function runPageScript() {
function sync() { function sync() {
if (!canUseLocalDB) return false; if (!canUseLocalDB) return false;
if (syncInProgress > 0) return false; if (syncInProgress > 0) return false;
var now = Math.floor(Date.now() / 1000); var now = Math.floor(Date.now() / 1000);
db.transaction('update_times').objectStore('update_times').getAll().onsuccess = function (event) { db.transaction('update_times').objectStore('update_times').getAll().onsuccess = function (event) {
var localTimes = {}; var localTimes = {};
event.target.result.forEach(function (entry) { event.target.result.forEach(function (entry) {
localTimes[entry['table']] = entry['time']; localTimes[entry['table']] = entry['time'];
}); });
syncInProgress = 11; syncInProgress = 11;
var syncOkay = true; var syncOkay = true;
console.log("Sync Start"); console.log("Sync Start");
$('#i-sync').addClass('fa-spin'); $('#i-sync').addClass('fa-spin');
var interval = window.setInterval(function () { var interval = window.setInterval(function () {
if (syncInProgress <= 0) { if (syncInProgress <= 0) {
window.clearInterval(interval); window.clearInterval(interval);
@@ -507,14 +507,14 @@ function sync() {
setTimeout(function(){ setTimeout(function(){
$('#i-sync').removeClass('fa-spin'); $('#i-sync').removeClass('fa-spin');
}, 500); }, 500);
runPageScript(); runPageScript();
} }
}, 100); }, 100);
getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) { getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) {
if (code == 200) { if (code == 200) {
// CLUBS // CLUBS
if (localTimes['clubs'] < serverTimes['clubs']) { if (localTimes['clubs'] < serverTimes['clubs']) {
getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) { getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) {
@@ -546,7 +546,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// BOATS // BOATS
if (localTimes['boats'] < serverTimes['boats']) { if (localTimes['boats'] < serverTimes['boats']) {
getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) {
@@ -578,7 +578,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// SAILORS // SAILORS
if (localTimes['sailors'] < serverTimes['sailors']) { if (localTimes['sailors'] < serverTimes['sailors']) {
getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) {
@@ -610,7 +610,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// REGATTAS // REGATTAS
if (localTimes['regattas'] < serverTimes['regattas']) { if (localTimes['regattas'] < serverTimes['regattas']) {
getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) {
@@ -643,7 +643,7 @@ function sync() {
osYears.put({ year: y }); osYears.put({ year: y });
} }
} }
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] });
syncInProgress --; syncInProgress --;
@@ -658,7 +658,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// RESULTS // RESULTS
if (localTimes['results'] < serverTimes['results']) { if (localTimes['results'] < serverTimes['results']) {
getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) {
@@ -690,7 +690,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// PLANNINGS // PLANNINGS
if (localTimes['plannings'] < serverTimes['plannings']) { if (localTimes['plannings'] < serverTimes['plannings']) {
getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) {
@@ -722,7 +722,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
if (isLoggedIn()) { if (isLoggedIn()) {
// TRIM_BOATS // TRIM_BOATS
if (localTimes['trim_boats'] < serverTimes['trim_boats']) { if (localTimes['trim_boats'] < serverTimes['trim_boats']) {
@@ -755,7 +755,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// TRIM_USERS // TRIM_USERS
if (localTimes['trim_users'] < serverTimes['trim_users']) { if (localTimes['trim_users'] < serverTimes['trim_users']) {
getJSON(QUERY_URL + 'get_trim_users?changed-after=' + localTimes['trim_users'], function (code, data) { getJSON(QUERY_URL + 'get_trim_users?changed-after=' + localTimes['trim_users'], function (code, data) {
@@ -787,7 +787,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// TRIM_TRIMS // TRIM_TRIMS
if (localTimes['trim_trims'] < serverTimes['trim_trims']) { if (localTimes['trim_trims'] < serverTimes['trim_trims']) {
getJSON(QUERY_URL + 'get_trim_trims?changed-after=' + localTimes['trim_trims'], function (code, data) { getJSON(QUERY_URL + 'get_trim_trims?changed-after=' + localTimes['trim_trims'], function (code, data) {
@@ -819,11 +819,11 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
} else { } else {
syncInProgress -= 3; syncInProgress -= 3;
} }
// NEWS // NEWS
if (localTimes['news'] < serverTimes['news']) { if (localTimes['news'] < serverTimes['news']) {
getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) {
@@ -855,7 +855,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
// USERS // USERS
if (localTimes['users'] < serverTimes['users']) { if (localTimes['users'] < serverTimes['users']) {
getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) {
@@ -887,7 +887,7 @@ function sync() {
} else { } else {
syncInProgress --; syncInProgress --;
} }
} else { } else {
console.log("Something went wrong (HTTP " + code + ")"); console.log("Something went wrong (HTTP " + code + ")");
syncOkay = false; syncOkay = false;
@@ -914,13 +914,13 @@ function initDatabase() {
var request = window.indexedDB.open('regatten_app_db_' + BOATCLASS, DB_VERSION); var request = window.indexedDB.open('regatten_app_db_' + BOATCLASS, DB_VERSION);
request.onerror = function (event) { request.onerror = function (event) {
console.log("Cannot open DB: " + event.target.errorCode); console.log("Cannot open DB: " + event.target.errorCode);
runPageScript(); runPageScript();
}; };
request.onsuccess = function (event) { request.onsuccess = function (event) {
console.log("Database loaded"); console.log("Database loaded");
db = event.target.result; db = event.target.result;
db.onversionchange = function (event) { db.onversionchange = function (event) {
if (syncTimer != null) window.clearInterval(syncTimer); if (syncTimer != null) window.clearInterval(syncTimer);
if (updateSyncStatusTimer != null) window.clearInterval(updateSyncStatusTimer); if (updateSyncStatusTimer != null) window.clearInterval(updateSyncStatusTimer);
@@ -929,15 +929,15 @@ function initDatabase() {
db.close(); db.close();
location.reload; location.reload;
} }
db.onerror = function (event) { db.onerror = function (event) {
console.log("DB Error: " + event.target.errorCode); console.log("DB Error: " + event.target.errorCode);
}; };
canUseLocalDB = true; canUseLocalDB = true;
if (typeof onDatabaseLoaded == 'function') onDatabaseLoaded(); if (typeof onDatabaseLoaded == 'function') onDatabaseLoaded();
db.transaction('update_times').objectStore('update_times').get('last_sync').onsuccess = function (event) { db.transaction('update_times').objectStore('update_times').get('last_sync').onsuccess = function (event) {
var lastSync = event.target.result.time; var lastSync = event.target.result.time;
if (lastSync > 0) { if (lastSync > 0) {
@@ -946,11 +946,11 @@ function initDatabase() {
db.transaction('update_times', 'readwrite').objectStore('update_times').put({ table: 'loggedin', status: isLoggedIn() }); db.transaction('update_times', 'readwrite').objectStore('update_times').put({ table: 'loggedin', status: isLoggedIn() });
} }
}; };
checkSync(); checkSync();
syncTimer = window.setInterval(checkSync, 300000); // 5 min syncTimer = window.setInterval(checkSync, 300000); // 5 min
window.ononline = function () { window.ononline = function () {
checkSync(); checkSync();
} }
@@ -960,9 +960,9 @@ function initDatabase() {
var upgradeTransaction = event.target.transaction; var upgradeTransaction = event.target.transaction;
var oldVersion = event.oldVersion; var oldVersion = event.oldVersion;
var newVersion = event.newVersion; var newVersion = event.newVersion;
console.log("Datenbank Version Upgrade von " + oldVersion + " auf " + newVersion); console.log("Datenbank Version Upgrade von " + oldVersion + " auf " + newVersion);
if ((oldVersion < 1) && (newVersion >= 1)) { if ((oldVersion < 1) && (newVersion >= 1)) {
console.log('to version 1'); console.log('to version 1');
var osClubs = db.createObjectStore('clubs', { keyPath: 'id' }); var osClubs = db.createObjectStore('clubs', { keyPath: 'id' });
@@ -991,7 +991,7 @@ function initDatabase() {
osUpdateTimes.add({ table: 'trim_users', time: 0 }); osUpdateTimes.add({ table: 'trim_users', time: 0 });
osUpdateTimes.add({ table: 'trim_trims', time: 0 }); osUpdateTimes.add({ table: 'trim_trims', time: 0 });
} }
if ((oldVersion < 2) && (newVersion >= 2)) { if ((oldVersion < 2) && (newVersion >= 2)) {
console.log('to version 2'); console.log('to version 2');
var osUsers = db.createObjectStore('users', { keyPath: 'id' }); var osUsers = db.createObjectStore('users', { keyPath: 'id' });
@@ -999,32 +999,32 @@ function initDatabase() {
var osUpdateTimes = upgradeTransaction.objectStore('update_times'); var osUpdateTimes = upgradeTransaction.objectStore('update_times');
osUpdateTimes.add({ table: 'users', time: 0 }); osUpdateTimes.add({ table: 'users', time: 0 });
} }
if ((oldVersion < 3) && (newVersion >= 3)) { if ((oldVersion < 3) && (newVersion >= 3)) {
console.log('to version 3'); console.log('to version 3');
var osYears = db.createObjectStore('years', { keyPath: 'year' }); var osYears = db.createObjectStore('years', { keyPath: 'year' });
var osUpdateTimes = upgradeTransaction.objectStore('update_times'); var osUpdateTimes = upgradeTransaction.objectStore('update_times');
osUpdateTimes.put({ table: 'regattas', time: 0 }); osUpdateTimes.put({ table: 'regattas', time: 0 });
} }
if ((oldVersion < 4) && (newVersion >= 4)) { if ((oldVersion < 4) && (newVersion >= 4)) {
console.log('to version 4'); console.log('to version 4');
var osUpdateTimes = upgradeTransaction.objectStore('update_times'); var osUpdateTimes = upgradeTransaction.objectStore('update_times');
osUpdateTimes.add({ table: 'loggedin', status: isLoggedIn() }); osUpdateTimes.add({ table: 'loggedin', status: isLoggedIn() });
} }
if ((oldVersion < 5) && (newVersion >= 5)) { if ((oldVersion < 5) && (newVersion >= 5)) {
console.log('to version 5'); console.log('to version 5');
var osPushes = db.createObjectStore('settings', { keyPath: 'key' }); var osPushes = db.createObjectStore('settings', { keyPath: 'key' });
} }
if ((oldVersion < 6) && (newVersion >= 6)) { if ((oldVersion < 6) && (newVersion >= 6)) {
console.log('to version 6'); console.log('to version 6');
var osNews = db.createObjectStore('news', { keyPath: 'id' }); var osNews = db.createObjectStore('news', { keyPath: 'id' });
var osUpdateTimes = upgradeTransaction.objectStore('update_times'); var osUpdateTimes = upgradeTransaction.objectStore('update_times');
osUpdateTimes.add({ table: 'news', time: 0 }); osUpdateTimes.add({ table: 'news', time: 0 });
} }
var osUpdateTimes = upgradeTransaction.objectStore('update_times'); var osUpdateTimes = upgradeTransaction.objectStore('update_times');
osUpdateTimes.put({ table: 'last_sync', time: 0 }); osUpdateTimes.put({ table: 'last_sync', time: 0 });
} }
@@ -1033,8 +1033,7 @@ function initDatabase() {
} }
} }
function resetDb(silent = true) { function resetDb() {
$('#menu-developer').hideMenu();
if (canUseLocalDB) { if (canUseLocalDB) {
showLoader(); showLoader();
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
@@ -1051,11 +1050,6 @@ function resetDb(silent = true) {
osUpdateTimes.put({ table: 'news', time: 0 }); osUpdateTimes.put({ table: 'news', time: 0 });
osUpdateTimes.put({ table: 'users', time: 0 }); osUpdateTimes.put({ table: 'users', time: 0 });
console.log('DB update times reset'); console.log('DB update times reset');
if (!silent)
toastInfo('The database was reset. Please reload or close this tab.<br>At the next visit, a full sync will be performed.');
hideLoader(); hideLoader();
} else {
if (!silent)
toastWarn('Your device does not support storing data locally. All data is fetched directly from our server.<br>As a result, you can not reset your database.');
} }
} }

View File

@@ -1,9 +1,9 @@
<?php <?php
header('Content-Type: text/javascript'); header('Content-Type: text/javascript');
require_once(__DIR__ . '/../../server/config.php'); require_once(__DIR__ . '/../../server/config.php');
?> ?>
const QUERY_URL = '<?php echo QUERY_URL; ?>'; const QUERY_URL = '<?php echo QUERY_URL; ?>';
@@ -203,7 +203,28 @@ var logout = function() {
}); });
} }
function resetCache() { function deleteDb() {
$('#menu-developer').hideMenu();
if (canUseLocalDB) {
showLoader();
var request = window.indexedDB.deleteDatabase('regatten_app_db_' + BOATCLASS);
request.onerror = function (event) {
console.log('Cannot delete DB: ', event.target.errorCode);
toastError('Beim Löschen der Datenbank ist ein Fehler aufgetreten.<br>Bitte melde diesen Fehler. (Dev-Menu => Problem melden)', 5000);
hideLoader();
}
request.onsuccess = function (event) {
console.log('DB deleted');
toastInfo('Die Datenbank wurde gelöscht. Die Seite lädt in wenigen Sekunden neu und erstellt damit eine neue Datenbank.', 10000);
hideLoader();
setTimeout(function(){ location.reload(); }, 3000);
}
} else {
toastWarn('Dein Gerät unterstützt kein lokales Speichern der Daten. Alle Daten werden direkt vom Server gezogen.<br>Entsprechend kannst Du die Datenbank auch nicht zurücksetzen.', 10000);
}
}
function deleteCache() {
$('#menu-developer').hideMenu(); $('#menu-developer').hideMenu();
navigator.serviceWorker.getRegistrations().then(function (registrations) { navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) { for (let registration of registrations) {
@@ -227,10 +248,10 @@ function urlB64ToUint8Array(base64String) {
const base64 = (base64String + padding) const base64 = (base64String + padding)
.replace(/\-/g, '+') .replace(/\-/g, '+')
.replace(/_/g, '/'); .replace(/_/g, '/');
const rawData = window.atob(base64); const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length); const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) { for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i); outputArray[i] = rawData.charCodeAt(i);
} }
@@ -317,7 +338,7 @@ async function updatePushSwitches() {
$('#switch-pushes-result-ready-my').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_my')); $('#switch-pushes-result-ready-my').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_my'));
$('#switch-pushes-result-ready-all').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_all')); $('#switch-pushes-result-ready-all').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_all'));
$('#switch-pushes-meldeschluss').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_meldeschluss')); $('#switch-pushes-meldeschluss').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_meldeschluss'));
if ($('#switch-pushes').prop('checked')) { if ($('#switch-pushes').prop('checked')) {
$('#p-pushes-info').show(); $('#p-pushes-info').show();
$('.a-switch-pushes-channel').show(); $('.a-switch-pushes-channel').show();
@@ -355,7 +376,7 @@ function pushesOpenMenu() {
toastWarn('Benachrichtigungen werden von Deinem Browser blockiert.', 5000); toastWarn('Benachrichtigungen werden von Deinem Browser blockiert.', 5000);
return; return;
} }
swRegistration.pushManager.getSubscription().then(function(subscription) { swRegistration.pushManager.getSubscription().then(function(subscription) {
var isSub = (subscription !== null); var isSub = (subscription !== null);
$('#switch-pushes').prop('checked', isSub); $('#switch-pushes').prop('checked', isSub);
@@ -382,9 +403,9 @@ function updatePushBadge() {
var initRegatten = function() { var initRegatten = function() {
showLoader(); showLoader();
initDatabase(); initDatabase();
if (isLoggedIn()) { if (isLoggedIn()) {
$('.show-loggedin').show(); $('.show-loggedin').show();
$('.show-notloggedin').hide(); $('.show-notloggedin').hide();
@@ -396,7 +417,7 @@ var initRegatten = function() {
$('.show-loggedin').hide(); $('.show-loggedin').hide();
$('.show-notloggedin').show(); $('.show-notloggedin').show();
} }
// Pushes // Pushes
$('#a-switch-pushes').click(pushesSubscribeClicked); $('#a-switch-pushes').click(pushesSubscribeClicked);
$('.a-switch-pushes-channel').click(pushesChannelClicked); $('.a-switch-pushes-channel').click(pushesChannelClicked);

View File

@@ -211,22 +211,22 @@
<div class="divider divider-margins mb-n2"></div> <div class="divider divider-margins mb-n2"></div>
<div class="content"> <div class="content">
<div class="list-group list-custom-small"> <div class="list-group list-custom-small">
<a href="https://info.ostertun.net/regatten/beta"> <a href="https://github.com/ostertun/RegattenApp/wiki">
<i class="fa font-14 fa-info rounded-s bg-highlight color-white"></i> <i class="fa font-14 fa-info rounded-s bg-highlight color-white"></i>
<span>Infos zur BETA</span> <span>App-Wiki</span>
<i class="fa fa-angle-right"></i> <i class="fa fa-angle-right"></i>
</a> </a>
<a href="javascript:resetDb(false);"> <a href="javascript:deleteDb();">
<i class="fa font-14 fa-database rounded-s bg-highlight color-white"></i> <i class="fa font-14 fa-database rounded-s bg-highlight color-white"></i>
<span>Reset Database</span> <span>Reset Database</span>
<i class="fa fa-angle-right"></i> <i class="fa fa-angle-right"></i>
</a> </a>
<a href="javascript:resetCache();"> <a href="javascript:deleteCache();">
<i class="fa font-14 fa-trash-alt rounded-s bg-highlight color-white"></i> <i class="fa font-14 fa-trash-alt rounded-s bg-highlight color-white"></i>
<span>Reset Cache</span> <span>Reset Cache</span>
<i class="fa fa-angle-right"></i> <i class="fa fa-angle-right"></i>
</a> </a>
<a href="https://report.regatten.net/"> <a href="https://github.com/ostertun/RegattenApp/issues">
<i class="fa font-14 fa-bug rounded-s bg-highlight color-white"></i> <i class="fa font-14 fa-bug rounded-s bg-highlight color-white"></i>
<span>Problem melden</span> <span>Problem melden</span>
<i class="fa fa-angle-right"></i> <i class="fa fa-angle-right"></i>