From 3db5ae1723566b22f8d8c1149e6c39eecd10d45f Mon Sep 17 00:00:00 2001 From: ostertun Date: Fri, 2 Oct 2020 14:24:00 +0200 Subject: [PATCH 01/11] RA-#21 News: mark unread and add pagination --- server/content/news.php | 20 ++++++++++------ server/scripts/news.js | 52 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/server/content/news.php b/server/content/news.php index 41f9efa..b561202 100644 --- a/server/content/news.php +++ b/server/content/news.php @@ -1,22 +1,28 @@ Neuigkeiten"; $content .= '

Aktuelles der letzten zwölf Monate

'; - + $sp['output'] .= $tpl->load('card', [$content]); - + + $sp['output'] .= '
'; + + // Pagination + $sp['output'] .= $tpl->load('pagination', ['html-id' => 'pagination']); + // Menu $sp['menus'] .= $tpl->load('menu/modal', ['html-id' => 'menu-news', 'title' => 'Details']); - + + $sp['scripts'] .= $scripts->load('pagination', ['pageChange', 'page', 'pageCount', 'pagination']); $cardTemplate = $tpl->load('card', ['%CONTENT%', 'html-id' => '%ID%', 'css-class' => 'card-news']); $cardTemplate = str_replace("\n", '', $cardTemplate); $cardTemplate = str_replace("\r", '', $cardTemplate); $sp['scripts'] .= ""; $sp['scripts'] .= $scripts->load('news'); - -?> \ No newline at end of file + +?> diff --git a/server/scripts/news.js b/server/scripts/news.js index 6b55da4..ddece8e 100644 --- a/server/scripts/news.js +++ b/server/scripts/news.js @@ -1,3 +1,9 @@ +var firstCall = true; +var rows = []; +var page = 1; +var pageCount = 0; +const showCount = 10; + async function onNewsClicked(id) { var newsEntry = await dbGetData('news', id); if (newsEntry == null) return; @@ -11,23 +17,50 @@ async function onNewsClicked(id) { $('#menu-news').showMenu(); } +function pageChange() { + $('h1')[0].scrollIntoView({ behavior: "smooth" }); + drawList(); +} + function addCard(newsEntry) { - var content = '

' + newsEntry.title + '

'; + var badge = ''; + if (newsEntry.unread) { + badge += 'NEW '; + } + var content = '

