dashboard-core/theme/dbd-soft-ui/views/partials/feeds.ejs

118 lines
3.3 KiB
Text
Raw Permalink Normal View History

2023-06-19 14:21:58 +05:00
<div class="card-body px-0 pt-0 pb-2">
2023-06-22 19:36:52 +05:00
<div class="table-responsive p-0">
<%
let feeds = [];
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
const db = require('quick.db');
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
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 => {
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
var delta = Math.abs(Date.now() - feed.published) / 1000;
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
// calculate (and subtract) whole days
var days = Math.floor(delta / 86400);
delta -= days * 86400;
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
// calculate (and subtract) whole hours
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
// calculate (and subtract) whole minutes
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
// what's left is seconds
var seconds = delta % 60; // in theory the modulus is not required
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
let dateString = `loading`;
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
//stupid variable names but yeah :sweat_smile:
if (seconds < 2) secsingle = "second";
else secsingle = "seconds";
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
if (minutes < 2) minsingle = "minute";
else minsingle = "minutes";
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
if (hours < 2) hrsingle = "hour";
else hrsingle = "hours";
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
if (days < 2) daysingle = "day";
else daysingle = "days";
2023-06-19 14:21:58 +05:00
2023-06-22 19:36:52 +05:00
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>
2023-06-19 14:21:58 +05:00
</div>