Added page regattas

This commit is contained in:
Timon Ostertun
2020-09-23 13:23:34 +02:00
parent f37f22c57f
commit 76878ed14d
11 changed files with 327 additions and 5 deletions

View File

@@ -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(){

View File

@@ -298,8 +298,9 @@ async function runPageScript() {
if (typeof siteScript === 'function') {
siteScript();
}
} else {
hideLoader();
}
}
function sync() {

View File

@@ -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,7 +245,9 @@ var initRegatten = function() {
if (isLoggedIn()) {
$('.show-loggedin').show();
$('.show-notloggedin').hide();
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();

View File

@@ -1,5 +1,8 @@
<?php
$sp['title'] = 'Fehler 404 - Regatten.net Pirat';
$sp['backbutton'] = true;
$content = $tpl->load('error', ['404', 'Seite nicht gefunden']);
$content .= '<p>';
$content .= 'Die gesuchte Seite wurde nicht gefunden.<br>';

View File

@@ -1,5 +1,8 @@
<?php
$sp['title'] = 'Startseite - Regatten.net Pirat';
$sp['activenav'] = 1;
// Title
$content = "<h1>$_CLASS[name]</h1>";
$content .= "<p>$_CLASS[desc]</p>";
@@ -68,6 +71,6 @@
$sp['output'] .= $tpl->load('card', [$content]);
$sp['scripts'] = '<!-- DEBUG -->' . $scripts->load('index');
$sp['scripts'] = $scripts->load('index');
?>

32
content/regattas.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
$sp['title'] = 'Regatten - Regatten.net Pirat';
$sp['backbutton'] = 'index';
$sp['activenav'] = 2;
// Title, Inputs
$content = "<h1>Regatten</h1>";
$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 = '<p id="p-count" class="mb-0"></p>';
$content .= $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text', 'css-class' => 'mt-2']);
$thead = '<tr><th id="th-number">#</th><th>Datum</th><th>Regatta</th>';
if (($showSpecial = $_CLASS['special']) !== false) {
$thead .= '<th>' . $_CLASS['special'] . '</th>';
}
$thead .= '<th>Informationen</th><th>Ergebnisse</th><th>RLF</th></tr>';
$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'] = '<script>const showSpecial = ' . ($showSpecial ? 'true' : 'false') . ';</script>';
$sp['scripts'] .= $scripts->load('regattas');
?>

View File

@@ -320,4 +320,6 @@ var siteScript = async function() {
$('#table-last').hide();
$('#p-last').show();
}
hideLoader();
}

250
server/scripts/regattas.js Normal file
View File

@@ -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('<option value="' + year + '">' + year + '</option>');
$('#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 += '<tr><td colspan="' + heuteLen + '" class="bg-highlight color-white">';
tbody += 'Heute ist der ' + formatDate('d.m.Y', today);
tbody += '</td></tr>';
} else if (search($('#input-search').val(), entry.keywords)) {
tbody += '<tr>';
entry.cells.forEach(function (cell) {
tbody += '<td>' + cell + '</td>';
});
tbody += '</tr>';
}
});
$('#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 = '<option value="user">Benutzerdefiniert</option>';
for (id in years) {
var year = years[id]['year'];
options += '<option value="' + year + '">' + year + '</option>';
}
$('#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 ? ('<span style="white-space:nowrap;">' + entry['number'] + '</span>') : '');
}
row.cells.push('<span style="white-space:nowrap;">' + formatDate("j. M 'y", dateFrom) + '<br>' + formatDate("j. M 'y", dateTo) + '</span>');
var content = '';
if (club != null) {
content = club['kurz'];
if (club['website'] != '') {
content = '<a href="' + club['website'] + '" target="_blank">' + content + '</a>';
}
}
row.cells.push(content + '<br>' + (entry['canceled'] == 1 ? '<s>' : '') + entry['name']) + (entry['canceled'] == 1 ? '</s>' : '');
if (showSpecial) {
row.cells.push('<span style="white-space:nowrap;">' + entry['special'] + '</span>');
}
var buf = '';
if (entry['info'] != '') {
buf += '<a target="_blank" href="' + entry['info'] + '">Informationen</a>';
}
if ((entry['meldung'] != '') && (dateTo >= today)) {
buf += '<br><a target="_blank" href="' + entry['meldung'] + '">Meldung</a>';
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 += ' <i>(du hast gemeldet)</i>';
} else if (entry['meldungOffen'] == "0") {
buf += ' <i>(geschlossen)</i>';
} 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 += ' <i>' + (red ? '<b><font style="color:red;">(' : '(') + txt + (early ? ' verg&uuml;nstigt' : '') + (red ? ')</font></b>' : ')') + '</i>';
} else {
buf += ' <i>(Meldeschluss abgelaufen)</i>';
}
}
}
if (entry['bericht'] != '') {
buf += '<br><a target="_blank" href="' + entry['bericht'] + '">Bericht</a>';
}
if (entry['oresults'] != '') {
buf += '<br><a target="_blank" href="' + entry['oresults'] + '">off. Ergebnisse</a>';
}
row.cells.push(buf);
buf = '';
if (entry['canceled'] == "1") {
buf = '<i style="color:red;" class="fas fa-times"></i> Ausgefallen</td>';
} else {
if (regattaResults[entry['id']]) {
buf = '<i style="color:green;" class="fas fa-check"></i> <a href="' + LINK_PRE + 'result?regatta=' + entry['id'] + '">Ergebnisse</a></td>';
} else {
var pC = plannings.length;
buf = '<i class="fas fa-calendar-alt"></i> In der Saison-Planung von ' + pC + ' Seglern.';
if (pC > 0) {
buf += '<br><a href="' + LINK_PRE + 'regatta_plan?regatta=' + entry['id'] + '">Ansehen</a>';
}
}
}
row.cells.push(buf);
row.cells.push('<span style="white-space:nowrap;">' + parseFloat(entry['rlf']).toFixed(2) + '</span>');
rows.push(row);
}
if (!heute) {
rows.push(null);
}
drawTable();
} else {
$('#p-count').html('Keine Regatten gefunden!');
$('#table-regattas').hide();
$('#input-search').hide();
}
hideLoader();
}

View File

@@ -0,0 +1,4 @@
<div class="input-style input-style-1 input-required">
<span class="color-highlight">$$placeholder;</span>
<input id="$$html-id;" class="form-control $$css-class;" type="$$type;" placeholder="$$placeholder;" value="$$value;" />
</div>

View File

@@ -0,0 +1,6 @@
<div class="input-style input-style-1 input-required">
<span class="color-highlight input-style-1-active">$$placeholder;</span>
<select id="$$html-id;" class="form-control $$css-class;">
$$options;
</select>
</div>

View File

@@ -0,0 +1,4 @@
<div class="input-style input-style-1 input-required">
<span class="color-highlight">$$placeholder;</span>
<textarea id="$$html-id;" class="form-control $$css-class;" placeholder="$$placeholder;">$$value;</textarea>
</div>