From 617de36fec8030e874fe75b5139038a73bf17dc3 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 3 Jan 2025 15:39:40 +0100 Subject: [PATCH] change admin panel --- dashboard/pages/admin/index.vue | 71 +++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/dashboard/pages/admin/index.vue b/dashboard/pages/admin/index.vue index 787bf71..cf2513a 100644 --- a/dashboard/pages/admin/index.vue +++ b/dashboard/pages/admin/index.vue @@ -5,6 +5,10 @@ import type { AdminProjectsList } from '~/server/api/admin/projects'; definePageMeta({ layout: 'dashboard' }); +const filterPremium = ref(false); +const filterAppsumo = ref(false); + + const timeRange = ref(9); @@ -12,7 +16,7 @@ function setTimeRange(n: number) { timeRange.value = n; } -const timeRangeTimestamp = computed(()=>{ +const timeRangeTimestamp = computed(() => { if (timeRange.value == 1) return Date.now() - 1000 * 60 * 60 * 24; if (timeRange.value == 2) return Date.now() - 1000 * 60 * 60 * 24 * 7; if (timeRange.value == 3) return Date.now() - 1000 * 60 * 60 * 24 * 30; @@ -21,7 +25,7 @@ const timeRangeTimestamp = computed(()=>{ const { data: projectsAggregatedResponseData } = await useFetch('/api/admin/projects', signHeaders()); -const { data: counts } = await useFetch(()=> `/api/admin/counts?from=${timeRangeTimestamp.value}`, signHeaders()); +const { data: counts } = await useFetch(() => `/api/admin/counts?from=${timeRangeTimestamp.value}`, signHeaders()); @@ -30,12 +34,56 @@ function onHideClicked() { } +function isAppsumoType(type: number) { + return type > 6000 && type < 6004 +} + const projectsAggregated = computed(() => { - return projectsAggregatedResponseData.value?.sort((a, b) => { + + let pool = projectsAggregatedResponseData.value ? [...projectsAggregatedResponseData.value] : []; + + let shownPool: AdminProjectsList[] = []; + + + for (const element of pool) { + + shownPool.push({ ...element, projects: [...element.projects] }); + + if (filterAppsumo.value === true) { + shownPool.forEach(e => { + e.projects = e.projects.filter(project => { + return isAppsumoType(project.premium_type) + }) + }) + + shownPool = shownPool.filter(e => { + return e.projects.length > 0; + }) + + } else if (filterPremium.value === true) { + shownPool.forEach(e => { + e.projects = e.projects.filter(project => { + return project.premium === true; + }) + }) + + shownPool = shownPool.filter(e => { + return e.projects.length > 0; + }) + + } else { + console.log('NO DATA') + } + } + + + + + return shownPool.sort((a, b) => { const sumVisitsA = a.projects.reduce((pa, pe) => pa + (pe.counts?.visits || 0) + (pe.counts?.events || 0), 0); const sumVisitsB = b.projects.reduce((pa, pe) => pa + (pe.counts?.visits || 0) + (pe.counts?.events || 0), 0); return sumVisitsB - sumVisitsA; - }).filter(e=>{ + }).filter(e => { return new Date(e.created_at).getTime() >= timeRangeTimestamp.value }); }) @@ -117,7 +165,6 @@ function getLogBg(last_logged_at?: string) { } - @@ -150,6 +197,11 @@ function getLogBg(last_logged_at?: string) {
All
+ + + + +
@@ -185,8 +237,9 @@ function getLogBg(last_logged_at?: string) {
-
+
@@ -194,7 +247,9 @@ function getLogBg(last_logged_at?: string) {
-
{{ project.premium ? 'PREMIUM' : 'FREE' }}
+
+ {{ project.premium ? 'PREMIUM' : 'FREE' }} +
{{ new Date(project.created_at).toLocaleDateString('it-IT') }}