analytics page fix
This commit is contained in:
@@ -58,10 +58,11 @@ export function useApi() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchCertificates = async () => {
|
const fetchCertificates = async () => {
|
||||||
const res = await apiClient.get('/certificates');
|
const res = await profilesApiClient.get('/profiles');
|
||||||
return res.data;
|
return res.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiClient,
|
apiClient,
|
||||||
profilesApiClient,
|
profilesApiClient,
|
||||||
|
|||||||
@@ -109,12 +109,12 @@
|
|||||||
<i class="fas fa-check-circle text-success me-2"></i>All Good
|
<i class="fas fa-check-circle text-success me-2"></i>All Good
|
||||||
</p>
|
</p>
|
||||||
<div v-else class="list-group list-group-flush">
|
<div v-else class="list-group list-group-flush">
|
||||||
<div v-for="cert in expiringCertsList" :key="cert.common_name" class="list-group-item px-0 py-2 d-flex justify-content-between align-items-center border-0">
|
<div v-for="cert in expiringCertsList" :key="cert.username" class="list-group-item px-0 py-2 d-flex justify-content-between align-items-center border-0">
|
||||||
<div>
|
<div>
|
||||||
<div class="fw-bold small">{{ cert.common_name }}</div>
|
<div class="fw-bold small">{{ cert.username }}</div>
|
||||||
<div class="text-muted" style="font-size: 0.75rem;">Expires: {{ cert.expiration_date }}</div>
|
<div class="text-muted" style="font-size: 0.75rem;">Expires: {{ cert.expiration_date }}</div>
|
||||||
</div>
|
</div>
|
||||||
<span class="badge status-warning text-dark">{{ cert.days_left }} days</span>
|
<span class="badge status-warning text-dark">{{ cert.days_remaining }} days</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -202,32 +202,15 @@ const loadCerts = async () => {
|
|||||||
loading.certs = true;
|
loading.certs = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetchCertificates();
|
const res = await fetchCertificates();
|
||||||
if(res.success) {
|
if(res.success && Array.isArray(res.data)) {
|
||||||
const now = new Date();
|
const list = res.data.filter(cert => {
|
||||||
const warningThreshold = new Date();
|
// Only active, non-revoked, and expiring soon (within 45 days)
|
||||||
warningThreshold.setDate(now.getDate() + 45);
|
return !cert.is_revoked && !cert.is_expired &&
|
||||||
|
cert.days_remaining !== null && cert.days_remaining <= 45;
|
||||||
let count = 0;
|
|
||||||
const list = [];
|
|
||||||
|
|
||||||
res.data.forEach(cert => {
|
|
||||||
if (cert.status === 'revoked') return;
|
|
||||||
const expDate = new Date(cert.expiration_date); // Assuming API returns ISO or parsable date
|
|
||||||
|
|
||||||
if (expDate <= warningThreshold) {
|
|
||||||
count++;
|
|
||||||
const diffTime = Math.abs(expDate - now);
|
|
||||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
||||||
|
|
||||||
list.push({
|
|
||||||
...cert,
|
|
||||||
days_left: diffDays
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
kpi.expiringCerts = count;
|
kpi.expiringCerts = list.length;
|
||||||
expiringCertsList.value = list.sort((a,b) => a.days_left - b.days_left);
|
expiringCertsList.value = list.sort((a,b) => (a.days_remaining || 0) - (b.days_remaining || 0));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -298,9 +281,9 @@ const renderMainChart = () => {
|
|||||||
mainChartInstance = new Chart(ctx, {
|
mainChartInstance = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels,
|
|
||||||
labels,
|
labels,
|
||||||
datasets: [
|
datasets: [
|
||||||
|
|
||||||
{
|
{
|
||||||
label: !isSpeedMode.value ? 'Received (MB)' : 'RX Mbps',
|
label: !isSpeedMode.value ? 'Received (MB)' : 'RX Mbps',
|
||||||
data: dataRx,
|
data: dataRx,
|
||||||
|
|||||||
Reference in New Issue
Block a user