From 5ffc886298fa6e918c5429387c56cb8467b56586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Fri, 16 Sep 2022 14:16:53 +0000 Subject: [PATCH] Simple API query wrappers --- ui/src/App.vue | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index 9435e9a..a73d92e 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -83,20 +83,50 @@ export default class App extends Vue { private ticker_html = "
changeme
"; private ticker_color = "primary"; - private fail(part: string): (arg0: unknown) => void { + private fail(name: string): (arg0: unknown) => void { return (reason: unknown) => - console.warn("Failed to update", part, "-", reason); + console.warn("Failed to query", name, "-", reason); + } + + private api_query_simple( + endpoint: string, + on_success: (data: unknown) => void + ): void { + this.$axios + .get(this.$ovdashboard.api_url(endpoint)) + .then((response) => on_success(response.data)) + .catch(this.fail(endpoint)); + } + + private api_query_simple_string( + endpoint: string, + on_success: (data: string) => void + ): void { + this.api_query_simple(endpoint, (data) => { + if (typeof data !== "string") return; + + on_success(data); + }); + } + + private api_query_simple_object( + endpoint: string, + on_success: (data: Record