Commit 7892a289 authored by guerler's avatar guerler
Browse files

Update masthead webhook loading

parent 31d0f63b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
<script setup lang="ts">
import { onMounted, ref } from "vue";

import { appendScriptStyle } from "@/utils/utils";
import { loadWebhooks, pickWebhook } from "@/utils/webhooks";
import { onMounted, ref } from "vue";

interface Props {
    type: string;
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import { setupMockConfig } from "tests/jest/mockConfig";

import { useUserStore } from "@/stores/userStore";

import { loadWebhookMenuItems } from "./_webhooks";
import { loadMastheadWebhooks } from "./_webhooks";

import Masthead from "./Masthead.vue";

@@ -38,7 +38,7 @@ describe("Masthead.vue", () => {
        });
    }

    loadWebhookMenuItems.mockImplementation(stubLoadWebhooks);
    loadMastheadWebhooks.mockImplementation(stubLoadWebhooks);

    beforeEach(async () => {
        localVue = getLocalVue();
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import { useRouter } from "vue-router/composables";
import { useConfig } from "@/composables/config";
import { useUserStore } from "@/stores/userStore";

import { loadWebhookMenuItems } from "./_webhooks";
import { loadMastheadWebhooks } from "./_webhooks";
import MastheadDropdown from "./MastheadDropdown";
import MastheadItem from "./MastheadItem";
import QuotaMeter from "./QuotaMeter";
@@ -72,7 +72,7 @@ function onWindowToggle() {
}

onMounted(() => {
    loadWebhookMenuItems(extensionTabs.value);
    loadMastheadWebhooks(extensionTabs.value);
});
</script>

+19 −23
Original line number Diff line number Diff line
import Utils from "utils/utils";
import Webhooks from "utils/webhooks";
import { appendScriptStyle } from "utils/utils";
import { loadWebhooks } from "utils/webhooks";

export function loadWebhookMenuItems(items) {
    Webhooks.load({
        type: "masthead",
        callback: function (webhooks) {
export async function loadMastheadWebhooks(items) {
    const webhooks = loadWebhooks("masthead");
    webhooks.forEach((webhook) => {
        if (webhook.activate) {
            const obj = {
@@ -18,9 +16,7 @@ export function loadWebhookMenuItems(items) {
            };
            items.push(obj);
            // Append masthead script and styles to Galaxy main
                    Utils.appendScriptStyle(webhook);
            appendScriptStyle(webhook);
        }
    });
        },
    });
}
+19 −19
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import { faCaretDown, faDownload, faExternalLinkAlt, faLink } from "@fortawesome
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import ToolSourceMenuItem from "components/Tool/ToolSourceMenuItem";
import { storeToRefs } from "pinia";
import Webhooks from "utils/webhooks";
import { loadWebhooks } from "utils/webhooks";
import { computed, ref } from "vue";

import { useUserStore } from "@/stores/userStore";
@@ -37,24 +37,6 @@ const props = defineProps({

const webhookDetails = ref([]);

Webhooks.load({
    type: "tool-menu",
    callback: (webhooks) => {
        webhooks.forEach((webhook) => {
            if (webhook.activate && webhook.config.function) {
                webhookDetails.value.push({
                    icon: `fa ${webhook.config.icon}`,
                    title: webhook.config.title,
                    onclick: () => {
                        const func = new Function("options", webhook.config.function);
                        func(props.options);
                    },
                });
            }
        });
    },
});

const showDownload = computed(() => currentUser.value?.is_admin);
const showLink = computed(() => Boolean(props.sharableUrl));

@@ -73,6 +55,24 @@ function onDownload() {
function onLink() {
    openLink(props.sharableUrl);
}

async function loadToolMenuWebhooks() {
    const webhooks = await loadWebhooks("tool-menu");
    webhooks.forEach((webhook) => {
        if (webhook.activate && webhook.config.function) {
            webhookDetails.value.push({
                icon: `fa ${webhook.config.icon}`,
                title: webhook.config.title,
                onclick: () => {
                    const func = new Function("options", webhook.config.function);
                    func(props.options);
                },
            });
        }
    });
}

loadToolMenuWebhooks();
</script>

<template>