From 02db83600313f2bb20b605b6857d895eb885e238 Mon Sep 17 00:00:00 2001 From: Emily Date: Tue, 6 Aug 2024 15:32:46 +0200 Subject: [PATCH] fix ui + sessions + reactivity --- broker/src/StreamLoopController.ts | 7 +- dashboard/components/CVerticalNavigation.vue | 92 +++++++++++-------- dashboard/components/CustomTab.vue | 2 +- dashboard/components/settings/General.vue | 18 +++- dashboard/pages/admin/index.vue | 32 ++++--- dashboard/server/api/admin/projects.ts | 6 +- dashboard/server/api/admin/reset_count.ts | 4 +- .../server/api/metrics/[project_id]/counts.ts | 4 +- dashboard/server/api/pay/webhook.post.ts | 2 - .../server/api/project/change_name.post.ts | 30 ++++++ dashboard/server/api/project/create.post.ts | 6 +- dashboard/server/services/CacheService.ts | 5 +- lyx-ui/components/Button.vue | 9 +- shared/schema/ProjectsCounts.ts | 2 + 14 files changed, 150 insertions(+), 69 deletions(-) create mode 100644 dashboard/server/api/project/change_name.post.ts diff --git a/broker/src/StreamLoopController.ts b/broker/src/StreamLoopController.ts index 5b3a04d..8110abd 100644 --- a/broker/src/StreamLoopController.ts +++ b/broker/src/StreamLoopController.ts @@ -22,7 +22,7 @@ export async function startStreamLoop() { delay: { base: 100, empty: 5000 }, readBlock: 2500 }, processStreamEvent); - + } @@ -97,6 +97,11 @@ async function process_keep_alive(data: Record, sessionHash: str const { pid, instant, flowHash } = data; + const existingSession = await SessionModel.findOne({ project_id: pid }, { _id: 1 }); + if (!existingSession) { + await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'sessions': 1 } }, { upsert: true }); + } + if (instant == "true") { await SessionModel.updateOne({ project_id: pid, session: sessionHash, }, { $inc: { duration: 0 }, diff --git a/dashboard/components/CVerticalNavigation.vue b/dashboard/components/CVerticalNavigation.vue index e990622..1761979 100644 --- a/dashboard/components/CVerticalNavigation.vue +++ b/dashboard/components/CVerticalNavigation.vue @@ -98,6 +98,15 @@ function onLogout() { const { projects } = useProjectsList(); const activeProject = useActiveProject(); + +const { data: maxProjects } = useFetch("/api/user/max_projects", { + headers: computed(() => { + return { + Authorization: authorizationHeaderComputed.value + } + }) +}); + const selected = ref(activeProject.value as TProject); watch(selected, () => { setActiveProject(selected.value._id.toString()) @@ -112,56 +121,57 @@ watch(selected, () => { 'hidden lg:flex': !isOpen }">
-
- +
- +
- + - - + +
+ +
- - - - -
-
+ +
+
Create new project
+
+
-
-
+
+ +
Snapshots
@@ -196,7 +206,7 @@ watch(selected, () => { -
+
From:
{{ new Date(snapshot.from).toLocaleString('it-IT').split(',')[0].trim() }} @@ -235,7 +245,9 @@ watch(selected, () => {
-
+
+ +
@@ -266,10 +278,10 @@ watch(selected, () => {
-
+
Litlyx is in Beta version.
-
+
diff --git a/dashboard/components/CustomTab.vue b/dashboard/components/CustomTab.vue index 9d476be..93a5590 100644 --- a/dashboard/components/CustomTab.vue +++ b/dashboard/components/CustomTab.vue @@ -12,7 +12,7 @@ const activeTabIndex = ref(0);
{{ tab.label }} diff --git a/dashboard/components/settings/General.vue b/dashboard/components/settings/General.vue index 765ac47..f8c877a 100644 --- a/dashboard/components/settings/General.vue +++ b/dashboard/components/settings/General.vue @@ -12,6 +12,10 @@ const entries: SettingsTemplateEntry[] = [ const activeProject = useActiveProject(); const projectNameInputVal = ref(activeProject.value?.name || ''); +watch(activeProject, () => { + projectNameInputVal.value = activeProject.value?.name || ""; +}) + const canChange = computed(() => { if (activeProject.value?.name == projectNameInputVal.value) return false; if (projectNameInputVal.value.length === 0) return false; @@ -19,15 +23,25 @@ const canChange = computed(() => { }); +async function changeProjectName() { + await $fetch("/api/project/change_name", { + method: 'POST', + ...signHeaders({ 'Content-Type': 'application/json' }), + body: JSON.stringify({ name: projectNameInputVal.value }) + }); + location.reload(); +} + +