From: Adam Dullage Date: Fri, 7 Jun 2024 11:44:26 +0000 (+0100) Subject: #170 - Add config option to hide recently modified X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=c69d91cba74ffb1dbd63bd4ae577aad4c7f15c08;p=flatnotes.git #170 - Add config option to hide recently modified --- diff --git a/client/App.vue b/client/App.vue index 3f16247..468d7dd 100644 --- a/client/App.vue +++ b/client/App.vue @@ -43,6 +43,7 @@ Mousetrap.bind("/", () => { getConfig() .then((data) => { globalStore.authType = data.authType; + globalStore.hideRecentlyModified = data.hideRecentlyModified; }) .catch((error) => { apiErrorHandler(error, toast); diff --git a/client/globalStore.js b/client/globalStore.js index ca9c6f5..23d0303 100644 --- a/client/globalStore.js +++ b/client/globalStore.js @@ -1,8 +1,11 @@ +import * as constants from "./constants.js"; + import { defineStore } from "pinia"; import { ref } from "vue"; export const useGlobalStore = defineStore("global", () => { - const authType = ref("authType"); + const authType = ref(constants.authTypes.password); + const hideRecentlyModified = ref(true); - return { authType }; + return { authType, hideRecentlyModified }; }); diff --git a/client/partials/SearchInput.vue b/client/partials/SearchInput.vue index c05234f..987f864 100644 --- a/client/partials/SearchInput.vue +++ b/client/partials/SearchInput.vue @@ -48,10 +48,10 @@ import { mdilMagnify } from "@mdi/light-js"; import { useToast } from "primevue/usetoast"; import { ref, watch } from "vue"; import { useRouter } from "vue-router"; -import * as constants from "../constants"; -import { getTags, apiErrorHandler } from "../api.js"; +import { apiErrorHandler, getTags } from "../api.js"; import IconLabel from "../components/IconLabel.vue"; +import * as constants from "../constants.js"; import { getToastOptions } from "../helpers.js"; const props = defineProps({ diff --git a/client/views/Home.vue b/client/views/Home.vue index 24e602d..89bbaeb 100644 --- a/client/views/Home.vue +++ b/client/views/Home.vue @@ -24,7 +24,7 @@ diff --git a/server/global_config.py b/server/global_config.py index 94c81d2..a620d48 100644 --- a/server/global_config.py +++ b/server/global_config.py @@ -9,6 +9,7 @@ class GlobalConfig: def __init__(self) -> None: logger.debug("Loading global config...") self.auth_type: AuthType = self._load_auth_type() + self.hide_recently_modified: bool = self._load_hide_recently_modified() def load_auth(self): if self.auth_type in (AuthType.NONE, AuthType.READ_ONLY): @@ -45,6 +46,10 @@ class GlobalConfig: sys.exit(1) return auth_type + def _load_hide_recently_modified(self): + key = "FLATNOTES_HIDE_RECENTLY_MODIFIED" + return get_env(key, mandatory=False, default=False, cast_bool=True) + class AuthType(str, Enum): NONE = "none" @@ -55,3 +60,4 @@ class AuthType(str, Enum): class GlobalConfigResponseModel(CustomBaseModel): auth_type: AuthType + hide_recently_modified: bool diff --git a/server/helpers.py b/server/helpers.py index 10e959f..977ef82 100644 --- a/server/helpers.py +++ b/server/helpers.py @@ -30,7 +30,9 @@ def strip_whitespace(value): return value.strip() -def get_env(key, mandatory=False, default=None, cast_int=False): +def get_env( + key, mandatory=False, default=None, cast_int=False, cast_bool=False +): """Get an environment variable. If `mandatory` is True and environment variable isn't set, exit the program""" value = os.environ.get(key) @@ -45,6 +47,15 @@ def get_env(key, mandatory=False, default=None, cast_int=False): except (TypeError, ValueError): logger.error(f"Invalid value '{value}' for {key}.") sys.exit(1) + if cast_bool: + value = value.lower() + if value == "true": + value = True + elif value == "false": + value = False + else: + logger.error(f"Invalid value '{value}' for {key}.") + sys.exit(1) return value diff --git a/server/main.py b/server/main.py index cf9eb13..cc27187 100644 --- a/server/main.py +++ b/server/main.py @@ -170,7 +170,10 @@ def get_tags(): @app.get("/api/config", response_model=GlobalConfigResponseModel) def get_config(): """Retrieve server-side config required for the UI.""" - return GlobalConfigResponseModel(auth_type=global_config.auth_type) + return GlobalConfigResponseModel( + auth_type=global_config.auth_type, + hide_recently_modified=global_config.hide_recently_modified, + ) # endregion