Merge branch 'feature/RA-20-update-news-badge' into develop
This commit is contained in:
@@ -508,6 +508,9 @@ function sync() {
|
|||||||
$('#i-sync').removeClass('fa-spin');
|
$('#i-sync').removeClass('fa-spin');
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
if (typeof onAfterSync === 'function') {
|
||||||
|
onAfterSync();
|
||||||
|
}
|
||||||
runPageScript();
|
runPageScript();
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ function parseDate(string) {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
|
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
|
||||||
if (year.toString().length == 2) year = (year < 70 ? 2000 : 1900) + year;
|
if (year.toString().length == 2) year = (year < 70 ? 2000 : 1900) + year;
|
||||||
if ((year < 1970) || (year > 3000)) return null;
|
if ((year < 1970) || (year > 3000)) return null;
|
||||||
if ((month < 1) || (month > 12)) return null;
|
if ((month < 1) || (month > 12)) return null;
|
||||||
if ((day < 1) || (day > 31)) return null;
|
if ((day < 1) || (day > 31)) return null;
|
||||||
|
|
||||||
var date = new Date(Date.UTC(year, month - 1, day));
|
var date = new Date(Date.UTC(year, month - 1, day));
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
@@ -51,37 +51,37 @@ function formatDate(format, date = null) {
|
|||||||
date = new Date(date.valueOf());
|
date = new Date(date.valueOf());
|
||||||
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
|
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
format = format.replace("M", "%1%");
|
format = format.replace("M", "%1%");
|
||||||
format = format.replace("F", "%2%");
|
format = format.replace("F", "%2%");
|
||||||
format = format.replace("D", "%3%");
|
format = format.replace("D", "%3%");
|
||||||
format = format.replace("l", "%4%");
|
format = format.replace("l", "%4%");
|
||||||
|
|
||||||
var tmp = date.getFullYear().toString();
|
var tmp = date.getFullYear().toString();
|
||||||
var tmp2 = tmp.substr(2);
|
var tmp2 = tmp.substr(2);
|
||||||
format = format.replace("Y", tmp);
|
format = format.replace("Y", tmp);
|
||||||
format = format.replace('y', tmp2);
|
format = format.replace('y', tmp2);
|
||||||
|
|
||||||
tmp = (date.getMonth() + 1).toString();
|
tmp = (date.getMonth() + 1).toString();
|
||||||
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
|
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
|
||||||
format = format.replace('n', tmp);
|
format = format.replace('n', tmp);
|
||||||
format = format.replace('m', tmp2);
|
format = format.replace('m', tmp2);
|
||||||
|
|
||||||
tmp = date.getDate().toString();
|
tmp = date.getDate().toString();
|
||||||
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
|
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
|
||||||
format = format.replace('j', tmp);
|
format = format.replace('j', tmp);
|
||||||
format = format.replace('d', tmp2);
|
format = format.replace('d', tmp2);
|
||||||
|
|
||||||
tmp = date.getDay();
|
tmp = date.getDay();
|
||||||
tmp2 = (tmp == 0 ? 7 : tmp);
|
tmp2 = (tmp == 0 ? 7 : tmp);
|
||||||
format = format.replace('w', tmp);
|
format = format.replace('w', tmp);
|
||||||
format = format.replace('N', tmp2);
|
format = format.replace('N', tmp2);
|
||||||
|
|
||||||
format = format.replace('%1%', strings.months_short[date.getMonth()]);
|
format = format.replace('%1%', strings.months_short[date.getMonth()]);
|
||||||
format = format.replace('%2%', strings.months_long[date.getMonth()]);
|
format = format.replace('%2%', strings.months_long[date.getMonth()]);
|
||||||
|
|
||||||
format = format.replace('%3%', strings.weekdays_short[date.getDay()]);
|
format = format.replace('%3%', strings.weekdays_short[date.getDay()]);
|
||||||
format = format.replace('%4%', strings.weekdays_long[date.getDay()]);
|
format = format.replace('%4%', strings.weekdays_long[date.getDay()]);
|
||||||
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,6 +402,22 @@ function updatePushBadge() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
var initRegatten = function() {
|
||||||
showLoader();
|
showLoader();
|
||||||
|
|
||||||
@@ -436,6 +452,12 @@ var onServiceWorkerLoaded = function() {
|
|||||||
var onDatabaseLoaded = function() {
|
var onDatabaseLoaded = function() {
|
||||||
onServiceWorkerLoaded();
|
onServiceWorkerLoaded();
|
||||||
initPushSettings();
|
initPushSettings();
|
||||||
|
|
||||||
|
updateNewsBadge();
|
||||||
|
}
|
||||||
|
|
||||||
|
var onAfterSync = function() {
|
||||||
|
updateNewsBadge();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add console opener to preloader
|
// Add console opener to preloader
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
async function onNewsClicked(id) {
|
async function onNewsClicked(id) {
|
||||||
var newsEntry = await dbGetData('news', id);
|
var newsEntry = await dbGetData('news', id);
|
||||||
if (newsEntry == null) return;
|
if (newsEntry == null) return;
|
||||||
|
|
||||||
$('#menu-news').css('height', '80%');
|
$('#menu-news').css('height', '80%');
|
||||||
$('#menu-news').css('width', '90%');
|
$('#menu-news').css('width', '90%');
|
||||||
$('#menu-news').find('.menu-title').find('p').text(newsEntry.title);
|
$('#menu-news').find('.menu-title').find('p').text(newsEntry.title);
|
||||||
$('#menu-news').find('.content').addClass('pb-3');
|
$('#menu-news').find('.content').addClass('pb-3');
|
||||||
$('#menu-news').find('.content').html(newsEntry.html);
|
$('#menu-news').find('.content').html(newsEntry.html);
|
||||||
|
|
||||||
$('#menu-news').showMenu();
|
$('#menu-news').showMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCard(newsEntry) {
|
function addCard(newsEntry) {
|
||||||
console.log(newsEntry);
|
|
||||||
var content = '<h2>' + newsEntry.title + '</h2>';
|
var content = '<h2>' + newsEntry.title + '</h2>';
|
||||||
content += '<p class="mb-2"><i>' + formatDate('d.m.Y', newsEntry.date) + '</i></p>';
|
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>';
|
content += '<p class="mb-0">' + newsEntry.description.replace('\n', '<br>') + '</p>';
|
||||||
if (newsEntry.html != '') {
|
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>';
|
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));
|
$('.page-content').append(cardTemplate.replace('%ID%', 'card-news-' + newsEntry.id).replace('%CONTENT%', content));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,16 +28,17 @@ var siteScript = async function() {
|
|||||||
news.sort(function (a,b) {
|
news.sort(function (a,b) {
|
||||||
return b.date.localeCompare(a.date);
|
return b.date.localeCompare(a.date);
|
||||||
});
|
});
|
||||||
var today = getToday();
|
var now = new Date();
|
||||||
var lastYear = new Date(today);
|
var lastYear = new Date();
|
||||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||||
console.log(today, lastYear);
|
|
||||||
for (var n in news) {
|
for (var n in news) {
|
||||||
var newsEntry = news[n];
|
var newsEntry = news[n];
|
||||||
newsEntry.date = parseDate(newsEntry.date.substring(0, 10));
|
newsEntry.date = new Date(Date.parse(newsEntry.date));
|
||||||
if (newsEntry.date > today) continue;
|
if (newsEntry.date > now) continue;
|
||||||
if (newsEntry.date < lastYear) break;
|
if (newsEntry.date < lastYear) break;
|
||||||
addCard(newsEntry);
|
addCard(newsEntry);
|
||||||
}
|
}
|
||||||
|
dbSettingsSet('news_read_' + BOATCLASS, now);
|
||||||
|
updateNewsBadge();
|
||||||
hideLoader();
|
hideLoader();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user