' + badge + 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)); + $('#news-entries').append(cardTemplate.replace('%ID%', 'card-news-' + newsEntry.id).replace('%CONTENT%', content)); +} + +async function drawList() { + $('.card-news').remove(); + if (rows.length > 0) { + var offset = (page - 1) * showCount; + var count = (page == pageCount ? (rows.length % showCount) : showCount); + if (count == 0) count = showCount; + + for (i = 0; i < count; i ++) { + addCard(rows[i + offset]); + } + } } var siteScript = async function() { - $('.card-news').remove(); + if (firstCall) { + firstCall = false; + initPagination(); + } + rows = []; var news = await dbGetData('news'); news.sort(function (a,b) { return b.date.localeCompare(a.date); }); + var newsRead = await dbSettingsGet('news_read_' + BOATCLASS); var now = new Date(); var lastYear = new Date(); lastYear.setFullYear(lastYear.getFullYear() - 1); @@ -36,8 +69,19 @@ var siteScript = async function() { newsEntry.date = new Date(Date.parse(newsEntry.date)); if (newsEntry.date > now) continue; if (newsEntry.date < lastYear) break; - addCard(newsEntry); + newsEntry.unread = (newsEntry.date > newsRead); + rows.push(newsEntry); } + pageCount = Math.ceil(rows.length / showCount); + if ((page < 1) || (page > pageCount)) { + if (page < 1) { + page = 1; + } else { + page = pageCount; + } + } + drawPagination(); + drawList(); dbSettingsSet('news_read_' + BOATCLASS, now); updateNewsBadge(); hideLoader(); From c2a482bba126ffd0d9cfe8aa71ec6076cc9904d2 Mon Sep 17 00:00:00 2001 From: ostertun Date: Fri, 2 Oct 2020 17:19:59 +0200 Subject: [PATCH 02/11] Fix RA-#10 background color of mobileConsole --- client/scripts/mobileconsole.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/scripts/mobileconsole.js b/client/scripts/mobileconsole.js index d6532e2..f5d21fc 100644 --- a/client/scripts/mobileconsole.js +++ b/client/scripts/mobileconsole.js @@ -335,7 +335,7 @@ var mobileConsole = (function () { var elements = { lines: [], acItems: [], - base: createElem('div', 'base', { + base: createElem('div', 'base page-bg', { boxSizing: 'border-box', position: 'fixed', resize: 'none', From ae9bf02c491850d0992b5d50f5a79be80b52ac45 Mon Sep 17 00:00:00 2001 From: ostertun Date: Fri, 2 Oct 2020 17:42:33 +0200 Subject: [PATCH 03/11] RA-#13 Dont show install promt when welcome banner active --- client/scripts/pwa.js.php | 125 +++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/client/scripts/pwa.js.php b/client/scripts/pwa.js.php index 35667bd..f407660 100644 --- a/client/scripts/pwa.js.php +++ b/client/scripts/pwa.js.php @@ -1,10 +1,10 @@ //Loading the Service Worker var swRegistration = null; @@ -16,31 +16,31 @@ if ('serviceWorker' in navigator) { } -$(document).ready(function(){ - 'use strict' - +$(document).ready(function(){ + 'use strict' + var pwaVersion = ''; //must be identical to _manifest.json version. If not it will create update window loop var pwaCookie = true; // if set to false, the PWA prompt will appear even if the user selects "maybe later" var pwaNoCache = false; // always keep the cache clear to serve the freshest possible content - - + + $('[data-pwa-version]').data('pwa-version', pwaVersion); - + //Creating Cookie System for PWA Hide function createCookie(e, t, n) {if (n) {var o = new Date;o.setTime(o.getTime() + n * 365 * 24 * 3600 * 1e3);var r = "; expires=" + o.toGMTString()} else var r = "";document.cookie = e + "=" + t + r + "; path=/"} function readCookie(e) {for (var t = e + "=", n = document.cookie.split(";"), o = 0; o < n.length; o++) {for (var r = n[o];" " == r.charAt(0);) r = r.substring(1, r.length);if (0 == r.indexOf(t)) return r.substring(t.length, r.length)}return null} function eraseCookie(e) {createCookie(e, "", -1)} - + //Enabling dismiss button setTimeout(function(){ $('.pwa-dismiss').on('click',function(){ console.log('User Closed Add to Home / PWA Prompt') createCookie('Sticky_pwa_rejected_install', true, 1); - $('body').find('#menu-install-pwa-android, #menu-install-pwa-ios, .menu-hider').removeClass('menu-active'); + $('body').find('#menu-install-pwa-android, #menu-install-pwa-ios, .menu-hider').removeClass('menu-active'); }); },1500); - + //Detecting Mobile Operating Systems var isMobile = { Android: function() {return navigator.userAgent.match(/Android/i);}, @@ -49,8 +49,8 @@ $(document).ready(function(){ }; var isInWebAppiOS = (window.navigator.standalone == true); var isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches); - - //Firing PWA prompts for specific versions and when not on home screen. + + //Firing PWA prompts for specific versions and when not on home screen. if (isMobile.Android()) { console.log('Android Detected'); function showInstallPromotion(){ @@ -60,7 +60,7 @@ $(document).ready(function(){ setTimeout(function(){ $('.add-to-home').addClass('add-to-home-visible add-to-home-android'); $('#menu-install-pwa-android, .menu-hider').addClass('menu-active') - },4500); + },3000); } } else { console.log('The div #menu-install-pwa-android was not found. Please add this div to show the install window') @@ -70,7 +70,12 @@ $(document).ready(function(){ window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferredPrompt = e; - showInstallPromotion(); + var welcomActive = $('#menu-welcome').hasClass('menu-active'); + if (welcomActive) { + $('#menu-welcome-a-okay').click(showInstallPromotion); + } else { + showInstallPromotion(); + } }); $('.pwa-install').on('click',function(e){ deferredPrompt.prompt(); @@ -87,26 +92,34 @@ $(document).ready(function(){ window.addEventListener('appinstalled', (evt) => { $('#menu-install-pwa-android, .menu-hider').removeClass('menu-active') }); - } - + } + if (isMobile.iOS()) { if(!isInWebAppiOS){ console.log('iOS Detected'); if($('#menu-install-pwa-ios, .add-to-home').length){ if (!readCookie('Sticky_pwa_rejected_install')) { - console.log('Triggering PWA / Add to Home Screen Menu for iOS'); - setTimeout(function(){ - $('.add-to-home').addClass('add-to-home-visible add-to-home-ios'); - $('#menu-install-pwa-ios, .menu-hider').addClass('menu-active'); - },4500); + function triggerPwaInstallIos() { + console.log('Triggering PWA / Add to Home Screen Menu for iOS'); + setTimeout(function(){ + $('.add-to-home').addClass('add-to-home-visible add-to-home-ios'); + $('#menu-install-pwa-ios, .menu-hider').addClass('menu-active'); + },3000); + } + var welcomActive = $('#menu-welcome').hasClass('menu-active'); + if (welcomActive) { + $('#menu-welcome-a-okay').click(triggerPwaInstallIos); + } else { + triggerPwaInstallIos(); + } }; } else { console.log('The div #menu-install-pwa-ios was not found. Please add this div to show the install window') } } - } + } + - //Creating Update Modal function updateModal(){ var body = $('body'); @@ -116,7 +129,7 @@ $(document).ready(function(){ if(!updateModal.length){ body.append(''); setTimeout(function(){ - body.find('#menu-update').load('menu-update.html?ver='+menuUpdate); + body.find('#menu-update').load('menu-update.html?ver='+menuUpdate); },250); } }; @@ -132,8 +145,8 @@ $(document).ready(function(){ window.location.reload(true) } }, 1000); - caches.delete('workbox-runtime').then(function() { - console.log('Content Updated - Cache Removed!'); + caches.delete('workbox-runtime').then(function() { + console.log('Content Updated - Cache Removed!'); }); //localStorage.clear(); sessionStorage.clear() @@ -143,17 +156,17 @@ $(document).ready(function(){ }); }); }; - - //Check Version + + //Check Version function check_version(){ if($('link[data-pwa-version]').length){ - function versionCheck(){ + function versionCheck(){ var dt = new Date(); var maniTimeVersion = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds(); var localVersionNumber = $('link[rel="manifest"]').data('pwa-version'); var onlineVersionJSON = "/manifest.json.php?ver=" + maniTimeVersion; var onlineVersionNumber = "Connection Offline. Waiting to Reconect"; - $.getJSON(onlineVersionJSON, function(onlineData) {onlineVersionNumber = onlineData.version;}); + $.getJSON(onlineVersionJSON, function(onlineData) {onlineVersionNumber = onlineData.version;}); setTimeout(function(){ //console.log(' Checking PWA Content for updates...\n PWA Server Version: ' + onlineVersionNumber + '\n' + ' PWA Cached Version: ' + localVersionNumber); if(onlineVersionNumber != localVersionNumber && onlineVersionNumber != "Connection Offline. Waiting to Reconect"){ @@ -161,16 +174,16 @@ $(document).ready(function(){ console.log('New Version of Content Available. Refreshing. On Desktop Browsers a manual refresh maybe required.') setTimeout(function(){ $('body').find('#menu-update').addClass('menu-active'); - $('.menu-hider').addClass('menu-active-no-click'); + $('.menu-hider').addClass('menu-active-no-click'); updateButton(); },500); - } - if(onlineVersionNumber == localVersionNumber){/*No update required. Versions Identical*/} - if(onlineVersionNumber === "undefined"){/*Error Checking for Updates*/} + } + if(onlineVersionNumber == localVersionNumber){/*No update required. Versions Identical*/} + if(onlineVersionNumber === "undefined"){/*Error Checking for Updates*/} if(onlineVersionNumber === "Finding Online Version..."){ - $('.reloadme').addClass('disabled'); + $('.reloadme').addClass('disabled'); $('body').find('#menu-update').removeClass('menu-active'); - $('.menu-hider').removeClass('menu-active-no-click'); + $('.menu-hider').removeClass('menu-active-no-click'); } },3000); } @@ -184,15 +197,15 @@ $(document).ready(function(){ if(pwaCookie == false){ eraseCookie('Sticky_pwa_rejected_install'); } - - //Reload To Clear Button + + //Reload To Clear Button $('body').on('click', '.page-update, .reloadme', function() { location.reload(); }); - + //Check for Version Change if Online If not Kill the Function if (navigator.onLine) {check_version();} else {function check_version(){}} - + //Adding Offline Alerts var offlineAlerts = $('.offline-message'); @@ -200,24 +213,24 @@ $(document).ready(function(){ $('body').append('

