RA-#20 Update news badge
This commit is contained in:
@@ -508,6 +508,9 @@ function sync() {
|
||||
$('#i-sync').removeClass('fa-spin');
|
||||
}, 500);
|
||||
|
||||
if (typeof onAfterSync === 'function') {
|
||||
onAfterSync();
|
||||
}
|
||||
runPageScript();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
@@ -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() {
|
||||
showLoader();
|
||||
|
||||
@@ -436,6 +452,12 @@ var onServiceWorkerLoaded = function() {
|
||||
var onDatabaseLoaded = function() {
|
||||
onServiceWorkerLoaded();
|
||||
initPushSettings();
|
||||
|
||||
updateNewsBadge();
|
||||
}
|
||||
|
||||
var onAfterSync = function() {
|
||||
updateNewsBadge();
|
||||
}
|
||||
|
||||
// Add console opener to preloader
|
||||
|
||||
@@ -12,7 +12,6 @@ async function onNewsClicked(id) {
|
||||
}
|
||||
|
||||
function addCard(newsEntry) {
|
||||
console.log(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>';
|
||||
@@ -29,16 +28,17 @@ var siteScript = async function() {
|
||||
news.sort(function (a,b) {
|
||||
return b.date.localeCompare(a.date);
|
||||
});
|
||||
var today = getToday();
|
||||
var lastYear = new Date(today);
|
||||
var now = new Date();
|
||||
var lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
console.log(today, lastYear);
|
||||
for (var n in news) {
|
||||
var newsEntry = news[n];
|
||||
newsEntry.date = parseDate(newsEntry.date.substring(0, 10));
|
||||
if (newsEntry.date > today) continue;
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user