From 730dd9112ffb17fc4364938010d60f2cfaa31f22 Mon Sep 17 00:00:00 2001 From: ostertun Date: Mon, 5 Oct 2020 17:19:24 +0200 Subject: [PATCH 1/4] Add planning_edit --- client/scripts/database.js | 655 ++++++++++++++++--------------- server/content/planning_edit.php | 38 +- server/scripts/planning.js | 2 - server/scripts/planning_edit.js | 471 ++++++++++++++++++++++ server/scripts/planning_view.js | 73 +--- 5 files changed, 825 insertions(+), 414 deletions(-) create mode 100644 server/scripts/planning_edit.js diff --git a/client/scripts/database.js b/client/scripts/database.js index 5d4b45a..817c247 100644 --- a/client/scripts/database.js +++ b/client/scripts/database.js @@ -483,255 +483,48 @@ function sync() { if (!canUseLocalDB) return false; if (syncInProgress > 0) return false; - var now = Math.floor(Date.now() / 1000); + return new Promise(function(resolve) { + 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']; - }); + 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'); + 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); - if (syncOkay) { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'last_sync', time: now }); + var interval = window.setInterval(function () { + if (syncInProgress <= 0) { + window.clearInterval(interval); + if (syncOkay) { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'last_sync', time: now }); + } + console.log("Sync Stop"); + setTimeout(function(){ + $('#i-sync').removeClass('fa-spin'); + }, 500); + + if (typeof onAfterSync === 'function') { + onAfterSync(); + } + runPageScript(); + resolve(); } - console.log("Sync Stop"); - setTimeout(function(){ - $('#i-sync').removeClass('fa-spin'); - }, 500); + }, 100); - if (typeof onAfterSync === 'function') { - onAfterSync(); - } - runPageScript(); - } - }, 100); + getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) { + if (code == 200) { - 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) { - if (code == 200) { - var os = db.transaction('clubs', 'readwrite').objectStore('clubs'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'clubs', time: serverTimes['clubs'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // BOATS - if (localTimes['boats'] < serverTimes['boats']) { - getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { - if (code == 200) { - var os = db.transaction('boats', 'readwrite').objectStore('boats'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'boats', time: serverTimes['boats'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // SAILORS - if (localTimes['sailors'] < serverTimes['sailors']) { - getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { - if (code == 200) { - var os = db.transaction('sailors', 'readwrite').objectStore('sailors'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'sailors', time: serverTimes['sailors'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // REGATTAS - if (localTimes['regattas'] < serverTimes['regattas']) { - getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { - if (code == 200) { - var os = db.transaction('regattas', 'readwrite').objectStore('regattas'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = async function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - // update years - var regattas = await dbGetData('regattas'); - var years = {}; - for (id in regattas) { - var entry = regattas[id]; - var date = parseDate(entry['date']); - var y = date.getFullYear(); - years[y] = y; - } - var osYears = db.transaction('years', 'readwrite').objectStore('years'); - osYears.clear().onsuccess = function (event) { - for (var y in years) { - osYears.put({ year: y }); - } - } - - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // RESULTS - if (localTimes['results'] < serverTimes['results']) { - getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { - if (code == 200) { - var os = db.transaction('results', 'readwrite').objectStore('results'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'results', time: serverTimes['results'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // PLANNINGS - if (localTimes['plannings'] < serverTimes['plannings']) { - getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { - if (code == 200) { - var os = db.transaction('plannings', 'readwrite').objectStore('plannings'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'plannings', time: serverTimes['plannings'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - if (isLoggedIn()) { - // TRIM_BOATS - if (localTimes['trim_boats'] < serverTimes['trim_boats']) { - getJSON(QUERY_URL + 'get_trim_boats?changed-after=' + localTimes['trim_boats'], function (code, data) { + // CLUBS + if (localTimes['clubs'] < serverTimes['clubs']) { + getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_boats', 'readwrite').objectStore('trim_boats'); + var os = db.transaction('clubs', 'readwrite').objectStore('clubs'); console.log(data); data.data.forEach(function (entry) { os.put(entry); @@ -745,7 +538,7 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_boats', time: serverTimes['trim_boats'] }); + osUpdateTimes.put({ table: 'clubs', time: serverTimes['clubs'] }); syncInProgress --; } }; @@ -759,11 +552,11 @@ function sync() { syncInProgress --; } - // TRIM_USERS - if (localTimes['trim_users'] < serverTimes['trim_users']) { - getJSON(QUERY_URL + 'get_trim_users?changed-after=' + localTimes['trim_users'], function (code, data) { + // BOATS + if (localTimes['boats'] < serverTimes['boats']) { + getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_users', 'readwrite').objectStore('trim_users'); + var os = db.transaction('boats', 'readwrite').objectStore('boats'); console.log(data); data.data.forEach(function (entry) { os.put(entry); @@ -777,7 +570,7 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_users', time: serverTimes['trim_users'] }); + osUpdateTimes.put({ table: 'boats', time: serverTimes['boats'] }); syncInProgress --; } }; @@ -791,11 +584,11 @@ function sync() { syncInProgress --; } - // TRIM_TRIMS - if (localTimes['trim_trims'] < serverTimes['trim_trims']) { - getJSON(QUERY_URL + 'get_trim_trims?changed-after=' + localTimes['trim_trims'], function (code, data) { + // SAILORS + if (localTimes['sailors'] < serverTimes['sailors']) { + getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_trims', 'readwrite').objectStore('trim_trims'); + var os = db.transaction('sailors', 'readwrite').objectStore('sailors'); console.log(data); data.data.forEach(function (entry) { os.put(entry); @@ -809,7 +602,284 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_trims', time: serverTimes['trim_trims'] }); + osUpdateTimes.put({ table: 'sailors', time: serverTimes['sailors'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + // REGATTAS + if (localTimes['regattas'] < serverTimes['regattas']) { + getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { + if (code == 200) { + var os = db.transaction('regattas', 'readwrite').objectStore('regattas'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = async function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + // update years + var regattas = await dbGetData('regattas'); + var years = {}; + for (id in regattas) { + var entry = regattas[id]; + var date = parseDate(entry['date']); + var y = date.getFullYear(); + years[y] = y; + } + var osYears = db.transaction('years', 'readwrite').objectStore('years'); + osYears.clear().onsuccess = function (event) { + for (var y in years) { + osYears.put({ year: y }); + } + } + + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + // RESULTS + if (localTimes['results'] < serverTimes['results']) { + getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { + if (code == 200) { + var os = db.transaction('results', 'readwrite').objectStore('results'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'results', time: serverTimes['results'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + // PLANNINGS + if (localTimes['plannings'] < serverTimes['plannings']) { + getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { + if (code == 200) { + var os = db.transaction('plannings', 'readwrite').objectStore('plannings'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'plannings', time: serverTimes['plannings'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + if (isLoggedIn()) { + // TRIM_BOATS + if (localTimes['trim_boats'] < serverTimes['trim_boats']) { + getJSON(QUERY_URL + 'get_trim_boats?changed-after=' + localTimes['trim_boats'], function (code, data) { + if (code == 200) { + var os = db.transaction('trim_boats', 'readwrite').objectStore('trim_boats'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_boats', time: serverTimes['trim_boats'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } 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) { + if (code == 200) { + var os = db.transaction('trim_users', 'readwrite').objectStore('trim_users'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_users', time: serverTimes['trim_users'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } 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) { + if (code == 200) { + var os = db.transaction('trim_trims', 'readwrite').objectStore('trim_trims'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_trims', time: serverTimes['trim_trims'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + } else { + syncInProgress -= 3; + } + + // NEWS + if (localTimes['news'] < serverTimes['news']) { + getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { + if (code == 200) { + var os = db.transaction('news', 'readwrite').objectStore('news'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'news', time: serverTimes['news'] }); + syncInProgress --; + } + }; + } else { + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + } + }); + } else { + syncInProgress --; + } + + // USERS + if (localTimes['users'] < serverTimes['users']) { + getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { + if (code == 200) { + var os = db.transaction('users', 'readwrite').objectStore('users'); + console.log(data); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'users', time: serverTimes['users'] }); syncInProgress --; } }; @@ -824,80 +894,13 @@ function sync() { } } else { - syncInProgress -= 3; + console.log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress = 0; } - - // NEWS - if (localTimes['news'] < serverTimes['news']) { - getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { - if (code == 200) { - var os = db.transaction('news', 'readwrite').objectStore('news'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'news', time: serverTimes['news'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - // USERS - if (localTimes['users'] < serverTimes['users']) { - getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { - if (code == 200) { - var os = db.transaction('users', 'readwrite').objectStore('users'); - console.log(data); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'users', time: serverTimes['users'] }); - syncInProgress --; - } - }; - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - } - }); - } else { - syncInProgress --; - } - - } else { - console.log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress = 0; - } - }); - }; + }); + }; + }); } function checkSync() { diff --git a/server/content/planning_edit.php b/server/content/planning_edit.php index ef7d037..4ef708c 100644 --- a/server/content/planning_edit.php +++ b/server/content/planning_edit.php @@ -1,21 +1,31 @@ Saison-Planung bearbeiten"; + $content .= $tpl->load('select', ['html-id' => 'select-year', 'placeholder' => 'Jahr', 'css-class' => 'mt-3 mb-0']); - $content = $tpl->load('error', ['404', 'Seite existiert noch nicht']); - $content .= '

'; - $content .= 'Du kannst die Saison-Planung momentan leider noch nicht in der App bearbeiten.
'; - $content .= 'Bis diese Funktion implementiert wurde, erstelle Deine Saison-Planung bitte auf unserer Website.
'; - $content .= 'Deine Saison-Planung wird dann automatisch synchronisiert und ist dann auch in dieser App verfügbar.
'; - $content .= 'Wir arbeiten daran, dass Du Deine Saison-Planung bald auch in der App bearbeiten kannst.
'; - $content .= '

'; - $content .= $tpl->load('button', ['Zur Website', 'https://regatten.net/' . BOATCLASS, 'css-class' => 'mb-3']); - $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]); - $sp['output'] = $tpl->load('card', [$content, 'css-class' => 'text-center pt-3']); + // 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']); + + // Menu + $items = $tpl->load('menu/item-switch', ['In die Saison-Planung aufnehmen', 'html-id' => 'switch-planning-include', 'icon' => 'fa-check']); + $items .= $tpl->load('menu/item-simple', ['', '#', 'html-id' => 'item-steuermann']); + $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-edit', 'title' => 'Regatta bearbeiten', 'height' => 320]); + + // Select sailor + $items = $tpl->load('input', ['html-id' => 'input-edit-search', 'placeholder' => 'Suche', 'type' => 'text']); + $sp['menus'] .= $tpl->load('menu/modal', [$items, 'html-id' => 'menu-sailor', 'height' => 500, 'width' => 350]); + + $sp['scripts'] .= $scripts->load('planning_edit'); ?> diff --git a/server/scripts/planning.js b/server/scripts/planning.js index e6a0e3e..59f30a7 100644 --- a/server/scripts/planning.js +++ b/server/scripts/planning.js @@ -35,8 +35,6 @@ async function planningSwitchChanged() { hideLoader(); } }); - console.log(id, gemeldet, bezahlt); - hideLoader(); } async function planningEditStatus(id) { diff --git a/server/scripts/planning_edit.js b/server/scripts/planning_edit.js new file mode 100644 index 0000000..5dc7b2f --- /dev/null +++ b/server/scripts/planning_edit.js @@ -0,0 +1,471 @@ +async function planningSwitchChanged() { + showLoader(); + var id = $('#switch-planning-include').data('regatta'); + var include = $('#switch-planning-include').prop('checked'); + var auth = { + id: localStorage.getItem('auth_id'), + hash: localStorage.getItem('auth_hash') + } + if (include) { + // add to planning + $.ajax({ + url: QUERY_URL + 'planning_add', + method: 'POST', + data: { + auth: auth, + regatta: id + }, + 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 die Änderungen zu speichern'); + } else { + console.log('planning_add: unbekannter Fehler', status, error); + console.log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + $('#menu-edit').hideMenu(); + hideLoader(); + }, + success: async function (data, status, xhr) { + await sync(); + planningEdit(id); + hideLoader(); + } + }); + } else { + // remove from planning + $.ajax({ + url: QUERY_URL + 'planning_remove', + method: 'POST', + data: { + auth: auth, + regatta: id + }, + 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 die Änderungen zu speichern'); + } else { + console.log('planning_remove: unbekannter Fehler', status, error); + console.log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + $('#menu-edit').hideMenu(); + hideLoader(); + }, + success: async function (data, status, xhr) { + await sync(); + planningEdit(id); + hideLoader(); + } + }); + } +} + +var sailorIsSteuermann; +var sailors = []; + +async function sailorSelected(sid) { + $('#menu-sailor').hideMenu(); + showLoader(); + var rid = $('#switch-planning-include').data('regatta'); + var action = (sailorIsSteuermann ? 'planning_set_steuermann' : 'planning_add_crew'); + // add sailor + var auth = { + id: localStorage.getItem('auth_id'), + hash: localStorage.getItem('auth_hash') + } + $.ajax({ + url: QUERY_URL + action, + method: 'POST', + data: { + auth: auth, + regatta: rid, + sailor: sid + }, + 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 die Änderungen zu speichern'); + } else { + console.log(action + ': unbekannter Fehler', status, error); + console.log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + hideLoader(); + }, + success: async function (data, status, xhr) { + await sync(); + planningEdit(rid); + hideLoader(); + } + }); +} + +async function sailorsSearch() { + $('.item-sailor-search').remove(); + if (sailorIsSteuermann) { + var item = ''; + item += 'noch unklar'; + item += ''; + item += ''; + $('#menu-sailor').find('.content').find('.list-group').append(item); + } + if ($('#input-edit-search').val().length >= 3) { + sailors.forEach(function (entry) { + if (search($('#input-edit-search').val(), entry.keywords)) { + $('#menu-sailor').find('.content').find('.list-group').append(entry.content); + } + }); + } else { + var item = ''; + $('#menu-sailor').find('.content').find('.list-group').append(item); + } +} + +async function initSailors() { + sailors = []; + var dbSailors = await dbGetData('sailors'); + dbSailors.sort(function(a,b){ + return a.name.localeCompare(b.name); + }); + for (s in dbSailors) { + var item = ''; + item += '' + dbSailors[s].name + ''; + item += ''; + item += ''; + sailors.push({ + keywords: [dbSailors[s].name], + content: item + }); + } +} + +async function planningChangeCrew(sid = null) { + if (sid !== null) { + showLoader(); + var rid = $('#switch-planning-include').data('regatta'); + // remove sailor + var auth = { + id: localStorage.getItem('auth_id'), + hash: localStorage.getItem('auth_hash') + } + $.ajax({ + url: QUERY_URL + 'planning_remove_crew', + method: 'POST', + data: { + auth: auth, + regatta: rid, + sailor: sid + }, + 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 die Änderungen zu speichern'); + } else { + console.log('planning_remove_crew: unbekannter Fehler', status, error); + console.log(xhr); + toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); + } + $('#menu-edit').hideMenu(); + hideLoader(); + }, + success: async function (data, status, xhr) { + await sync(); + planningEdit(rid); + hideLoader(); + } + }); + } else { + sailorIsSteuermann = false; + $('#input-edit-search').val('').trigger('focusin').trigger('focusout'); + sailorsSearch(); + $('#menu-edit').hideMenu(); + $('#menu-sailor').find('.menu-title').find('h1').text('Crew hinzufügen'); + $('#menu-sailor').showMenu(); + } +} + +async function planningChangeSteuermann() { + sailorIsSteuermann = true; + $('#input-edit-search').val('').trigger('focusin').trigger('focusout'); + sailorsSearch(); + $('#menu-edit').hideMenu(); + $('#menu-sailor').find('.menu-title').find('h1').text('Steuermann/-frau bearbeiten'); + $('#menu-sailor').showMenu(); +} + +async function planningEdit(id) { + var regatta = await dbGetData('regattas', id); + + $('#menu-edit').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; + } + } + } + + $('#switch-planning-include').data('regatta', id); + if (planning !== null) { + $('#switch-planning-include').prop('checked', true); + $('#item-steuermann').show(); + if (planning.steuermann !== null) { + $('#item-steuermann').find('span').text('Steuer: ' + (await dbGetData('sailors', planning.steuermann)).name); + } else { + $('#item-steuermann').find('span').html('Steuer: noch unklar'); + } + $('.item-crew').remove(); + var crew = planning.crew.split(','); + for (c in crew) { + var sailor = await dbGetData('sailors', crew[c]); + if (sailor !== null) { + var item = ''; + item += '' + sailor.name + ''; + item += ''; + item += ''; + $('#menu-edit').find('.content').find('.list-group').append(item); + } + } + var item = ''; + item += 'Weiteren Segler hinzufügen'; + item += ''; + item += ''; + $('#menu-edit').find('.content').find('.list-group').append(item); + } else { + $('#switch-planning-include').prop('checked', false); + $('#item-steuermann').hide(); + $('.item-crew').remove(); + } + $('#menu-edit').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()) { + location.href = LINK_PRE + 'planning'; + return; + } + + if (firstCall) { + firstCall = false; + initYear(); + $('#select-year').change(selectChange); + $('#input-search').on('input', drawList); + $('#switch-planning-include').parent().parent().click(planningSwitchChanged); + $('#item-steuermann').click(planningChangeSteuermann); + $('#input-edit-search').on('input', sailorsSearch); + initSailors(); + } + + 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[i].planning = null; + } + } + + 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 !== null) { + 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 (!heute && (today <= dateFrom)) { + rows.push(null); + heute = true; + } + + if (entry.planning !== null) { + row.content += '
'; + } else { + 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']) : '') + '
'; + + // Special + row.content += '
' + entry['special'] + '
'; + + // Club + row.content += '
' + ((club != null) ? club['kurz'] : '') + '
'; + + 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 += '
'; + + if (entry.planning !== null) { + // ZEILE 4 + row.content += '
'; + + // ZEILE 5 + row.content += '
'; + row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'noch unklar') + '
'; + row.content += '
'; + + // ZEILE 6... + for (var i in entry.planning.crew) { + row.content += '
'; + row.content += '
' + entry.planning.crew[i] + '
'; + row.content += '
'; + } + } else { + row.content += '
Du planst nicht, hierhin zu fahren
'; + } + + row.content += '
'; + + rows.push(row); + } + + if (!heute) { + rows.push(null); + } + + drawList(); + + } else { + $('#p-count').html('Keine Regatten gefunden!'); + $('#div-regattas').hide(); + $('#input-search').parent().hide(); + } + + hideLoader(); +} diff --git a/server/scripts/planning_view.js b/server/scripts/planning_view.js index e1f770b..c1da637 100644 --- a/server/scripts/planning_view.js +++ b/server/scripts/planning_view.js @@ -83,12 +83,6 @@ var siteScript = async function() { 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) { @@ -194,7 +188,7 @@ var siteScript = async function() { // ZEILE 5 row.content += '
'; - row.content += '
' + entry.planning.steuermann + '
'; + row.content += '
' + (entry.planning.steuermann !== null ? entry.planning.steuermann : 'noch unklar') + '
'; row.content += '
'; // ZEILE 6... @@ -205,72 +199,7 @@ var siteScript = async function() { } row.content += '
'; -/* - // 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['info'] != '') - icons.push(''); - if ((entry['meldung'] != '') && (dateTo >= today) && (entry['meldungOffen'] == '1')) { - var color = ''; - if (entry['meldungSchluss'] != null) { - 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'; - } - } - icons.push(''); - } - if (entry['bericht'] != '') - icons.push(''); - if (entry['canceled'] == '1') { - icons.push(''); - } else if (regattaResults[entry['id']]) { - 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); } From fcf9dc9a2093b69f718aad90016853156c537a3e Mon Sep 17 00:00:00 2001 From: ostertun Date: Mon, 5 Oct 2020 17:35:10 +0200 Subject: [PATCH 2/4] Fixes --- client/scripts/database.js | 691 ++++++++++++++++---------------- server/scripts/planning.js | 6 +- server/scripts/planning_edit.js | 24 +- 3 files changed, 362 insertions(+), 359 deletions(-) diff --git a/client/scripts/database.js b/client/scripts/database.js index 2872bb9..37186f6 100644 --- a/client/scripts/database.js +++ b/client/scripts/database.js @@ -483,262 +483,49 @@ function sync() { if (!canUseLocalDB) return false; if (syncInProgress > 0) return false; - var now = Math.floor(Date.now() / 1000); + return new Promise(function(resolve) { + 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']; - }); + 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; - log("Sync Start"); - $('#i-sync').addClass('fa-spin'); + syncInProgress = 11; + var syncOkay = true; + log("Sync Start"); + $('#i-sync').addClass('fa-spin'); - var interval = window.setInterval(function () { - if (syncInProgress <= 0) { - window.clearInterval(interval); - if (syncOkay) { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'last_sync', time: now }); + var interval = window.setInterval(function () { + if (syncInProgress <= 0) { + window.clearInterval(interval); + if (syncOkay) { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'last_sync', time: now }); + } + log("Sync Stop"); + setTimeout(function(){ + $('#i-sync').removeClass('fa-spin'); + }, 500); + + if (typeof onAfterSync === 'function') { + onAfterSync(); + } + removeSyncInfoToPreloader(); + runPageScript(); + resolve(); } - log("Sync Stop"); - setTimeout(function(){ - $('#i-sync').removeClass('fa-spin'); - }, 500); + }, 100); - if (typeof onAfterSync === 'function') { - onAfterSync(); - } - removeSyncInfoToPreloader(); - runPageScript(); - } - }, 100); + getJSON(QUERY_URL + 'get_update_time', function (code, serverTimes) { + if (code == 200) { - 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) { - if (code == 200) { - var os = db.transaction('clubs', 'readwrite').objectStore('clubs'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'clubs', time: serverTimes['clubs'] }); - syncInProgress --; - log('clubs synced, remaining:', syncInProgress); - } - }; - } else { - log("clubs: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('clubs failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // BOATS - if (localTimes['boats'] < serverTimes['boats']) { - getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { - if (code == 200) { - var os = db.transaction('boats', 'readwrite').objectStore('boats'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'boats', time: serverTimes['boats'] }); - syncInProgress --; - log('boats synced, remaining:', syncInProgress); - } - }; - } else { - log("boats: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('boats failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // SAILORS - if (localTimes['sailors'] < serverTimes['sailors']) { - getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { - if (code == 200) { - var os = db.transaction('sailors', 'readwrite').objectStore('sailors'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'sailors', time: serverTimes['sailors'] }); - syncInProgress --; - log('sailors synced, remaining:', syncInProgress); - } - }; - } else { - log("sailors: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('sailors failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // REGATTAS - if (localTimes['regattas'] < serverTimes['regattas']) { - getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { - if (code == 200) { - var os = db.transaction('regattas', 'readwrite').objectStore('regattas'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = async function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - // update years - var regattas = await dbGetData('regattas'); - var years = {}; - for (id in regattas) { - var entry = regattas[id]; - var date = parseDate(entry['date']); - var y = date.getFullYear(); - years[y] = y; - } - var osYears = db.transaction('years', 'readwrite').objectStore('years'); - osYears.clear().onsuccess = function (event) { - for (var y in years) { - osYears.put({ year: y }); - } - } - - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); - syncInProgress --; - log('regattas synced, remaining:', syncInProgress); - } - }; - } else { - log("regattas: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('regattas failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // RESULTS - if (localTimes['results'] < serverTimes['results']) { - getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { - if (code == 200) { - var os = db.transaction('results', 'readwrite').objectStore('results'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'results', time: serverTimes['results'] }); - syncInProgress --; - log('results synced, remaining:', syncInProgress); - } - }; - } else { - log("results: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('results failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // PLANNINGS - if (localTimes['plannings'] < serverTimes['plannings']) { - getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { - if (code == 200) { - var os = db.transaction('plannings', 'readwrite').objectStore('plannings'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'plannings', time: serverTimes['plannings'] }); - syncInProgress --; - log('plannings synced, remaining:', syncInProgress); - } - }; - } else { - log("plannings: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('plannings failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - if (isLoggedIn()) { - // TRIM_BOATS - if (localTimes['trim_boats'] < serverTimes['trim_boats']) { - getJSON(QUERY_URL + 'get_trim_boats?changed-after=' + localTimes['trim_boats'], function (code, data) { + // CLUBS + if (localTimes['clubs'] < serverTimes['clubs']) { + getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_boats', 'readwrite').objectStore('trim_boats'); + var os = db.transaction('clubs', 'readwrite').objectStore('clubs'); data.data.forEach(function (entry) { os.put(entry); }); @@ -751,27 +538,27 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_boats', time: serverTimes['trim_boats'] }); + osUpdateTimes.put({ table: 'clubs', time: serverTimes['clubs'] }); syncInProgress --; - log('trim_boats synced, remaining:', syncInProgress); + log('clubs synced, remaining:', syncInProgress); } }; } else { - log("trim_boats: Something went wrong (HTTP " + code + ")"); + log("clubs: Something went wrong (HTTP " + code + ")"); syncOkay = false; syncInProgress --; - log('trim_boats failed, remaining:', syncInProgress); + log('clubs failed, remaining:', syncInProgress); } }); } 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) { + // BOATS + if (localTimes['boats'] < serverTimes['boats']) { + getJSON(QUERY_URL + 'get_boats?changed-after=' + localTimes['boats'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_users', 'readwrite').objectStore('trim_users'); + var os = db.transaction('boats', 'readwrite').objectStore('boats'); data.data.forEach(function (entry) { os.put(entry); }); @@ -784,27 +571,27 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_users', time: serverTimes['trim_users'] }); + osUpdateTimes.put({ table: 'boats', time: serverTimes['boats'] }); syncInProgress --; - log('trim_users synced, remaining:', syncInProgress); + log('boats synced, remaining:', syncInProgress); } }; } else { - log("trim_users: Something went wrong (HTTP " + code + ")"); + log("boats: Something went wrong (HTTP " + code + ")"); syncOkay = false; syncInProgress --; - log('trim_users failed, remaining:', syncInProgress); + log('boats failed, remaining:', syncInProgress); } }); } 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) { + // SAILORS + if (localTimes['sailors'] < serverTimes['sailors']) { + getJSON(QUERY_URL + 'get_sailors?changed-after=' + localTimes['sailors'], function (code, data) { if (code == 200) { - var os = db.transaction('trim_trims', 'readwrite').objectStore('trim_trims'); + var os = db.transaction('sailors', 'readwrite').objectStore('sailors'); data.data.forEach(function (entry) { os.put(entry); }); @@ -817,16 +604,301 @@ function sync() { cursor.continue(); } else { var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'trim_trims', time: serverTimes['trim_trims'] }); + osUpdateTimes.put({ table: 'sailors', time: serverTimes['sailors'] }); syncInProgress --; - log('trim_trims synced, remaining:', syncInProgress); + log('sailors synced, remaining:', syncInProgress); } }; } else { - log("trim_trims: Something went wrong (HTTP " + code + ")"); + log("sailors: Something went wrong (HTTP " + code + ")"); syncOkay = false; syncInProgress --; - log('trim_trims failed, remaining:', syncInProgress); + log('sailors failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + // REGATTAS + if (localTimes['regattas'] < serverTimes['regattas']) { + getJSON(QUERY_URL + 'get_regattas?changed-after=' + localTimes['regattas'], function (code, data) { + if (code == 200) { + var os = db.transaction('regattas', 'readwrite').objectStore('regattas'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = async function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + // update years + var regattas = await dbGetData('regattas'); + var years = {}; + for (id in regattas) { + var entry = regattas[id]; + var date = parseDate(entry['date']); + var y = date.getFullYear(); + years[y] = y; + } + var osYears = db.transaction('years', 'readwrite').objectStore('years'); + osYears.clear().onsuccess = function (event) { + for (var y in years) { + osYears.put({ year: y }); + } + } + + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'regattas', time: serverTimes['regattas'] }); + syncInProgress --; + log('regattas synced, remaining:', syncInProgress); + } + }; + } else { + log("regattas: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('regattas failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + // RESULTS + if (localTimes['results'] < serverTimes['results']) { + getJSON(QUERY_URL + 'get_results?changed-after=' + localTimes['results'], function (code, data) { + if (code == 200) { + var os = db.transaction('results', 'readwrite').objectStore('results'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'results', time: serverTimes['results'] }); + syncInProgress --; + log('results synced, remaining:', syncInProgress); + } + }; + } else { + log("results: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('results failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + // PLANNINGS + if (localTimes['plannings'] < serverTimes['plannings']) { + getJSON(QUERY_URL + 'get_plannings?changed-after=' + localTimes['plannings'], function (code, data) { + if (code == 200) { + var os = db.transaction('plannings', 'readwrite').objectStore('plannings'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'plannings', time: serverTimes['plannings'] }); + syncInProgress --; + log('plannings synced, remaining:', syncInProgress); + } + }; + } else { + log("plannings: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('plannings failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + if (isLoggedIn()) { + // TRIM_BOATS + if (localTimes['trim_boats'] < serverTimes['trim_boats']) { + getJSON(QUERY_URL + 'get_trim_boats?changed-after=' + localTimes['trim_boats'], function (code, data) { + if (code == 200) { + var os = db.transaction('trim_boats', 'readwrite').objectStore('trim_boats'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_boats', time: serverTimes['trim_boats'] }); + syncInProgress --; + log('trim_boats synced, remaining:', syncInProgress); + } + }; + } else { + log("trim_boats: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('trim_boats failed, remaining:', syncInProgress); + } + }); + } 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) { + if (code == 200) { + var os = db.transaction('trim_users', 'readwrite').objectStore('trim_users'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_users', time: serverTimes['trim_users'] }); + syncInProgress --; + log('trim_users synced, remaining:', syncInProgress); + } + }; + } else { + log("trim_users: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('trim_users failed, remaining:', syncInProgress); + } + }); + } 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) { + if (code == 200) { + var os = db.transaction('trim_trims', 'readwrite').objectStore('trim_trims'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'trim_trims', time: serverTimes['trim_trims'] }); + syncInProgress --; + log('trim_trims synced, remaining:', syncInProgress); + } + }; + } else { + log("trim_trims: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('trim_trims failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + } else { + syncInProgress -= 3; + } + + // NEWS + if (localTimes['news'] < serverTimes['news']) { + getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { + if (code == 200) { + var os = db.transaction('news', 'readwrite').objectStore('news'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'news', time: serverTimes['news'] }); + syncInProgress --; + log('news synced, remaining:', syncInProgress); + } + }; + } else { + log("news: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('news failed, remaining:', syncInProgress); + } + }); + } else { + syncInProgress --; + } + + // USERS + if (localTimes['users'] < serverTimes['users']) { + getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { + if (code == 200) { + var os = db.transaction('users', 'readwrite').objectStore('users'); + data.data.forEach(function (entry) { + os.put(entry); + }); + os.openCursor().onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + if (!data.keys.includes(parseInt(cursor.key))) { + os.delete(cursor.key); + } + cursor.continue(); + } else { + var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); + osUpdateTimes.put({ table: 'users', time: serverTimes['users'] }); + syncInProgress --; + log('users synced, remaining:', syncInProgress); + } + }; + } else { + log("users: Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress --; + log('users failed, remaining:', syncInProgress); } }); } else { @@ -834,82 +906,13 @@ function sync() { } } else { - syncInProgress -= 3; + log("Something went wrong (HTTP " + code + ")"); + syncOkay = false; + syncInProgress = 0; } - - // NEWS - if (localTimes['news'] < serverTimes['news']) { - getJSON(QUERY_URL + 'get_news?changed-after=' + localTimes['news'], function (code, data) { - if (code == 200) { - var os = db.transaction('news', 'readwrite').objectStore('news'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'news', time: serverTimes['news'] }); - syncInProgress --; - log('news synced, remaining:', syncInProgress); - } - }; - } else { - log("news: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('news failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - // USERS - if (localTimes['users'] < serverTimes['users']) { - getJSON(QUERY_URL + 'get_users?changed-after=' + localTimes['users'], function (code, data) { - if (code == 200) { - var os = db.transaction('users', 'readwrite').objectStore('users'); - data.data.forEach(function (entry) { - os.put(entry); - }); - os.openCursor().onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - if (!data.keys.includes(parseInt(cursor.key))) { - os.delete(cursor.key); - } - cursor.continue(); - } else { - var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times'); - osUpdateTimes.put({ table: 'users', time: serverTimes['users'] }); - syncInProgress --; - log('users synced, remaining:', syncInProgress); - } - }; - } else { - log("users: Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress --; - log('users failed, remaining:', syncInProgress); - } - }); - } else { - syncInProgress --; - } - - } else { - log("Something went wrong (HTTP " + code + ")"); - syncOkay = false; - syncInProgress = 0; - } - }); - }; + }); + }; + }); } function checkSync() { diff --git a/server/scripts/planning.js b/server/scripts/planning.js index 59f30a7..fa1e8b7 100644 --- a/server/scripts/planning.js +++ b/server/scripts/planning.js @@ -18,13 +18,13 @@ async function planningSwitchChanged() { }, error: function (xhr, status, error) { if (xhr.status == 401) { - console.log('authentification failed'); + 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); + log('Login: unbekannter Fehler', status, error); + log(xhr); toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); } $('#menu-status').hideMenu(); diff --git a/server/scripts/planning_edit.js b/server/scripts/planning_edit.js index 5dc7b2f..a7b8d34 100644 --- a/server/scripts/planning_edit.js +++ b/server/scripts/planning_edit.js @@ -17,13 +17,13 @@ async function planningSwitchChanged() { }, error: function (xhr, status, error) { if (xhr.status == 401) { - console.log('authentification failed'); + log('authentification failed'); toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); } else if (xhr.status == 0) { toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um die Änderungen zu speichern'); } else { - console.log('planning_add: unbekannter Fehler', status, error); - console.log(xhr); + log('planning_add: unbekannter Fehler', status, error); + log(xhr); toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); } $('#menu-edit').hideMenu(); @@ -46,13 +46,13 @@ async function planningSwitchChanged() { }, error: function (xhr, status, error) { if (xhr.status == 401) { - console.log('authentification failed'); + log('authentification failed'); toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); } else if (xhr.status == 0) { toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um die Änderungen zu speichern'); } else { - console.log('planning_remove: unbekannter Fehler', status, error); - console.log(xhr); + log('planning_remove: unbekannter Fehler', status, error); + log(xhr); toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); } $('#menu-edit').hideMenu(); @@ -90,13 +90,13 @@ async function sailorSelected(sid) { }, error: function (xhr, status, error) { if (xhr.status == 401) { - console.log('authentification failed'); + log('authentification failed'); toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); } else if (xhr.status == 0) { toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um die Änderungen zu speichern'); } else { - console.log(action + ': unbekannter Fehler', status, error); - console.log(xhr); + log(action + ': unbekannter Fehler', status, error); + log(xhr); toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); } hideLoader(); @@ -167,13 +167,13 @@ async function planningChangeCrew(sid = null) { }, error: function (xhr, status, error) { if (xhr.status == 401) { - console.log('authentification failed'); + log('authentification failed'); toastError('Authentifizierung fehlgeschlagen. Versuche es erneut.'); } else if (xhr.status == 0) { toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um die Änderungen zu speichern'); } else { - console.log('planning_remove_crew: unbekannter Fehler', status, error); - console.log(xhr); + log('planning_remove_crew: unbekannter Fehler', status, error); + log(xhr); toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000); } $('#menu-edit').hideMenu(); From 2dc22252636a447cec8284fd5314e8942e1cb3df Mon Sep 17 00:00:00 2001 From: ostertun Date: Mon, 5 Oct 2020 17:38:00 +0200 Subject: [PATCH 3/4] Focus search input on show sailor selector --- server/scripts/planning_edit.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/scripts/planning_edit.js b/server/scripts/planning_edit.js index a7b8d34..43c4e69 100644 --- a/server/scripts/planning_edit.js +++ b/server/scripts/planning_edit.js @@ -192,6 +192,7 @@ async function planningChangeCrew(sid = null) { $('#menu-edit').hideMenu(); $('#menu-sailor').find('.menu-title').find('h1').text('Crew hinzufügen'); $('#menu-sailor').showMenu(); + $('#input-edit-search').focus(); } } @@ -202,6 +203,7 @@ async function planningChangeSteuermann() { $('#menu-edit').hideMenu(); $('#menu-sailor').find('.menu-title').find('h1').text('Steuermann/-frau bearbeiten'); $('#menu-sailor').showMenu(); + $('#input-edit-search').focus(); } async function planningEdit(id) { @@ -225,9 +227,9 @@ async function planningEdit(id) { $('#switch-planning-include').prop('checked', true); $('#item-steuermann').show(); if (planning.steuermann !== null) { - $('#item-steuermann').find('span').text('Steuer: ' + (await dbGetData('sailors', planning.steuermann)).name); + $('#item-steuermann').find('span').text('Am Steuer: ' + (await dbGetData('sailors', planning.steuermann)).name); } else { - $('#item-steuermann').find('span').html('Steuer: noch unklar'); + $('#item-steuermann').find('span').html('Am Steuer: noch unklar'); } $('.item-crew').remove(); var crew = planning.crew.split(','); From fa526b11a8cf28c3a3e1889e047006fb4d4bc6ec Mon Sep 17 00:00:00 2001 From: ostertun Date: Mon, 5 Oct 2020 17:44:43 +0200 Subject: [PATCH 4/4] Release v_1.10 --- server/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/version.php b/server/version.php index 7486a96..53fd6d4 100644 --- a/server/version.php +++ b/server/version.php @@ -1,5 +1,5 @@