import axios from "axios"; export class ResourceRepo { private resources: Ref = ref(undefined); private interval: NodeJS.Timeout | undefined = undefined; static init() { return new ResourceRepo(); } load(resourceType: string) { this.refresh(resourceType); return this; } clear() { clearTimeout(this.interval); } get() { return computed(() => { return this.resources.value; }) } private refresh(resourceType: string) { const namespace = this.getNamespace(); let url = useRuntimeConfig().public.apiBase + '/resources/' + resourceType if (namespace) { url = url + "/" + namespace; } axios.get(url) .then((response) => { this.resources.value = undefined; this.resources.value = response.data; }); } private getNamespace() { const namespace = useRoute().params.namespace as string; if (namespace !== "_all") { return namespace as string; } return undefined; } }