From 1e90dc2022c5a1261f9e4b47c4f3828ed90b72a8 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sun, 27 Mar 2022 15:12:18 -0800 Subject: [PATCH] feat: add group statistics on profile page * resolve file not found error and add constants * add group stats and storage functionality * generate new types * add statistics and storage cap graphs * fix: add loadFood query param #1103 * refactor to flex view --- frontend/api/class-interfaces/groups.ts | 11 ++ frontend/components/global/StatsCards.vue | 53 ++++++++ frontend/composables/recipes/use-recipes.ts | 2 +- frontend/pages/user/profile/index.vue | 124 +++++++++++++++++- frontend/types/api-types/group.ts | 13 ++ frontend/types/components.d.ts | 2 + mealie/pkgs/stats/fs_stats.py | 9 +- mealie/repos/repository_group.py | 33 +++-- mealie/repos/repository_recipes.py | 6 +- .../groups/controller_group_self_service.py | 38 ++++-- mealie/schema/group/__init__.py | 1 + mealie/schema/group/group_statistics.py | 26 ++++ .../services/group_services/group_service.py | 40 ++++++ 13 files changed, 326 insertions(+), 32 deletions(-) create mode 100644 frontend/components/global/StatsCards.vue create mode 100644 mealie/schema/group/group_statistics.py create mode 100644 mealie/services/group_services/group_service.py diff --git a/frontend/api/class-interfaces/groups.ts b/frontend/api/class-interfaces/groups.ts index 26446bb9636e..1bd4d872f184 100644 --- a/frontend/api/class-interfaces/groups.ts +++ b/frontend/api/class-interfaces/groups.ts @@ -1,5 +1,6 @@ import { BaseCRUDAPI } from "../_base"; import { GroupInDB, UserOut } from "~/types/api-types/user"; +import { GroupStatistics, GroupStorage } from "~/types/api-types/group"; const prefix = "/api"; @@ -11,6 +12,8 @@ const routes = { permissions: `${prefix}/groups/permissions`, preferences: `${prefix}/groups/preferences`, + statistics: `${prefix}/groups/statistics`, + storage: `${prefix}/groups/storage`, invitation: `${prefix}/groups/invitations`, @@ -103,4 +106,12 @@ export class GroupAPI extends BaseCRUDAPI { // TODO: This should probably be a patch request, which isn't offered by the API currently return await this.requests.put(routes.permissions, payload); } + + async statistics() { + return await this.requests.get(routes.statistics); + } + + async storage() { + return await this.requests.get(routes.storage); + } } diff --git a/frontend/components/global/StatsCards.vue b/frontend/components/global/StatsCards.vue new file mode 100644 index 000000000000..ca3d8589cc69 --- /dev/null +++ b/frontend/components/global/StatsCards.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/frontend/composables/recipes/use-recipes.ts b/frontend/composables/recipes/use-recipes.ts index 17931d4a28cc..a9c15d52712e 100644 --- a/frontend/composables/recipes/use-recipes.ts +++ b/frontend/composables/recipes/use-recipes.ts @@ -97,7 +97,7 @@ export const useRecipes = (all = false, fetchRecipes = true) => { })(); async function refreshRecipes() { - const { data } = await api.recipes.getAll(start, end); + const { data } = await api.recipes.getAll(start, end, { loadFood: true }); if (data) { recipes.value = data; } diff --git a/frontend/pages/user/profile/index.vue b/frontend/pages/user/profile/index.vue index ab48e9f4e3b5..e37c72ab014f 100644 --- a/frontend/pages/user/profile/index.vue +++ b/frontend/pages/user/profile/index.vue @@ -38,6 +38,51 @@ +
+
+

Account Summary

+

Here's a summary of your group's information

+
+ + + + Group Statistics + + Your Group Statistics provide some insight how you're using Mealie. + + + + + + + + + + + + Storage Capacity + + Your storage capacity is a calculation of the images and assets you have uploaded. + This feature is currently inactive + + + + + + + + + +
+

Personal

@@ -149,18 +194,21 @@