diff --git a/client/scripts/database.js b/client/scripts/database.js index 88c1219..627eace 100644 --- a/client/scripts/database.js +++ b/client/scripts/database.js @@ -1,4 +1,4 @@ -const DB_VERSION = 6; +const DB_VERSION = 7; const USER_ID = localStorage.getItem('auth_user'); const USER_NAME = localStorage.getItem('auth_username'); @@ -351,7 +351,7 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) { if (sailors[i].german == '0') { sailors.splice(i, 1); } else if (jugend) { - if (((sailors[i].year != null) && (sailors[i].year < (formatDate('Y', maxDate) - YOUTH_AGE))) || + if (((sailors[i].year != null) && (sailors[i].year < (formatDate('Y', maxDate) - (await dbGetClassProp('youth-age'))))) || ((sailors[i].year == null) && (jugstrict))) { sailors.splice(i, 1); } @@ -417,6 +417,27 @@ function dbSettingsSet(key, value) { } } +function dbGetClassProp(key) { + return new Promise(function(resolve) { + if (canUseLocalDB) { + var request = db.transaction('class').objectStore('class').get(key); + request.onsuccess = function (event) { + resolve(typeof request.result != 'undefined' ? request.result.value : null); + } + } else { + getJSON(QUERY_URL + 'get_class_prop?key=' + key, function (code, data) { + if (code == 200) { + resolve(data.value); + } else { + log("[db] Something went wrong (HTTP " + code + ")"); + fail(strings.error_network, 5000); + resolve(null); + } + }); + } + }); +} + async function updateSyncStatus() { var lastSync = await dbGetData('update_times', 'last_sync'); lastSync = new Date(lastSync.time * 1000); @@ -503,7 +524,7 @@ function sync() { localTimes[entry['table']] = entry['time']; }); - syncInProgress = 11; + syncInProgress = 12; var syncOkay = true; log("[db] Sync Start"); $('#i-sync').addClass('fa-spin'); @@ -533,6 +554,24 @@ function sync() { getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) { if (code == 200) { + // CLASS + getJSON(QUERY_URL + 'get_class', function (code, data) { + if (code == 200) { + var os = db.transaction('class', 'readwrite').objectStore('class'); + log(data); + for (key in data) { + os.put({ key: key, value: data[key] }); + } + syncInProgress --; + log('[db] class synced, remaining:', syncInProgress); + } else { + log("[db] class: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('[db] class failed, remaining:', syncInProgress); + } + }); + // CLUBS if (localTimes['clubs'] < serverTimes['clubs']) { getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) { @@ -1065,6 +1104,11 @@ function initDatabase() { osUpdateTimes.add({ table: 'news', time: 0 }); } + if ((oldVersion < 7) && (newVersion >= 7)) { + log('[db] to version 7'); + var osClass = db.createObjectStore('class', { keyPath: 'key' }); + } + // Force resync after db update if (oldVersion >= 1) { var osUpdateTimes = upgradeTransaction.objectStore('update_times'); diff --git a/client/scripts/regatten.js.php b/client/scripts/regatten.js.php index 87484af..3205b33 100644 --- a/client/scripts/regatten.js.php +++ b/client/scripts/regatten.js.php @@ -10,8 +10,6 @@ const QUERY_URL = ''; const BOATCLASS = ''; const LINK_PRE = '/'; -const YOUTH_AGE = ''; -const YOUTH_GERMAN_NAME = ''; const PUSH_SERVER_KEY = ''; var consoleOutput = []; diff --git a/index.php b/index.php index 69f3a2a..517e8c9 100644 --- a/index.php +++ b/index.php @@ -1,13 +1,13 @@ 'Regatten.net ' . $_CLASS['name'], // This is the page title 'backbutton' => false, // Show a back button (true, false, string). If a string is given, the back button is a link to this page. @@ -37,12 +37,12 @@ 'menus' => '', // Additional menus go here 'scripts' => '' // Site specific scripts ]; - + $tpl = new Templates(__DIR__ . '/server/templates/'); $scripts = new Scripts(__DIR__ . '/server/scripts/'); - + require_once(__DIR__ . '/server/content/' . $site . '.php'); - + require_once(__DIR__ . '/server/buildpage.php'); - -?> \ No newline at end of file + +?> diff --git a/server/content/index.php b/server/content/index.php index acd380f..e1a0c6d 100644 --- a/server/content/index.php +++ b/server/content/index.php @@ -80,7 +80,8 @@ $sp['output'] .= $tpl->load('card', [$content]); // Regattas Menu - $items = ''; + $items = ''; + $items .= ''; $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']); diff --git a/server/content/planning.php b/server/content/planning.php index 5f2a026..01ac587 100644 --- a/server/content/planning.php +++ b/server/content/planning.php @@ -27,7 +27,8 @@ $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-regattas', 'css-class' => 'show-loggedin']); // Menu - $items = ''; + $items = ''; + $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']); diff --git a/server/content/planning_view.php b/server/content/planning_view.php index ba8b855..1670a5e 100644 --- a/server/content/planning_view.php +++ b/server/content/planning_view.php @@ -20,7 +20,8 @@ $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-regattas']); // Menu - $items = ''; + $items = ''; + $items .= ''; $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']); diff --git a/server/content/regattas.php b/server/content/regattas.php index 3254a2c..36be855 100644 --- a/server/content/regattas.php +++ b/server/content/regattas.php @@ -1,28 +1,31 @@ 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']); $content .= '
'; - + $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-regattas']); - + + $sp['output'] .= $tpl->load('card', ['

', 'html-id' => 'card-special']); + // Menu - $items = ''; + $items = ''; + $items .= ''; $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']); @@ -31,8 +34,8 @@ $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]); - + $sp['scripts'] .= $scripts->load('onRegattaClicked'); $sp['scripts'] .= $scripts->load('regattas'); - -?> \ No newline at end of file + +?> diff --git a/server/scripts/index.js b/server/scripts/index.js index 438b91e..1477283 100644 --- a/server/scripts/index.js +++ b/server/scripts/index.js @@ -188,6 +188,9 @@ var siteScript = async function() { list += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special + if (regatta.special.substr(0, 1) == '#') { + regatta.special = '* ' + regatta.special.substr(1); + } list += '
' + regatta['special'] + '
'; // Icons @@ -287,6 +290,9 @@ var siteScript = async function() { list += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special + if (regatta.special.substr(0, 1) == '#') { + regatta.special = '* ' + regatta.special.substr(1); + } list += '
' + regatta['special'] + '
'; // Icons @@ -393,6 +399,9 @@ var siteScript = async function() { list += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special + if (regatta.special.substr(0, 1) == '#') { + regatta.special = '* ' + regatta.special.substr(1); + } list += '
' + regatta['special'] + '
'; // Icons diff --git a/server/scripts/onRegattaClicked.js b/server/scripts/onRegattaClicked.js index 9aea702..60fa9ec 100644 --- a/server/scripts/onRegattaClicked.js +++ b/server/scripts/onRegattaClicked.js @@ -6,6 +6,20 @@ async function onRegattaClicked(id) { var dateTo = parseDate(regatta['date']); dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0)); + var specialFields = await dbGetClassProp('special-fields'); + if (specialFields === null) specialFields = {}; + if (regatta.special.substr(0, 1) == '#') { + regatta.special = regatta.special.substr(1); + if (typeof specialFields[regatta.special] !== 'undefined') { + $('#menu-item-special').text(specialFields[regatta.special]); + } else { + $('#menu-item-special').text('ERROR'); + } + $('#menu-item-special').show(); + } else { + $('#menu-item-special').hide(); + } + var plannings = await dbGetDataIndex('plannings', 'regatta', regatta['id']); var planning = null; if (isLoggedIn()) { diff --git a/server/scripts/planning.js b/server/scripts/planning.js index 251a448..c434b0d 100644 --- a/server/scripts/planning.js +++ b/server/scripts/planning.js @@ -214,6 +214,9 @@ var siteScript = async function() { row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special + if (entry.special.substr(0, 1) == '#') { + entry.special = '* ' + entry.special.substr(1); + } row.content += '
' + entry['special'] + '
'; // Icons diff --git a/server/scripts/planning_edit.js b/server/scripts/planning_edit.js index 1e9dcbd..0b74b4d 100644 --- a/server/scripts/planning_edit.js +++ b/server/scripts/planning_edit.js @@ -408,6 +408,9 @@ var siteScript = async function() { row.content += '
' + ((entry['number'] != null) ? ('# ' + entry['number']) : '') + '
'; // Special + if (entry.special.substr(0, 1) == '#') { + entry.special = '* ' + entry.special.substr(1); + } row.content += '
' + entry['special'] + '
'; // Club diff --git a/server/scripts/planning_view.js b/server/scripts/planning_view.js index a36ee7d..7043b26 100644 --- a/server/scripts/planning_view.js +++ b/server/scripts/planning_view.js @@ -158,6 +158,9 @@ var siteScript = async function() { row.content += '
' + ((entry['number'] != null) ? ('# ' + entry['number']) : '') + '
'; // Special + if (entry.special.substr(0, 1) == '#') { + entry.special = '* ' + entry.special.substr(1); + } row.content += '
' + entry['special'] + '
'; // Club diff --git a/server/scripts/rank.js b/server/scripts/rank.js index 3c412dd..c90e55d 100644 --- a/server/scripts/rank.js +++ b/server/scripts/rank.js @@ -137,6 +137,7 @@ async function selectChange(callSiteScript = true) { jugend = jugstrict = true; break; case 'idjm': + var youthGermanName = await dbGetClassProp('youth-german-name'); var beginn = null; var regattas = await dbGetData('regattas'); regattas.sort(function(a,b){ return b.date.localeCompare(a.date); }); @@ -146,7 +147,7 @@ async function selectChange(callSiteScript = true) { if ((date < parseDate('01.01.' + year)) || (date > parseDate('31.12.' + year))) { continue; } - if (regatta.name.indexOf(YOUTH_GERMAN_NAME) >= 0) { + if (regatta.name.indexOf(youthGermanName) >= 0) { beginn = ((regatta.meldungSchluss != null) ? parseDate(regatta.meldungSchluss) : date); break; } @@ -162,7 +163,7 @@ async function selectChange(callSiteScript = true) { jugend = true; jugstrict = false; } else { - $('#div-rank').html('Keine ' + YOUTH_GERMAN_NAME + ' gefunden!'); + $('#div-rank').html('Keine ' + youthGermanName + ' gefunden!'); $('#input-search').parent().hide(); return; } diff --git a/server/scripts/regattas.js b/server/scripts/regattas.js index a200199..7857f1a 100644 --- a/server/scripts/regattas.js +++ b/server/scripts/regattas.js @@ -109,6 +109,9 @@ var siteScript = async function() { var heute = false; rows = []; + var specialFields = await dbGetClassProp('special-fields'); + if (specialFields === null) specialFields = {}; + var specialShown = {}; for (id in regattas) { var entry = regattas[id]; @@ -146,7 +149,16 @@ var siteScript = async function() { row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; // Special - row.content += '
' + entry['special'] + '
'; + if (entry.special.substr(0, 1) == '#') { + entry.special = entry.special.substr(1); + if (typeof specialFields[entry.special] !== 'undefined') { + specialShown[entry.special] = specialFields[entry.special]; + entry.special = '* ' + entry.special; + } else { + entry.special = 'ERROR'; + } + } + row.content += '
' + entry.special + '
'; // Icons var icons = []; @@ -223,12 +235,24 @@ var siteScript = async function() { rows.push(null); } + if (Object.keys(specialShown).length > 0) { + var specialText = ''; + for (key in specialShown) { + specialText += '* ' + key + ': ' + specialShown[key] + '
'; + } + $('#card-special').find('p').html(specialText); + $('#card-special').show(); + } else { + $('#card-special').hide(); + } + drawList(); } else { $('#p-count').html('Keine Regatten gefunden!'); $('#div-regattas').hide(); $('#input-search').parent().hide(); + $('#card-special').hide(); } hideLoader();