' + strings['inetMsgOffline'] + '

'); $('body').append('

' + strings['inetMsgOnline'] + '

'); } - + //Offline Function Show function isOffline(){ $('.offline-message').addClass('offline-message-active'); $('.online-message').removeClass('online-message-active'); setTimeout(function(){$('.offline-message').removeClass('offline-message-active');},2000); } - + //Online Function Show function isOnline(){ $('.online-message').addClass('online-message-active'); $('.offline-message').removeClass('offline-message-active'); setTimeout(function(){$('.online-message').removeClass('online-message-active');},2000); - } - + } + $('.simulate-offline').on('click',function(){isOffline();}) $('.simulate-online').on('click',function(){isOnline();}) - + //Disable links to other pages if offline. //Warning! Enabling offline for iOS can cause issues //To allow offline functionality delete the next 7 lines @@ -226,9 +239,9 @@ $(document).ready(function(){ if(detectHREF.match(/.html/)){ isOffline(); return false; - } - } - + } + } + //Check if Online / Offline function updateOnlineStatus(event) { var condition = navigator.onLine ? "online" : "offline"; @@ -243,10 +256,10 @@ $(document).ready(function(){ } window.addEventListener('online', updateOnlineStatus); window.addEventListener('offline', updateOfflineStatus); - - + + if(pwaNoCache == true){ - caches.delete('workbox-runtime').then(function() { + caches.delete('workbox-runtime').then(function() { }); localStorage.clear(); sessionStorage.clear() @@ -256,6 +269,6 @@ $(document).ready(function(){ }); }); } - - -}); \ No newline at end of file + + +}); From 760c05286e603556847f0cd4b94d1f792ba2b490 Mon Sep 17 00:00:00 2001 From: ostertun Date: Fri, 2 Oct 2020 19:26:03 +0200 Subject: [PATCH 04/11] RA-#22 Added planning incl setState --- client/styles/regatten.css | 2 +- server/content/planning.php | 64 +++-- server/scripts/onRegattaClicked.js | 41 ++-- server/scripts/planning.js | 312 +++++++++++++++++++++++++ server/templates/menu/item-switch.html | 8 + 5 files changed, 395 insertions(+), 32 deletions(-) create mode 100644 server/scripts/planning.js create mode 100644 server/templates/menu/item-switch.html diff --git a/client/styles/regatten.css b/client/styles/regatten.css index 4f22174..951cde7 100644 --- a/client/styles/regatten.css +++ b/client/styles/regatten.css @@ -194,4 +194,4 @@ blockquote { -ms-animation: fa-blink .75s linear infinite; -o-animation: fa-blink .75s linear infinite; animation: fa-blink .75s linear infinite; -} \ No newline at end of file +} diff --git a/server/content/planning.php b/server/content/planning.php index 85a23df..657f3db 100644 --- a/server/content/planning.php +++ b/server/content/planning.php @@ -1,19 +1,47 @@ load('error', ['404', 'Seite existiert noch nicht']); - $content .= '

