Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45af73c25 | ||
|
|
f30eac8aa5 | ||
|
|
99b624ff92 | ||
|
|
e74ffa9a70 | ||
|
|
cbb398988d | ||
|
|
856f6c1d66 | ||
|
|
2ea26408be | ||
|
|
fb1ca6d28e | ||
|
|
6a5d06325d | ||
|
|
72ac8df460 | ||
|
|
246231fd0e | ||
|
|
3e533f65fc | ||
|
|
2533c3d66a | ||
|
|
cacee5a54a | ||
|
|
274aa85cf7 | ||
|
|
4317e4fe87 | ||
|
|
b7dec825ca | ||
|
|
6ca6a79dc3 | ||
|
|
d1e5d753b4 | ||
|
|
7afacc3fff | ||
|
|
77ea57d643 | ||
|
|
a72c462483 | ||
|
|
b739e6cc4e | ||
|
|
eb47cdf016 | ||
|
|
12c1a614bb | ||
|
|
0fb1bb0462 | ||
|
|
1b1176b952 | ||
|
|
00c1c93b80 | ||
|
|
876776eb5b | ||
|
|
a92dc45bb7 |
20
.github/ISSUE_TEMPLATE/-de--feature-anfrage.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/-de--feature-anfrage.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: "[DE] Feature-Anfrage"
|
||||
about: Schlage eine Idee für dieses Projekt vor
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Bezieht sich Deine Feature-Anfrage auf ein Problem? Bitte beschreiben.**
|
||||
Eine klare und präzise Beschreibung des Problems. Z.B. Ich bin immer frustriert, wenn [...]
|
||||
|
||||
**Beschreibe die gewünschte Lösung**
|
||||
Eine klare und präzise Beschreibung dessen, was passieren soll.
|
||||
|
||||
**Beschreibe Alternativen, die Du in Betracht gezogen hast**
|
||||
Eine klare und präzise Beschreibung aller alternativen Lösungen oder Funktionen, die Du in Betracht gezogen hast.
|
||||
|
||||
**Zusätzlicher Kontext**
|
||||
Füge hier weitere Kontexte oder Screenshots zur Feature-Anfrage hinzu.
|
||||
38
.github/ISSUE_TEMPLATE/-de--fehlerbericht.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/-de--fehlerbericht.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: "[DE] Fehlerbericht"
|
||||
about: Erstelle einen Bericht, um uns zu helfen, die App zu verbessern
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Beschreibe den Fehler**
|
||||
Eine klare und präzise Beschreibung des Fehlers.
|
||||
|
||||
**Reproduzierung**
|
||||
Schritte zum Reproduzieren des Fehlers:
|
||||
1. Gehe zu '...'
|
||||
2. Klicke auf '....'
|
||||
3. Scrolle nach unten zu '....'
|
||||
4. Sieh den Fehler
|
||||
|
||||
**Erwartetes Verhalten**
|
||||
Eine klare und präzise Beschreibung dessen, was Du erwartet hattest.
|
||||
|
||||
**Screenshots**
|
||||
Füge gegebenenfalls Screenshots hinzu, um Dein Problem zu erklären.
|
||||
|
||||
**Desktop (bitte verfolständige die folgenden Informationen):**
|
||||
- Betriebssystem: [z.B. Windows 10]
|
||||
- Browser [z.B. chrome, safari]
|
||||
- Version [z.B. 2.14]
|
||||
|
||||
**Smartphone (bitte verfolständige die folgenden Informationen):**
|
||||
- Gerät: [z.B. iPhone 6]
|
||||
- Betriebssystem: [z.B. iOS 8.1]
|
||||
- Browser [z.B. stock browser, safari]
|
||||
- Version [z.B. 2.14]
|
||||
|
||||
**Zusätzlicher Kontext**
|
||||
Füge hier einen anderen Kontext zum Problem hinzu.
|
||||
38
.github/ISSUE_TEMPLATE/-en--bug-report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/-en--bug-report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: "[EN] Bug report"
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. Windows 10]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 2.14]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone 6]
|
||||
- OS: [e.g. iOS 8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 2.14]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
20
.github/ISSUE_TEMPLATE/-en--feature-request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/-en--feature-request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: "[EN] Feature request"
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Regatten.net App
|
||||
|
||||
Willkommen im GitHub-Repository unserer neuen Regatten.net App.
|
||||
|
||||
Falls sich jemand dafür interessiert, ist hier der gesamte Quellcode unserer neuen App zu finden.
|
||||
Bitte beachtet, dass diese App einschließlich dem gesamten Quellcode exklusivem Urheberrecht unterliegt. Sie darf also nicht kopiert, verteilt oder verändert werden.
|
||||
Sollte Interesse an einer Anbindung an unser System bestehen, kontaktiere uns bitte einfach (https://regatten.net/contact)
|
||||
|
||||
Der Hauptzweck dieses Repository besteht jedoch darin, Feedback von Euch zu unserer neuen App zu bekommen.
|
||||
Selbstverständlich könnt Ihr uns auch weiterhin auf anderen Kanälen erreichen, doch für Problem-Meldungen und Verbesserungsvorschläge ist GitHub am besten geeignet.
|
||||
Wie Du Teil unseres BETA-Programmes wirst, die App installierst und Feedback gibst, erfährst Du in unserem [Wiki](https://github.com/ostertun/RegattenApp/wiki).
|
||||
@@ -1,4 +1,4 @@
|
||||
const DB_VERSION = 4;
|
||||
const DB_VERSION = 6;
|
||||
|
||||
const USER_ID = localStorage.getItem('auth_user');
|
||||
const USER_NAME = localStorage.getItem('auth_username');
|
||||
@@ -397,6 +397,26 @@ function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
|
||||
});
|
||||
}
|
||||
|
||||
function dbSettingsGet(key) {
|
||||
return new Promise(function(resolve) {
|
||||
if (canUseLocalDB) {
|
||||
var request = db.transaction('settings').objectStore('settings').get(key);
|
||||
request.onsuccess = function (event) {
|
||||
resolve(typeof request.result != 'undefined' ? request.result.value : null);
|
||||
}
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function dbSettingsSet(key, value) {
|
||||
if (canUseLocalDB) {
|
||||
var os = db.transaction('settings', 'readwrite').objectStore('settings');
|
||||
os.put({ key: key, value: value});
|
||||
}
|
||||
}
|
||||
|
||||
async function updateSyncStatus() { // TODO
|
||||
// var syncStatus = document.getElementById('syncstatus');
|
||||
// var lastSync = await dbGetData('update_times', 'last_sync');
|
||||
@@ -433,6 +453,12 @@ async function runPageScript() {
|
||||
}
|
||||
};
|
||||
updateSyncStatus();
|
||||
|
||||
if (isLoggedIn()) {
|
||||
var plannings = await dbGetDataIndex('plannings', 'user', USER_ID);
|
||||
plannings = plannings.map(function (e) { return e.regatta; });
|
||||
dbSettingsSet('myregattas_' + BOATCLASS, plannings);
|
||||
}
|
||||
}
|
||||
if (typeof updateSyncStatusTimer == 'undefined') { // TODO
|
||||
// var syncStatus = document.getElementById('syncstatus');
|
||||
@@ -465,7 +491,7 @@ function sync() {
|
||||
localTimes[entry['table']] = entry['time'];
|
||||
});
|
||||
|
||||
syncInProgress = 10;
|
||||
syncInProgress = 11;
|
||||
var syncOkay = true;
|
||||
console.log("Sync Start");
|
||||
$('#i-sync').addClass('fa-spin');
|
||||
@@ -482,6 +508,9 @@ function sync() {
|
||||
$('#i-sync').removeClass('fa-spin');
|
||||
}, 500);
|
||||
|
||||
if (typeof onAfterSync === 'function') {
|
||||
onAfterSync();
|
||||
}
|
||||
runPageScript();
|
||||
}
|
||||
}, 100);
|
||||
@@ -798,6 +827,38 @@ function sync() {
|
||||
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) {
|
||||
@@ -878,6 +939,8 @@ function initDatabase() {
|
||||
|
||||
canUseLocalDB = true;
|
||||
|
||||
if (typeof onDatabaseLoaded == 'function') onDatabaseLoaded();
|
||||
|
||||
db.transaction('update_times').objectStore('update_times').get('last_sync').onsuccess = function (event) {
|
||||
var lastSync = event.target.result.time;
|
||||
if (lastSync > 0) {
|
||||
@@ -953,6 +1016,18 @@ function initDatabase() {
|
||||
osUpdateTimes.add({ table: 'loggedin', status: isLoggedIn() });
|
||||
}
|
||||
|
||||
if ((oldVersion < 5) && (newVersion >= 5)) {
|
||||
console.log('to version 5');
|
||||
var osPushes = db.createObjectStore('settings', { keyPath: 'key' });
|
||||
}
|
||||
|
||||
if ((oldVersion < 6) && (newVersion >= 6)) {
|
||||
console.log('to version 6');
|
||||
var osNews = db.createObjectStore('news', { keyPath: 'id' });
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
osUpdateTimes.add({ table: 'news', time: 0 });
|
||||
}
|
||||
|
||||
var osUpdateTimes = upgradeTransaction.objectStore('update_times');
|
||||
osUpdateTimes.put({ table: 'last_sync', time: 0 });
|
||||
}
|
||||
@@ -961,8 +1036,7 @@ function initDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
function resetDb(silent = true) {
|
||||
$('#menu-developer').hideMenu();
|
||||
function resetDb() {
|
||||
if (canUseLocalDB) {
|
||||
showLoader();
|
||||
var osUpdateTimes = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
@@ -976,13 +1050,9 @@ function resetDb(silent = true) {
|
||||
osUpdateTimes.put({ table: 'trim_boats', time: 0 });
|
||||
osUpdateTimes.put({ table: 'trim_users', time: 0 });
|
||||
osUpdateTimes.put({ table: 'trim_trims', time: 0 });
|
||||
osUpdateTimes.put({ table: 'news', time: 0 });
|
||||
osUpdateTimes.put({ table: 'users', time: 0 });
|
||||
console.log('DB update times reset');
|
||||
if (!silent)
|
||||
toastInfo('The database was reset. Please reload or close this tab.<br>At the next visit, a full sync will be performed.');
|
||||
hideLoader();
|
||||
} else {
|
||||
if (!silent)
|
||||
toastWarn('Your device does not support storing data locally. All data is fetched directly from our server.<br>As a result, you can not reset your database.');
|
||||
}
|
||||
}
|
||||
|
||||
1485
client/scripts/mobileconsole.js
Normal file
1485
client/scripts/mobileconsole.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,11 @@
|
||||
|
||||
?>
|
||||
//Loading the Service Worker
|
||||
var swRegistration = null;
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register('<?php echo SERVER_ADDR; ?>/service-worker.js.php');
|
||||
window.addEventListener('load', async function() {
|
||||
swRegistration = await navigator.serviceWorker.register('<?php echo SERVER_ADDR; ?>/service-worker.js.php');
|
||||
if (typeof onServiceWorkerLoaded === 'function') onServiceWorkerLoaded();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ const BOATCLASS = '<?php echo BOATCLASS; ?>';
|
||||
const LINK_PRE = '<?php echo SERVER_ADDR; ?>/';
|
||||
const YOUTH_AGE = '<?php echo $_CLASS['youth-age']; ?>';
|
||||
const YOUTH_GERMAN_NAME = '<?php echo $_CLASS['youth-german-name']; ?>';
|
||||
const PUSH_SERVER_KEY = '<?php echo PUSH_SERVER_KEY; ?>';
|
||||
|
||||
var randomId = function() { return '_' + Math.random().toString(36).substr(2, 9); }
|
||||
|
||||
@@ -121,8 +122,8 @@ var login = function() {
|
||||
showLoader();
|
||||
var username = $('#input-login-username').val();
|
||||
var password = $('#input-login-password').val();
|
||||
$('#input-login-username').val('');
|
||||
$('#input-login-password').val('');
|
||||
$('#input-login-username').val('').trigger('focusin').trigger('focusout');
|
||||
$('#input-login-password').val('').trigger('focusin').trigger('focusout');
|
||||
$.ajax({
|
||||
url: QUERY_URL + 'login',
|
||||
method: 'POST',
|
||||
@@ -134,7 +135,7 @@ var login = function() {
|
||||
error: function (xhr, status, error) {
|
||||
if (xhr.status == 401) {
|
||||
toastError('Benutzername oder Passwort falsch');
|
||||
$('#input-login-username').val(username);
|
||||
$('#input-login-username').val(username).trigger('focusin').trigger('focusout');
|
||||
} else if (xhr.status == 0) {
|
||||
toastError('Du bist momentan offline.<br>Stelle eine Internetverbindung her, um Dich anzumelden');
|
||||
$('#menu-login').hideMenu();
|
||||
@@ -202,7 +203,28 @@ var logout = function() {
|
||||
});
|
||||
}
|
||||
|
||||
function resetCache() {
|
||||
function deleteDb() {
|
||||
$('#menu-developer').hideMenu();
|
||||
if (canUseLocalDB) {
|
||||
showLoader();
|
||||
var request = window.indexedDB.deleteDatabase('regatten_app_db_' + BOATCLASS);
|
||||
request.onerror = function (event) {
|
||||
console.log('Cannot delete DB: ', event.target.errorCode);
|
||||
toastError('Beim Löschen der Datenbank ist ein Fehler aufgetreten.<br>Bitte melde diesen Fehler. (Dev-Menu => Problem melden)', 5000);
|
||||
hideLoader();
|
||||
}
|
||||
request.onsuccess = function (event) {
|
||||
console.log('DB deleted');
|
||||
toastInfo('Die Datenbank wurde gelöscht. Die Seite lädt in wenigen Sekunden neu und erstellt damit eine neue Datenbank.', 10000);
|
||||
hideLoader();
|
||||
setTimeout(function(){ location.reload(); }, 3000);
|
||||
}
|
||||
} else {
|
||||
toastWarn('Dein Gerät unterstützt kein lokales Speichern der Daten. Alle Daten werden direkt vom Server gezogen.<br>Entsprechend kannst Du die Datenbank auch nicht zurücksetzen.', 10000);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCache() {
|
||||
$('#menu-developer').hideMenu();
|
||||
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
||||
for (let registration of registrations) {
|
||||
@@ -216,7 +238,190 @@ function resetCache() {
|
||||
return caches.delete(key);
|
||||
}));
|
||||
});
|
||||
toastInfo('The serviceWorker and the cache were deleted. A new serviceWorker will be generated on the next refresh.');
|
||||
toastInfo('Der serviceWorker und alle Caches wurden gelöscht. Die Seite lädt in wenigen Sekunden neu und erstellt damit neue Caches.', 10000);
|
||||
setTimeout(function(){ location.reload(); }, 3000);
|
||||
}
|
||||
|
||||
var pushesPossible = false;
|
||||
|
||||
function urlB64ToUint8Array(base64String) {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
.replace(/\-/g, '+')
|
||||
.replace(/_/g, '/');
|
||||
|
||||
const rawData = window.atob(base64);
|
||||
const outputArray = new Uint8Array(rawData.length);
|
||||
|
||||
for (let i = 0; i < rawData.length; ++i) {
|
||||
outputArray[i] = rawData.charCodeAt(i);
|
||||
}
|
||||
return outputArray;
|
||||
}
|
||||
|
||||
function pushesSubscribe() {
|
||||
console.log('Subscribing');
|
||||
const applicationServerKey = urlB64ToUint8Array(PUSH_SERVER_KEY);
|
||||
swRegistration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: applicationServerKey
|
||||
})
|
||||
.then(function(subscription) {
|
||||
pushesUpdateServerSubscription(subscription, true);
|
||||
updatePushSwitches();
|
||||
updatePushBadge();
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log('Failed to subscribe the user: ', err);
|
||||
toastError('Da ist leider etwas schief gelaufen. Bitte stelle sicher, dass Du mit dem Internet verbunden bist und versuche es erneut.', 5000);
|
||||
pushesUnSubscribe(true);
|
||||
});
|
||||
}
|
||||
|
||||
function pushesUnSubscribe(silent = false) {
|
||||
console.log('Unsubscribing');
|
||||
swRegistration.pushManager.getSubscription()
|
||||
.then(function(subscription) {
|
||||
if (subscription) {
|
||||
pushesUpdateServerSubscription(subscription, false);
|
||||
subscription.unsubscribe();
|
||||
$('#menu-pushes').hideMenu();
|
||||
updatePushBadge();
|
||||
hideLoader();
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.log('Error unsubscribing', error);
|
||||
$('#menu-pushes').hideMenu();
|
||||
if (!silent) toastError('Da ist leider etwas schief gelaufen. Bitte versuche es erneut oder wende Dich an unseren Support.', 5000);
|
||||
updatePushBadge();
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
function pushesUpdateServerSubscription(subscription, enabled) {
|
||||
console.log('updateServer', enabled, subscription);
|
||||
$.ajax({
|
||||
url: QUERY_URL + (enabled ? 'add' : 'remove') + '_subscription',
|
||||
type: 'POST',
|
||||
data: { subscription: JSON.stringify(subscription) },
|
||||
success: function (data, textStatus, jqXHR) {
|
||||
if (!enabled) {
|
||||
toastOk('Du erhältst ab sofort keine Benachrichtigungen mehr von uns.');
|
||||
}
|
||||
hideLoader();
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
throw 'Cannot update server subscription';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function initPushSettings() {
|
||||
var items = [
|
||||
['notify_channel_' + BOATCLASS + '_news', true],
|
||||
['notify_channel_' + BOATCLASS + '_regatta_changed_my', true],
|
||||
['notify_channel_' + BOATCLASS + '_regatta_changed_all', false],
|
||||
['notify_channel_' + BOATCLASS + '_result_ready_my', true],
|
||||
['notify_channel_' + BOATCLASS + '_result_ready_all', true],
|
||||
['notify_channel_' + BOATCLASS + '_meldeschluss', true]
|
||||
];
|
||||
for (var i in items) {
|
||||
var item = items[i];
|
||||
if ((await dbSettingsGet(item[0])) == null) dbSettingsSet(item[0], item[1]);
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePushSwitches() {
|
||||
$('#switch-pushes-news').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_news'));
|
||||
$('#switch-pushes-regatta-changed-my').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_regatta_changed_my'));
|
||||
$('#switch-pushes-regatta-changed-all').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_regatta_changed_all'));
|
||||
$('#switch-pushes-result-ready-my').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_my'));
|
||||
$('#switch-pushes-result-ready-all').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_result_ready_all'));
|
||||
$('#switch-pushes-meldeschluss').prop('checked', await dbSettingsGet('notify_channel_' + BOATCLASS + '_meldeschluss'));
|
||||
|
||||
if ($('#switch-pushes').prop('checked')) {
|
||||
$('#p-pushes-info').show();
|
||||
$('.a-switch-pushes-channel-all').show();
|
||||
$('.a-switch-pushes-channel-my').show();
|
||||
if (!isLoggedIn()) {
|
||||
$('.a-switch-pushes-channel-my').find('div').remove();
|
||||
$('.a-switch-pushes-channel-my').find('.badge').text('nicht angemeldet');
|
||||
}
|
||||
} else {
|
||||
$('#p-pushes-info').hide();
|
||||
$('.a-switch-pushes-channel-all').hide();
|
||||
$('.a-switch-pushes-channel-my').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function pushesSubscribeClicked() {
|
||||
showLoader();
|
||||
if ($('#switch-pushes').prop('checked')) {
|
||||
pushesSubscribe();
|
||||
} else {
|
||||
pushesUnSubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
function pushesChannelClicked() {
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_news', $('#switch-pushes-news').prop('checked'));
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_regatta_changed_my', $('#switch-pushes-regatta-changed-my').prop('checked'));
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_regatta_changed_all', $('#switch-pushes-regatta-changed-all').prop('checked'));
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_result_ready_my', $('#switch-pushes-result-ready-my').prop('checked'));
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_result_ready_all', $('#switch-pushes-result-ready-all').prop('checked'));
|
||||
dbSettingsSet('notify_channel_' + BOATCLASS + '_meldeschluss', $('#switch-pushes-meldeschluss').prop('checked'));
|
||||
}
|
||||
|
||||
function pushesOpenMenu() {
|
||||
$('#menu-settings').hideMenu();
|
||||
if (!pushesPossible) {
|
||||
toastWarn('Dein Browser unterstützt leider keine Benachrichtigungen.', 5000);
|
||||
return;
|
||||
}
|
||||
if (Notification.permission == 'denied') {
|
||||
toastWarn('Benachrichtigungen werden von Deinem Browser blockiert.', 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
swRegistration.pushManager.getSubscription().then(function(subscription) {
|
||||
var isSub = (subscription !== null);
|
||||
$('#switch-pushes').prop('checked', isSub);
|
||||
updatePushSwitches();
|
||||
$('#menu-pushes').showMenu();
|
||||
});
|
||||
}
|
||||
|
||||
function updatePushBadge() {
|
||||
if (!pushesPossible) return;
|
||||
if (Notification.permission == 'denied') {
|
||||
$('#badge-pushes').removeClass('bg-green2-dark').addClass('bg-red2-dark').text('BLOCKED');
|
||||
return;
|
||||
}
|
||||
swRegistration.pushManager.getSubscription().then(function(subscription) {
|
||||
var isSub = (subscription !== null);
|
||||
if (isSub) {
|
||||
$('#badge-pushes').removeClass('bg-red2-dark').addClass('bg-green2-dark').text('AN');
|
||||
} else {
|
||||
$('#badge-pushes').removeClass('bg-green2-dark').addClass('bg-red2-dark').text('AUS');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function updateNewsBadge() {
|
||||
var newsRead = await dbSettingsGet('news_read_' + BOATCLASS);
|
||||
if (newsRead === null) dbSettingsSet('news_read_' + BOATCLASS, newsRead = new Date());
|
||||
var news = await dbGetData('news');
|
||||
var now = new Date();
|
||||
var sum = 0;
|
||||
for (var n in news) {
|
||||
var newsEntry = news[n];
|
||||
newsEntry.date = new Date(Date.parse(newsEntry.date));
|
||||
if (newsEntry.date > now) continue;
|
||||
if (newsEntry.date < newsRead) continue;
|
||||
sum ++;
|
||||
}
|
||||
updateBadge('more/news', sum);
|
||||
}
|
||||
|
||||
var initRegatten = function() {
|
||||
@@ -235,4 +440,51 @@ var initRegatten = function() {
|
||||
$('.show-loggedin').hide();
|
||||
$('.show-notloggedin').show();
|
||||
}
|
||||
|
||||
// Pushes
|
||||
$('#a-switch-pushes').click(pushesSubscribeClicked);
|
||||
$('.a-switch-pushes-channel-all').click(pushesChannelClicked);
|
||||
$('.a-switch-pushes-channel-my').click(pushesChannelClicked);
|
||||
}
|
||||
|
||||
var onServiceWorkerLoaded = function() {
|
||||
if ((swRegistration !== null) && canUseLocalDB) {
|
||||
pushesPossible = true;
|
||||
updatePushBadge();
|
||||
} else {
|
||||
$('#badge-pushes').removeClass('bg-green2-dark').addClass('bg-red2-dark').text('NOT SUPPORTED');
|
||||
}
|
||||
}
|
||||
|
||||
var onDatabaseLoaded = function() {
|
||||
onServiceWorkerLoaded();
|
||||
initPushSettings();
|
||||
|
||||
updateNewsBadge();
|
||||
}
|
||||
|
||||
var onAfterSync = function() {
|
||||
updateNewsBadge();
|
||||
}
|
||||
|
||||
// Add console opener to preloader
|
||||
var addConsoleOpenerToPreloader = function() {
|
||||
addConsoleOpenerToPreloader = function(){};
|
||||
var preloader = document.getElementById('preloader');
|
||||
var button = document.createElement('a');
|
||||
button.href = '#';
|
||||
button.classList = 'btn btn-full rounded-s text-uppercase font-900 shadow-m bg-highlight m-3';
|
||||
button.style.position = 'fixed';
|
||||
button.style.bottom = 0;
|
||||
button.style.left = 0;
|
||||
button.style.right = 0;
|
||||
button.innerHTML = 'Show Console';
|
||||
button.onclick = function(){
|
||||
mobileConsole.displayConsole();
|
||||
return false;
|
||||
}
|
||||
setTimeout(function(){
|
||||
preloader.appendChild(button);
|
||||
}, 5000);
|
||||
}
|
||||
addConsoleOpenerToPreloader();
|
||||
|
||||
@@ -173,6 +173,13 @@
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/*** BLOCKQUOTE ***/
|
||||
blockquote {
|
||||
border-left: 0.5em solid rgba(0, 0, 0, 0.125);
|
||||
font-style: italic;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
/*** BLINKING ICONS ***/
|
||||
@keyframes fa-blink {
|
||||
0% { opacity: 1; }
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
define('QUERY_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/api/' . BOATCLASS . '/'); // url to api backend
|
||||
define('LOGGING_APIKEY', 'xxx'); // Apikey for Logging API -> get from ostertun.net/logging
|
||||
|
||||
// PUSH
|
||||
define('PUSH_SERVER_KEY', '');
|
||||
|
||||
// BOAT CLASS
|
||||
$_CLASS = array(
|
||||
'name' => 'Pirat',
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
// TODO: Create site
|
||||
|
||||
$sp['title'] = 'Seite noch nicht unterstuuml;tzt - Regatten.net ' . $_CLASS['name'];
|
||||
$sp['title'] = 'News - Regatten.net ' . $_CLASS['name'];
|
||||
$sp['backbutton'] = true;
|
||||
$sp['activenav'] = 5;
|
||||
|
||||
$content = $tpl->load('error', ['404', 'Seite existiert noch nicht']);
|
||||
$content .= '<p>';
|
||||
$content .= 'Die gesuchte Seite ist leider noch nicht verfügbar.<br>';
|
||||
$content .= 'Wir arbeiten daran, sie schnellstmöglich zur Verfügung zu stellen.<br>';
|
||||
$content .= 'Wie wäre es mit der Homepage?';
|
||||
$content .= '</p>';
|
||||
$content .= $tpl->load('button', ['Zur Startseite', LINK_PRE . 'index', 'css-class' => 'mb-3']);
|
||||
$content .= $tpl->load('button', ['Kontakt', LINK_PRE . 'contact']);
|
||||
// Title
|
||||
$content = "<h1>Neuigkeiten</h1>";
|
||||
$content .= '<p>Aktuelles der letzten zwölf Monate</p>';
|
||||
|
||||
$sp['output'] = $tpl->load('card', [$content, 'css-class' => 'text-center pt-3']);
|
||||
$sp['output'] .= $tpl->load('card', [$content]);
|
||||
|
||||
// Menu
|
||||
$sp['menus'] .= $tpl->load('menu/modal', ['html-id' => 'menu-news', 'title' => 'Details']);
|
||||
|
||||
$cardTemplate = $tpl->load('card', ['%CONTENT%', 'html-id' => '%ID%', 'css-class' => 'card-news']);
|
||||
$cardTemplate = str_replace("\n", '', $cardTemplate);
|
||||
$cardTemplate = str_replace("\r", '', $cardTemplate);
|
||||
$sp['scripts'] .= "<script>const cardTemplate = '" . $cardTemplate . "';</script>";
|
||||
$sp['scripts'] .= $scripts->load('news');
|
||||
|
||||
?>
|
||||
@@ -92,7 +92,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="menu-settings" class="menu menu-box-bottom menu-box-detached rounded-m" data-menu-height="270">
|
||||
<div id="menu-settings" class="menu menu-box-bottom menu-box-detached rounded-m" data-menu-height="310">
|
||||
<div class="menu-title"><h1>Einstellungen</h1><p class="color-highlight"> </p><a href="#" class="close-menu"><i class="fa fa-times"></i></a></div>
|
||||
<div class="divider divider-margins mb-n2"></div>
|
||||
<div class="content">
|
||||
@@ -110,7 +110,7 @@
|
||||
<span>Login</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="#" data-menu="menu-signup" class="show-notloggedin border-0">
|
||||
<a href="#" data-menu="menu-signup" class="show-notloggedin">
|
||||
<i class="fa font-14 fa-user-plus rounded-s bg-highlight color-white"></i>
|
||||
<span>Registrieren</span>
|
||||
<span class="badge bg-red2-dark color-white">FREE</span>
|
||||
@@ -120,40 +120,125 @@
|
||||
<span>Account</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="#" onclick="logout();" class="show-loggedin border-0">
|
||||
<a href="#" onclick="logout();" class="show-loggedin">
|
||||
<i class="fa font-14 fa-sign-out-alt rounded-s bg-highlight color-white"></i>
|
||||
<span>Logout</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="#" onclick="pushesOpenMenu()" class="border-0">
|
||||
<i class="fa font-14 fa-bell rounded-s bg-highlight color-white"></i>
|
||||
<span>Benachrichtigungen</span>
|
||||
<span id="badge-pushes" class="badge color-white"></span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="menu-developer" class="menu menu-box-bottom menu-box-detached rounded-m" data-menu-height="310">
|
||||
<div id="menu-pushes" class="menu menu-box-bottom menu-box-detached rounded-m" data-menu-height="500">
|
||||
<div class="menu-title"><h1>Benachrichtigungen</h1><p class="color-highlight">Bleibe immer auf dem aktuellen Stand</p><a href="#" class="close-menu"><i class="fa fa-times"></i></a></div>
|
||||
<div class="divider divider-margins mb-n2"></div>
|
||||
<div class="content">
|
||||
<div class="list-group list-custom-small">
|
||||
<a id="a-switch-pushes" href="#" data-trigger-switch="switch-pushes" class="pb-2">
|
||||
<i class="fa font-14 fa-bell rounded-s bg-highlight color-white"></i>
|
||||
<span>Benachrichtigungen aktivieren</span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes">
|
||||
<label class="custom-control-label" for="switch-pushes"></label>
|
||||
</div>
|
||||
</a>
|
||||
<div class="divider"></div>
|
||||
<p style="line-height: 1.5em;" id="p-pushes-info">
|
||||
Wähle hier, über was Du informiert werden möchtest.<br>
|
||||
(meine) bezieht sich auf die Regatten, die in Deiner Saison-Planung sind,<br>
|
||||
(alle) informiert Dich über alle Regatten
|
||||
</p>
|
||||
<a href="#" data-trigger-switch="switch-pushes-news" class="pb-2 a-switch-pushes-channel-all">
|
||||
<i class="fa font-14 fa-newspaper rounded-s bg-highlight color-white"></i>
|
||||
<span>Neuigkeiten</span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-news">
|
||||
<label class="custom-control-label" for="switch-pushes-news"></label>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#" data-trigger-switch="switch-pushes-regatta-changed-my" class="pb-2 a-switch-pushes-channel-my">
|
||||
<i class="fa font-14 fa-calendar-check rounded-s bg-highlight color-white"></i>
|
||||
<span>Regatta verschoben (meine)</span>
|
||||
<span class="badge bg-red2-dark color-white"></span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-regatta-changed-my">
|
||||
<label class="custom-control-label" for="switch-pushes-regatta-changed-my"></label>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#" data-trigger-switch="switch-pushes-regatta-changed-all" class="pb-2 a-switch-pushes-channel-all">
|
||||
<i class="fa font-14 fa-calendar-check rounded-s bg-highlight color-white"></i>
|
||||
<span>Regatta verschoben (alle)</span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-regatta-changed-all">
|
||||
<label class="custom-control-label" for="switch-pushes-regatta-changed-all"></label>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#" data-trigger-switch="switch-pushes-result-ready-my" class="pb-2 a-switch-pushes-channel-my">
|
||||
<i class="fa font-14 fa-poll rounded-s bg-highlight color-white"></i>
|
||||
<span>Ergebnisse verfügbar (meine)</span>
|
||||
<span class="badge bg-red2-dark color-white"></span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-result-ready-my">
|
||||
<label class="custom-control-label" for="switch-pushes-result-ready-my"></label>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#" data-trigger-switch="switch-pushes-result-ready-all" class="pb-2 a-switch-pushes-channel-all">
|
||||
<i class="fa font-14 fa-poll rounded-s bg-highlight color-white"></i>
|
||||
<span>Ergebnisse verfügbar (alle)</span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-result-ready-all">
|
||||
<label class="custom-control-label" for="switch-pushes-result-ready-all"></label>
|
||||
</div>
|
||||
</a>
|
||||
<a href="#" data-trigger-switch="switch-pushes-meldeschluss" class="pb-2 a-switch-pushes-channel-my">
|
||||
<i class="fa font-14 fa-file-signature rounded-s bg-highlight color-white"></i>
|
||||
<span>Melde-Erinnerungen</span>
|
||||
<span class="badge bg-red2-dark color-white"></span>
|
||||
<div class="custom-control scale-switch ios-switch">
|
||||
<input type="checkbox" class="ios-input" id="switch-pushes-meldeschluss">
|
||||
<label class="custom-control-label" for="switch-pushes-meldeschluss"></label>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="menu-developer" class="menu menu-box-bottom menu-box-detached rounded-m" data-menu-height="360">
|
||||
<div class="menu-title"><h1>Entwickler-Optionen</h1><p class="color-highlight">Version <?php echo PWA_VERSION; ?></p><a href="#" class="close-menu"><i class="fa fa-times"></i></a></div>
|
||||
<div class="divider divider-margins mb-n2"></div>
|
||||
<div class="content">
|
||||
<div class="list-group list-custom-small">
|
||||
<a href="https://info.ostertun.net/regatten/beta">
|
||||
<a href="https://github.com/ostertun/RegattenApp/wiki">
|
||||
<i class="fa font-14 fa-info rounded-s bg-highlight color-white"></i>
|
||||
<span>Infos zur BETA</span>
|
||||
<span>App-Wiki</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="javascript:resetDb(false);">
|
||||
<a href="javascript:deleteDb();">
|
||||
<i class="fa font-14 fa-database rounded-s bg-highlight color-white"></i>
|
||||
<span>Reset Database</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="javascript:resetCache();">
|
||||
<a href="javascript:deleteCache();">
|
||||
<i class="fa font-14 fa-trash-alt rounded-s bg-highlight color-white"></i>
|
||||
<span>Reset Cache</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="https://report.regatten.net/" class="border-0">
|
||||
<a href="https://github.com/ostertun/RegattenApp/issues">
|
||||
<i class="fa font-14 fa-bug rounded-s bg-highlight color-white"></i>
|
||||
<span>Problem melden</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
<a href="#" onclick="mobileConsole.displayConsole(); return false;" class="border-0 menu-close">
|
||||
<i class="fa font-14 fa-terminal rounded-s bg-highlight color-white"></i>
|
||||
<span>Console anzeigen</span>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<script type="text/javascript" src="<?php echo SERVER_ADDR; ?>/client/scripts/mobileconsole.js"></script>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
|
||||
@@ -68,10 +68,10 @@ function addRace() {
|
||||
rlp: (100 * rlf * ((fb + 1 - pl) / fb))
|
||||
};
|
||||
|
||||
$('#input-rlf').val('');
|
||||
$('#input-m').val('');
|
||||
$('#input-fb').val('');
|
||||
$('#input-pl').val('');
|
||||
$('#input-rlf').val('').trigger('focusin').trigger('focusout');
|
||||
$('#input-m').val('').trigger('focusin').trigger('focusout');
|
||||
$('#input-fb').val('').trigger('focusin').trigger('focusout');
|
||||
$('#input-pl').val('').trigger('focusin').trigger('focusout');
|
||||
|
||||
races.push(race);
|
||||
reCalc();
|
||||
|
||||
@@ -31,8 +31,8 @@ function sendMessage() {
|
||||
},
|
||||
success: function (data, status, xhr) {
|
||||
toastOk('Nachricht erfolgreich versandt!');
|
||||
$('#input-subject').val('');
|
||||
$('#input-message').val('');
|
||||
$('#input-subject').val('').trigger('focusin').trigger('focusout');
|
||||
$('#input-message').val('').trigger('focusin').trigger('focusout');
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -120,8 +120,10 @@ var siteScript = async function() {
|
||||
ms = parseDate(regatta['meldungSchluss']);
|
||||
}
|
||||
var diff = Math.round((ms - today) / 86400000);
|
||||
if ((ms >= today) && (diff < 7)) {
|
||||
if (ms < today) {
|
||||
color = ' color-red2-dark';
|
||||
} else if (diff < 7) {
|
||||
color = ' color-yellow2-dark';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,8 +229,10 @@ var siteScript = async function() {
|
||||
ms = parseDate(regatta['meldungSchluss']);
|
||||
}
|
||||
var diff = Math.round((ms - today) / 86400000);
|
||||
if ((ms >= today) && (diff < 7)) {
|
||||
if (ms < today) {
|
||||
color = ' color-red2-dark';
|
||||
} else if (diff < 7) {
|
||||
color = ' color-yellow2-dark';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
server/scripts/news.js
Normal file
44
server/scripts/news.js
Normal file
@@ -0,0 +1,44 @@
|
||||
async function onNewsClicked(id) {
|
||||
var newsEntry = await dbGetData('news', id);
|
||||
if (newsEntry == null) return;
|
||||
|
||||
$('#menu-news').css('height', '80%');
|
||||
$('#menu-news').css('width', '90%');
|
||||
$('#menu-news').find('.menu-title').find('p').text(newsEntry.title);
|
||||
$('#menu-news').find('.content').addClass('pb-3');
|
||||
$('#menu-news').find('.content').html(newsEntry.html);
|
||||
|
||||
$('#menu-news').showMenu();
|
||||
}
|
||||
|
||||
function addCard(newsEntry) {
|
||||
var content = '<h2>' + newsEntry.title + '</h2>';
|
||||
content += '<p class="mb-2"><i>' + formatDate('d.m.Y', newsEntry.date) + '</i></p>';
|
||||
content += '<p class="mb-0">' + newsEntry.description.replace('\n', '<br>') + '</p>';
|
||||
if (newsEntry.html != '') {
|
||||
content += '<a class="btn btn-full rounded-s text-uppercase font-900 shadow-m bg-highlight mt-3" href="#" onclick="onNewsClicked(' + newsEntry.id + '); return false;">Mehr lesen</a>';
|
||||
}
|
||||
|
||||
$('.page-content').append(cardTemplate.replace('%ID%', 'card-news-' + newsEntry.id).replace('%CONTENT%', content));
|
||||
}
|
||||
|
||||
var siteScript = async function() {
|
||||
$('.card-news').remove();
|
||||
var news = await dbGetData('news');
|
||||
news.sort(function (a,b) {
|
||||
return b.date.localeCompare(a.date);
|
||||
});
|
||||
var now = new Date();
|
||||
var lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
for (var n in news) {
|
||||
var newsEntry = news[n];
|
||||
newsEntry.date = new Date(Date.parse(newsEntry.date));
|
||||
if (newsEntry.date > now) continue;
|
||||
if (newsEntry.date < lastYear) break;
|
||||
addCard(newsEntry);
|
||||
}
|
||||
dbSettingsSet('news_read_' + BOATCLASS, now);
|
||||
updateNewsBadge();
|
||||
hideLoader();
|
||||
}
|
||||
@@ -111,8 +111,8 @@ async function selectChange(callSiteScript = true) {
|
||||
var year = parseInt($('#select-year').val());
|
||||
if (type == "user") {
|
||||
$('#select-year').parent().hide();
|
||||
$('#input-from').parent().show();
|
||||
$('#input-to').parent().show();
|
||||
$('#input-from').trigger('focusin').trigger('focusout').parent().show();
|
||||
$('#input-to').trigger('focusin').trigger('focusout').parent().show();
|
||||
$('#input-jugend').parent().parent().show();
|
||||
$('#input-jugstrict').parent().parent().show();
|
||||
$('#button-show').show();
|
||||
@@ -174,8 +174,20 @@ async function selectChange(callSiteScript = true) {
|
||||
$('#input-jugend').prop('checked', jugend);
|
||||
$('#input-jugstrict').prop('checked', jugstrict);
|
||||
|
||||
if (callSiteScript && (typeof siteScript === 'function'))
|
||||
if (callSiteScript && (typeof siteScript === 'function')) {
|
||||
history.replaceState(null, '', '?type=' + type + '&year=' + year)
|
||||
siteScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buttonShowPressed() {
|
||||
if (typeof siteScript === 'function') {
|
||||
var chboxes = '';
|
||||
if ($('#input-jugend').prop('checked')) chboxes += '&jugend=on'
|
||||
if ($('#input-jugstrict').prop('checked')) chboxes += '&jugstrict=on'
|
||||
history.replaceState(null, '', '?type=user&from=' + $('#input-from').val() + "&to=" + $('#input-to').val() + chboxes)
|
||||
siteScript();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +202,19 @@ function initSelects() {
|
||||
$('#select-year').html('<option value="' + year + '">' + year + '</option>');
|
||||
$('#select-year').val(year);
|
||||
|
||||
if (type == "user") {
|
||||
var from = findGetParameter('from');
|
||||
var to = findGetParameter('to');
|
||||
if (from === null) from = formatDate('Y-m-d')
|
||||
if (to === null) to = formatDate('Y-m-d')
|
||||
$('#input-from').val(from).trigger('focusin').trigger('focusout');
|
||||
$('#input-to').val(to).trigger('focusin').trigger('focusout');
|
||||
var jugend = findGetParameter('jugend');
|
||||
var jugstrict = findGetParameter('jugstrict');
|
||||
$('#input-jugend').prop('checked', jugend !== null);
|
||||
$('#input-jugstrict').prop('checked', jugstrict !== null);
|
||||
}
|
||||
|
||||
selectChange(false);
|
||||
}
|
||||
|
||||
@@ -218,7 +243,7 @@ var siteScript = async function() {
|
||||
initSelects();
|
||||
$('#select-type').change(selectChange);
|
||||
$('#select-year').change(selectChange);
|
||||
$('#button-show').click(siteScript);
|
||||
$('#button-show').click(buttonShowPressed);
|
||||
$('#input-search').on('input', drawList);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
function selectChange(callSiteScript = true) {
|
||||
var val = $('#select-year').val();
|
||||
if (val == "user") {
|
||||
$('#input-from').parent().show();
|
||||
$('#input-to').parent().show();
|
||||
$('#input-from').trigger('focusin').trigger('focusout').parent().show();
|
||||
$('#input-to').trigger('focusin').trigger('focusout').parent().show();
|
||||
$('#button-show').show();
|
||||
} else {
|
||||
$('#input-from').parent().hide();
|
||||
@@ -12,8 +12,17 @@ function selectChange(callSiteScript = true) {
|
||||
$('#input-from').val(val + '-01-01');
|
||||
$('#input-to').val(val + '-12-31');
|
||||
|
||||
if (callSiteScript && (typeof siteScript === 'function'))
|
||||
if (callSiteScript && (typeof siteScript === 'function')) {
|
||||
history.replaceState(null, '', '?year=' + val);
|
||||
siteScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buttonShowPressed() {
|
||||
if (typeof siteScript === 'function') {
|
||||
history.replaceState(null, '', '?year=user&from=' + $('#input-from').val() + "&to=" + $('#input-to').val())
|
||||
siteScript();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +33,15 @@ function initYear() {
|
||||
$('#select-year').html('<option value="' + year + '">' + year + '</option>');
|
||||
$('#select-year').val(year);
|
||||
|
||||
if (year == "user") {
|
||||
var from = findGetParameter('from');
|
||||
var to = findGetParameter('to');
|
||||
if (from === null) from = formatDate('Y-m-d')
|
||||
if (to === null) to = formatDate('Y-m-d')
|
||||
$('#input-from').val(from).trigger('focusin').trigger('focusout');
|
||||
$('#input-to').val(to).trigger('focusin').trigger('focusout');
|
||||
}
|
||||
|
||||
selectChange(false);
|
||||
}
|
||||
|
||||
@@ -50,7 +68,7 @@ var siteScript = async function() {
|
||||
firstCall = false;
|
||||
initYear();
|
||||
$('#select-year').change(selectChange);
|
||||
$('#button-show').click(siteScript);
|
||||
$('#button-show').click(buttonShowPressed);
|
||||
$('#input-search').on('input', drawList);
|
||||
}
|
||||
|
||||
@@ -160,8 +178,10 @@ var siteScript = async function() {
|
||||
ms = parseDate(entry['meldungSchluss']);
|
||||
}
|
||||
var diff = Math.round((ms - today) / 86400000);
|
||||
if ((ms >= today) && (diff < 7)) {
|
||||
if (ms < today) {
|
||||
color = ' color-red2-dark';
|
||||
} else if (diff < 7) {
|
||||
color = ' color-yellow2-dark';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
define('PWA_VERSION', '1.5');
|
||||
define('PWA_VERSION', '1.8');
|
||||
|
||||
?>
|
||||
@@ -56,15 +56,19 @@ workbox.precaching.precacheAndRoute([
|
||||
'/manifest.json.php',
|
||||
];
|
||||
$dirsToCache = [
|
||||
'/client',
|
||||
'/client/app',
|
||||
'/client/fonts/css',
|
||||
'/client/fonts/webfonts',
|
||||
'/client/images',
|
||||
'/client/scripts',
|
||||
'/client/styles',
|
||||
];
|
||||
|
||||
function addDir($path) {
|
||||
global $filesToCache;
|
||||
if ($dir = opendir(__DIR__ . $path)) {
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
if ($file == '.') continue;
|
||||
if ($file == '..') continue;
|
||||
if (substr($file, 0, 1) == '.') continue;
|
||||
if (is_dir(__DIR__ . $path . '/' . $file)) {
|
||||
addDir($path . '/' . $file);
|
||||
} else {
|
||||
@@ -105,3 +109,204 @@ workbox.routing.registerRoute(
|
||||
|
||||
//Learn more about Service Workers and Configurations
|
||||
//https://developers.google.com/web/tools/workbox/
|
||||
|
||||
|
||||
// DB
|
||||
|
||||
function openDb() {
|
||||
return new Promise(function(resolve) {
|
||||
if (indexedDB) {
|
||||
var request = indexedDB.open('regatten_app_db_<?php echo BOATCLASS; ?>');
|
||||
request.onerror = function (e) {
|
||||
console.log('[sW] Cannot open DB:', e.targer.errorCode);
|
||||
resolve(null);
|
||||
};
|
||||
request.onupgradeneeded = function (e) {
|
||||
console.log('[sW] DB does not exist');
|
||||
e.target.transaction.abort();
|
||||
resolve(null);
|
||||
};
|
||||
request.onsuccess = function (e) {
|
||||
console.log('[sW] DB loaded');
|
||||
var db = e.target.result;
|
||||
db.onerror = function (e) {
|
||||
console.log('[sW] DB Error:', e);
|
||||
};
|
||||
resolve(db);
|
||||
}
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function dbSettingsGet(key) {
|
||||
return new Promise(async function(resolve) {
|
||||
var db = await openDb();
|
||||
if (db !== null) {
|
||||
var request = db.transaction('settings').objectStore('settings').get(key);
|
||||
request.onsuccess = function (event) {
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
resolve(typeof request.result != 'undefined' ? request.result.value : null);
|
||||
}
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function dbSettingsSet(key, value) {
|
||||
var db = await openDb();
|
||||
if (db != null) {
|
||||
var os = db.transaction('settings', 'readwrite').objectStore('settings');
|
||||
var request = os.put({ key: key, value: value});
|
||||
request.onerror = function (event) {
|
||||
console.log('[sW] Error while saving data to DB:', e);
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
request.onsuccess = function (event) {
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// PUSHES
|
||||
|
||||
function getEntry(data, index, defaultValue) {
|
||||
return ((typeof data[index] !== "undefined") ? data[index] : defaultValue);
|
||||
}
|
||||
|
||||
function isMyRegatta(id) {
|
||||
return new Promise(async function (resolve) {
|
||||
var regattas = await dbSettingsGet('myregattas_<?php echo BOATCLASS; ?>');
|
||||
if (regattas == null) resolve(false);
|
||||
else resolve(regattas.includes(id.toString()));
|
||||
});
|
||||
}
|
||||
|
||||
self.addEventListener('push', async function(event) {
|
||||
console.log('[sW] Push received:', event.data.text());
|
||||
|
||||
var data;
|
||||
try {
|
||||
data = JSON.parse(event.data.text());
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
data = undefined;
|
||||
}
|
||||
|
||||
if (typeof data.type !== "undefined") {
|
||||
switch (data.type) {
|
||||
case 'notification':
|
||||
if (typeof data.title === "undefined") break;
|
||||
if (typeof data.body === "undefined") break;
|
||||
if (typeof data.channel === "undefined") break;
|
||||
|
||||
// check channel
|
||||
var okay = false;
|
||||
switch (data.channel) {
|
||||
case 'news':
|
||||
if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_news')) okay = true;
|
||||
break;
|
||||
case 'regatta_changed':
|
||||
if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_regatta_changed_all')) okay = true;
|
||||
else if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_regatta_changed_my')) {
|
||||
if (await isMyRegatta(getEntry(data, 'id', ''))) okay = true;
|
||||
}
|
||||
break;
|
||||
case 'result_ready':
|
||||
if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_result_ready_all')) okay = true;
|
||||
else if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_result_ready_my')) {
|
||||
if (await isMyRegatta(getEntry(data, 'id', ''))) okay = true;
|
||||
}
|
||||
break;
|
||||
case 'meldeschluss':
|
||||
if (await dbSettingsGet('notify_channel_<?php echo BOATCLASS; ?>_meldeschluss')) {
|
||||
if (await isMyRegatta(getEntry(data, 'id', ''))) okay = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log('Unknown channel:', data.channel);
|
||||
break;
|
||||
}
|
||||
if (!okay) {
|
||||
console.log('Notification channel not subscribed');
|
||||
return;
|
||||
}
|
||||
|
||||
const options = {
|
||||
data: data,
|
||||
body: data.body,
|
||||
icon: getEntry(data, 'icon', '<?php echo SERVER_ADDR; ?>/client/app/icons/icon-512x512.png'),
|
||||
badge: '<?php echo SERVER_ADDR; ?>/client/app/icons/badge-128x128.png',
|
||||
vibrate: [500,100,500]
|
||||
};
|
||||
if ((image = getEntry(data, 'image', null)) !== null) {
|
||||
options.image = image;
|
||||
}
|
||||
|
||||
// Force refresh on next app open
|
||||
var db = await openDb();
|
||||
if (db != null) {
|
||||
var os = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
var request = os.put({ table: 'last_sync', time: 0 });
|
||||
request.onerror = function (event) {
|
||||
console.log('[sW] Error while saving data to DB:', e);
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
request.onsuccess = function (event) {
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Showing notification');
|
||||
self.registration.showNotification(data.title, options);
|
||||
break;
|
||||
|
||||
case 'forcesync':
|
||||
// Force refresh on next app open
|
||||
var db = await openDb();
|
||||
if (db != null) {
|
||||
var os = db.transaction('update_times', 'readwrite').objectStore('update_times');
|
||||
var request = os.put({ table: 'last_sync', time: 0 });
|
||||
request.onerror = function (event) {
|
||||
console.log('[sW] Error while saving data to DB:', e);
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
request.onsuccess = function (event) {
|
||||
console.log('[sW] Data successfully saved');
|
||||
db.close();
|
||||
console.log('[sW] DB closed');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log('[sW] Push type unknown:', data.type);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.log('[sW] No push type given!');
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function(event) {
|
||||
var data = event.notification.data;
|
||||
|
||||
event.notification.close();
|
||||
|
||||
var url = '<?php echo SERVER_ADDR; ?>' + getEntry(data, 'url', '');
|
||||
|
||||
event.waitUntil(
|
||||
clients.openWindow(url)
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user