2023-08-25 15:28:12 +00:00
|
|
|
<script lang="ts" setup>
|
2024-05-30 07:01:15 +00:00
|
|
|
import { usePluginModuleStore } from "@/stores/plugin";
|
|
|
|
import { usePermission } from "@/utils/permission";
|
2023-08-25 15:28:12 +00:00
|
|
|
import type { Plugin } from "@halo-dev/api-client";
|
2024-05-30 07:01:15 +00:00
|
|
|
import { VButton, VModal, VTabbar } from "@halo-dev/components";
|
|
|
|
import type { PluginInstallationTab } from "@halo-dev/console-shared";
|
|
|
|
import { useRouteQuery } from "@vueuse/router";
|
2024-03-26 10:48:07 +00:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
markRaw,
|
|
|
|
nextTick,
|
|
|
|
onMounted,
|
|
|
|
provide,
|
|
|
|
ref,
|
|
|
|
toRefs,
|
2024-05-30 07:01:15 +00:00
|
|
|
type Ref,
|
2024-03-26 10:48:07 +00:00
|
|
|
} from "vue";
|
2023-08-25 15:28:12 +00:00
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import LocalUpload from "./installation-tabs/LocalUpload.vue";
|
|
|
|
import RemoteDownload from "./installation-tabs/RemoteDownload.vue";
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
2023-09-22 09:14:32 +00:00
|
|
|
const { currentUserHasPermission } = usePermission();
|
2023-08-25 15:28:12 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
pluginToUpgrade?: Plugin;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
pluginToUpgrade: undefined,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: "close"): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const { pluginToUpgrade } = toRefs(props);
|
|
|
|
provide<Ref<Plugin | undefined>>("pluginToUpgrade", pluginToUpgrade);
|
|
|
|
|
2024-05-27 08:56:57 +00:00
|
|
|
const modal = ref<InstanceType<typeof VModal> | null>(null);
|
2024-03-26 10:48:07 +00:00
|
|
|
|
2023-08-25 15:28:12 +00:00
|
|
|
const tabs = ref<PluginInstallationTab[]>([
|
|
|
|
{
|
|
|
|
id: "local",
|
|
|
|
label: t("core.plugin.upload_modal.tabs.local"),
|
|
|
|
component: markRaw(LocalUpload),
|
|
|
|
priority: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "remote",
|
|
|
|
label: t("core.plugin.upload_modal.tabs.remote.title"),
|
|
|
|
component: markRaw(RemoteDownload),
|
|
|
|
priority: 20,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const activeTabId = ref();
|
|
|
|
|
|
|
|
const modalTitle = computed(() => {
|
|
|
|
return props.pluginToUpgrade
|
|
|
|
? t("core.plugin.upload_modal.titles.upgrade", {
|
|
|
|
display_name: props.pluginToUpgrade.spec.displayName,
|
|
|
|
})
|
|
|
|
: t("core.plugin.upload_modal.titles.install");
|
|
|
|
});
|
|
|
|
|
|
|
|
// handle remote download url from route
|
|
|
|
const routeRemoteDownloadUrl = useRouteQuery<string | null>(
|
|
|
|
"remote-download-url"
|
|
|
|
);
|
|
|
|
|
2024-03-26 10:48:07 +00:00
|
|
|
onMounted(() => {
|
|
|
|
if (routeRemoteDownloadUrl.value) {
|
|
|
|
nextTick(() => {
|
2023-08-25 15:28:12 +00:00
|
|
|
activeTabId.value = "remote";
|
2024-03-26 10:48:07 +00:00
|
|
|
});
|
2023-08-25 15:28:12 +00:00
|
|
|
}
|
2024-03-26 10:48:07 +00:00
|
|
|
});
|
2023-08-25 15:28:12 +00:00
|
|
|
|
|
|
|
const { pluginModules } = usePluginModuleStore();
|
|
|
|
|
2024-05-30 07:01:15 +00:00
|
|
|
onMounted(async () => {
|
|
|
|
for (const pluginModule of pluginModules) {
|
|
|
|
try {
|
|
|
|
const callbackFunction =
|
|
|
|
pluginModule?.extensionPoints?.["plugin:installation:tabs:create"];
|
2023-08-25 15:28:12 +00:00
|
|
|
|
2024-05-30 07:01:15 +00:00
|
|
|
if (typeof callbackFunction !== "function") {
|
|
|
|
continue;
|
|
|
|
}
|
2023-09-22 09:14:32 +00:00
|
|
|
|
2024-05-30 07:01:15 +00:00
|
|
|
const items = await callbackFunction();
|
|
|
|
|
|
|
|
tabs.value.push(
|
|
|
|
...items.filter((item) => {
|
|
|
|
return currentUserHasPermission(item.permissions);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(`Error processing plugin module:`, pluginModule, error);
|
|
|
|
}
|
|
|
|
}
|
2023-08-25 15:28:12 +00:00
|
|
|
|
|
|
|
tabs.value.sort((a, b) => {
|
|
|
|
return a.priority - b.priority;
|
|
|
|
});
|
|
|
|
|
|
|
|
activeTabId.value = tabs.value[0].id;
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<VModal
|
2024-03-26 10:48:07 +00:00
|
|
|
ref="modal"
|
2023-08-25 15:28:12 +00:00
|
|
|
:title="modalTitle"
|
|
|
|
:centered="true"
|
|
|
|
:width="920"
|
|
|
|
height="calc(100vh - 20px)"
|
2024-03-26 10:48:07 +00:00
|
|
|
@close="emit('close')"
|
2023-08-25 15:28:12 +00:00
|
|
|
>
|
|
|
|
<VTabbar
|
|
|
|
v-model:active-id="activeTabId"
|
|
|
|
:items="
|
|
|
|
tabs.map((tab) => {
|
|
|
|
return { label: tab.label, id: tab.id };
|
|
|
|
})
|
|
|
|
"
|
|
|
|
type="outline"
|
|
|
|
/>
|
|
|
|
<div class="mt-2">
|
|
|
|
<template v-for="tab in tabs" :key="tab.id">
|
|
|
|
<component
|
|
|
|
:is="tab.component"
|
|
|
|
v-bind="tab.props"
|
|
|
|
v-if="tab.id === activeTabId"
|
2024-05-27 08:56:57 +00:00
|
|
|
@close-modal="modal?.close()"
|
2023-08-25 15:28:12 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<template #footer>
|
2024-05-27 08:56:57 +00:00
|
|
|
<VButton @click="modal?.close()">
|
2023-08-30 04:54:15 +00:00
|
|
|
{{ $t("core.common.buttons.close") }}
|
|
|
|
</VButton>
|
2023-08-25 15:28:12 +00:00
|
|
|
</template>
|
|
|
|
</VModal>
|
|
|
|
</template>
|