'; - $content .= 'Die gesuchte Seite ist leider noch nicht verfügbar.
'; - $content .= 'Wir arbeiten daran, sie schnellstmöglich zur Verfügung zu stellen.
'; - $content .= 'Wie wäre es mit der Homepage?'; - $content .= '

'; - $content .= $tpl->load('button', ['Zur Startseite', LINK_PRE . 'index', 'css-class' => 'mb-3']); - $content .= $tpl->load('button', ['Kontakt', LINK_PRE . 'contact']); - - $sp['output'] = $tpl->load('card', [$content, 'css-class' => 'text-center pt-3']); - -?> \ No newline at end of file + + $sp['title'] = 'Saison-Planung - Regatten.net ' . $_CLASS['name']; + $sp['backbutton'] = 'index'; + $sp['activenav'] = 5; + + // Title + $content = '

Saison-Planung

'; + $content .= '

Hinweis: Diese Seite kannst nur Du sehen.
Wenn Du Deine Saison-Planung teilen möchtest, klicke hier

'; + $content .= $tpl->load('select', ['html-id' => 'select-year', 'placeholder' => 'Jahr', 'css-class' => 'mt-3 mb-0']); + + $sp['output'] .= $tpl->load('card', [$content, 'css-class' => 'show-loggedin']); + + // Not loggedin + $content = '

