From 76878ed14dd28968f3ae6b6ece8b4810531226a0 Mon Sep 17 00:00:00 2001 From: Timon Ostertun Date: Wed, 23 Sep 2020 13:23:34 +0200 Subject: [PATCH] Added page regattas --- client/scripts/custom.js.php | 2 +- client/scripts/database.js | 3 +- client/scripts/regatten.js.php | 21 ++- content/404.php | 3 + content/index.php | 5 +- content/regattas.php | 32 +++++ server/scripts/index.js | 2 + server/scripts/regattas.js | 250 +++++++++++++++++++++++++++++++++ server/templates/input.html | 4 + server/templates/select.html | 6 + server/templates/textarea.html | 4 + 11 files changed, 327 insertions(+), 5 deletions(-) create mode 100644 content/regattas.php create mode 100644 server/scripts/regattas.js create mode 100644 server/templates/input.html create mode 100644 server/templates/select.html create mode 100644 server/templates/textarea.html diff --git a/client/scripts/custom.js.php b/client/scripts/custom.js.php index 61eb389..d88da26 100644 --- a/client/scripts/custom.js.php +++ b/client/scripts/custom.js.php @@ -30,7 +30,7 @@ $(window).on('load',function(){ $(document).ready(function(){ 'use strict' - var isAJAX = true; //Enables or disable AJAX page transitions and loading. + 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(){ diff --git a/client/scripts/database.js b/client/scripts/database.js index 4bd023a..ba7a4b3 100644 --- a/client/scripts/database.js +++ b/client/scripts/database.js @@ -298,8 +298,9 @@ async function runPageScript() { if (typeof siteScript === 'function') { siteScript(); + } else { + hideLoader(); } - hideLoader(); } function sync() { diff --git a/client/scripts/regatten.js.php b/client/scripts/regatten.js.php index f213d84..fc3aa66 100644 --- a/client/scripts/regatten.js.php +++ b/client/scripts/regatten.js.php @@ -100,6 +100,21 @@ var toastWarn = function (text, time = 3000) { return makeToast('bg-yellow1-dar var toastInfo = function (text, time = 3000) { return makeToast('bg-blue2-dark', 'fa-info', text, time); } var toastError = function (text, time = 3000) { return makeToast('bg-red2-dark', 'fa-times', text, time); } +function findGetParameter(parameterName) { + var result = null; + var tmp = []; + location.search + .substr(1) + .split("&") + .forEach(function (item) { + tmp = item.split("="); + if (tmp[0] === parameterName) { + result = decodeURIComponent(tmp[1]); + } + }); + return result; +} + var login = function() { showLoader(); var username = $('#input-login-username').val(); @@ -230,8 +245,10 @@ var initRegatten = function() { if (isLoggedIn()) { $('.show-loggedin').show(); $('.show-notloggedin').hide(); - $('.replace-userid-href').attr('href', $('.replace-userid-href').attr('href').replace('%USERID%', USER_ID)); - $('.replace-username').html(USER_NAME); + if ($('.replace-userid-href').length > 0) + $('.replace-userid-href').attr('href', $('.replace-userid-href').attr('href').replace('%USERID%', USER_ID)); + if ($('.replace-username').length > 0) + $('.replace-username').html(USER_NAME); } else { $('.show-loggedin').hide(); $('.show-notloggedin').show(); diff --git a/content/404.php b/content/404.php index 8a1cc69..47e5e75 100644 --- a/content/404.php +++ b/content/404.php @@ -1,5 +1,8 @@ load('error', ['404', 'Seite nicht gefunden']); $content .= '

'; $content .= 'Die gesuchte Seite wurde nicht gefunden.
'; diff --git a/content/index.php b/content/index.php index 3b4130a..7fd163a 100644 --- a/content/index.php +++ b/content/index.php @@ -1,5 +1,8 @@ $_CLASS[name]"; $content .= "

$_CLASS[desc]

"; @@ -68,6 +71,6 @@ $sp['output'] .= $tpl->load('card', [$content]); - $sp['scripts'] = '' . $scripts->load('index'); + $sp['scripts'] = $scripts->load('index'); ?> \ No newline at end of file diff --git a/content/regattas.php b/content/regattas.php new file mode 100644 index 0000000..0cfad75 --- /dev/null +++ b/content/regattas.php @@ -0,0 +1,32 @@ +Regatten"; + + $content .= $tpl->load('select', ['html-id' => 'select-year', 'placeholder' => 'Jahr', 'css-class' => 'mt-3 mb-0']); + $content .= $tpl->load('input', ['html-id' => 'input-from', 'placeholder' => 'Von', 'type' => 'date', 'css-class' => 'mt-3']); + $content .= $tpl->load('input', ['html-id' => 'input-to', 'placeholder' => 'Bis', 'type' => 'date']); + $content .= $tpl->load('button', ['Anzeigen', '#', 'html-id' => 'button-show']); + + $sp['output'] .= $tpl->load('card', [$content]); + + // Regattas + $content = '

'; + $content .= $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text', 'css-class' => 'mt-2']); + $thead = '#DatumRegatta'; + if (($showSpecial = $_CLASS['special']) !== false) { + $thead .= '' . $_CLASS['special'] . ''; + } + $thead .= 'InformationenErgebnisseRLF'; + $content .= $tpl->load('table', [$thead, 'html-id' => 'table-regattas', 'css-class' => 'mb-0']); + + $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-regattas']); + + $sp['scripts'] = ''; + $sp['scripts'] .= $scripts->load('regattas'); + +?> \ No newline at end of file diff --git a/server/scripts/index.js b/server/scripts/index.js index 8691a02..3fbe39e 100644 --- a/server/scripts/index.js +++ b/server/scripts/index.js @@ -320,4 +320,6 @@ var siteScript = async function() { $('#table-last').hide(); $('#p-last').show(); } + + hideLoader(); } \ No newline at end of file diff --git a/server/scripts/regattas.js b/server/scripts/regattas.js new file mode 100644 index 0000000..26bf482 --- /dev/null +++ b/server/scripts/regattas.js @@ -0,0 +1,250 @@ +function selectChange(callSiteScript = true) { + var val = $('#select-year').val(); + if (val == "user") { + $('#input-from').show(); + $('#input-to').show(); + $('#button-show').show(); + } else { + $('#input-from').hide(); + $('#input-to').hide(); + $('#button-show').hide(); + + $('#input-from').val(val + '-01-01'); + $('#input-to').val(val + '-12-31'); + + if (callSiteScript && (typeof siteScript === 'function')) + siteScript(); + } +} + +function initYear() { + var year = findGetParameter('year'); + if (year === null) year = new Date().getFullYear(); + + $('#select-year').html(''); + $('#select-year').val(year); + + selectChange(false); +} + +var firstCall = true; +var rows = []; +var heuteLen = 0; +var today; + +async function drawTable () { + //setLoading(true, 'loading'); + + window.setTimeout(function () { + tbody = ''; + rows.forEach(function (entry) { + if (entry == null) { + tbody += ''; + tbody += 'Heute ist der ' + formatDate('d.m.Y', today); + tbody += ''; + } else if (search($('#input-search').val(), entry.keywords)) { + tbody += ''; + entry.cells.forEach(function (cell) { + tbody += '' + cell + ''; + }); + tbody += ''; + } + }); + $('#table-regattas').find('tbody').html(tbody); + + //setLoading(false, 'loading'); + }, 0); +} + +var siteScript = async function() { + if (firstCall) { + firstCall = false; + initYear(); + $('#select-year').change(selectChange); + $('#button-show').click(siteScript); + $('#input-search').on('input', drawTable); + } + + today = getToday(); + + var minDate = parseDate($('#input-from').val()); + var maxDate = parseDate($('#input-to').val()); + var regattas = await dbGetRegattasRange(minDate, maxDate); + var regattaResults = []; + var showNumbers = false; + for (id in regattas) { + var entry = regattas[id]; + var results = await dbGetDataIndex('results', 'regatta', entry['id']); + regattaResults[entry['id']] = (results.length > 0); + if (entry['number'] != null) + showNumbers = true; + } + + var selectedYear = $('#select-year').val(); + + 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!'); + } + $('#table-regattas').show(); + $('#input-search').show(); + if (showNumbers) { + $('#th-number').show(); + } else { + $('#th-number').hide(); + } + + var heute = false; + heuteLen = 5; + if (showNumbers) heuteLen ++; + if (showSpecial) heuteLen ++; + + rows = []; + + for (id in regattas) { + var entry = regattas[id]; + var club = null; + if (entry['club'] != null) + club = await dbGetData('clubs', entry['club']); + var plannings = await dbGetDataIndex('plannings', 'regatta', entry['id']); + + var dateFrom = entry['dateFrom']; + var dateTo = entry['dateTo']; + + var row = { keywords: [], cells: [] }; + 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 (!heute && (today <= dateFrom)) { + rows.push(null); + heute = true; + } + + if (showNumbers) { + row.cells.push(entry['number'] != null ? ('' + entry['number'] + '') : ''); + } + + row.cells.push('' + formatDate("j. M 'y", dateFrom) + '
' + formatDate("j. M 'y", dateTo) + '
'); + + var content = ''; + if (club != null) { + content = club['kurz']; + if (club['website'] != '') { + content = '' + content + ''; + } + } + row.cells.push(content + '
' + (entry['canceled'] == 1 ? '' : '') + entry['name']) + (entry['canceled'] == 1 ? '' : ''); + + if (showSpecial) { + row.cells.push('' + entry['special'] + ''); + } + + var buf = ''; + if (entry['info'] != '') { + buf += 'Informationen'; + } + if ((entry['meldung'] != '') && (dateTo >= today)) { + buf += '
Meldung'; + var planning = null; + if (isLoggedIn()) { + for (id in plannings) { + if (plannings[id]['user'] == USER_ID) { + planning = plannings[id]; + break; + } + } + } + + if ((planning != null) && (planning['gemeldet'] == "1")) { + buf += ' (du hast gemeldet)'; + } else if (entry['meldungOffen'] == "0") { + buf += ' (geschlossen)'; + } else if (entry['meldungSchluss'] != null) { + early = false; + if (entry['meldungEarly'] != null) { + ms = parseDate(entry['meldungEarly']); + if (ms >= today) { + early = true; + } + } + if (!early) + ms = parseDate(entry['meldungSchluss']); + if (ms >= today) { + diff = Math.round((ms - today) / 86400000); + red = (diff < 7); + if (diff <= 14) { + txt = 'noch ' + diff + ' Tag' + (diff != 1 ? 'e' : ''); + } else if (diff < 35) { + diff = Math.floor(diff / 7); + txt = 'noch ' + diff + ' Woche' + (diff != 1 ? 'n' : ''); + } else { + diff = Math.floor(diff / 30.5); + txt = 'noch ' + diff + ' Monat' + (diff != 1 ? 'e' : ''); + } + buf += ' ' + (red ? '(' : '(') + txt + (early ? ' vergünstigt' : '') + (red ? ')' : ')') + ''; + } else { + buf += ' (Meldeschluss abgelaufen)'; + } + } + } + if (entry['bericht'] != '') { + buf += '
Bericht'; + } + if (entry['oresults'] != '') { + buf += '
off. Ergebnisse'; + } + row.cells.push(buf); + + buf = ''; + if (entry['canceled'] == "1") { + buf = ' Ausgefallen'; + } else { + if (regattaResults[entry['id']]) { + buf = ' Ergebnisse'; + } else { + var pC = plannings.length; + buf = ' In der Saison-Planung von ' + pC + ' Seglern.'; + if (pC > 0) { + buf += '
Ansehen'; + } + } + } + row.cells.push(buf); + + row.cells.push('' + parseFloat(entry['rlf']).toFixed(2) + ''); + + rows.push(row); + } + + if (!heute) { + rows.push(null); + } + + drawTable(); + + } else { + $('#p-count').html('Keine Regatten gefunden!'); + $('#table-regattas').hide(); + $('#input-search').hide(); + } + + hideLoader(); +} \ No newline at end of file diff --git a/server/templates/input.html b/server/templates/input.html new file mode 100644 index 0000000..14302d2 --- /dev/null +++ b/server/templates/input.html @@ -0,0 +1,4 @@ +
+ $$placeholder; + +
\ No newline at end of file diff --git a/server/templates/select.html b/server/templates/select.html new file mode 100644 index 0000000..816ec58 --- /dev/null +++ b/server/templates/select.html @@ -0,0 +1,6 @@ +
+ $$placeholder; + +
\ No newline at end of file diff --git a/server/templates/textarea.html b/server/templates/textarea.html new file mode 100644 index 0000000..d3fd3ae --- /dev/null +++ b/server/templates/textarea.html @@ -0,0 +1,4 @@ +
+ $$placeholder; + +
\ No newline at end of file