From 9f3019b4c574b93fb855eefd141c29952d536518 Mon Sep 17 00:00:00 2001
From: ostertun
Date: Thu, 15 Oct 2020 15:19:04 +0200
Subject: [PATCH 1/4] Notification info banner
---
client/scripts/regatten.js.php | 1 +
server/content/index.php | 50 +++++++++++++++++++++-------------
server/scripts/index.js | 32 ++++++++++++++++++++++
3 files changed, 64 insertions(+), 19 deletions(-)
diff --git a/client/scripts/regatten.js.php b/client/scripts/regatten.js.php
index d85764a..21a5d22 100644
--- a/client/scripts/regatten.js.php
+++ b/client/scripts/regatten.js.php
@@ -406,6 +406,7 @@ function pushesOpenMenu() {
}
function updatePushBadge() {
+ if (typeof onUpdatePushBadge === 'function') onUpdatePushBadge();
if (!pushesPossible) return;
if (Notification.permission == 'denied') {
$('#badge-pushes').removeClass('bg-green2-dark').addClass('bg-red2-dark').text('BLOCKED');
diff --git a/server/content/index.php b/server/content/index.php
index 0df2a33..e35051d 100644
--- a/server/content/index.php
+++ b/server/content/index.php
@@ -1,14 +1,14 @@
$_CLASS[name]";
$content .= "$_CLASS[desc]
";
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// Favorites
$content = 'Deine Favoriten
';
$thead = '| Segler | Rangliste |
';
@@ -17,45 +17,57 @@
$content .= 'Du folgst keinen Seglern.
';
$content .= 'Um jemandem zu folgen, gehe zur Segler-Liste und wähle bis zu fünf Segler aus.';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-favorites']);
-
+
// Planning next
$content = 'Deine nächsten Regatten
';
$content .= '';
$content .= '';
$content .= 'Du fährst in den nächsten vier Wochen auf keine Regatta!';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-yournext']);
-
+
// Not logged in
$content = 'Nicht angemeldet
';
$content .= '';
$content .= 'Um alle Funktionen dieser Seite nutzen zu können, logge Dich bitte ein.
';
$content .= 'Solltest Du noch kein Benutzerkonto haben, kannst Du Dich kostenlos registrieren.';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-notloggedin']);
-
+
+ // Notification Info
+ $content = 'Push-Benachrichtigungen
';
+ $content .= '';
+ $content .= 'Bleibe immer auf dem Laufendem!
';
+ $content .= 'Aktiviere einfach unsere Push-Benachrichtigungen und wir informieren Dich über alle Änderungen.
';
+ $content .= 'Du bestimmst natürlich, welche Benachrichtigungen Du bekommen möchtest.';
+ $content .= '
';
+ $content .= $tpl->load('button', ['Jetzt aktivieren', '#', 'html-id' => 'button-notifications-activate', 'css-class' => 'bg-green2-dark']);
+ $content .= 'Vielleicht später
';
+
+ $sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-notifications', 'css-class' => 'bg-blue2-dark']);
+
// Next
$content = 'Nächste Regatten
';
$content .= '';
$content .= '';
$content .= 'Keine Regatten in den nächsten zwei Wochen!';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-next']);
-
+
// Last
$content = 'Letzte Regatten
';
$content .= '';
$content .= '';
$content .= 'Keine Regatten in den letzten zwei Wochen!';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-last']);
-
+
// Calendar
$content = 'Regatta-Kalender
';
$content .= 'Du willst alle Regatta-Termine in deinem Kalender, aber nicht alles abtippen?
Kein Problem! Abonniere einfach unseren ics-Kalender.
';
@@ -65,9 +77,9 @@
$content .= '';
$content .= $tpl->load('button', [' Regatta-Kalender', 'https://regatten.net/client/calendar/' . BOATCLASS . '/everything.ics', 'css-class' => 'mb-2']);
$content .= $tpl->load('button', [' Kalender für ', 'https://regatten.net/client/calendar/' . BOATCLASS . '/user_%USERID%.ics', 'css-class' => 'show-loggedin replace-userid-href']);
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// Regattas Menu
$items = '';
$items .= $tpl->load('menu/item-icon', ['Saison-Planungen', '', 'html-id' => 'menu-item-plannings', 'icon' => 'fa-calendar-alt']);
@@ -78,8 +90,8 @@
$items .= $tpl->load('menu/item-icon', ['offizielle Ergebnisse', '', 'html-id' => 'menu-item-oresults', 'icon' => 'fa-poll']);
$items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe']);
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-regatta', 'title' => 'Regatta-Details', 'height' => 320]);
-
+
$sp['scripts'] .= $scripts->load('onRegattaClicked');
$sp['scripts'] .= $scripts->load('index');
-
-?>
\ No newline at end of file
+
+?>
diff --git a/server/scripts/index.js b/server/scripts/index.js
index cc6d154..a30f36e 100644
--- a/server/scripts/index.js
+++ b/server/scripts/index.js
@@ -1,8 +1,40 @@
+var firstCall = true;
var today;
+var onUpdatePushBadge;
var siteScript = async function() {
today = getToday();
+ if (firstCall) {
+ firstCall = false;
+ $('#button-notifications-activate').click(function(){
+ $('#menu-pushes').showMenu();
+ });
+ $('#a-notifications-later').click(function(){
+ createCookie('regatten_app_' + BOATCLASS + '_rejected_push', true, 1);
+ $('#card-notifications').hide();
+ });
+ if (readCookie('regatten_app_' + BOATCLASS + '_rejected_push')) {
+ $('#card-notifications').hide();
+ } else {
+ onUpdatePushBadge = function () {
+ if (!pushesPossible || (Notification.permission == 'denied')) {
+ $('#card-notifications').hide();
+ } else {
+ swRegistration.pushManager.getSubscription().then(function(subscription) {
+ var isSub = (subscription !== null);
+ if (isSub) {
+ $('#card-notifications').hide();
+ } else {
+ $('#card-notifications').show();
+ }
+ });
+ }
+ }
+ onUpdatePushBadge();
+ }
+ }
+
if (isLoggedIn()) {
$('#card-notloggedin').hide();
From 5962e1cc902cc0fa7fc6a11dc6578e4db9336454 Mon Sep 17 00:00:00 2001
From: ostertun
Date: Thu, 15 Oct 2020 19:02:25 +0200
Subject: [PATCH 2/4] RA-#29 Follow Sailors
---
server/content/index.php | 7 ++--
server/content/sailors.php | 32 +++++++++--------
server/scripts/index.js | 74 ++++++++++++++++++++++++++++++++------
server/scripts/sailors.js | 67 ++++++++++++++++++++++++++++++++++
4 files changed, 153 insertions(+), 27 deletions(-)
diff --git a/server/content/index.php b/server/content/index.php
index e35051d..0f054f5 100644
--- a/server/content/index.php
+++ b/server/content/index.php
@@ -11,8 +11,7 @@
// Favorites
$content = 'Deine Favoriten
';
- $thead = '| Segler | Rangliste |
';
- $content .= $tpl->load('table', [$thead, 'html-id' => 'table-favorites', 'css-class' => 'mb-0 mt-3']);
+ $content .= '';
$content .= '';
$content .= 'Du folgst keinen Seglern.
';
$content .= 'Um jemandem zu folgen, gehe zur Segler-Liste und wähle bis zu fünf Segler aus.';
@@ -91,6 +90,10 @@
$items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe']);
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-regatta', 'title' => 'Regatta-Details', 'height' => 320]);
+ // Favorites Menu
+ $items = $tpl->load('menu/item-icon', ['Nicht mehr folgen', '#', 'html-id' => 'menu-item-unfollow', 'icon' => 'fa-heart', 'css-class' => ' border-0']);
+ $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-favorite', 'title' => 'Favorit', 'height' => 150]);
+
$sp['scripts'] .= $scripts->load('onRegattaClicked');
$sp['scripts'] .= $scripts->load('index');
diff --git a/server/content/sailors.php b/server/content/sailors.php
index 29e65f6..42858e7 100644
--- a/server/content/sailors.php
+++ b/server/content/sailors.php
@@ -1,14 +1,14 @@
Segler";
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// Info Years
$content = '
Jahrgänge
';
$content .= '';
@@ -17,30 +17,32 @@
$content .= 'Klicke dazu einfach auf den entsprechenden Segler und wähle Jahrgang bearbeiten aus.
';
$content .= 'Vielen Dank für Deine Unterstützung!';
$content .= '
';
-
+
$sp['output'] .= $tpl->load('card', [$content]);
-
+
// List
$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-list']);
-
+
// Pagination
$sp['output'] .= $tpl->load('pagination', ['html-id' => 'pagination']);
-
+
// Menu
- $items = $tpl->load('menu/item-icon', ['', '#', 'html-id' => 'menu-item-year', 'icon' => 'fa-edit']);
+ $items = $tpl->load('menu/item-switch', ['Favorit', 'html-id' => 'menu-item-follow', 'icon' => 'fa-heart']);
+ $items .= $tpl->load('menu/item-icon-badge', ['Favorit', '#', 'html-id' => 'menu-item-follow-disabled', 'icon' => 'fa-heart', 'badge-value' => 'MAX REACHED']);
+ $items .= $tpl->load('menu/item-icon', ['', '#', 'html-id' => 'menu-item-year', 'icon' => 'fa-edit']);
$items .= $tpl->load('menu/item-icon', ['Vereins-Website', '', 'html-id' => 'menu-item-clubwebsite', 'icon' => 'fa-globe', 'css-class' => 'border-0']);
- $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-sailor', 'title' => 'Segler-Details', 'height' => 200]);
-
+ $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-sailor', 'title' => 'Segler-Details', 'height' => 260]);
+
$items = 'Bitte trage hier den Jahrgang ein:
';
$items .= $tpl->load('input', ['html-id' => 'input-edityear', 'placeholder' => 'Jahrgang', 'type' => 'number']);
$items .= $tpl->load('button', ['Speichern', '#', 'html-id' => 'button-edityear']);
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-edityear', 'height' => 240]);
-
+
$sp['scripts'] .= $scripts->load('pagination', ['pageChange', 'page', 'pageCount', 'pagination']);
$sp['scripts'] .= $scripts->load('sailors');
-
-?>
\ No newline at end of file
+
+?>
diff --git a/server/scripts/index.js b/server/scripts/index.js
index a30f36e..438b91e 100644
--- a/server/scripts/index.js
+++ b/server/scripts/index.js
@@ -2,6 +2,49 @@ var firstCall = true;
var today;
var onUpdatePushBadge;
+var onUnfollowClicked = async function() {
+ var id = $('#menu-item-unfollow').attr('data-sailor-id');
+ showLoader();
+ $('#menu-favorite').hideMenu();
+ var auth = {
+ id: localStorage.getItem('auth_id'),
+ hash: localStorage.getItem('auth_hash')
+ }
+ $.ajax({
+ url: QUERY_URL + 'sailor_unfollow',
+ method: 'POST',
+ data: {
+ auth: auth,
+ sailor: id
+ },
+ error: function (xhr, status, error) {
+ if (xhr.status == 0) {
+ toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Deine Favoriten zu bearbeiten.');
+ } else {
+ log('Unfollow: unbekannter Fehler', status, error);
+ log(xhr);
+ toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000);
+ }
+ hideLoader();
+ },
+ success: async function (data, status, xhr) {
+ await sync();
+ toastOk('Erfolgreich');
+ hideLoader();
+ }
+ });
+}
+
+var onFavoriteClicked = async function(id) {
+ var sailor = await dbGetData('sailors', id);
+
+ $('#menu-favorite').find('.menu-title').find('p').text(sailor.name);
+
+ $('#menu-item-unfollow').attr('data-sailor-id', sailor.id);
+
+ $('#menu-favorite').showMenu();
+}
+
var siteScript = async function() {
today = getToday();
@@ -33,6 +76,7 @@ var siteScript = async function() {
}
onUpdatePushBadge();
}
+ $('#menu-item-unfollow').click(onUnfollowClicked);
}
if (isLoggedIn()) {
@@ -50,31 +94,41 @@ var siteScript = async function() {
}
if (watched.length > 0) {
var year = (new Date()).getFullYear();
- $('#th-ranking').html('Rangliste ' + year);
var ranking = (await dbGetRanking(parseDate('01.12.' + (year - 1)), parseDate('30.11.' + year), false, false))[0];
- tbody = '';
+ var list = '';
for (i in watched) {
sailor = watched[i];
- tbody += '| ' + sailor.name + ' | ';
+ var club = null;
+ if (sailor.club != null)
+ club = await dbGetData('clubs', sailor.club);
var rank = null;
for (r in ranking) {
if (ranking[r].id == sailor.id) {
- rank = ranking[r].rank;
+ rank = ranking[r];
break;
}
}
+
+ list += '';
+ list += ' ';
+ // Name
+ list += ' ' + sailor.name + ' ';
+ list += ' ';
if (rank == null) {
- tbody += ' nicht in der Rangliste';
+ list += ' Nicht in der Rangliste ';
} else {
- tbody += ' ' + rank + '. Platz';
+ // Rank
+ list += ' Platz ' + rank.rank + ' ';
+ // rlp
+ list += ' ' + rank.rlp.toFixed(3) + ' Punkte ';
}
- tbody += ' |
';
+ list += '';
}
- $('#table-favorites').find('tbody').html(tbody);
+ $('#div-favorites').html(list);
$('#p-favorites').hide();
- $('#table-favorites').show();
+ $('#div-favorites').show();
} else {
- $('#table-favorites').hide();
+ $('#div-favorites').hide();
$('#p-favorites').show();
}
$('#card-favorites').show();
diff --git a/server/scripts/sailors.js b/server/scripts/sailors.js
index d3da25b..3f088ea 100644
--- a/server/scripts/sailors.js
+++ b/server/scripts/sailors.js
@@ -4,6 +4,40 @@ var displayed = [];
var page = 1;
var pageCount = 0;
const showCount = 25;
+var followedSailors = [];
+
+async function onFollowChange() {
+ var id = $('#menu-item-follow').attr('data-sailor-id');
+ showLoader();
+ $('#menu-sailor').hideMenu();
+ var auth = {
+ id: localStorage.getItem('auth_id'),
+ hash: localStorage.getItem('auth_hash')
+ }
+ $.ajax({
+ url: QUERY_URL + ($('#menu-item-follow').prop('checked') ? 'sailor_follow' : 'sailor_unfollow'),
+ method: 'POST',
+ data: {
+ auth: auth,
+ sailor: id
+ },
+ error: function (xhr, status, error) {
+ if (xhr.status == 0) {
+ toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Deine Favoriten zu bearbeiten.');
+ } else {
+ log('Un/Follow: unbekannter Fehler', status, error);
+ log(xhr);
+ toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000);
+ }
+ hideLoader();
+ },
+ success: async function (data, status, xhr) {
+ await sync();
+ toastOk('Erfolgreich');
+ hideLoader();
+ }
+ });
+}
async function onEditYearClick() {
var id = $('#button-edityear').attr('data-sailor-id');
@@ -50,6 +84,26 @@ async function onListClicked(id) {
$('#menu-sailor').find('.menu-title').find('p').text(sailor.name);
+ // Follow
+ if (isLoggedIn()) {
+ var found = false;
+ for (var i in followedSailors) {
+ if (followedSailors[i].id == sailor.id) found = true;
+ }
+ if (found || (followedSailors.length < 5)) {
+ $('#menu-item-follow').attr('data-sailor-id', sailor.id);
+ $('#menu-item-follow').prop('checked', found);
+ $('#menu-item-follow').parent().parent().show();
+ $('#menu-item-follow-disabled').hide();
+ } else {
+ $('#menu-item-follow').parent().parent().hide();
+ $('#menu-item-follow-disabled').show();
+ }
+ } else {
+ $('#menu-item-follow').parent().parent().hide();
+ $('#menu-item-follow-disabled').hide();
+ }
+
// Edit Year
$('#button-edityear').attr('data-sailor-id', sailor.id);
$('#menu-edityear').find('.menu-title').find('p').text(sailor.name);
@@ -134,6 +188,19 @@ var siteScript = async function() {
$('#input-search').on('input', reSearch);
$('#menu-item-year').click(function(){ $('#menu-sailor').hideMenu(); $('#menu-edityear').showMenu(); });
$('#button-edityear').click(onEditYearClick);
+ $('#menu-item-follow').parent().parent().click(onFollowChange);
+ $('#menu-item-follow-disabled').click(function(){ $('#menu-sailor').hideMenu(); toastInfo('Du kannst maximal 5 Seglern folgen. Entferne erst einen Segler aus Deinen Favoriten, bevor Du andere aufnimmst.', 5000); });
+ }
+
+ if (isLoggedIn()) {
+ var user = await dbGetData('users', USER_ID);
+ followedSailors = [];
+ for (var i = 1; i <= 5; i ++) {
+ sailor_id = user['sailor' + i];
+ if (sailor_id != null) {
+ followedSailors.push(await dbGetData('sailors', sailor_id));
+ }
+ }
}
var results = await dbGetData('sailors');
From f5d059202e31899472b992129f17521e1c9c1879 Mon Sep 17 00:00:00 2001
From: ostertun
Date: Thu, 15 Oct 2020 19:39:47 +0200
Subject: [PATCH 3/4] RA-#9 Signup
---
client/scripts/regatten.js.php | 41 ++++++++++++++++++++++++++++++++++
server/content/index.php | 2 +-
server/page/menus.php | 27 +++++++++++++++-------
3 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/client/scripts/regatten.js.php b/client/scripts/regatten.js.php
index 21a5d22..e09be45 100644
--- a/client/scripts/regatten.js.php
+++ b/client/scripts/regatten.js.php
@@ -131,6 +131,47 @@ function findGetParameter(parameterName) {
return result;
}
+var signup = function() {
+ var username = $('#input-signup-username').val();
+ var email = $('#input-signup-email').val();
+ var password = $('#input-signup-password').val();
+ if (username == '') { $('#input-signup-username').focus(); return; }
+ if (email == '') { $('#input-signup-email').focus(); return; }
+ if (password == '') { $('#input-signup-password').focus(); return; }
+ showLoader();
+ $('#input-signup-username').val('').trigger('focusin').trigger('focusout');
+ $('#input-signup-email').val('').trigger('focusin').trigger('focusout');
+ $('#input-signup-password').val('').trigger('focusin').trigger('focusout');
+ $.ajax({
+ url: QUERY_URL + 'signup',
+ method: 'POST',
+ data: {
+ username: username,
+ email: email,
+ password: password
+ },
+ error: function (xhr, status, error) {
+ if (xhr.status == 409) {
+ toastError('Benutzername bereits vergeben');
+ $('#input-signup-email').val(email).trigger('focusin').trigger('focusout');
+ } else if (xhr.status == 0) {
+ toastError('Du bist momentan offline.
Stelle eine Internetverbindung her, um Dich anzumelden');
+ $('#menu-signup').hideMenu();
+ } else {
+ log('[app] Signup: unbekannter Fehler', status, error);
+ log(xhr);
+ toastError('Ein unbekannter Fehler ist aufgetreten. Bitte versuche es noch einmal', 5000);
+ }
+ hideLoader();
+ },
+ success: function (data, status, xhr) {
+ $('#input-login-username').val(username);
+ $('#input-login-password').val(password);
+ login();
+ }
+ });
+}
+
var login = function() {
showLoader();
var username = $('#input-login-username').val();
diff --git a/server/content/index.php b/server/content/index.php
index 0f054f5..acd380f 100644
--- a/server/content/index.php
+++ b/server/content/index.php
@@ -92,7 +92,7 @@
// Favorites Menu
$items = $tpl->load('menu/item-icon', ['Nicht mehr folgen', '#', 'html-id' => 'menu-item-unfollow', 'icon' => 'fa-heart', 'css-class' => ' border-0']);
- $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-favorite', 'title' => 'Favorit', 'height' => 150]);
+ $sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-favorite', 'title' => 'Favorit', 'height' => 200]);
$sp['scripts'] .= $scripts->load('onRegattaClicked');
$sp['scripts'] .= $scripts->load('index');
diff --git a/server/page/menus.php b/server/page/menus.php
index 30917c2..0b1374e 100644
--- a/server/page/menus.php
+++ b/server/page/menus.php
@@ -245,7 +245,7 @@
-