Saison-Planung

'; + $content .= '

Um Deine Saison-Planung zu sehen, musst Du angemeldet sein.
Melde Dich hier an oder registriere Dich jetzt kostenlos.

'; + + $sp['output'] .= $tpl->load('card', [$content, 'css-class' => 'show-notloggedin']); + + // Regattas + $content = '

'; + $content .= $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text', 'css-class' => 'mt-2']); + $content .= '
'; + + $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-regattas', 'css-class' => 'show-loggedin']); + + // Menu + $items = ''; + $items .= $tpl->load('menu/item-icon', ['Status bearbeiten', '#', 'html-id' => 'menu-item-status', 'icon' => 'fa-edit']); + $items .= $tpl->load('menu/item-icon', ['Saison-Planungen', '', 'html-id' => 'menu-item-plannings', 'icon' => 'fa-calendar-alt']); + $items .= $tpl->load('menu/item-icon', ['Ergebnisse', '', 'html-id' => 'menu-item-results', 'icon' => 'fa-poll']); + $items .= $tpl->load('menu/item-icon', ['Bericht', '', 'html-id' => 'menu-item-bericht', 'icon' => 'fa-book']); + $items .= $tpl->load('menu/item-icon', ['Informationen', '', 'html-id' => 'menu-item-info', 'icon' => 'fa-info']); + $items .= $tpl->load('menu/item-icon-badge', ['Meldung', '', 'html-id' => 'menu-item-meldung', 'icon' => 'fa-file-signature', 'badge-id' => 'badge-regatta-meldung']); + $items .= $tpl->load('menu/item-icon', ['offizielle Ergebnisse', '', 'html-id' => 'menu-item-oresults', 'icon' => 'fa-poll']); + $items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe']); + $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-regatta', 'title' => 'Regatta-Details', 'height' => 320]); + + // Menu Edit status + $items = $tpl->load('menu/item-switch', ['Gemeldet', 'html-id' => 'switch-status-gemeldet', 'icon' => 'fa-file-signature']); + $items .= $tpl->load('menu/item-switch', ['Bezahlt', 'html-id' => 'switch-status-bezahlt', 'icon' => 'fa-euro-sign', 'css-class' => 'border-0']); + $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-status', 'title' => 'Status bearbeiten', 'height' => 220]); + + $sp['scripts'] .= $scripts->load('onRegattaClicked'); + $sp['scripts'] .= $scripts->load('planning'); + +?> diff --git a/server/scripts/onRegattaClicked.js b/server/scripts/onRegattaClicked.js index 0c7dd64..af713a4 100644 --- a/server/scripts/onRegattaClicked.js +++ b/server/scripts/onRegattaClicked.js @@ -1,11 +1,11 @@ async function onRegattaClicked(id) { var regatta = await dbGetData('regattas', id); - + $('#menu-regatta').find('.menu-title').find('p').text(regatta.name); - + var dateTo = parseDate(regatta['date']); dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0)); - + var plannings = await dbGetDataIndex('plannings', 'regatta', regatta['id']); var planning = null; if (isLoggedIn()) { @@ -16,7 +16,7 @@ async function onRegattaClicked(id) { } } } - + // Your Planning if (planning != null) { $('#menu-item-yourplanning').show(); @@ -32,11 +32,26 @@ async function onRegattaClicked(id) { crew.push(sailor.name); } } + var status = ''; + if (planning.gemeldet == '1') status = 'gemeldet'; + if (planning.bezahlt == '1') { + if (status != '') status += ' und '; + status += 'bezahlt'; + } + if (status != '') crew.push('' + status + ''); $('#menu-item-yourplanning').html(crew.join('
')); } else { $('#menu-item-yourplanning').hide(); } - + + // Planning: Edit Status + if ((planning != null) && (typeof planningEditStatus === 'function')) { + $('#menu-item-status').show(); + $('#menu-item-status').attr('onclick', 'planningEditStatus(' + regatta['id'] + ')'); + } else { + $('#menu-item-status').hide(); + } + // Planning if ((plannings.length > 0) && (dateTo >= today)) { $('#menu-item-plannings').show(); @@ -44,7 +59,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-plannings').hide(); } - + // Results var results = await dbGetDataIndex('results', 'regatta', regatta['id']); if (results.length > 0) { @@ -53,7 +68,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-results').hide(); } - + // Bericht if (regatta['bericht'] != '') { $('#menu-item-bericht').show(); @@ -62,7 +77,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-bericht').hide(); } - + // Info if (regatta['info'] != '') { $('#menu-item-info').show(); @@ -71,7 +86,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-info').hide(); } - + // Meldung if ((regatta['meldung'] != '') && (dateTo >= today)) { $('#menu-item-meldung').show(); @@ -129,7 +144,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-meldung').hide(); } - + // off. results if (regatta['oresults'] != '') { $('#menu-item-oresults').show(); @@ -138,7 +153,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-oresults').hide(); } - + // club website var clubwebsite = ''; if (regatta['club'] != null) { @@ -151,7 +166,7 @@ async function onRegattaClicked(id) { } else { $('#menu-item-clubwebsite').hide(); } - + $('#menu-regatta').showMenu(); $('#menu-regatta').scrollTop(0); -} \ No newline at end of file +} diff --git a/server/scripts/planning.js b/server/scripts/planning.js new file mode 100644 index 0000000..a109b34 --- /dev/null +++ b/server/scripts/planning.js @@ -0,0 +1,312 @@ +async function planningSwitchChanged() { + showLoader(); + var id = $('#switch-status-gemeldet').data('regatta'); + var gemeldet = $('#switch-status-gemeldet').prop('checked'); + var bezahlt = $('#switch-status-bezahlt').prop('checked'); + var auth = { + id: localStorage.getItem('auth_id'), + hash: localStorage.getItem('auth_hash') + } + $.ajax({ + url: QUERY_URL + 'planning_set_state', + method: 'POST', + data: { + auth: auth, + regatta: id, + gemeldet: gemeldet, + bezahlt: bezahlt + }, + error: function (xhr, status, error) { + if (xhr.status == 401) { + console.log('authentification failed'); + toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); + } else if (xhr.status == 0) { + toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um den Status zu ändern'); + } else { + console.log('Login: unbekannter Fehler', status, error); + console.log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + $('#menu-status').hideMenu(); + hideLoader(); + }, + success: function (data, status, xhr) { + sync(); + hideLoader(); + } + }); + console.log(id, gemeldet, bezahlt); + hideLoader(); +} + +async function planningEditStatus(id) { + $('#menu-regatta').hideMenu(); + + var regatta = await dbGetData('regattas', id); + + $('#menu-status').find('.menu-title').find('p').text(regatta.name); + + var plannings = await dbGetDataIndex('plannings', 'regatta', regatta['id']); + var planning = null; + if (isLoggedIn()) { + for (i in plannings) { + if (plannings[i]['user'] == USER_ID) { + planning = plannings[i]; + break; + } + } + } + + if (planning !== null) { + $('#switch-status-gemeldet').data('regatta', id); + $('#switch-status-gemeldet').prop('checked', planning.gemeldet == '1'); + $('#switch-status-bezahlt').prop('checked', planning.bezahlt == '1'); + $('#menu-status').showMenu(); + } +} + +function selectChange() { + var val = $('#select-year').val(); + + if (typeof siteScript === 'function') { + history.replaceState(null, '', '?year=' + val); + siteScript(); + } +} + +function initYear() { + var year = findGetParameter('year'); + if (year === null) year = new Date().getFullYear(); + + $('#select-year').html(''); + $('#select-year').val(year); +} + +var firstCall = true; +var rows = []; +var today; + +async function drawList () { + window.setTimeout(function () { + var list = ''; + rows.forEach(function (entry) { + if (entry == null) { + list += '
Heute ist der ' + formatDate('d.m.Y', today) + '
'; + } else if (search($('#input-search').val(), entry.keywords)) { + list += entry.content; + } + }); + $('#div-regattas').html(list); + }, 0); +} + +var siteScript = async function() { + if (!isLoggedIn()) { + hideLoader(); + return; + } + + if (firstCall) { + firstCall = false; + initYear(); + $('#select-year').change(selectChange); + $('#input-search').on('input', drawList); + $('#switch-status-gemeldet').parent().parent().click(planningSwitchChanged); + $('#switch-status-bezahlt').parent().parent().click(planningSwitchChanged); + } + + today = getToday(); + + var selectedYear = $('#select-year').val(); + var minDate = parseDate(selectedYear + '-01-01'); + var maxDate = parseDate(selectedYear + '-12-31'); + var regattas = await dbGetRegattasRange(minDate, maxDate); + var plannings = await dbGetDataIndex('plannings', 'user', USER_ID); + for (var i = regattas.length - 1; i >= 0; i --) { + var entry = regattas[i]; + var okay = false; + for (p in plannings) { + if (plannings[p].regatta == entry.id) { + regattas[i].planning = plannings[p]; + okay = true; + break; + } + } + if (!okay) { + regattas.splice(i, 1); + } + } + var regattaResults = []; + for (id in regattas) { + var entry = regattas[id]; + var results = await dbGetDataIndex('results', 'regatta', entry['id']); + regattaResults[entry['id']] = (results.length > 0); + } + + var years = await dbGetData('years'); + years.sort(function (a, b) { + if (a['year'] > b['year']) return -1; + if (a['year'] < b['year']) return 1; + return 0; + }); + var options = ''; + for (id in years) { + var year = years[id]['year']; + options += ''; + } + $('#select-year').html(options); + $('#select-year').val(selectedYear); + + var count = regattas.length; + if (count > 0) { + if (count == 1) { + $('#p-count').html('Es wurde 1 Regatta gefunden!'); + } else { + $('#p-count').html('Es wurden ' + count + ' Regatten gefunden!'); + } + $('#div-regattas').show(); + $('#input-search').parent().show(); + + var heute = false; + + rows = []; + + for (id in regattas) { + var entry = regattas[id]; + var club = null; + if (entry['club'] != null) + club = await dbGetData('clubs', entry['club']); + if (entry.planning.steuermann !== null) { + entry.planning.steuermann = (await dbGetData('sailors', entry.planning.steuermann)).name; + } + var crewString = entry.planning.crew.split(','); + entry.planning.crew = []; + for (c in crewString) { + var sailor = await dbGetData('sailors', crewString[c]); + if (sailor !== null) { + entry.planning.crew.push(sailor.name); + } + } + + var dateFrom = entry['dateFrom']; + var dateTo = entry['dateTo']; + + var row = { keywords: [], content: '' }; + row.keywords.push(entry['name']); + if (entry['number'] != null) row.keywords.push(entry['number']); + if (club != null) row.keywords.push(club['kurz'], club['name']); + if (entry.planning.steuermann != null) row.keywords.push(entry.planning.steuermann); + for (c in entry.planning.crew) row.keywords.push(entry.planning.crew[c]); + + if (!heute && (today <= dateFrom)) { + rows.push(null); + heute = true; + } + + row.content += '
'; + + // ZEILE 1 + // Name + row.content += '
' + (entry['canceled'] == 1 ? '' : '') + entry['name'] + (entry['canceled'] == 1 ? '' : '') + '
'; + + // ZEILE 2 + row.content += '
'; + + // Number + row.content += '
' + ((entry['number'] != null) ? ('# ' + entry['number']) : '') + '
'; + + // Club + row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; + + // Special + row.content += '
' + entry['special'] + '
'; + + // Icons + var icons = []; + if ((entry['meldung'] != '') && (dateTo >= today) && (entry['meldungOffen'] == '1') && (entry.planning.gemeldet != '1')) { + var color = ''; + var planning = null; + if (isLoggedIn()) { + var plannings = await dbGetDataIndex('plannings', 'regatta', entry['id']); + for (id in plannings) { + if (plannings[id]['user'] == USER_ID) { + planning = plannings[id]; + break; + } + } + } + if (entry['meldungSchluss'] != null) { + if ((planning == null) || (planning['gemeldet'] == '0')) { + var ms = 0; + if (entry['meldungEarly'] != null) { + ms = parseDate(entry['meldungEarly']); + } + if (ms < today) { + ms = parseDate(entry['meldungSchluss']); + } + var diff = Math.round((ms - today) / 86400000); + if (ms < today) { + color = ' color-red2-dark'; + } else if (diff < 7) { + color = ' color-yellow2-dark'; + } + } + } + if ((planning != null) && (planning['gemeldet'] == '0')) { + color += ' fa-blink'; + } + icons.push(''); + } + if (entry['bericht'] != '') + icons.push(''); + if (entry['canceled'] == '1') { + icons.push(''); + } else if (regattaResults[entry['id']]) { + icons.push(''); + } + if (entry.planning.gemeldet == '1') { + icons.push(''); + } + if (entry.planning.bezahlt == '1') { + icons.push(''); + } + row.content += '
' + icons.join(' ') + '
'; + + row.content += '
'; + + // ZEILE 3 + row.content += '
'; + + // Date + if (entry['length'] < 1) { + if (formatDate('d.m', dateFrom) == '01.01') { + row.content += '
Datum noch unklar
'; + } else { + row.content += '
' + formatDate("d.m.Y", dateFrom) + ' - Datum nicht final
'; + } + } else { + row.content += '
' + formatDate("d.m.Y", dateFrom) + ' - ' + formatDate("d.m.Y", dateTo) + '
'; + } + + // RLF + row.content += '
' + parseFloat(entry['rlf']).toFixed(2) + '
'; + + row.content += '
'; + + rows.push(row); + } + + if (!heute) { + rows.push(null); + } + + drawList(); + + } else { + $('#p-count').html('Du hast noch keine Regatten in Deiner Saison-Planung!'); + $('#div-regattas').hide(); + $('#input-search').parent().hide(); + } + + hideLoader(); +} diff --git a/server/templates/menu/item-switch.html b/server/templates/menu/item-switch.html new file mode 100644 index 0000000..5a9d966 --- /dev/null +++ b/server/templates/menu/item-switch.html @@ -0,0 +1,8 @@ + + + $$0; +
+ + +
+
From eaa08ba3015fcf14006deba8524ddbe64e3ea451 Mon Sep 17 00:00:00 2001 From: ostertun Date: Mon, 5 Oct 2020 11:53:54 +0200 Subject: [PATCH 05/11] Custom log function => log current time --- client/scripts/custom.js.php | 274 ++++++++++++++++---------------- client/scripts/database.js | 82 +++++----- client/scripts/mobileconsole.js | 47 +++++- client/scripts/pwa.js.php | 28 ++-- client/scripts/regatten.js.php | 45 ++++-- server/scripts/boats.js | 52 +++--- server/scripts/contact.js | 4 +- server/scripts/sailors.js | 52 +++--- 8 files changed, 313 insertions(+), 271 deletions(-) diff --git a/client/scripts/custom.js.php b/client/scripts/custom.js.php index 51efae7..308f4a4 100644 --- a/client/scripts/custom.js.php +++ b/client/scripts/custom.js.php @@ -1,9 +1,9 @@ var loaderCount = 2; @@ -29,17 +29,17 @@ $(window).on('load',function(){ $(document).ready(function(){ 'use strict' - + var isAJAX = false; //Enables or disable AJAX page transitions and loading. var isDevelopment = false; // Enables development mode. Clean cache & Stops BG & Highlights from changing defaults. - + function init_template(){ - + //ADD YOUR CUSTOM JAVASCRIPT CODES HERE! //Do not put inside HTML files. //The init_template() function will be triggered when pages open. - - + + //Generating Dynamic Styles to decrease CSS size and execute faster loading times. var colorsArray = [ //colors must be in HEX format. @@ -93,24 +93,24 @@ $(document).ready(function(){ ["skype","#12A5F4"], ["instagram","#e1306c"] ]; - - + + //Back Button Scroll Stop //if ('scrollRestoration' in history) {history.scrollRestoration = 'manual';} - + //Disable Page Jump on Empty Links. $('a').on('click', function(){var attrs = $(this).attr('href'); if(attrs === '#'){return false;}}); - + //Adding Background for Gradient if(!$('.menu-hider').length){$('#page').append('