#170 - Add config option to hide recently modified
authorAdam Dullage <redacted>
Fri, 7 Jun 2024 11:44:26 +0000 (12:44 +0100)
committerAdam Dullage <redacted>
Fri, 7 Jun 2024 11:44:26 +0000 (12:44 +0100)
client/App.vue
client/globalStore.js
client/partials/SearchInput.vue
client/views/Home.vue
server/global_config.py
server/helpers.py
server/main.py

index 3f162471d1d472b5b255a5b6edb7d39db845f8c2..468d7ddb1be5b0f580930dfbdcb0efd759276ae4 100644 (file)
@@ -43,6 +43,7 @@ Mousetrap.bind("/", () => {
 getConfig()\r
   .then((data) => {\r
     globalStore.authType = data.authType;\r
+    globalStore.hideRecentlyModified = data.hideRecentlyModified;\r
   })\r
   .catch((error) => {\r
     apiErrorHandler(error, toast);\r
index ca9c6f59913add7f3e756274e4fdc4764ff2561e..23d030329e2a3287db35b7b4064fb357ee7afcd2 100644 (file)
@@ -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 };
 });
index c05234f4d4beeb8ded818a62dd96c183430e5f04..987f8642c3485adcad32732e64c05ca62c46daf8 100644 (file)
@@ -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({
index 24e602d888a786a90d1f037090f84e95d8df76c0..89bbaeb034cf7a86f38a404ab4d4fd3966c60a9d 100644 (file)
@@ -24,7 +24,7 @@
 
 <script setup>
 import { useToast } from "primevue/usetoast";
-import { onMounted, ref } from "vue";
+import { onMounted, ref, watch } from "vue";
 import { RouterLink } from "vue-router";
 
 import { mdiPencil } from "@mdi/js";
@@ -32,8 +32,10 @@ import { apiErrorHandler, getNotes } from "../api.js";
 import CustomButton from "../components/CustomButton.vue";
 import LoadingIndicator from "../components/LoadingIndicator.vue";
 import Logo from "../components/Logo.vue";
+import { useGlobalStore } from "../globalStore.js";
 import SearchInput from "../partials/SearchInput.vue";
 
+const globalStore = useGlobalStore();
 const loadingIndicator = ref();
 const noNotesMessage =
   "Click the 'New Note' button at the top of the page to get started.";
@@ -41,6 +43,9 @@ const notes = ref([]);
 const toast = useToast();
 
 function init() {
+  if (globalStore.hideRecentlyModified) {
+    return;
+  }
   getNotes("*", "lastModified", "desc", 5)
     .then((data) => {
       notes.value = data;
@@ -56,5 +61,7 @@ function init() {
     });
 }
 
+// Watch to allow for delayed config load.
+watch(() => globalStore.hideRecentlyModified, init);
 onMounted(init);
 </script>
index 94c81d2ef477e130baf02a4af83537209fb8505f..a620d48ed36e25aa68097433bc22c7236e008576 100644 (file)
@@ -9,6 +9,7 @@ class GlobalConfig:
     def __init__(self) -> None:\r
         logger.debug("Loading global config...")\r
         self.auth_type: AuthType = self._load_auth_type()\r
+        self.hide_recently_modified: bool = self._load_hide_recently_modified()\r
 \r
     def load_auth(self):\r
         if self.auth_type in (AuthType.NONE, AuthType.READ_ONLY):\r
@@ -45,6 +46,10 @@ class GlobalConfig:
             sys.exit(1)\r
         return auth_type\r
 \r
+    def _load_hide_recently_modified(self):\r
+        key = "FLATNOTES_HIDE_RECENTLY_MODIFIED"\r
+        return get_env(key, mandatory=False, default=False, cast_bool=True)\r
+\r
 \r
 class AuthType(str, Enum):\r
     NONE = "none"\r
@@ -55,3 +60,4 @@ class AuthType(str, Enum):
 \r
 class GlobalConfigResponseModel(CustomBaseModel):\r
     auth_type: AuthType\r
+    hide_recently_modified: bool\r
index 10e959f80e68efb7b97764cdb7d6f8e7468d2de9..977ef828fb6a8494dc02bf2e4c5f881db5e20aec 100644 (file)
@@ -30,7 +30,9 @@ def strip_whitespace(value):
     return value.strip()\r
 \r
 \r
-def get_env(key, mandatory=False, default=None, cast_int=False):\r
+def get_env(\r
+    key, mandatory=False, default=None, cast_int=False, cast_bool=False\r
+):\r
     """Get an environment variable. If `mandatory` is True and environment\r
     variable isn't set, exit the program"""\r
     value = os.environ.get(key)\r
@@ -45,6 +47,15 @@ def get_env(key, mandatory=False, default=None, cast_int=False):
         except (TypeError, ValueError):\r
             logger.error(f"Invalid value '{value}' for {key}.")\r
             sys.exit(1)\r
+    if cast_bool:\r
+        value = value.lower()\r
+        if value == "true":\r
+            value = True\r
+        elif value == "false":\r
+            value = False\r
+        else:\r
+            logger.error(f"Invalid value '{value}' for {key}.")\r
+            sys.exit(1)\r
     return value\r
 \r
 \r
index cf9eb139a20d5c8f88ae0f534af6dba7561aeda1..cc271879622bad4bda443152524de43e52c219cd 100644 (file)
@@ -170,7 +170,10 @@ def get_tags():
 @app.get("/api/config", response_model=GlobalConfigResponseModel)\r
 def get_config():\r
     """Retrieve server-side config required for the UI."""\r
-    return GlobalConfigResponseModel(auth_type=global_config.auth_type)\r
+    return GlobalConfigResponseModel(\r
+        auth_type=global_config.auth_type,\r
+        hide_recently_modified=global_config.hide_recently_modified,\r
+    )\r
 \r
 \r
 # endregion\r
git clone https://git.99rst.org/PROJECT