From abc0d0d59f8a4c139aba09de0d6d78f74f95cde7 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Thu, 2 Sep 2021 11:24:17 -0800 Subject: [PATCH] =?UTF-8?q?refactor(=E2=99=BB=EF=B8=8F):=20update=20'about?= =?UTF-8?q?'=20page=20to=20new=20composition=20API=20(#667)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test-commit * Remove PR Name Checker * refactor(backend): :recycle: split unrelated routes into clearer router paths Add an /app and /admin router base paths to split previously grouped public/admin data into different paths. Part of a longer migration to move 'admin' operations under the admin path. * refactor(backend): :recycle: rename imports * refactor(frontend): :recycle: refactor frontend API and Pages to refelect new API design Co-authored-by: hay-kot --- .github/workflows/convenitonal-commits.yml | 23 ----- README.md | 2 + frontend/api/class-interfaces/admin-about.ts | 37 ++++++++ frontend/api/class-interfaces/debug.ts | 51 ---------- frontend/api/index.ts | 22 ++++- frontend/components/Layout/AppHeader.vue | 86 ++--------------- frontend/components/Layout/AppSidebar.vue | 30 +++--- frontend/composables/use-api.ts | 7 +- frontend/layouts/default.vue | 9 ++ frontend/pages/admin/about.vue | 93 ++++++++++++++++++- frontend/pages/admin/dashboard.vue | 6 +- mealie/app.py | 5 +- mealie/routes/__init__.py | 5 +- mealie/routes/about/__init__.py | 3 +- mealie/routes/admin/__init__.py | 8 ++ mealie/routes/admin/admin_about.py | 38 ++++++++ mealie/routes/admin/admin_log.py | 44 +++++++++ mealie/routes/app/__init__.py | 8 ++ mealie/routes/app/app_about.py | 18 ++++ .../defaults.py => app/app_defaults.py} | 6 +- mealie/routes/debug_routes.py | 89 ------------------ mealie/routes/media/user.py | 0 mealie/schema/admin/about.py | 2 +- 23 files changed, 317 insertions(+), 275 deletions(-) delete mode 100644 .github/workflows/convenitonal-commits.yml create mode 100644 frontend/api/class-interfaces/admin-about.ts delete mode 100644 frontend/api/class-interfaces/debug.ts create mode 100644 mealie/routes/admin/__init__.py create mode 100644 mealie/routes/admin/admin_about.py create mode 100644 mealie/routes/admin/admin_log.py create mode 100644 mealie/routes/app/__init__.py create mode 100644 mealie/routes/app/app_about.py rename mealie/routes/{about/defaults.py => app/app_defaults.py} (53%) delete mode 100644 mealie/routes/debug_routes.py delete mode 100644 mealie/routes/media/user.py diff --git a/.github/workflows/convenitonal-commits.yml b/.github/workflows/convenitonal-commits.yml deleted file mode 100644 index eee9576f6642..000000000000 --- a/.github/workflows/convenitonal-commits.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check PR title -on: - pull_request: - branches: - - mealie-next - types: - - opened - - reopened - - edited - - synchronize - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: aslafy-z/conventional-pr-title-action@master - with: - success-state: Title follows the specification. - failure-state: Title does not follow the specification. - context-name: conventional-pr-title - preset: conventional-changelog-angular@latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 34585313d449..b57b197db768 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ [![Project Tests Production](https://github.com/hay-kot/mealie/actions/workflows/test-all.yml/badge.svg)](https://github.com/hay-kot/mealie/actions/workflows/test-all.yml) [![Docker Build Dev](https://github.com/hay-kot/mealie/actions/workflows/dockerbuild.dev.yml/badge.svg?branch=dev)](https://github.com/hay-kot/mealie/actions/workflows/dockerbuild.dev.yml) [![Project Tests Dev](https://github.com/hay-kot/mealie/actions/workflows/test-all.yml/badge.svg?branch=dev)](https://github.com/hay-kot/mealie/actions/workflows/test-all.yml) + +

diff --git a/frontend/api/class-interfaces/admin-about.ts b/frontend/api/class-interfaces/admin-about.ts new file mode 100644 index 000000000000..548fd76667f1 --- /dev/null +++ b/frontend/api/class-interfaces/admin-about.ts @@ -0,0 +1,37 @@ +import { BaseAPI } from "./_base"; + +const prefix = "/api"; + +const routes = { + about: `${prefix}/admin/about`, + aboutStatistics: `${prefix}/admin/about/statistics`, +}; + +export interface AdminAboutInfo { + production: boolean; + version: string; + demoStatus: boolean; + apiPort: number; + apiDocs: boolean; + dbType: string; + dbUrl: string; + defaultGroup: string; +} + +export interface AdminStatistics { + totalRecipes: number; + totalUsers: number; + totalGroups: number; + uncategorizedRecipes: number; + untaggedRecipes: number; +} + +export class AdminAboutAPI extends BaseAPI { + async about() { + return await this.requests.get(routes.about); + } + + async statistics() { + return await this.requests.get(routes.aboutStatistics); + } +} diff --git a/frontend/api/class-interfaces/debug.ts b/frontend/api/class-interfaces/debug.ts deleted file mode 100644 index 3bc0450dfdc3..000000000000 --- a/frontend/api/class-interfaces/debug.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { BaseAPI } from "./_base"; - -export interface AppStatistics { - totalRecipes: number; - totalUsers: number; - totalGroups: number; - uncategorizedRecipes: number; - untaggedRecipes: number; -} - -const prefix = "/api"; - -const routes = { - debugVersion: `${prefix}/debug/version`, - debug: `${prefix}/debug`, - debugStatistics: `${prefix}/debug/statistics`, - debugLastRecipeJson: `${prefix}/debug/last-recipe-json`, - debugLog: `${prefix}/debug/log`, - - debugLogNum: (num: number) => `${prefix}/debug/log/${num}`, -}; - -export class DebugAPI extends BaseAPI { - /** Returns the current version of mealie - */ - async getMealieVersion() { - return await this.requests.get(routes.debugVersion); - } - - /** Returns general information about the application for debugging - */ - async getDebugInfo() { - return await this.requests.get(routes.debug); - } - - async getAppStatistics() { - return await this.requests.get(routes.debugStatistics); - } - - /** Doc Str - */ - async getLog(num: number) { - return await this.requests.get(routes.debugLogNum(num)); - } - - /** Returns a token to download a file - */ - async getLogFile() { - return await this.requests.get(routes.debugLog); - } -} diff --git a/frontend/api/index.ts b/frontend/api/index.ts index 2af113f2359d..e7c0972f81dd 100644 --- a/frontend/api/index.ts +++ b/frontend/api/index.ts @@ -1,7 +1,6 @@ import { RecipeAPI } from "./class-interfaces/recipes"; import { UserApi } from "./class-interfaces/users"; import { GroupAPI } from "./class-interfaces/groups"; -import { DebugAPI } from "./class-interfaces/debug"; import { EventsAPI } from "./class-interfaces/events"; import { BackupAPI } from "./class-interfaces/backups"; import { UploadFile } from "./class-interfaces/upload"; @@ -13,14 +12,30 @@ import { FoodAPI } from "./class-interfaces/recipe-foods"; import { UnitAPI } from "./class-interfaces/recipe-units"; import { CookbookAPI } from "./class-interfaces/cookbooks"; import { WebhooksAPI } from "./class-interfaces/group-webhooks"; +import { AdminAboutAPI } from "./class-interfaces/admin-about"; import { ApiRequestInstance } from "~/types/api"; +class AdminAPI { + private static instance: AdminAPI; + public about: AdminAboutAPI; + + constructor(requests: ApiRequestInstance) { + if (AdminAPI.instance instanceof AdminAPI) { + return AdminAPI.instance; + } + + this.about = new AdminAboutAPI(requests); + + Object.freeze(this); + AdminAPI.instance = this; + } +} + class Api { private static instance: Api; public recipes: RecipeAPI; public users: UserApi; public groups: GroupAPI; - public debug: DebugAPI; public events: EventsAPI; public backups: BackupAPI; public categories: CategoriesAPI; @@ -54,7 +69,6 @@ class Api { this.groupWebhooks = new WebhooksAPI(requests); // Admin - this.debug = new DebugAPI(requests); this.events = new EventsAPI(requests); this.backups = new BackupAPI(requests); this.notifications = new NotificationsAPI(requests); @@ -68,4 +82,4 @@ class Api { } } -export { Api }; +export { Api, AdminAPI }; diff --git a/frontend/components/Layout/AppHeader.vue b/frontend/components/Layout/AppHeader.vue index 17dbb65b044e..6572756978cb 100644 --- a/frontend/components/Layout/AppHeader.vue +++ b/frontend/components/Layout/AppHeader.vue @@ -30,42 +30,16 @@ --> - - - - - - - {{ item.icon }} - - - - {{ item.title }} - - - - - - + @@ -83,46 +57,6 @@ export default defineComponent({ default: true, }, }, - setup() { - return {}; - }, - data() { - return { - itemSelected: null, - items: [ - { - icon: this.$globals.icons.user, - title: this.$t("user.login"), - restricted: false, - nav: "/user/login", - }, - { - icon: this.$globals.icons.logout, - title: this.$t("user.logout"), - restricted: true, - logout: true, - }, - { - icon: this.$globals.icons.cog, - title: this.$t("general.settings"), - nav: "/user/profile", - restricted: true, - }, - ], - }; - }, - computed: { - filteredItems(): Array { - if (this.loggedIn) { - return this.items.filter((x) => x.restricted === true); - } else { - return this.items.filter((x) => x.restricted === false); - } - }, - loggedIn(): Boolean { - return this.$auth.loggedIn; - }, - }, }); \ No newline at end of file diff --git a/frontend/components/Layout/AppSidebar.vue b/frontend/components/Layout/AppSidebar.vue index ae3fcbfc6e93..338fd7ed8719 100644 --- a/frontend/components/Layout/AppSidebar.vue +++ b/frontend/components/Layout/AppSidebar.vue @@ -102,20 +102,22 @@ diff --git a/frontend/composables/use-api.ts b/frontend/composables/use-api.ts index 8af01e432e7d..25cae9e17aac 100644 --- a/frontend/composables/use-api.ts +++ b/frontend/composables/use-api.ts @@ -1,7 +1,7 @@ import { AxiosResponse } from "axios"; import { useContext } from "@nuxtjs/composition-api"; import { NuxtAxiosInstance } from "@nuxtjs/axios"; -import { Api } from "~/api"; +import { AdminAPI, Api } from "~/api"; import { ApiRequestInstance } from "~/types/api"; interface RequestResponse { @@ -53,6 +53,11 @@ function getRequests(axoisInstance: NuxtAxiosInstance): ApiRequestInstance { return requests; } +export const useAdminApi = function (): AdminAPI { + const { $axios } = useContext(); + const requests = getRequests($axios); + return new AdminAPI(requests); +}; export const useApiSingleton = function (): Api { const { $axios } = useContext(); diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index be4969d60165..643dfcc40bc1 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -8,6 +8,7 @@ :top-link="topLinks" secondary-header="Cookbooks" :secondary-links="cookbookLinks || []" + :bottom-links="bottomLink" @input="sidebar = !sidebar" /> @@ -57,6 +58,14 @@ export default defineComponent({ data() { return { sidebar: null, + bottomLink: [ + { + icon: this.$globals.icons.cog, + title: this.$t("general.settings"), + to: "/user/profile", + restricted: true, + }, + ], topLinks: [ { icon: this.$globals.icons.calendar, diff --git a/frontend/pages/admin/about.vue b/frontend/pages/admin/about.vue index e81fede7c18d..5f00be604e34 100644 --- a/frontend/pages/admin/about.vue +++ b/frontend/pages/admin/about.vue @@ -1,16 +1,103 @@ diff --git a/frontend/pages/admin/dashboard.vue b/frontend/pages/admin/dashboard.vue index 5c0a39a30f72..ec02d93b077e 100644 --- a/frontend/pages/admin/dashboard.vue +++ b/frontend/pages/admin/dashboard.vue @@ -94,7 +94,7 @@