diff --git a/client/scripts/database.js b/client/scripts/database.js index 7496e0a..5d4b45a 100644 --- a/client/scripts/database.js +++ b/client/scripts/database.js @@ -161,19 +161,19 @@ function dbGetResultCalculated(regatta) { return new Promise(async function(resolve) { var results = await dbGetDataIndex('results', 'regatta', regatta.id); if (results.length > 0) { - + var gemeldet = results.length; - + for (id in results) { results[id]['finished'] = false; results[id]['values'] = []; results[id]['values_all'] = []; results[id]['texts'] = []; var copy = []; - + for (var i = 0; i < regatta['races']; i ++) { var race = results[id]['race' + (i + 1)].replace(',', '.'); - + if (!isNaN(race)) { copy[i] = results[id]['values'][i] = parseFloat(race); results[id]['texts'][i] = race; @@ -198,7 +198,7 @@ function dbGetResultCalculated(regatta) { // Unbekannt default: results[id]['values'][i] = 0; copy[i] = 0; break; } - + if (results[id]['values'][i] != 0) { results[id]['texts'][i] = race + ' (' + results[id]['values'][i] + ')'; } else { @@ -206,7 +206,7 @@ function dbGetResultCalculated(regatta) { } } } - + results[id]['values_all'] = [...results[id]['values']]; for (var s = 0; s < regatta['streicher']; s ++) { var max = Math.max(...copy); @@ -217,7 +217,7 @@ function dbGetResultCalculated(regatta) { } } } - + var brutto = 0; var netto = 0; for (var i = 0; i < regatta['races']; i ++) { @@ -233,11 +233,11 @@ function dbGetResultCalculated(regatta) { results[id]['brutto'] = brutto; results[id]['netto'] = netto; } - + compareResultsRaceCount = regatta['races']; - + results.sort(compareResults); - + var place = 1; for (id in results) { if ((id > 0) && (compareResults(results[id], results[id - 1]) == 0)) { @@ -247,9 +247,9 @@ function dbGetResultCalculated(regatta) { } place ++; } - + resolve(results); - + } else { resolve([]); } @@ -259,26 +259,26 @@ function dbGetResultCalculated(regatta) { function dbGetRanking(minDate, maxDate, jugend, jugstrict) { return new Promise(async function(resolve) { var rankNoResults = []; - + var sailors = await dbGetData('sailors'); var regattas = await dbGetRegattasRange(minDate, maxDate); - + var sailorIds = {}; for (s in sailors) { sailorIds[sailors[s].id] = s; } - + for (var i in sailors) { sailors[i].regattas = {}; sailors[i].tmp_rlp = []; } - + for (var i in regattas) { var regatta = regattas[i]; - + // regatta has to be min. 2 days to be ranking regatta if (regatta.length < 2) continue; - + var results = await dbGetDataIndex('results', 'regatta', regatta.id); if (results.length <= 0) { if (regatta.dateTo <= getToday()) { @@ -288,7 +288,7 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { } continue; } - + // in one race there must be at least 10 boats started var ok = false; for (var j = 1; j <= regatta.races; j ++) { @@ -304,9 +304,9 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { } } if (!ok) continue; - + var fb = regatta.finishedBoats; - + // calc m var m; if (regatta.m > 0) { @@ -320,16 +320,16 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { m = 4; } } - + // add regatta to each sailor for (var r in results) { var result = results[r]; - + if (result.rlp == 0) continue; - + // check if crew is youth // TODO: not used - + sailors[sailorIds[result.steuermann]].regattas[regatta.id] = { regatta: regatta.id, boat: result.boat, @@ -345,7 +345,7 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { } } } - + // remove not german or not youth sailors for (var i = sailors.length - 1; i >= 0; i --) { if (sailors[i].german == '0') { @@ -357,13 +357,13 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { } } } - + for (var i = sailors.length - 1; i >= 0; i --) { // sort rlps desc sailors[i].tmp_rlp.sort(function (a,b) { return b[1] - a[1]; }); - + // calc mean rlp var sum = 0; var cnt = 0; @@ -383,16 +383,16 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { sailors.splice(i, 1); } } - + sailors.sort(function (a,b) { if (a.m != b.m) return b.m - a.m; return b.rlp - a.rlp; }); - + for (var i = 0; i < sailors.length; i ++) { sailors[i].rank = (i + 1); } - + resolve([sailors, rankNoResults]); }); } @@ -424,7 +424,7 @@ async function updateSyncStatus() { // TODO // var now = new Date(); // var diff = Math.round((now - lastSync) / 1000); // var txt = ''; -// +// // if (diff < 30) { // 30 sec // txt = 'jetzt'; // } else if (diff < 3600) { // 60 min @@ -437,7 +437,7 @@ async function updateSyncStatus() { // TODO // diff = Math.round(diff / 86400); // txt = 'vor ' + diff + ' ' + (diff == 1 ? 'Tag' : 'Tagen'); // } -// +// // var btn = ' Sync'; // syncStatus.innerHTML = 'Zuletzt aktualisiert: ' + txt + btn; } @@ -453,7 +453,7 @@ async function runPageScript() { } }; updateSyncStatus(); - + if (isLoggedIn()) { var plannings = await dbGetDataIndex('plannings', 'user', USER_ID); plannings = plannings.map(function (e) { return e.regatta; }); @@ -471,7 +471,7 @@ async function runPageScript() { } // syncStatus.style.display = 'block'; } - + if (typeof siteScript === 'function') { siteScript(); } else { @@ -482,20 +482,20 @@ async function runPageScript() { function sync() { if (!canUseLocalDB) return false; if (syncInProgress > 0) return false; - + var now = Math.floor(Date.now() / 1000); - + db.transaction('update_times').objectStore('update_times').getAll().onsuccess = function (event) { var localTimes = {}; event.target.result.forEach(function (entry) { localTimes[entry['table']] = entry['time']; }); - + syncInProgress = 11; var syncOkay = true; console.log("Sync Start"); $('#i-sync').addClass('fa-spin'); - + var interval = window.setInterval(function () { if (syncInProgress <= 0) { window.clearInterval(interval); @@ -507,14 +507,17 @@ function sync() { setTimeout(function(){ $('#i-sync').removeClass('fa-spin'); }, 500); - + + if (typeof onAfterSync === 'function') { + onAfterSync(); + } runPageScript(); } }, 100); - + getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) { if (code == 200) { - + // CLUBS if (localTimes['clubs'] < serverTimes['clubs']) { getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) { @@ -546,7 +549,7 @@ function sync() { } else { syncInProgress --; } - + // BOATS if (localTimes['boats'] < serverTimes['boats']) { getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { @@ -578,7 +581,7 @@ function sync() { } else { syncInProgress --; } - + // SAILORS if (localTimes['sailors'] < serverTimes['sailors']) { getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { @@ -610,7 +613,7 @@ function sync() { } else { syncInProgress --; } - + // REGATTAS if (localTimes['regattas'] < serverTimes['regattas']) { getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { @@ -643,7 +646,7 @@ function sync() { osYears.put({ year: y }); } } - + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); syncInProgress --; @@ -658,7 +661,7 @@ function sync() { } else { syncInProgress --; } - + // RESULTS if (localTimes['results'] < serverTimes['results']) { getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { @@ -690,7 +693,7 @@ function sync() { } else { syncInProgress --; } - + // PLANNINGS if (localTimes['plannings'] < serverTimes['plannings']) { getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { @@ -722,7 +725,7 @@ function sync() { } else { syncInProgress --; } - + if (isLoggedIn()) { // TRIM_BOATS if (localTimes['trim_boats'] < serverTimes['trim_boats']) { @@ -755,7 +758,7 @@ function sync() { } else { syncInProgress --; } - + // TRIM_USERS if (localTimes['trim_users'] < serverTimes['trim_users']) { getJSON(QUERY_URL + 'get_trim_users?changed-after=' + localTimes['trim_users'], function (code, data) { @@ -787,7 +790,7 @@ function sync() { } else { syncInProgress --; } - + // TRIM_TRIMS if (localTimes['trim_trims'] < serverTimes['trim_trims']) { getJSON(QUERY_URL + 'get_trim_trims?changed-after=' + localTimes['trim_trims'], function (code, data) { @@ -819,11 +822,11 @@ function sync() { } else { syncInProgress --; } - + } else { syncInProgress -= 3; } - + // NEWS if (localTimes['news'] < serverTimes['news']) { getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { @@ -855,7 +858,7 @@ function sync() { } else { syncInProgress --; } - + // USERS if (localTimes['users'] < serverTimes['users']) { getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { @@ -887,7 +890,7 @@ function sync() { } else { syncInProgress --; } - + } else { console.log("Something went wrong (HTTP " + code + ")"); syncOkay = false; @@ -914,13 +917,13 @@ function initDatabase() { var request = window.indexedDB.open('regatten_app_db_' + BOATCLASS, DB_VERSION); request.onerror = function (event) { console.log("Cannot open DB: " + event.target.errorCode); - + runPageScript(); }; request.onsuccess = function (event) { console.log("Database loaded"); db = event.target.result; - + db.onversionchange = function (event) { if (syncTimer != null) window.clearInterval(syncTimer); if (updateSyncStatusTimer != null) window.clearInterval(updateSyncStatusTimer); @@ -929,15 +932,15 @@ function initDatabase() { db.close(); location.reload; } - + db.onerror = function (event) { console.log("DB Error: " + event.target.errorCode); }; - + canUseLocalDB = true; - + if (typeof onDatabaseLoaded == 'function') onDatabaseLoaded(); - + db.transaction('update_times').objectStore('update_times').get('last_sync').onsuccess = function (event) { var lastSync = event.target.result.time; if (lastSync > 0) { @@ -946,11 +949,11 @@ function initDatabase() { db.transaction('update_times', 'readwrite').objectStore('update_times').put({ table: 'loggedin', status: isLoggedIn() }); } }; - + checkSync(); - + syncTimer = window.setInterval(checkSync, 300000); // 5 min - + window.ononline = function () { checkSync(); } @@ -960,9 +963,9 @@ function initDatabase() { var upgradeTransaction = event.target.transaction; var oldVersion = event.oldVersion; var newVersion = event.newVersion; - + console.log("Datenbank Version Upgrade von " + oldVersion + " auf " + newVersion); - + if ((oldVersion < 1) && (newVersion >= 1)) { console.log('to version 1'); var osClubs = db.createObjectStore('clubs', { keyPath: 'id' }); @@ -991,7 +994,7 @@ function initDatabase() { osUpdateTimes.add({ table: 'trim_users', time: 0 }); osUpdateTimes.add({ table: 'trim_trims', time: 0 }); } - + if ((oldVersion < 2) && (newVersion >= 2)) { console.log('to version 2'); var osUsers = db.createObjectStore('users', { keyPath: 'id' }); @@ -999,32 +1002,32 @@ function initDatabase() { var osUpdateTimes = upgradeTransaction.objectStore('update_times'); osUpdateTimes.add({ table: 'users', time: 0 }); } - + if ((oldVersion < 3) && (newVersion >= 3)) { console.log('to version 3'); var osYears = db.createObjectStore('years', { keyPath: 'year' }); var osUpdateTimes = upgradeTransaction.objectStore('update_times'); osUpdateTimes.put({ table: 'regattas', time: 0 }); } - + if ((oldVersion < 4) && (newVersion >= 4)) { console.log('to version 4'); var osUpdateTimes = upgradeTransaction.objectStore('update_times'); osUpdateTimes.add({ table: 'loggedin', status: isLoggedIn() }); } - + if ((oldVersion < 5) && (newVersion >= 5)) { console.log('to version 5'); var osPushes = db.createObjectStore('settings', { keyPath: 'key' }); } - + if ((oldVersion < 6) && (newVersion >= 6)) { console.log('to version 6'); var osNews = db.createObjectStore('news', { keyPath: 'id' }); var osUpdateTimes = upgradeTransaction.objectStore('update_times'); osUpdateTimes.add({ table: 'news', time: 0 }); } - + var osUpdateTimes = upgradeTransaction.objectStore('update_times'); osUpdateTimes.put({ table: 'last_sync', time: 0 }); } @@ -1033,8 +1036,7 @@ function initDatabase() { } } -function resetDb(silent = true) { - $('#menu-developer').hideMenu(); +function resetDb() { if (canUseLocalDB) { showLoader(); var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); @@ -1051,11 +1053,6 @@ function resetDb(silent = true) { osUpdateTimes.put({ table: 'news', time: 0 }); osUpdateTimes.put({ table: 'users', time: 0 }); console.log('DB update times reset'); - if (!silent) - toastInfo('The database was reset. Please reload or close this tab.
At the next visit, a full sync will be performed.'); hideLoader(); - } else { - if (!silent) - toastWarn('Your device does not support storing data locally. All data is fetched directly from our server.
As a result, you can not reset your database.'); } } diff --git a/client/scripts/datetime.js b/client/scripts/datetime.js index ac5e354..ca2789d 100644 --- a/client/scripts/datetime.js +++ b/client/scripts/datetime.js @@ -27,13 +27,13 @@ function parseDate(string) { } else { return null; } - + if (isNaN(year) || isNaN(month) || isNaN(day)) return null; if (year.toString().length == 2) year = (year < 70 ? 2000 : 1900) + year; if ((year < 1970) || (year > 3000)) return null; if ((month < 1) || (month > 12)) return null; if ((day < 1) || (day > 31)) return null; - + var date = new Date(Date.UTC(year, month - 1, day)); return date; } @@ -51,37 +51,37 @@ function formatDate(format, date = null) { date = new Date(date.valueOf()); date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); } - + format = format.replace("M", "%1%"); format = format.replace("F", "%2%"); format = format.replace("D", "%3%"); format = format.replace("l", "%4%"); - + var tmp = date.getFullYear().toString(); var tmp2 = tmp.substr(2); format = format.replace("Y", tmp); format = format.replace('y', tmp2); - + tmp = (date.getMonth() + 1).toString(); tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp)); format = format.replace('n', tmp); format = format.replace('m', tmp2); - + tmp = date.getDate().toString(); tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp)); format = format.replace('j', tmp); format = format.replace('d', tmp2); - + tmp = date.getDay(); tmp2 = (tmp == 0 ? 7 : tmp); format = format.replace('w', tmp); format = format.replace('N', tmp2); - + format = format.replace('%1%', strings.months_short[date.getMonth()]); format = format.replace('%2%', strings.months_long[date.getMonth()]); - + format = format.replace('%3%', strings.weekdays_short[date.getDay()]); format = format.replace('%4%', strings.weekdays_long[date.getDay()]); - + return format; } diff --git a/client/scripts/mobileconsole.js b/client/scripts/mobileconsole.js index 6c463fb..d6532e2 100644 --- a/client/scripts/mobileconsole.js +++ b/client/scripts/mobileconsole.js @@ -345,7 +345,7 @@ var mobileConsole = (function () { top: 'auto', right: 0, width: '100%', - zIndex: 10000, + zIndex: 1000000, padding: 0, paddingBottom: options.browserinfo.isMobile ? '35px' : '25px', margin: 0, @@ -662,7 +662,7 @@ var mobileConsole = (function () { height: newHeight }); setCSS(document.body, { - paddingBottom: existingPadding + Math.abs(parseInt(newHeight, 10) + elements.topbar.offsetHeight) + 'px' + //paddingBottom: existingPadding + Math.abs(parseInt(newHeight, 10) + elements.topbar.offsetHeight) + 'px' }); elements.buttons.toggler.innerHTML = (elements.base.minimized) ? elements.arrowDown : elements.arrowUp; elements.buttons.toggler.setAttribute('title', (elements.base.minimized) ? 'Minimize console' : 'Maximize console'); @@ -747,7 +747,7 @@ var mobileConsole = (function () { }); var existingPadding = isNaN(parseInt(document.body.style.paddingBottom, 10)) ? 0 : parseInt(document.body.style.paddingBottom, 10); setCSS(document.body, { - paddingBottom: existingPadding + Math.abs(console.offsetHeight + elements.topbar.offsetHeight) + 'px' + //paddingBottom: existingPadding + Math.abs(console.offsetHeight + elements.topbar.offsetHeight) + 'px' }); elements.scrollcontainer.scrollTop = elements.scrollcontainer.scrollHeight; @@ -914,6 +914,7 @@ var mobileConsole = (function () { while (i--) { thisLine = lines[i].trim(); lineAndColumn = thisLine.match(/(?::)(\d+)(?::)(\d+)/); + if (lineAndColumn === null) continue; url = urlFromString(thisLine).replace(lineAndColumn[0], '').split('#')[0] || ''; caller = htmlToString(thisLine.replace(urlFromString(thisLine), '').replace(separator, '').replace('at ', '').trim()); if (caller === '' || caller === lineAndColumn[0]) { continue; } diff --git a/client/scripts/regatten.js.php b/client/scripts/regatten.js.php index 5061132..6bee92b 100644 --- a/client/scripts/regatten.js.php +++ b/client/scripts/regatten.js.php @@ -1,9 +1,9 @@ const QUERY_URL = ''; @@ -122,8 +122,8 @@ var login = function() { showLoader(); var username = $('#input-login-username').val(); var password = $('#input-login-password').val(); - $('#input-login-username').val(''); - $('#input-login-password').val(''); + $('#input-login-username').val('').trigger('focusin').trigger('focusout'); + $('#input-login-password').val('').trigger('focusin').trigger('focusout'); $.ajax({ url: QUERY_URL + 'login', method: 'POST', @@ -135,7 +135,7 @@ var login = function() { error: function (xhr, status, error) { if (xhr.status == 401) { toastError('Benutzername oder Passwort falsch'); - $('#input-login-username').val(username); + $('#input-login-username').val(username).trigger('focusin').trigger('focusout'); } else if (xhr.status == 0) { toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Dich anzumelden'); $('#menu-login').hideMenu(); @@ -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.
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.
Entsprechend kannst Du die Datenbank auch nicht zurücksetzen.', 10000); + } +} + +function deleteCache() { $('#menu-developer').hideMenu(); navigator.serviceWorker.getRegistrations().then(function (registrations) { for (let registration of registrations) { @@ -217,7 +238,8 @@ function resetCache() { return caches.delete(key); })); }); - toastInfo('The serviceWorker and the cache were deleted. A new serviceWorker will be generated on the next refresh.'); + toastInfo('Der serviceWorker und alle Caches wurden gelöscht. Die Seite lädt in wenigen Sekunden neu und erstellt damit neue Caches.', 10000); + setTimeout(function(){ location.reload(); }, 3000); } var pushesPossible = false; @@ -227,10 +249,10 @@ function urlB64ToUint8Array(base64String) { const base64 = (base64String + padding) .replace(/\-/g, '+') .replace(/_/g, '/'); - + const rawData = window.atob(base64); const outputArray = new Uint8Array(rawData.length); - + for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } @@ -317,13 +339,19 @@ async function updatePushSwitches() { $('#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-meldeschluss').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_meldeschluss')); - + if ($('#switch-pushes').prop('checked')) { $('#p-pushes-info').show(); - $('.a-switch-pushes-channel').show(); + $('.a-switch-pushes-channel-all').show(); + $('.a-switch-pushes-channel-my').show(); + if (!isLoggedIn()) { + $('.a-switch-pushes-channel-my').find('div').remove(); + $('.a-switch-pushes-channel-my').find('.badge').text('nicht angemeldet'); + } } else { $('#p-pushes-info').hide(); - $('.a-switch-pushes-channel').hide(); + $('.a-switch-pushes-channel-all').hide(); + $('.a-switch-pushes-channel-my').hide(); } } @@ -355,7 +383,7 @@ function pushesOpenMenu() { toastWarn('Benachrichtigungen werden von Deinem Browser blockiert.', 5000); return; } - + swRegistration.pushManager.getSubscription().then(function(subscription) { var isSub = (subscription !== null); $('#switch-pushes').prop('checked', isSub); @@ -380,11 +408,27 @@ function updatePushBadge() { }); } +async function updateNewsBadge() { + var newsRead = await dbSettingsGet('news_read_' + BOATCLASS); + if (newsRead === null) dbSettingsSet('news_read_' + BOATCLASS, newsRead = new Date()); + var news = await dbGetData('news'); + var now = new Date(); + var sum = 0; + for (var n in news) { + var newsEntry = news[n]; + newsEntry.date = new Date(Date.parse(newsEntry.date)); + if (newsEntry.date > now) continue; + if (newsEntry.date < newsRead) continue; + sum ++; + } + updateBadge('more/news', sum); +} + var initRegatten = function() { showLoader(); - + initDatabase(); - + if (isLoggedIn()) { $('.show-loggedin').show(); $('.show-notloggedin').hide(); @@ -396,10 +440,11 @@ var initRegatten = function() { $('.show-loggedin').hide(); $('.show-notloggedin').show(); } - + // Pushes $('#a-switch-pushes').click(pushesSubscribeClicked); - $('.a-switch-pushes-channel').click(pushesChannelClicked); + $('.a-switch-pushes-channel-all').click(pushesChannelClicked); + $('.a-switch-pushes-channel-my').click(pushesChannelClicked); } var onServiceWorkerLoaded = function() { @@ -414,4 +459,32 @@ var onServiceWorkerLoaded = function() { var onDatabaseLoaded = function() { onServiceWorkerLoaded(); initPushSettings(); + + updateNewsBadge(); } + +var onAfterSync = function() { + updateNewsBadge(); +} + +// Add console opener to preloader +var addConsoleOpenerToPreloader = function() { + addConsoleOpenerToPreloader = function(){}; + var preloader = document.getElementById('preloader'); + var button = document.createElement('a'); + button.href = '#'; + button.classList = 'btn btn-full rounded-s text-uppercase font-900 shadow-m bg-highlight m-3'; + button.style.position = 'fixed'; + button.style.bottom = 0; + button.style.left = 0; + button.style.right = 0; + button.innerHTML = 'Show Console'; + button.onclick = function(){ + mobileConsole.displayConsole(); + return false; + } + setTimeout(function(){ + preloader.appendChild(button); + }, 5000); +} +addConsoleOpenerToPreloader(); diff --git a/server/page/menus.php b/server/page/menus.php index b3ce2ed..ff88dde 100644 --- a/server/page/menus.php +++ b/server/page/menus.php @@ -154,7 +154,7 @@ (meine) bezieht sich auf die Regatten, die in Deiner Saison-Planung sind,
(alle) informiert Dich über alle Regatten

- + Neuigkeiten
@@ -162,15 +162,16 @@
- + Regatta verschoben (meine) +
- + Regatta verschoben (alle)
@@ -178,15 +179,16 @@
- + Ergebnisse verfügbar (meine) +
- + Ergebnisse verfügbar (alle)
@@ -194,9 +196,10 @@
- + Melde-Erinnerungen +
@@ -211,22 +214,22 @@
- + - Infos zur BETA + App-Wiki - + Reset Database - + Reset Cache - + Problem melden diff --git a/server/scripts/calc.js b/server/scripts/calc.js index 1912e6c..9863499 100644 --- a/server/scripts/calc.js +++ b/server/scripts/calc.js @@ -42,7 +42,7 @@ function addRace() { var m = parseFloat($('#input-m').val()); var fb = parseFloat($('#input-fb').val()); var pl = parseFloat($('#input-pl').val().replace(',', '.')); - + if (isNaN(rlf) || (rlf < 1) || (rlf > 1.6)) { toastError('RLF ungültig'); return; @@ -59,7 +59,7 @@ function addRace() { toastError('pl ungültig'); return; } - + var race = { rlf: rlf, m: m, @@ -67,12 +67,12 @@ function addRace() { pl: pl, rlp: (100 * rlf * ((fb + 1 - pl) / fb)) }; - - $('#input-rlf').val(''); - $('#input-m').val(''); - $('#input-fb').val(''); - $('#input-pl').val(''); - + + $('#input-rlf').val('').trigger('focusin').trigger('focusout'); + $('#input-m').val('').trigger('focusin').trigger('focusout'); + $('#input-fb').val('').trigger('focusin').trigger('focusout'); + $('#input-pl').val('').trigger('focusin').trigger('focusout'); + races.push(race); reCalc(); } @@ -89,4 +89,4 @@ var siteScript = async function () { } reCalc(); hideLoader(); -} \ No newline at end of file +} diff --git a/server/scripts/contact.js b/server/scripts/contact.js index 9a0fdcd..0ae07df 100644 --- a/server/scripts/contact.js +++ b/server/scripts/contact.js @@ -3,12 +3,12 @@ function sendMessage() { var email = $('#input-email').val(); var subject = $('#input-subject').val(); var message = $('#input-message').val(); - + if ((name == '') || (email == '') || (subject == '') || (message == '')) { toastError('Bitte fülle alle Felder aus!'); return; } - + showLoader(); $.ajax({ url: QUERY_URL + 'contact', @@ -31,8 +31,8 @@ function sendMessage() { }, success: function (data, status, xhr) { toastOk('Nachricht erfolgreich versandt!'); - $('#input-subject').val(''); - $('#input-message').val(''); + $('#input-subject').val('').trigger('focusin').trigger('focusout'); + $('#input-message').val('').trigger('focusin').trigger('focusout'); hideLoader(); } }); @@ -46,4 +46,4 @@ var siteScript = async function () { } $('#button-send').click(sendMessage); hideLoader(); -} \ No newline at end of file +} diff --git a/server/scripts/news.js b/server/scripts/news.js index 914f340..6b55da4 100644 --- a/server/scripts/news.js +++ b/server/scripts/news.js @@ -1,25 +1,24 @@ async function onNewsClicked(id) { var newsEntry = await dbGetData('news', id); if (newsEntry == null) return; - + $('#menu-news').css('height', '80%'); $('#menu-news').css('width', '90%'); $('#menu-news').find('.menu-title').find('p').text(newsEntry.title); $('#menu-news').find('.content').addClass('pb-3'); $('#menu-news').find('.content').html(newsEntry.html); - + $('#menu-news').showMenu(); } function addCard(newsEntry) { - console.log(newsEntry); var content = '

' + newsEntry.title + '

'; content += '

' + formatDate('d.m.Y', newsEntry.date) + '

'; content += '

' + newsEntry.description.replace('\n', '
') + '

'; if (newsEntry.html != '') { content += '
Mehr lesen'; } - + $('.page-content').append(cardTemplate.replace('%ID%', 'card-news-' + newsEntry.id).replace('%CONTENT%', content)); } @@ -29,16 +28,17 @@ var siteScript = async function() { news.sort(function (a,b) { return b.date.localeCompare(a.date); }); - var today = getToday(); - var lastYear = new Date(today); + var now = new Date(); + var lastYear = new Date(); lastYear.setFullYear(lastYear.getFullYear() - 1); - console.log(today, lastYear); for (var n in news) { var newsEntry = news[n]; - newsEntry.date = parseDate(newsEntry.date.substring(0, 10)); - if (newsEntry.date > today) continue; + newsEntry.date = new Date(Date.parse(newsEntry.date)); + if (newsEntry.date > now) continue; if (newsEntry.date < lastYear) break; addCard(newsEntry); } + dbSettingsSet('news_read_' + BOATCLASS, now); + updateNewsBadge(); hideLoader(); -} \ No newline at end of file +} diff --git a/server/scripts/rank.js b/server/scripts/rank.js index 6e811ba..847bb62 100644 --- a/server/scripts/rank.js +++ b/server/scripts/rank.js @@ -11,7 +11,7 @@ async function onRankingClicked(id) { } } if (sailor == null) return; - + $('#menu-rank').find('.menu-title').find('p').text(sailor.name); if (lastRanking != null) { var lastRank; @@ -25,83 +25,83 @@ async function onRankingClicked(id) { } else { $('#menu-item-text').hide(); } - + list = ''; for (var i in sailor.regattas) { var entry = sailor.regattas[i]; var regatta = entry.regatta; var boat = await dbGetData('boats', entry.boat); - + var dateFrom = parseDate(regatta.date); var dateTo = parseDate(regatta.date); dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta.length) - 1, 0)); - + list += '
'; - + // ZEILE 1 list += '
' + regatta.name + '
'; - + // ZEILE 2 list += '
'; - + // DATE list += '
' + formatDate('d.m.Y', dateFrom) + ' - ' + formatDate('d.m.Y', dateTo) + '
'; - + // m list += '
m: ' + entry.m + '
'; - + // rlf list += '
RLF: ' + parseFloat(regatta.rlf).toFixed(2) + '
'; - + list += '
'; - + // ZEILE 3 list += '
'; - + // Place list += '
Platz ' + entry.place + ' / ' + entry.fb + '
'; - + // rlp var color; if (entry.used == 0) { color = 'color-red2-dark'; } else if (entry.used == entry.m) { color = 'color-green2-dark'; } else { color = 'color-yellow2-dark'; } list += '
Punkte: ' + entry.used + ' x ' + parseFloat(entry.rlp).toFixed(2) + '
'; - + list += '
'; - + // ZEILE 4 list += '
'; - + // Sailnumber list += '
' + boat.sailnumber + '
'; - + // Boatname list += '
' + boat.name + '
'; - + list += '
'; - + // ZEILE 5... var crew = entry.crew.split(','); for (var c in crew) { var cr = await dbGetData('sailors', crew[c]); if (cr != null) { list += '
'; - + // Name list += '
' + cr.name + '
'; - + // Year list += '
' + ((cr.year != null) ? ('(' + cr.year + ')') : '') + '
'; - + list += '
'; } } - + list += '
'; } $('#div-details').html(list); - + $('#menu-rank').showMenu(); $('#menu-rank').scrollTop(0); } @@ -111,8 +111,8 @@ async function selectChange(callSiteScript = true) { var year = parseInt($('#select-year').val()); if (type == "user") { $('#select-year').parent().hide(); - $('#input-from').parent().show(); - $('#input-to').parent().show(); + $('#input-from').trigger('focusin').trigger('focusout').parent().show(); + $('#input-to').trigger('focusin').trigger('focusout').parent().show(); $('#input-jugend').parent().parent().show(); $('#input-jugstrict').parent().parent().show(); $('#button-show').show(); @@ -123,7 +123,7 @@ async function selectChange(callSiteScript = true) { $('#input-jugend').parent().parent().hide(); $('#input-jugstrict').parent().parent().hide(); $('#button-show').hide(); - + var from, to, jugend, jugstrict; switch (type) { case 'year': @@ -168,14 +168,26 @@ async function selectChange(callSiteScript = true) { } break; } - + $('#input-from').val(from); $('#input-to').val(to); $('#input-jugend').prop('checked', jugend); $('#input-jugstrict').prop('checked', jugstrict); - - if (callSiteScript && (typeof siteScript === 'function')) + + if (callSiteScript && (typeof siteScript === 'function')) { + history.replaceState(null, '', '?type=' + type + '&year=' + year) siteScript(); + } + } +} + +function buttonShowPressed() { + if (typeof siteScript === 'function') { + var chboxes = ''; + if ($('#input-jugend').prop('checked')) chboxes += '&jugend=on' + if ($('#input-jugstrict').prop('checked')) chboxes += '&jugstrict=on' + history.replaceState(null, '', '?type=user&from=' + $('#input-from').val() + "&to=" + $('#input-to').val() + chboxes) + siteScript(); } } @@ -186,10 +198,23 @@ function initSelects() { if (year === null) year = new Date().getFullYear(); $('#select-type').val(type); - + $('#select-year').html(''); $('#select-year').val(year); - + + if (type == "user") { + var from = findGetParameter('from'); + var to = findGetParameter('to'); + if (from === null) from = formatDate('Y-m-d') + if (to === null) to = formatDate('Y-m-d') + $('#input-from').val(from).trigger('focusin').trigger('focusout'); + $('#input-to').val(to).trigger('focusin').trigger('focusout'); + var jugend = findGetParameter('jugend'); + var jugstrict = findGetParameter('jugstrict'); + $('#input-jugend').prop('checked', jugend !== null); + $('#input-jugstrict').prop('checked', jugstrict !== null); + } + selectChange(false); } @@ -218,17 +243,17 @@ var siteScript = async function() { initSelects(); $('#select-type').change(selectChange); $('#select-year').change(selectChange); - $('#button-show').click(siteScript); + $('#button-show').click(buttonShowPressed); $('#input-search').on('input', drawList); } - + var minDate = parseDate($('#input-from').val()); var maxDate = parseDate($('#input-to').val()); var jugend = $('#input-jugend').prop('checked'); var jugstrict = $('#input-jugstrict').prop('checked'); var dbRanking = await dbGetRanking(minDate, maxDate, jugend, jugstrict); ranking = dbRanking[0]; - + lastRanking = null; if (($('#select-type').val() == 'year') || ($('#select-type').val() == 'youth')) { lastRanking = {}; @@ -240,9 +265,9 @@ var siteScript = async function() { lastRanking[lDbRanking[i].id] = lDbRanking[i].rank; } } - + var selectedYear = $('#select-year').val(); - + var years = await dbGetData('years'); years.sort(function (a, b) { if (a['year'] > b['year']) return -1; @@ -256,7 +281,7 @@ var siteScript = async function() { } $('#select-year').html(options); $('#select-year').val(selectedYear); - + if (dbRanking[1].length > 0) { $('#card-noresults').show(); list = ''; @@ -269,18 +294,18 @@ var siteScript = async function() { } else { $('#card-noresults').hide(); } - + var count = ranking.length; if (count > 0) { $('#input-search').parent().show(); - + var dsvEnd = false; - + rows = []; - + for (id in ranking) { var entry = ranking[id]; - + for (var i in entry.regattas) { entry.regattas[i].regatta = await dbGetData('regattas', entry.regattas[i].regatta); } @@ -288,26 +313,26 @@ var siteScript = async function() { entry.regattas.sort(function (a,b) { return a.regatta.date.localeCompare(b.regatta.date); }); - + var club = null; if (entry['club'] != null) club = await dbGetData('clubs', entry['club']); - + var row = { keywords: [], content: '' }; row.keywords.push(entry['name']); if (entry['year'] != null) row.keywords.push(entry['year']); if (club != null) row.keywords.push(club['kurz'], club['name']); - + if (!dsvEnd && (entry.m < 9)) { rows.push(null); dsvEnd = true; } - + row.content += '
'; - + // ZEILE 1 row.content += '
'; - + // Rank var icon = ''; if (lastRanking != null) { @@ -321,39 +346,39 @@ var siteScript = async function() { icon = ' '; } row.content += '
' + icon + '' + entry.rank + '.
'; - + // m row.content += '
m = ' + entry.m + '
'; - + // rlp row.content += '
' + entry.rlp.toFixed(3) + '
'; - + row.content += '
'; - + // ZEILE 2 row.content += '
'; - + // Name row.content += '
' + entry.name + '
'; - + // Year row.content += '
' + ((entry.year != null) ? ('(' + entry.year + ')') : '') + '
'; - + row.content += '
'; - + rows.push(row); } - + if (!dsvEnd) { rows.push(null); } - + drawList(); - + } else { $('#div-rank').html('Keine Ergebnisse gefunden!'); $('#input-search').parent().hide(); } - + hideLoader(); -} \ No newline at end of file +} diff --git a/server/scripts/regattas.js b/server/scripts/regattas.js index ffe2c6b..3c667e6 100644 --- a/server/scripts/regattas.js +++ b/server/scripts/regattas.js @@ -1,8 +1,8 @@ function selectChange(callSiteScript = true) { var val = $('#select-year').val(); if (val == "user") { - $('#input-from').parent().show(); - $('#input-to').parent().show(); + $('#input-from').trigger('focusin').trigger('focusout').parent().show(); + $('#input-to').trigger('focusin').trigger('focusout').parent().show(); $('#button-show').show(); } else { $('#input-from').parent().hide(); @@ -12,8 +12,17 @@ function selectChange(callSiteScript = true) { $('#input-from').val(val + '-01-01'); $('#input-to').val(val + '-12-31'); - if (callSiteScript && (typeof siteScript === 'function')) + if (callSiteScript && (typeof siteScript === 'function')) { + history.replaceState(null, '', '?year=' + val); siteScript(); + } + } +} + +function buttonShowPressed() { + if (typeof siteScript === 'function') { + history.replaceState(null, '', '?year=user&from=' + $('#input-from').val() + "&to=" + $('#input-to').val()) + siteScript(); } } @@ -24,6 +33,15 @@ function initYear() { $('#select-year').html(''); $('#select-year').val(year); + if (year == "user") { + var from = findGetParameter('from'); + var to = findGetParameter('to'); + if (from === null) from = formatDate('Y-m-d') + if (to === null) to = formatDate('Y-m-d') + $('#input-from').val(from).trigger('focusin').trigger('focusout'); + $('#input-to').val(to).trigger('focusin').trigger('focusout'); + } + selectChange(false); } @@ -50,7 +68,7 @@ var siteScript = async function() { firstCall = false; initYear(); $('#select-year').change(selectChange); - $('#button-show').click(siteScript); + $('#button-show').click(buttonShowPressed); $('#input-search').on('input', drawList); } diff --git a/server/version.php b/server/version.php index 722613f..18d77de 100644 --- a/server/version.php +++ b/server/version.php @@ -1,5 +1,5 @@