dashboard-core/theme/dbd-soft-ui/views/partials/feeds.ejs
Jonny_Bro (Nikita) 849a93887a
2023-06-22 19:36:52 +05:00

118 lines
No EOL
3.3 KiB
Text

<div class="card-body px-0 pt-0 pb-2">
<div class="table-responsive p-0">
<%
let feeds = [];
const db = require('quick.db');
if (db.get('feeds.three')) {
const fd = db.get('feeds.three');
const fdata = {
color: fd.color,
description: fd.description,
icon: fd.icon,
published: fd.published,
diff: fd.diff,
feedNum: 3
}
feeds.push(fdata);
}
if (db.get('feeds.two')) {
const fd = db.get('feeds.two');
const fdata = {
color: fd.color,
description: fd.description,
icon: fd.icon,
published: fd.published,
diff: fd.diff,
feedNum: 2
}
feeds.push(fdata);
}
if (db.get('feeds.one')) {
const fd = db.get('feeds.one');
const fdata = {
color: fd.color,
description: fd.description,
published: fd.published,
icon: fd.icon,
diff: fd.diff,
feedNum: 1
}
feeds.push(fdata);
}
feeds.forEach(feed => {
var delta = Math.abs(Date.now() - feed.published) / 1000;
// calculate (and subtract) whole days
var days = Math.floor(delta / 86400);
delta -= days * 86400;
// calculate (and subtract) whole hours
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;
// calculate (and subtract) whole minutes
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;
// what's left is seconds
var seconds = delta % 60; // in theory the modulus is not required
let dateString = `loading`;
//stupid variable names but yeah :sweat_smile:
if (seconds < 2) secsingle = "second";
else secsingle = "seconds";
if (minutes < 2) minsingle = "minute";
else minsingle = "minutes";
if (hours < 2) hrsingle = "hour";
else hrsingle = "hours";
if (days < 2) daysingle = "day";
else daysingle = "days";
if (minutes < 1) dateString = `${Math.round(seconds)} ${secsingle} ago`;
else if (hours < 1) dateString = `${minutes} ${minsingle} ago`;
else if (days < 1) dateString = `${hours} ${hrsingle} ago`;
else dateString = `${days} ${daysingle} ago`;
let faString = "fas fa-";
if (feed.diff) faString = "fab fa-";
%>
<div>
<div class="alert alert-<%- feed.color %> text-white font-weight-bold" role="alert"
style="display: flex; margin-top: 20px;">
<div class="icon icon-shape icon-sm shadow border-radius-md bg-white text-center me-2 d-flex align-items-center justify-content-center gray-icon-bg"
style="margin: auto 0px; width: 30px !important; height: 30px !important;">
<i class="<%- faString %><%- feed.icon %> invert-img" style="font-size: 80%; color: black;"></i>
</div>
<span style="margin: auto 0px"><%- feed.description %></span>
<span class="tagnamecolor-date"
style="color:rgb(155, 148, 148); margin: auto 0px; font-size: 75%; flex: 1; text-align: right; white-space: nowrap;">
<%- dateString %>
</span>
<% if(admin) { %>
<div class="ms-auto text-end">
<a id="deleteFeed<%- feed.feedNum %>" class="btn btn-link text-text-gradient px-3 mb-0"
style="color:white;" href="javascript:"><i class="far fa-trash-alt me-2"></i>Delete</a>
</div>
<% } %>
</div>
</div>
<%
})
if(!feeds[0]) {
%>
<div>
<span class="tagnamecolor-date" style="color:rgb(155, 148, 148); white-space: nowrap;">
There are no feeds.
</span>
</div>
<%
}
%>
</div>
</div>