mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-17 12:31:11 -06:00
Compare commits
11 Commits
web-stack/
...
rest-api-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f18e799646 | ||
|
|
f91ae35322 | ||
|
|
11a4ceddce | ||
|
|
b97268727c | ||
|
|
3a21290fde | ||
|
|
299a109eb6 | ||
|
|
4235e98166 | ||
|
|
281ccbb8ba | ||
|
|
7053fc4a08 | ||
|
|
cd2f74cd63 | ||
|
|
6d836df6bf |
@@ -3,6 +3,7 @@
|
||||
## **next**
|
||||
|
||||
- Fix persistent scrollbar on the right (PR [#8191](https://github.com/vatesfr/xen-orchestra/pull/8191))
|
||||
- [Console]: Displays a loader when the console is loading (PR [#8226](https://github.com/vatesfr/xen-orchestra/pull/8226))
|
||||
|
||||
## **0.6.0** (2024-11-29)
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<template>
|
||||
<div ref="vmConsoleContainer" class="vm-console" />
|
||||
<div class="remote-console">
|
||||
<VtsLoadingHero :disabled="isReady" type="panel" />
|
||||
<div ref="vmConsoleContainer" class="vm-console" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsLoadingHero from '@core/components/state-hero/VtsLoadingHero.vue'
|
||||
import VncClient from '@novnc/novnc/lib/rfb'
|
||||
import { promiseTimeout } from '@vueuse/shared'
|
||||
import { fibonacci } from 'iterable-backoff'
|
||||
@@ -18,6 +22,8 @@ const N_TOTAL_TRIES = 8
|
||||
const FIBONACCI_MS_ARRAY: number[] = Array.from(fibonacci().toMs().take(N_TOTAL_TRIES))
|
||||
|
||||
const vmConsoleContainer = ref<HTMLDivElement>()
|
||||
const isReady = ref(false)
|
||||
|
||||
const xenApiStore = useXenApiStore()
|
||||
const url = computed(() => {
|
||||
if (xenApiStore.currentSessionId == null) {
|
||||
@@ -54,9 +60,11 @@ function handleDisconnectionEvent() {
|
||||
|
||||
function handleConnectionEvent() {
|
||||
nConnectionAttempts = 0
|
||||
isReady.value = true
|
||||
}
|
||||
|
||||
function clearVncClient() {
|
||||
isReady.value = false
|
||||
if (vncClient === undefined) {
|
||||
return
|
||||
}
|
||||
@@ -109,17 +117,21 @@ defineExpose({
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.vm-console {
|
||||
flex: 1;
|
||||
.remote-console {
|
||||
flex-grow: 1;
|
||||
max-width: 100%;
|
||||
|
||||
& > :deep(div) {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
.vm-console {
|
||||
height: 100%;
|
||||
|
||||
/* Required because the library adds "margin: auto" to the canvas which makes the canvas centered in space and not aligned to the rest of the layout */
|
||||
:deep(canvas) {
|
||||
margin: 0 auto !important;
|
||||
& > :deep(div) {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
/* Required because the library adds "margin: auto" to the canvas which makes the canvas centered in space and not aligned to the rest of the layout */
|
||||
:deep(canvas) {
|
||||
margin: 0 auto !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -13,17 +13,13 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import TabItem from '@core/components/tab/TabItem.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
to: RouteLocationRaw
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
to: RouteLocationRaw
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
</script>
|
||||
|
||||
@@ -1,53 +1,61 @@
|
||||
<template>
|
||||
<UiAccountMenuButton
|
||||
v-tooltip="menu.$isOpen ? false : { content: $t('settings'), placement: 'left' }"
|
||||
size="medium"
|
||||
v-bind="omit(menu.$trigger, ['as', 'submenu'])"
|
||||
/>
|
||||
|
||||
<VtsMenuList border v-bind="menu.$target">
|
||||
<VtsMenuItem :icon="faGear" v-bind="menu.settings">{{ $t('settings') }}</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faBook" v-bind="menu.documentation">
|
||||
<MenuList placement="bottom-end" border>
|
||||
<template #trigger="{ open, isOpen }">
|
||||
<UiAccountMenuButton
|
||||
v-tooltip="isOpen ? false : { content: $t('settings'), placement: 'left' }"
|
||||
:selected="isOpen"
|
||||
size="medium"
|
||||
@click="open($event)"
|
||||
/>
|
||||
</template>
|
||||
<MenuItem :icon="faGear" @click="openSettings">{{ $t('settings') }}</MenuItem>
|
||||
<MenuItem :icon="faBook" @click="openUrl('https://docs.xcp-ng.org?utm_campaign=xolite&utm_term=xcpdoc')">
|
||||
{{ $t('documentation-name', { name: 'XCP-ng' }) }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faHeadset" v-bind="menu.support">{{ $t('professional-support') }}</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faComments" v-bind="menu.forum">{{ $t('access-forum') }}</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faArrowRightFromBracket" class="menu-item-logout" v-bind="menu.logout">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:icon="faHeadset"
|
||||
@click="openUrl('https://vates.tech/pricing-and-support?utm_campaign=xolite&utm_term=pricing')"
|
||||
>
|
||||
{{ $t('professional-support') }}
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:icon="faComments"
|
||||
@click="openUrl('https://xcp-ng.org/forum/topic/4731/xen-orchestra-lite?utm_campaign=xolite&utm_term=forum')"
|
||||
>
|
||||
{{ $t('access-forum') }}
|
||||
</MenuItem>
|
||||
<MenuItem :icon="faArrowRightFromBracket" class="menu-item-logout" @click="logout">
|
||||
{{ $t('log-out') }}
|
||||
</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import UiAccountMenuButton from '@core/components/ui/account-menu-button/UiAccountMenuButton.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { action, link, routerLink, useMenuToggle } from '@core/packages/menu'
|
||||
import { faArrowRightFromBracket, faBook, faComments, faGear, faHeadset } from '@fortawesome/free-solid-svg-icons'
|
||||
import { objectOmit as omit } from '@vueuse/shared'
|
||||
import { nextTick } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const menu = useMenuToggle({
|
||||
placement: 'bottom-end',
|
||||
items: {
|
||||
settings: routerLink({ name: 'settings' }),
|
||||
documentation: link('https://docs.xcp-ng.org?utm_campaign=xolite&utm_term=xcpdoc'),
|
||||
support: link('https://vates.tech/pricing-and-support?utm_campaign=xolite&utm_term=pricing'),
|
||||
forum: link('https://xcp-ng.org/forum/topic/4731/xen-orchestra-lite?utm_campaign=xolite&utm_term=forum'),
|
||||
logout: action(async () => {
|
||||
await useXenApiStore().disconnect()
|
||||
void router.push({ name: 'home' })
|
||||
}),
|
||||
},
|
||||
})
|
||||
const logout = () => {
|
||||
const xenApiStore = useXenApiStore()
|
||||
xenApiStore.disconnect()
|
||||
nextTick(() => router.push({ name: 'home' }))
|
||||
}
|
||||
|
||||
const openUrl = (url: string) => {
|
||||
window.open(url, '_blank', 'noopener noreferrer')
|
||||
}
|
||||
const openSettings = () => router.push({ name: 'settings' })
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
:deep(.menu-item-logout) {
|
||||
.menu-item-logout {
|
||||
color: var(--color-danger-txt-base);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -7,23 +7,23 @@
|
||||
v-if="unreadEventsCount > 0"
|
||||
:value="unreadEventsCount"
|
||||
accent="success"
|
||||
size="small"
|
||||
variant="primary"
|
||||
size="small"
|
||||
/>
|
||||
</TabItem>
|
||||
<TabItem v-bind="tab(TAB.SLOTS, slotParams)">Slots</TabItem>
|
||||
<TabItem v-bind="tab(TAB.SETTINGS, settingParams)">Settings</TabItem>
|
||||
<TabItem class="preset-tab" v-bind="presetMenu.$trigger">
|
||||
<UiIcon :icon="faSliders" />
|
||||
Presets
|
||||
</TabItem>
|
||||
<Teleport to="body">
|
||||
<VtsMenuList border v-bind="presetMenu.$target">
|
||||
<VtsMenuItem v-for="(preset, label) in presets" :key="label" v-bind="presetMenu[label]">
|
||||
{{ label }}
|
||||
</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
</Teleport>
|
||||
<MenuList placement="bottom" border>
|
||||
<template #trigger="{ open, isOpen }">
|
||||
<TabItem :active="isOpen" :disabled="presets === undefined" class="preset-tab" @click="open">
|
||||
<UiIcon :icon="faSliders" />
|
||||
Presets
|
||||
</TabItem>
|
||||
</template>
|
||||
<MenuItem v-for="(preset, label) in presets" :key="label" @click="applyPreset(preset)">
|
||||
{{ label }}
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</TabList>
|
||||
|
||||
<div :class="{ 'full-width': fullWidthComponent }" class="tabs">
|
||||
@@ -43,8 +43,8 @@
|
||||
<template #right>
|
||||
<UiButton
|
||||
v-if="eventsLog.length > 0"
|
||||
accent="info"
|
||||
size="medium"
|
||||
accent="info"
|
||||
variant="tertiary"
|
||||
@click="eventsLog = []"
|
||||
>
|
||||
@@ -91,13 +91,12 @@ import {
|
||||
ModelParam,
|
||||
type Param,
|
||||
} from '@/libs/story/story-param'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import TabItem from '@core/components/tab/TabItem.vue'
|
||||
import TabList from '@core/components/tab/TabList.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
|
||||
import { action, useMenuToggle } from '@core/packages/menu'
|
||||
import { faSliders } from '@fortawesome/free-solid-svg-icons'
|
||||
import 'highlight.js/styles/github-dark.css'
|
||||
import { uniqueId, upperFirst } from 'lodash-es'
|
||||
@@ -267,17 +266,6 @@ const applyPreset = (preset: { props?: Record<string, any>; settings?: Record<st
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const presetMenu = useMenuToggle({
|
||||
placement: 'bottom-end',
|
||||
items: computed(() =>
|
||||
Object.fromEntries(
|
||||
Object.entries(props.presets ?? {}).map(([label, preset]) => {
|
||||
return [label, action(() => applyPreset(preset))]
|
||||
})
|
||||
)
|
||||
),
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -16,23 +16,19 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { DisabledContext } from '@/context'
|
||||
import { IK_CHECKBOX_TYPE, IK_FORM_HAS_LABEL } from '@/types/injection-keys'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { faCheck, faCircle, faMinus } from '@fortawesome/free-solid-svg-icons'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { computed, type HTMLAttributes, inject, useAttrs } from 'vue'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: unknown
|
||||
disabled?: boolean
|
||||
wrapperAttrs?: HTMLAttributes
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
modelValue?: unknown
|
||||
disabled?: boolean
|
||||
wrapperAttrs?: HTMLAttributes
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
@@ -46,7 +42,7 @@ const hasLabel = inject(
|
||||
IK_FORM_HAS_LABEL,
|
||||
computed(() => false)
|
||||
)
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
const icon = computed(() => {
|
||||
if (type !== 'checkbox') {
|
||||
return faCircle
|
||||
|
||||
@@ -53,9 +53,10 @@
|
||||
<script lang="ts" setup>
|
||||
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { ColorContext, DisabledContext } from '@/context'
|
||||
import { ColorContext } from '@/context'
|
||||
import type { Color } from '@/types'
|
||||
import { IK_INPUT_ID, IK_INPUT_TYPE } from '@/types/injection-keys'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faAngleDown } from '@fortawesome/free-solid-svg-icons'
|
||||
import { useTextareaAutosize, useVModel } from '@vueuse/core'
|
||||
@@ -63,22 +64,19 @@ import { computed, type HTMLAttributes, inject, nextTick, ref, useAttrs, watch }
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
id?: string
|
||||
modelValue?: any
|
||||
color?: Color
|
||||
before?: IconDefinition | string
|
||||
after?: IconDefinition | string
|
||||
beforeWidth?: string
|
||||
afterWidth?: string
|
||||
disabled?: boolean
|
||||
required?: boolean
|
||||
right?: boolean
|
||||
wrapperAttrs?: HTMLAttributes
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
id?: string
|
||||
modelValue?: any
|
||||
color?: Color
|
||||
before?: IconDefinition | string
|
||||
after?: IconDefinition | string
|
||||
beforeWidth?: string
|
||||
afterWidth?: string
|
||||
disabled?: boolean
|
||||
required?: boolean
|
||||
right?: boolean
|
||||
wrapperAttrs?: HTMLAttributes
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: any]
|
||||
@@ -94,7 +92,7 @@ const value = useVModel(props, 'modelValue', emit)
|
||||
const isEmpty = computed(() => props.modelValue == null || String(props.modelValue).trim() === '')
|
||||
const inputType = inject(IK_INPUT_TYPE, 'input')
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
|
||||
const wrapperClass = computed(() => [
|
||||
`form-${inputType}`,
|
||||
|
||||
@@ -36,28 +36,26 @@
|
||||
<script lang="ts" setup>
|
||||
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { ColorContext, DisabledContext } from '@/context'
|
||||
import { ColorContext } from '@/context'
|
||||
import type { Color } from '@/types'
|
||||
import { IK_FORM_HAS_LABEL, IK_INPUT_ID } from '@/types/injection-keys'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons'
|
||||
import { uniqueId } from 'lodash-es'
|
||||
import { computed, provide } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
label?: string
|
||||
id?: string
|
||||
icon?: IconDefinition
|
||||
learnMoreUrl?: string
|
||||
warning?: string
|
||||
error?: string
|
||||
help?: string
|
||||
disabled?: boolean
|
||||
light?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
label?: string
|
||||
id?: string
|
||||
icon?: IconDefinition
|
||||
learnMoreUrl?: string
|
||||
warning?: string
|
||||
error?: string
|
||||
help?: string
|
||||
disabled?: boolean
|
||||
light?: boolean
|
||||
}>()
|
||||
|
||||
const id = computed(() => props.id ?? uniqueId('form-input-'))
|
||||
provide(IK_INPUT_ID, id)
|
||||
@@ -80,7 +78,7 @@ provide(
|
||||
)
|
||||
|
||||
useContext(ColorContext, color)
|
||||
useContext(DisabledContext, () => props.disabled)
|
||||
useDisabled(() => props.disabled)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -17,21 +17,17 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { DisabledContext } from '@/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
icon?: IconDefinition
|
||||
active?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
icon?: IconDefinition
|
||||
active?: boolean
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { ColorContext, DisabledContext } from '@/context'
|
||||
import { ColorContext } from '@/context'
|
||||
import type { Color } from '@/types'
|
||||
import { IK_MODAL } from '@/types/injection-keys'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { useMagicKeys, whenever } from '@vueuse/core'
|
||||
import { inject, useAttrs } from 'vue'
|
||||
|
||||
@@ -28,7 +29,7 @@ const attrs = useAttrs()
|
||||
const modal = inject(IK_MODAL)!
|
||||
|
||||
useContext(ColorContext, () => props.color)
|
||||
useContext(DisabledContext, () => props.disabled || modal.isBusy)
|
||||
useDisabled(() => props.disabled || modal.isBusy)
|
||||
|
||||
const { escape } = useMagicKeys()
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faCopy" v-bind="menuItem">
|
||||
<MenuItem
|
||||
v-tooltip="!areAllSelectedVmsHalted && $t(isSingleAction ? 'vm-is-running' : 'selected-vms-in-execution')"
|
||||
:busy="areSomeSelectedVmsCloning"
|
||||
:disabled="isDisabled"
|
||||
:icon="faCopy"
|
||||
@click="handleCopy"
|
||||
>
|
||||
{{ $t('copy') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -10,42 +16,41 @@ import { VM_OPERATION, VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import { type MenuLike, useMenuAction } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faCopy } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
selectedRefs: XenApiVm['$ref'][]
|
||||
isSingleAction?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const { getByOpaqueRef } = useVmStore().subscribe()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
|
||||
const selectedVms = computed(() => getByOpaqueRefs(props.selectedRefs))
|
||||
|
||||
const vmRefsToClone = computed(() =>
|
||||
Object.fromEntries(selectedVms.value.map(vm => [vm.$ref, `${vm.name_label} (COPY)`]))
|
||||
const selectedVms = computed(() =>
|
||||
props.selectedRefs.map(vmRef => getByOpaqueRef(vmRef)).filter((vm): vm is XenApiVm => vm !== undefined)
|
||||
)
|
||||
|
||||
const menuItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
handler: () => useXenApiStore().getXapi().vm.clone(vmRefsToClone.value),
|
||||
disabled: () => {
|
||||
if (props.selectedRefs.length === 0) {
|
||||
return true
|
||||
}
|
||||
const areAllSelectedVmsHalted = computed(
|
||||
() =>
|
||||
selectedVms.value.length > 0 &&
|
||||
selectedVms.value.every(selectedVm => selectedVm.power_state === VM_POWER_STATE.HALTED)
|
||||
)
|
||||
|
||||
if (!selectedVms.value.every(selectedVm => selectedVm.power_state === VM_POWER_STATE.HALTED)) {
|
||||
return props.isSingleAction ? t('vm-is-running') : t('selected-vms-in-execution')
|
||||
}
|
||||
const areSomeSelectedVmsCloning = computed(() =>
|
||||
selectedVms.value.some(vm => isVmOperationPending(vm, VM_OPERATION.CLONE))
|
||||
)
|
||||
|
||||
return false
|
||||
},
|
||||
busy: computed(() => selectedVms.value.some(vm => isVmOperationPending(vm, VM_OPERATION.CLONE))),
|
||||
const isDisabled = computed(() => {
|
||||
return selectedVms.value.length === 0 || !areAllSelectedVmsHalted.value
|
||||
})
|
||||
|
||||
const handleCopy = async () => {
|
||||
const xapiStore = useXenApiStore()
|
||||
|
||||
const vmRefsToClone = Object.fromEntries(selectedVms.value.map(vm => [vm.$ref, `${vm.name_label} (COPY)`]))
|
||||
|
||||
await xapiStore.getXapi().vm.clone(vmRefsToClone)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faTrashCan" v-bind="menuItem">
|
||||
<MenuItem
|
||||
v-tooltip="areSomeVmsInExecution && $t('selected-vms-in-execution')"
|
||||
:disabled="isDisabled"
|
||||
:icon="faTrashCan"
|
||||
@click="openDeleteModal"
|
||||
>
|
||||
{{ $t('delete') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -9,39 +14,25 @@ import { useModal } from '@/composables/modal.composable'
|
||||
import { VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import { type MenuLike, useMenuAction } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faTrashCan } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
vmRefs: XenApiVm['$ref'][]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const { getByOpaqueRef: getVm } = useVmStore().subscribe()
|
||||
|
||||
const { getByOpaqueRefs: getVms } = useVmStore().subscribe()
|
||||
const vms = computed<XenApiVm[]>(() => props.vmRefs.map(getVm).filter((vm): vm is XenApiVm => vm !== undefined))
|
||||
|
||||
const vms = computed(() => getVms(props.vmRefs))
|
||||
const areSomeVmsInExecution = computed(() => vms.value.some(vm => vm.power_state !== VM_POWER_STATE.HALTED))
|
||||
|
||||
const menuItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
handler: () =>
|
||||
useModal(() => import('@/components/modals/VmDeleteModal.vue'), {
|
||||
vmRefs: props.vmRefs,
|
||||
}),
|
||||
disabled: computed(() => {
|
||||
if (vms.value.length === 0) {
|
||||
return true
|
||||
}
|
||||
const isDisabled = computed(() => vms.value.length === 0 || areSomeVmsInExecution.value)
|
||||
|
||||
if (vms.value.some(vm => vm.power_state !== VM_POWER_STATE.HALTED)) {
|
||||
return t('selected-vms-in-execution')
|
||||
}
|
||||
|
||||
return false
|
||||
}),
|
||||
})
|
||||
const openDeleteModal = () =>
|
||||
useModal(() => import('@/components/modals/VmDeleteModal.vue'), {
|
||||
vmRefs: props.vmRefs,
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faDisplay" v-bind="menuItem">
|
||||
<MenuItem
|
||||
v-tooltip="
|
||||
vmRefs.length > 0 && !isSomeExportable && $t(isSingleAction ? 'vm-is-running' : 'no-selected-vm-can-be-exported')
|
||||
"
|
||||
:disabled="isDisabled"
|
||||
:icon="faDisplay"
|
||||
@click="openModal"
|
||||
>
|
||||
{{ $t(isSingleAction ? 'export-vm' : 'export-vms') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -10,40 +17,28 @@ import { areSomeVmOperationAllowed } from '@/libs/vm'
|
||||
import { VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import { type MenuLike, useMenuAction } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faDisplay } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
vmRefs: XenApiVm['$ref'][]
|
||||
isSingleAction?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
|
||||
const vms = computed(() => getByOpaqueRefs(props.vmRefs))
|
||||
const isSomeExportable = computed(() =>
|
||||
getByOpaqueRefs(props.vmRefs).some(vm => areSomeVmOperationAllowed(vm, VM_OPERATION.EXPORT))
|
||||
)
|
||||
|
||||
const menuItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
handler: () =>
|
||||
useModal(() => import('@/components/modals/VmExportModal.vue'), {
|
||||
vmRefs: props.vmRefs,
|
||||
}),
|
||||
disabled: () => {
|
||||
if (props.vmRefs.length === 0) {
|
||||
return true
|
||||
}
|
||||
const isDisabled = useDisabled(() => !isSomeExportable.value)
|
||||
|
||||
if (!vms.value.some(vm => areSomeVmOperationAllowed(vm, VM_OPERATION.EXPORT))) {
|
||||
return props.isSingleAction ? t('vm-is-running') : t('no-selected-vm-can-be-exported')
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
})
|
||||
const openModal = () => {
|
||||
useModal(() => import('@/components/modals/VmExportModal.vue'), {
|
||||
vmRefs: props.vmRefs,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
<template>
|
||||
<li>
|
||||
<VtsMenuTrigger :icon="faFileExport" v-bind="toggle.$trigger">
|
||||
{{ $t('export') }}
|
||||
</VtsMenuTrigger>
|
||||
|
||||
<VtsMenuList v-bind="toggle.$target">
|
||||
<VmActionExportItem :menu="toggle" :vm-refs="vmRefs" />
|
||||
<VtsMenuItem :icon="faCode" v-bind="toggle.exportAsJson">
|
||||
<MenuItem :icon="faFileExport">
|
||||
{{ $t('export') }}
|
||||
<template #submenu>
|
||||
<VmActionExportItem :vm-refs="vmRefs" />
|
||||
<MenuItem :icon="faCode" @click="exportVmsAsJsonFile(vms, `vms_${new Date().toISOString()}.json`)">
|
||||
{{ $t('export-table-to', { type: '.json' }) }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faFileCsv" v-bind="toggle.exportAsCsv">
|
||||
</MenuItem>
|
||||
<MenuItem :icon="faFileCsv" @click="exportVmsAsCsvFile(vms, `vms_${new Date().toISOString()}.csv`)">
|
||||
{{ $t('export-table-to', { type: '.csv' }) }}
|
||||
</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
</li>
|
||||
</MenuItem>
|
||||
</template>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -21,31 +18,14 @@ import VmActionExportItem from '@/components/vm/VmActionItems/VmActionExportItem
|
||||
import { exportVmsAsCsvFile, exportVmsAsJsonFile } from '@/libs/vm'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import VtsMenuTrigger from '@core/components/menu/VtsMenuTrigger.vue'
|
||||
import { action, type MenuLike, useMenuToggle } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { faCode, faFileCsv, faFileExport } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
vmRefs: XenApiVm['$ref'][]
|
||||
}>()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
|
||||
const vms = computed(() => getByOpaqueRefs(props.vmRefs))
|
||||
|
||||
const toggle = useMenuToggle({
|
||||
parent: props.menu,
|
||||
items: {
|
||||
exportAsJson: action(() => exportVmsAsJsonFile(vms.value, `vms_${new Date().toISOString()}.json`), {
|
||||
disabled: computed(() => vms.value.length === 0),
|
||||
}),
|
||||
exportAsCsv: action(() => exportVmsAsCsvFile(vms.value, `vms_${new Date().toISOString()}.csv`), {
|
||||
disabled: computed(() => vms.value.length === 0),
|
||||
}),
|
||||
},
|
||||
})
|
||||
const { getByOpaqueRef: getVm } = useVmStore().subscribe()
|
||||
const vms = computed(() => props.vmRefs.map(getVm).filter((vm): vm is XenApiVm => vm !== undefined))
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faRoute" v-bind="menuItem">
|
||||
<MenuItem
|
||||
v-tooltip="
|
||||
selectedRefs.length > 0 &&
|
||||
!isMigratable &&
|
||||
$t(isSingleAction ? 'this-vm-cant-be-migrated' : 'no-selected-vm-can-be-migrated')
|
||||
"
|
||||
:busy="isMigrating"
|
||||
:disabled="isDisabled"
|
||||
:icon="faRoute"
|
||||
@click="openModal()"
|
||||
>
|
||||
{{ $t('migrate') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -10,41 +20,35 @@ import { areSomeVmOperationAllowed, isVmOperationPending } from '@/libs/vm'
|
||||
import { VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import { type MenuLike, useMenuAction } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faRoute } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
selectedRefs: XenApiVm['$ref'][]
|
||||
isSingleAction?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
|
||||
const vms = computed(() => getByOpaqueRefs(props.selectedRefs))
|
||||
const isMigratable = computed(() =>
|
||||
getByOpaqueRefs(props.selectedRefs).some(vm =>
|
||||
areSomeVmOperationAllowed(vm, [VM_OPERATION.POOL_MIGRATE, VM_OPERATION.MIGRATE_SEND])
|
||||
)
|
||||
)
|
||||
|
||||
const menuItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
handler: () =>
|
||||
useModal(() => import('@/components/modals/VmMigrateModal.vue'), {
|
||||
vmRefs: props.selectedRefs,
|
||||
}),
|
||||
disabled: () => {
|
||||
if (props.selectedRefs.length === 0) {
|
||||
return true
|
||||
}
|
||||
const isMigrating = computed(() =>
|
||||
getByOpaqueRefs(props.selectedRefs).some(vm =>
|
||||
isVmOperationPending(vm, [VM_OPERATION.POOL_MIGRATE, VM_OPERATION.MIGRATE_SEND])
|
||||
)
|
||||
)
|
||||
|
||||
if (!vms.value.some(vm => areSomeVmOperationAllowed(vm, [VM_OPERATION.POOL_MIGRATE, VM_OPERATION.MIGRATE_SEND]))) {
|
||||
return props.isSingleAction ? t('this-vm-cant-be-migrated') : t('no-selected-vm-can-be-migrated')
|
||||
}
|
||||
},
|
||||
busy: computed(() =>
|
||||
vms.value.some(vm => isVmOperationPending(vm, [VM_OPERATION.POOL_MIGRATE, VM_OPERATION.MIGRATE_SEND]))
|
||||
),
|
||||
})
|
||||
const isDisabled = useDisabled(() => !isMigratable.value)
|
||||
|
||||
const openModal = () =>
|
||||
useModal(() => import('@/components/modals/VmMigrateModal.vue'), {
|
||||
vmRefs: props.selectedRefs,
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faPlay" v-bind="startItem">
|
||||
<MenuItem :busy="areVmsBusyToStart" :disabled="!areVmsHalted" :icon="faPlay" @click="xenApi.vm.start(vmRefs)">
|
||||
{{ $t('start') }}
|
||||
</VtsMenuItem>
|
||||
<li>
|
||||
<VtsMenuTrigger :icon="faServer" v-bind="startOnHostItem.$trigger">
|
||||
{{ $t('start-on-host') }}
|
||||
</VtsMenuTrigger>
|
||||
<VtsMenuList border v-bind="startOnHostItem.$target">
|
||||
<VtsMenuItem v-for="host in hosts" :key="host.$ref" :icon="faServer" v-bind="startOnHostItem[host.$ref]">
|
||||
</MenuItem>
|
||||
<MenuItem :busy="areVmsBusyToStartOnHost" :disabled="!areVmsHalted" :icon="faServer">
|
||||
{{ $t('start-on-host') }}
|
||||
<template #submenu>
|
||||
<MenuItem v-for="host in hosts" :key="host.$ref" :icon="faServer" @click="xenApi.vm.startOn(vmRefs, host.$ref)">
|
||||
<div class="wrapper">
|
||||
{{ host.name_label }}
|
||||
<div>
|
||||
@@ -15,30 +13,55 @@
|
||||
<PowerStateIcon :state="getHostState(host)" />
|
||||
</div>
|
||||
</div>
|
||||
</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
</li>
|
||||
<VtsMenuItem :icon="faPause" v-bind="pauseItem">
|
||||
</MenuItem>
|
||||
</template>
|
||||
</MenuItem>
|
||||
<MenuItem :busy="areVmsBusyToPause" :disabled="!areVmsRunning" :icon="faPause" @click="xenApi.vm.pause(vmRefs)">
|
||||
{{ $t('pause') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faMoon" v-bind="suspendItem">
|
||||
</MenuItem>
|
||||
<MenuItem :busy="areVmsBusyToSuspend" :disabled="!areVmsRunning" :icon="faMoon" @click="xenApi.vm.suspend(vmRefs)">
|
||||
{{ $t('suspend') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faCirclePlay" v-bind="resumeItem">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:busy="areVmsBusyToResume"
|
||||
:disabled="!areVmsSuspended && !areVmsPaused"
|
||||
:icon="faCirclePlay"
|
||||
@click="xenApi.vm.resume(vmRefsWithPowerState)"
|
||||
>
|
||||
{{ $t('resume') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faRotateLeft" v-bind="rebootItem">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:busy="areVmsBusyToReboot"
|
||||
:disabled="!areVmsRunning"
|
||||
:icon="faRotateLeft"
|
||||
@click="xenApi.vm.reboot(vmRefs)"
|
||||
>
|
||||
{{ $t('reboot') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faRepeat" v-bind="forceRebootItem">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:busy="areVmsBusyToForceReboot"
|
||||
:disabled="!areVmsRunning && !areVmsPaused"
|
||||
:icon="faRepeat"
|
||||
@click="xenApi.vm.reboot(vmRefs, true)"
|
||||
>
|
||||
{{ $t('force-reboot') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faPowerOff" v-bind="shutdownItem">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:busy="areVmsBusyToShutdown"
|
||||
:disabled="!areVmsRunning"
|
||||
:icon="faPowerOff"
|
||||
@click="xenApi.vm.shutdown(vmRefs)"
|
||||
>
|
||||
{{ $t('shutdown') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faPlug" v-bind="forceShutdownItem">
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
:busy="areVmsBusyToForceShutdown"
|
||||
:disabled="!areVmsRunning && !areVmsSuspended && !areVmsPaused"
|
||||
:icon="faPlug"
|
||||
@click="xenApi.vm.shutdown(vmRefs, true)"
|
||||
>
|
||||
{{ $t('force-shutdown') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -52,10 +75,7 @@ import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import VtsMenuTrigger from '@core/components/menu/VtsMenuTrigger.vue'
|
||||
import { action, type MenuLike, useMenuAction, useMenuToggle } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import {
|
||||
faCirclePlay,
|
||||
faMoon,
|
||||
@@ -71,26 +91,17 @@ import {
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
vmRefs: XenApiVm['$ref'][]
|
||||
}>()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
const { getByOpaqueRef: getVm } = useVmStore().subscribe()
|
||||
const { records: hosts } = useHostStore().subscribe()
|
||||
const { pool } = usePoolStore().subscribe()
|
||||
const { isHostRunning } = useHostMetricsStore().subscribe()
|
||||
|
||||
const vms = computed(() => getByOpaqueRefs(props.vmRefs))
|
||||
const vms = computed(() => props.vmRefs.map(getVm).filter((vm): vm is XenApiVm => vm !== undefined))
|
||||
|
||||
const vmRefsWithPowerState = computed(() =>
|
||||
vms.value.reduce(
|
||||
(acc, vm) => ({
|
||||
...acc,
|
||||
[vm.$ref]: vm.power_state,
|
||||
}),
|
||||
{}
|
||||
)
|
||||
)
|
||||
const vmRefsWithPowerState = computed(() => vms.value.reduce((acc, vm) => ({ ...acc, [vm.$ref]: vm.power_state }), {}))
|
||||
|
||||
const xenApi = useXenApiStore().getXapi()
|
||||
|
||||
@@ -112,78 +123,6 @@ const areVmsBusyToForceReboot = computed(() => areOperationsPending(VM_OPERATION
|
||||
const areVmsBusyToShutdown = computed(() => areOperationsPending(VM_OPERATION.CLEAN_SHUTDOWN))
|
||||
const areVmsBusyToForceShutdown = computed(() => areOperationsPending(VM_OPERATION.HARD_SHUTDOWN))
|
||||
const getHostState = (host: XenApiHost) => (isHostRunning(host) ? VM_POWER_STATE.RUNNING : VM_POWER_STATE.HALTED)
|
||||
|
||||
const hasVm = computed(() => vms.value.length > 0)
|
||||
|
||||
const startItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToStart,
|
||||
disabled: computed(() => !hasVm.value || !areVmsHalted.value),
|
||||
handler: () => xenApi.vm.start(props.vmRefs),
|
||||
})
|
||||
|
||||
const startOnHostItem = useMenuToggle({
|
||||
parent: props.menu,
|
||||
placement: 'right-start',
|
||||
items: Object.fromEntries(
|
||||
hosts.value.map(host => [
|
||||
host.$ref,
|
||||
action(() => xenApi.vm.startOn(props.vmRefs, host.$ref), {
|
||||
busy: areVmsBusyToStartOnHost,
|
||||
disabled: computed(() => !hasVm.value || !areVmsHalted.value),
|
||||
}),
|
||||
])
|
||||
),
|
||||
})
|
||||
|
||||
const pauseItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToPause,
|
||||
disabled: computed(() => !hasVm.value || !areVmsRunning.value),
|
||||
handler: () => xenApi.vm.pause(props.vmRefs),
|
||||
})
|
||||
|
||||
const suspendItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToSuspend,
|
||||
disabled: computed(() => !hasVm.value || !areVmsRunning.value),
|
||||
handler: () => xenApi.vm.suspend(props.vmRefs),
|
||||
})
|
||||
|
||||
const resumeItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToResume,
|
||||
disabled: computed(() => !hasVm.value || (!areVmsSuspended.value && !areVmsPaused.value)),
|
||||
handler: () => xenApi.vm.resume(vmRefsWithPowerState.value),
|
||||
})
|
||||
|
||||
const rebootItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToReboot,
|
||||
disabled: computed(() => !hasVm.value || !areVmsRunning.value),
|
||||
handler: () => xenApi.vm.reboot(props.vmRefs),
|
||||
})
|
||||
|
||||
const forceRebootItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToForceReboot,
|
||||
disabled: computed(() => !hasVm.value || (!areVmsRunning.value && !areVmsPaused.value)),
|
||||
handler: () => xenApi.vm.reboot(props.vmRefs, true),
|
||||
})
|
||||
|
||||
const shutdownItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToShutdown,
|
||||
disabled: computed(() => !hasVm.value || !areVmsRunning.value),
|
||||
handler: () => xenApi.vm.shutdown(props.vmRefs),
|
||||
})
|
||||
|
||||
const forceShutdownItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
busy: areVmsBusyToForceShutdown,
|
||||
disabled: computed(() => !hasVm.value || (!areVmsRunning.value && !areVmsSuspended.value && !areVmsPaused.value)),
|
||||
handler: () => xenApi.vm.shutdown(props.vmRefs, true),
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<VtsMenuItem :icon="faCamera" v-bind="menuItem">
|
||||
<MenuItem :busy="areSomeVmsSnapshoting" :disabled="isDisabled" :icon="faCamera" @click="handleSnapshot">
|
||||
{{ $t('snapshot') }}
|
||||
</VtsMenuItem>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -10,28 +10,28 @@ import { VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import { type MenuLike, useMenuAction } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { faCamera } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
menu: MenuLike
|
||||
vmRefs: XenApiVm['$ref'][]
|
||||
}>()
|
||||
|
||||
const { getByOpaqueRefs } = useVmStore().subscribe()
|
||||
const { getByOpaqueRef } = useVmStore().subscribe()
|
||||
|
||||
const vms = computed(() => getByOpaqueRefs(props.vmRefs))
|
||||
|
||||
const vmRefsToSnapshot = computed(() =>
|
||||
Object.fromEntries(vms.value.map(vm => [vm.$ref, `${vm.name_label}_${new Date().toISOString()}`]))
|
||||
const vms = computed(() =>
|
||||
props.vmRefs.map(vmRef => getByOpaqueRef(vmRef)).filter((vm): vm is XenApiVm => vm !== undefined)
|
||||
)
|
||||
|
||||
const menuItem = useMenuAction({
|
||||
parent: props.menu,
|
||||
handler: () => useXenApiStore().getXapi().vm.snapshot(vmRefsToSnapshot.value),
|
||||
busy: computed(() => vms.value.some(vm => isVmOperationPending(vm, VM_OPERATION.SNAPSHOT))),
|
||||
disabled: computed(() => vms.value.length === 0),
|
||||
})
|
||||
const areSomeVmsSnapshoting = computed(() => vms.value.some(vm => isVmOperationPending(vm, VM_OPERATION.SNAPSHOT)))
|
||||
|
||||
const isDisabled = computed(() => vms.value.length === 0 || areSomeVmsSnapshoting.value)
|
||||
|
||||
const handleSnapshot = () => {
|
||||
const vmRefsToSnapshot = Object.fromEntries(
|
||||
vms.value.map(vm => [vm.$ref, `${vm.name_label}_${new Date().toISOString()}`])
|
||||
)
|
||||
return useXenApiStore().getXapi().vm.snapshot(vmRefsToSnapshot)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,39 +1,50 @@
|
||||
<template>
|
||||
<TitleBar :icon="faDisplay">
|
||||
{{ name }}
|
||||
<template v-if="vm !== undefined" #actions>
|
||||
<UiDropdownButton :icon="faPowerOff" v-bind="omit(powerMenu.$trigger, ['as', 'submenu'])">
|
||||
{{ $t('change-state') }}
|
||||
</UiDropdownButton>
|
||||
|
||||
<VtsMenuList border v-bind="powerMenu.$target">
|
||||
<VmActionPowerStateItems :menu="powerMenu" :vm-refs="[vm.$ref]" />
|
||||
</VtsMenuList>
|
||||
|
||||
<UiButtonIcon
|
||||
v-tooltip="{
|
||||
placement: 'left',
|
||||
content: $t('more-actions'),
|
||||
}"
|
||||
:icon="faEllipsisVertical"
|
||||
accent="info"
|
||||
class="more-actions-button"
|
||||
size="large"
|
||||
v-bind="omit(moreMenu.$trigger, ['as', 'submenu'])"
|
||||
/>
|
||||
|
||||
<VtsMenuList border v-bind="moreMenu.$target">
|
||||
<VmActionCopyItem :menu="moreMenu" :selected-refs="[vm.$ref]" is-single-action />
|
||||
<VmActionExportItem :menu="moreMenu" :vm-refs="[vm.$ref]" is-single-action />
|
||||
<VmActionSnapshotItem :menu="moreMenu" :vm-refs="[vm.$ref]" />
|
||||
<VmActionMigrateItem :menu="moreMenu" :selected-refs="[vm.$ref]" is-single-action />
|
||||
</VtsMenuList>
|
||||
<template #actions>
|
||||
<MenuList v-if="vm !== undefined" placement="bottom-end" border>
|
||||
<template #trigger="{ open, isOpen }">
|
||||
<UiButton
|
||||
size="medium"
|
||||
accent="info"
|
||||
variant="primary"
|
||||
:class="{ pressed: isOpen }"
|
||||
:left-icon="faPowerOff"
|
||||
@click="open"
|
||||
>
|
||||
{{ $t('change-state') }}
|
||||
<UiIcon :icon="faAngleDown" />
|
||||
</UiButton>
|
||||
</template>
|
||||
<VmActionPowerStateItems :vm-refs="[vm.$ref]" />
|
||||
</MenuList>
|
||||
<MenuList v-if="vm !== undefined" placement="bottom-end" border>
|
||||
<template #trigger="{ open, isOpen }">
|
||||
<UiButtonIcon
|
||||
v-tooltip="{
|
||||
placement: 'left',
|
||||
content: $t('more-actions'),
|
||||
}"
|
||||
:selected="isOpen"
|
||||
:icon="faEllipsisVertical"
|
||||
accent="info"
|
||||
class="more-actions-button"
|
||||
size="large"
|
||||
@click="open"
|
||||
/>
|
||||
</template>
|
||||
<VmActionCopyItem :selected-refs="[vm.$ref]" is-single-action />
|
||||
<VmActionExportItem :vm-refs="[vm.$ref]" is-single-action />
|
||||
<VmActionSnapshotItem :vm-refs="[vm.$ref]" />
|
||||
<VmActionMigrateItem :selected-refs="[vm.$ref]" is-single-action />
|
||||
</MenuList>
|
||||
</template>
|
||||
</TitleBar>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import TitleBar from '@/components/TitleBar.vue'
|
||||
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||
import VmActionCopyItem from '@/components/vm/VmActionItems/VmActionCopyItem.vue'
|
||||
import VmActionExportItem from '@/components/vm/VmActionItems/VmActionExportItem.vue'
|
||||
import VmActionMigrateItem from '@/components/vm/VmActionItems/VmActionMigrateItem.vue'
|
||||
@@ -41,13 +52,11 @@ import VmActionPowerStateItems from '@/components/vm/VmActionItems/VmActionPower
|
||||
import VmActionSnapshotItem from '@/components/vm/VmActionItems/VmActionSnapshotItem.vue'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import UiDropdownButton from '@core/components/ui/dropdown-button/UiDropdownButton.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useMenuToggle } from '@core/packages/menu'
|
||||
import { faDisplay, faEllipsisVertical, faPowerOff } from '@fortawesome/free-solid-svg-icons'
|
||||
import { objectOmit as omit } from '@vueuse/shared'
|
||||
import { faAngleDown, faDisplay, faEllipsisVertical, faPowerOff } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
@@ -57,8 +66,4 @@ const { currentRoute } = useRouter()
|
||||
const vm = computed(() => getVmByUuid(currentRoute.value.params.uuid as XenApiVm['uuid']))
|
||||
|
||||
const name = computed(() => vm.value?.name_label)
|
||||
|
||||
const powerMenu = useMenuToggle({ placement: 'bottom-end' })
|
||||
|
||||
const moreMenu = useMenuToggle({ placement: 'bottom-end' })
|
||||
</script>
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
<template>
|
||||
<UiButtonIcon v-if="isMobile" :icon="faEllipsis" accent="info" size="medium" v-bind="menu.$trigger" />
|
||||
|
||||
<VtsMenuList
|
||||
:border="isMobile"
|
||||
<MenuList
|
||||
:disabled="selectedRefs.length === 0"
|
||||
:horizontal="!isMobile"
|
||||
:border="isMobile"
|
||||
class="vms-actions-bar"
|
||||
v-bind="isMobile ? menu.$target : undefined"
|
||||
placement="bottom-end"
|
||||
>
|
||||
<VtsMenuItem :icon="faPowerOff" v-bind="menu.powerState.$trigger">
|
||||
<template v-if="isMobile" #trigger="{ isOpen, open }">
|
||||
<UiButtonIcon accent="info" size="medium" :selected="isOpen" :icon="faEllipsis" @click="open" />
|
||||
</template>
|
||||
<MenuItem :icon="faPowerOff">
|
||||
{{ $t('change-state') }}
|
||||
</VtsMenuItem>
|
||||
<Teleport to="body">
|
||||
<VtsMenuList border v-bind="menu.powerState.$target">
|
||||
<VmActionPowerStateItems :menu="menu.powerState" :vm-refs="selectedRefs" />
|
||||
</VtsMenuList>
|
||||
</Teleport>
|
||||
<VmActionMigrateItem :menu :selected-refs="selectedRefs" />
|
||||
<VmActionCopyItem :menu :selected-refs="selectedRefs" />
|
||||
<VtsMenuItem :icon="faEdit" v-bind="menu.editConfig">
|
||||
<template #submenu>
|
||||
<VmActionPowerStateItems :vm-refs="selectedRefs" />
|
||||
</template>
|
||||
</MenuItem>
|
||||
<VmActionMigrateItem :selected-refs="selectedRefs" />
|
||||
<VmActionCopyItem :selected-refs="selectedRefs" />
|
||||
<MenuItem v-tooltip="$t('coming-soon')" :icon="faEdit">
|
||||
{{ $t('edit-config') }}
|
||||
</VtsMenuItem>
|
||||
<VmActionSnapshotItem :menu :vm-refs="selectedRefs" />
|
||||
<VmActionExportItems :menu :vm-refs="selectedRefs" />
|
||||
<VmActionDeleteItem :menu :vm-refs="selectedRefs" />
|
||||
</VtsMenuList>
|
||||
</MenuItem>
|
||||
<VmActionSnapshotItem :vm-refs="selectedRefs" />
|
||||
<VmActionExportItems :vm-refs="selectedRefs" />
|
||||
<VmActionDeleteItem :vm-refs="selectedRefs" />
|
||||
</MenuList>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -34,32 +34,20 @@ import VmActionMigrateItem from '@/components/vm/VmActionItems/VmActionMigrateIt
|
||||
import VmActionPowerStateItems from '@/components/vm/VmActionItems/VmActionPowerStateItems.vue'
|
||||
import VmActionSnapshotItem from '@/components/vm/VmActionItems/VmActionSnapshotItem.vue'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import { action, toggle, useMenuToggle } from '@core/packages/menu'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import { faEdit, faEllipsis, faPowerOff } from '@fortawesome/free-solid-svg-icons'
|
||||
import { noop } from '@vueuse/shared'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
disabled?: boolean
|
||||
selectedRefs: XenApiVm['$ref'][]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { isMobile } = storeToRefs(useUiStore())
|
||||
|
||||
const menu = useMenuToggle({
|
||||
placement: 'bottom-end',
|
||||
items: {
|
||||
powerState: toggle({}),
|
||||
editConfig: action(noop, { disabled: t('coming-soon') }),
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -2,8 +2,6 @@ import { createContext } from '@/composables/context.composable'
|
||||
import type { Color } from '@/types'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const DisabledContext = createContext(false)
|
||||
|
||||
export const ColorContext = createContext('info' as Color, color => ({
|
||||
name: color,
|
||||
textClass: computed(() => `context-color-${color.value}`),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<template>
|
||||
<div :class="uiStore.isMobile ? 'mobile' : undefined" class="vts-remote-console">
|
||||
<VtsLoadingHero :disabled="isReady" type="panel" />
|
||||
<div ref="consoleContainer" class="console" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsLoadingHero from '@core/components/state-hero/VtsLoadingHero.vue'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import VncClient from '@novnc/novnc/lib/rfb'
|
||||
import { promiseTimeout } from '@vueuse/shared'
|
||||
@@ -19,6 +21,7 @@ const N_TOTAL_TRIES = 8
|
||||
const FIBONACCI_MS_ARRAY: number[] = Array.from(fibonacci().toMs().take(N_TOTAL_TRIES))
|
||||
|
||||
const consoleContainer = ref<HTMLDivElement | null>(null)
|
||||
const isReady = ref(false)
|
||||
|
||||
let vncClient: VncClient | undefined
|
||||
let nConnectionAttempts = 0
|
||||
@@ -43,9 +46,11 @@ function handleDisconnectionEvent() {
|
||||
|
||||
function handleConnectionEvent() {
|
||||
nConnectionAttempts = 0
|
||||
isReady.value = true
|
||||
}
|
||||
|
||||
function clearVncClient() {
|
||||
isReady.value = false
|
||||
if (vncClient === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,36 +23,28 @@
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
/** @deprecated Use VtsMenuItem or VtsMenuTrigger */
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import MenuTrigger from '@core/components/menu/MenuTrigger.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { IK_CLOSE_MENU, IK_MENU_HORIZONTAL } from '@core/utils/injection-keys.util'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faAngleDown, faAngleRight } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed, inject, ref } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
icon?: IconDefinition
|
||||
onClick?: () => any
|
||||
disabled?: boolean
|
||||
busy?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
icon?: IconDefinition
|
||||
onClick?: () => any
|
||||
disabled?: boolean
|
||||
busy?: boolean
|
||||
}>()
|
||||
|
||||
const isParentHorizontal = inject(
|
||||
IK_MENU_HORIZONTAL,
|
||||
computed(() => false)
|
||||
)
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
|
||||
const submenuIcon = computed(() => (isParentHorizontal.value ? faAngleDown : faAngleRight))
|
||||
|
||||
|
||||
@@ -8,13 +8,8 @@
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
/** @deprecated Use VtsMenuList */
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { IK_CLOSE_MENU, IK_MENU_HORIZONTAL, IK_MENU_TELEPORTED } from '@core/utils/injection-keys.util'
|
||||
import { onClickOutside, unrefElement, whenever } from '@vueuse/core'
|
||||
import placementJs, { type Options } from 'placement.js'
|
||||
@@ -24,15 +19,12 @@ defineOptions({
|
||||
inheritAttrs: false,
|
||||
})
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
horizontal?: boolean
|
||||
border?: boolean
|
||||
disabled?: boolean
|
||||
placement?: Options['placement']
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
horizontal?: boolean
|
||||
border?: boolean
|
||||
disabled?: boolean
|
||||
placement?: Options['placement']
|
||||
}>()
|
||||
|
||||
const slots = useSlots()
|
||||
const isOpen = ref(false)
|
||||
@@ -46,7 +38,7 @@ provide(
|
||||
computed(() => props.horizontal ?? false)
|
||||
)
|
||||
|
||||
useContext(DisabledContext, () => props.disabled)
|
||||
useDisabled(() => props.disabled)
|
||||
|
||||
let clearClickOutsideEvent: (() => void) | undefined
|
||||
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
/** @deprecated Use VtsMenuTrigger */
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<template>
|
||||
<li>
|
||||
<VtsMenuTrigger v-bind="{ ...props, ...attrs }">
|
||||
<slot />
|
||||
</VtsMenuTrigger>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsMenuTrigger, { type MenuTriggerProps } from '@core/components/menu/VtsMenuTrigger.vue'
|
||||
import { useAttrs } from 'vue'
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
})
|
||||
|
||||
const props = defineProps<MenuTriggerProps>()
|
||||
const attrs = useAttrs()
|
||||
</script>
|
||||
@@ -1,43 +0,0 @@
|
||||
<!-- v1.0 -->
|
||||
<template>
|
||||
<ul :class="{ horizontal, border }" class="menu-list">
|
||||
<slot />
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { IK_MENU_HORIZONTAL } from '@core/utils/injection-keys.util'
|
||||
import { computed, provide } from 'vue'
|
||||
|
||||
const { horizontal, border } = defineProps<{
|
||||
horizontal?: boolean
|
||||
border?: boolean
|
||||
}>()
|
||||
|
||||
provide(
|
||||
IK_MENU_HORIZONTAL,
|
||||
computed(() => horizontal ?? false)
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.menu-list {
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.4rem;
|
||||
cursor: default;
|
||||
color: var(--color-neutral-txt-primary);
|
||||
border-radius: 0.4rem;
|
||||
background-color: var(--color-neutral-background-primary);
|
||||
gap: 0.2rem;
|
||||
|
||||
&.horizontal {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
&.border {
|
||||
border: 0.1rem solid var(--color-neutral-border);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,83 +0,0 @@
|
||||
<!-- v1.0 -->
|
||||
<template>
|
||||
<component
|
||||
:is="as"
|
||||
v-tooltip="tooltip ?? false"
|
||||
:class="{ selected, disabled }"
|
||||
class="vts-menu-trigger typo p2-medium"
|
||||
>
|
||||
<VtsIcon :busy :icon accent="current" />
|
||||
<slot />
|
||||
<VtsIcon v-if="submenu" :fixed-width="false" :icon="submenuIcon" accent="current" class="submenu-icon" />
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { type TooltipDirectiveContent, vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { IK_MENU_HORIZONTAL } from '@core/utils/injection-keys.util'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faAngleDown, faAngleRight } from '@fortawesome/free-solid-svg-icons'
|
||||
import { type Component, computed, inject } from 'vue'
|
||||
|
||||
export type MenuTriggerProps = {
|
||||
as: string | Component
|
||||
tooltip?: TooltipDirectiveContent
|
||||
selected?: boolean
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
icon?: IconDefinition
|
||||
submenu?: boolean
|
||||
}
|
||||
|
||||
defineProps<MenuTriggerProps>()
|
||||
|
||||
defineSlots<{
|
||||
default(): any
|
||||
}>()
|
||||
|
||||
const isParentHorizontal = inject(IK_MENU_HORIZONTAL, undefined)
|
||||
|
||||
const submenuIcon = computed(() => (isParentHorizontal?.value ? faAngleDown : faAngleRight))
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.vts-menu-trigger {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
height: 4.4rem;
|
||||
padding-right: 1.5rem;
|
||||
padding-left: 1.5rem;
|
||||
white-space: nowrap;
|
||||
border-radius: 0.8rem;
|
||||
gap: 1rem;
|
||||
color: var(--color-neutral-txt-primary);
|
||||
background-color: var(--color-neutral-background-primary);
|
||||
border: none;
|
||||
text-decoration: none;
|
||||
|
||||
&.disabled {
|
||||
color: var(--color-neutral-txt-secondary);
|
||||
}
|
||||
|
||||
&:not(.disabled) {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--color-neutral-txt-primary);
|
||||
background-color: var(--color-info-background-selected);
|
||||
}
|
||||
|
||||
&:active,
|
||||
&.selected {
|
||||
color: var(--color-neutral-txt-primary);
|
||||
background-color: var(--color-info-background-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.submenu-icon {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -6,8 +6,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed } from 'vue'
|
||||
@@ -18,12 +17,12 @@ const props = withDefaults(
|
||||
active?: boolean
|
||||
tag?: string
|
||||
}>(),
|
||||
{ tag: 'span', disabled: undefined }
|
||||
{ tag: 'span' }
|
||||
)
|
||||
|
||||
const { isMobile } = storeToRefs(useUiStore())
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
|
||||
const classNames = computed(() => {
|
||||
return [
|
||||
|
||||
@@ -6,17 +6,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
useContext(DisabledContext, () => props.disabled)
|
||||
useDisabled(() => props.disabled)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiUserLogo from '@core/components/ui/user-logo/UiUserLogo.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
|
||||
defineProps<{
|
||||
size: 'small' | 'medium'
|
||||
selected?: boolean
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext)
|
||||
const isDisabled = useDisabled()
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { toVariants } from '@core/utils/to-variants.util'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faLock } from '@fortawesome/free-solid-svg-icons'
|
||||
@@ -20,26 +19,21 @@ type ButtonVariant = 'primary' | 'secondary' | 'tertiary'
|
||||
type ButtonAccent = 'info' | 'success' | 'warning' | 'danger'
|
||||
type ButtonSize = 'small' | 'medium' | 'large'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
variant: ButtonVariant
|
||||
accent: ButtonAccent
|
||||
size: ButtonSize
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
lockIcon?: boolean
|
||||
leftIcon?: IconDefinition
|
||||
}>(),
|
||||
{
|
||||
disabled: undefined,
|
||||
}
|
||||
)
|
||||
const props = defineProps<{
|
||||
variant: ButtonVariant
|
||||
accent: ButtonAccent
|
||||
size: ButtonSize
|
||||
busy?: boolean
|
||||
disabled?: boolean
|
||||
lockIcon?: boolean
|
||||
leftIcon?: IconDefinition
|
||||
}>()
|
||||
|
||||
defineSlots<{
|
||||
default(): any
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
|
||||
const fontClasses = {
|
||||
small: 'typo p3-medium',
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<!-- v3 -->
|
||||
<template>
|
||||
<label class="ui-checkbox" :class="classNames" v-bind="wrapperAttrs">
|
||||
<label :class="classNames" class="ui-checkbox" v-bind="wrapperAttrs">
|
||||
<input
|
||||
v-model="checkboxModel"
|
||||
:class="{ indeterminate: isIndeterminate }"
|
||||
:disabled="isDisabled"
|
||||
type="checkbox"
|
||||
class="input"
|
||||
type="checkbox"
|
||||
v-bind="attrs"
|
||||
/>
|
||||
<span class="fake-checkbox">
|
||||
<VtsIcon :icon class="icon" accent="info" />
|
||||
<VtsIcon :icon accent="info" class="icon" />
|
||||
</span>
|
||||
<span v-if="slots.default" class="typo p1-regular">
|
||||
<slot />
|
||||
@@ -24,8 +24,7 @@
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiInfo from '@core/components/ui/info/UiInfo.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { toVariants } from '@core/utils/to-variants.util'
|
||||
import { faCheck, faMinus } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed, type LabelHTMLAttributes, useAttrs } from 'vue'
|
||||
@@ -34,14 +33,11 @@ type CheckboxAccent = 'info' | 'success' | 'warning' | 'danger'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
accent: CheckboxAccent
|
||||
disabled?: boolean
|
||||
wrapperAttrs?: LabelHTMLAttributes
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const props = defineProps<{
|
||||
accent: CheckboxAccent
|
||||
disabled?: boolean
|
||||
wrapperAttrs?: LabelHTMLAttributes
|
||||
}>()
|
||||
|
||||
const checkboxModel = defineModel<boolean | undefined>({ default: undefined })
|
||||
|
||||
@@ -50,7 +46,7 @@ const slots = defineSlots<{
|
||||
info?(): any
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => props.disabled)
|
||||
|
||||
const classNames = computed(() => [
|
||||
toVariants({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- v3 -->
|
||||
<template>
|
||||
<button type="button" class="ui-dropdown-item" :class="{ selected }" :disabled="isDisabled">
|
||||
<button :class="{ selected }" :disabled="isDisabled" class="ui-dropdown-item" type="button">
|
||||
<VtsIcon :icon accent="current" class="left-icon" fixed-width />
|
||||
<span class="typo p1-regular label">
|
||||
<slot />
|
||||
@@ -11,24 +11,20 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
|
||||
import { faAngleDown } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
disabled?: boolean
|
||||
selected?: boolean
|
||||
icon?: IconDefinition
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const { disabled, selected, icon } = defineProps<{
|
||||
disabled?: boolean
|
||||
selected?: boolean
|
||||
icon?: IconDefinition
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => disabled)
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
<style lang="postcss" scoped>
|
||||
.ui-dropdown-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<template>
|
||||
<label :class="variant" class="ui-radio-button typo p1-regular">
|
||||
<span class="radio-container">
|
||||
<input v-model="model" :value :disabled="isDisabled" class="input" type="radio" />
|
||||
<input v-model="model" :disabled="isDisabled" :value class="input" type="radio" />
|
||||
<VtsIcon :icon="faCircle" accent="current" class="radio-icon" />
|
||||
</span>
|
||||
<slot />
|
||||
@@ -11,31 +11,26 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { toVariants } from '@core/utils/to-variants.util'
|
||||
import { faCircle } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
accent: 'info' | 'success' | 'warning' | 'danger'
|
||||
value: any
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{
|
||||
disabled: undefined,
|
||||
}
|
||||
)
|
||||
const { accent, value, disabled } = defineProps<{
|
||||
accent: 'info' | 'success' | 'warning' | 'danger'
|
||||
value: any
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
const model = defineModel<boolean>()
|
||||
|
||||
defineSlots<{
|
||||
default(): any
|
||||
}>()
|
||||
|
||||
const variant = computed(() => toVariants({ accent: props.accent }))
|
||||
const variant = computed(() => toVariants({ accent }))
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => disabled)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
@@ -60,6 +55,7 @@ const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
|
||||
&:has(input:focus-visible) {
|
||||
outline: none;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
content: '';
|
||||
@@ -68,6 +64,7 @@ const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
border-radius: 0.4rem;
|
||||
}
|
||||
}
|
||||
|
||||
&:has(.input:disabled) {
|
||||
cursor: not-allowed;
|
||||
|
||||
|
||||
@@ -13,16 +13,12 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
disabled?: boolean
|
||||
busy?: boolean
|
||||
}>(),
|
||||
{ disabled: undefined }
|
||||
)
|
||||
const { busy, disabled } = defineProps<{
|
||||
disabled?: boolean
|
||||
busy?: boolean
|
||||
}>()
|
||||
|
||||
const checked = defineModel<boolean>()
|
||||
|
||||
@@ -30,7 +26,7 @@ defineSlots<{
|
||||
default(): any
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext, () => props.disabled)
|
||||
const isDisabled = useDisabled(() => disabled)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IK_DISABLED } from '@core/utils/injection-keys.util'
|
||||
import { computed, inject, type MaybeRefOrGetter, provide, toValue } from 'vue'
|
||||
|
||||
export function useDisabled(condition?: MaybeRefOrGetter<boolean>) {
|
||||
const previousValue = inject(
|
||||
IK_DISABLED,
|
||||
computed(() => false)
|
||||
)
|
||||
|
||||
const currentValue = computed(() => previousValue.value || toValue(condition ?? false))
|
||||
|
||||
provide(IK_DISABLED, currentValue)
|
||||
|
||||
return currentValue
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { createContext } from '@core/composables/context.composable'
|
||||
import type { Color } from '@core/types/color.type'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const DisabledContext = createContext(false)
|
||||
|
||||
export const ColorContext = createContext('info' as Color, (color, previousColor) => ({
|
||||
name: color,
|
||||
colorContextClass: computed(() => (previousColor.value === color.value ? undefined : `color-context-${color.value}`)),
|
||||
}))
|
||||
@@ -6,18 +6,18 @@ A menu system for Vue applications supporting props binding for actions, links,
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<VtsMenuList>
|
||||
<VtsMenuItem v-bind="menu.save">Save</VtsMenuItem>
|
||||
<VtsMenuItem v-bind="menu.doc">Documentation</VtsMenuItem>
|
||||
<VtsMenuItem v-bind="menu.profile">Profile</VtsMenuItem>
|
||||
<MenuList>
|
||||
<li><MenuTrigger v-bind="menu.save">Save</MenuTrigger></li>
|
||||
<li><MenuTrigger v-bind="menu.doc">Documentation</MenuTrigger></li>
|
||||
<li><MenuTrigger v-bind="menu.profile">Profile</MenuTrigger></li>
|
||||
<li>
|
||||
<VtsMenuTrigger v-bind="menu.more.$trigger">More...</VtsMenuTrigger>
|
||||
<VtsMenuList v-bind="menu.more.$target">
|
||||
<VtsMenuItem v-bind="menu.more.settings">Settings</VtsMenuItem>
|
||||
<VtsMenuItem v-bind="menu.more.logout">Logout</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
<MenuTrigger v-bind="menu.more.$trigger">More...</MenuTrigger>
|
||||
<MenuList v-bind="menu.more.$target">
|
||||
<MenuTrigger v-bind="menu.more.settings">Settings</MenuTrigger>
|
||||
<MenuTrigger v-bind="menu.more.logout">Logout</MenuTrigger>
|
||||
</MenuList>
|
||||
</li>
|
||||
</VtsMenuList>
|
||||
</MenuList>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -35,8 +35,6 @@ const menu = useMenu({
|
||||
</script>
|
||||
```
|
||||
|
||||
> [!NOTE] > `VtsMenuItem` is a `VtsMenuTrigger` wrapped in a `<li>`
|
||||
|
||||
## Core Composables
|
||||
|
||||
### useMenu
|
||||
@@ -168,15 +166,15 @@ type Props = {
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<VtsMenuTrigger v-bind="menu.save">Save</VtsMenuTrigger>
|
||||
<VtsMenuTrigger v-bind="menu.docs">Documentation</VtsMenuTrigger>
|
||||
<VtsMenuTrigger v-bind="menu.profile">Profile</VtsMenuTrigger>
|
||||
<MenuTrigger v-bind="menu.save">Save</MenuTrigger>
|
||||
<MenuTrigger v-bind="menu.docs">Documentation</MenuTrigger>
|
||||
<MenuTrigger v-bind="menu.profile">Profile</MenuTrigger>
|
||||
|
||||
<!-- Toggle/Dropdown menu -->
|
||||
<VtsMenuTrigger v-bind="menu.more.$trigger">More</VtsMenuTrigger>
|
||||
<MenuTrigger v-bind="menu.more.$trigger">More</MenuTrigger>
|
||||
<div v-bind="menu.more.$target">
|
||||
<VtsMenuTrigger v-bind="menu.more.settings">Settings</VtsMenuTrigger>
|
||||
<VtsMenuTrigger v-bind="menu.more.logout">Logout</VtsMenuTrigger>
|
||||
<MenuTrigger v-bind="menu.more.settings">Settings</MenuTrigger>
|
||||
<MenuTrigger v-bind="menu.more.logout">Logout</MenuTrigger>
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
@@ -69,7 +69,7 @@ export function parseConfigHolder<TConfigHolder extends ConfigHolder>(
|
||||
$target: target.props,
|
||||
$isOpen: trigger.isOpen,
|
||||
[MENU_SYMBOL]: trigger.subMenu,
|
||||
...parseStructure(trigger.subMenu, configHolder.config.items ?? {}),
|
||||
...parseStructure(trigger.subMenu, configHolder.config.items),
|
||||
} as ParseConfigHolder<TConfigHolder>
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ export class MenuToggleTarget {
|
||||
|
||||
get props(): MenuToggleTargetProps {
|
||||
return reactive({
|
||||
as: 'button',
|
||||
type: 'button',
|
||||
ref: (element: HTMLElement | null | undefined) => {
|
||||
const newElement = unrefElement(element)
|
||||
|
||||
|
||||
@@ -15,3 +15,5 @@ export const IK_MENU_HORIZONTAL = Symbol('IK_MENU_HORIZONTAL') as InjectionKey<C
|
||||
export const IK_CLOSE_MENU = Symbol('IK_CLOSE_MENU') as InjectionKey<() => void>
|
||||
|
||||
export const IK_MENU_TELEPORTED = Symbol('IK_MENU_TELEPORTED') as InjectionKey<boolean>
|
||||
|
||||
export const IK_DISABLED = Symbol('IK_DISABLED') as InjectionKey<ComputedRef<boolean>>
|
||||
|
||||
@@ -1,42 +1,64 @@
|
||||
<template>
|
||||
<AccountMenuTrigger v-bind="omit(menu.$trigger, ['as', 'submenu'])" />
|
||||
|
||||
<VtsMenuList border v-bind="menu.$target">
|
||||
<VtsMenuItem :icon="faBook" v-bind="menu.documentation">
|
||||
{{ $t('documentation-name', { name: 'XCP-ng' }) }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faHeadset" v-bind="menu.support">
|
||||
{{ $t('professional-support') }}
|
||||
</VtsMenuItem>
|
||||
<VtsMenuItem :icon="faArrowRightFromBracket" class="logout" v-bind="menu.logout">
|
||||
<MenuList border :disabled placement="bottom-end">
|
||||
<template #trigger="{ isOpen, open }">
|
||||
<UiAccountMenuButton
|
||||
v-tooltip="isOpen ? false : { content: $t('account-organization-more'), placement: 'bottom-end' }"
|
||||
:selected="isOpen"
|
||||
size="medium"
|
||||
@click="open($event)"
|
||||
/>
|
||||
</template>
|
||||
<MenuItem :icon="faBook">
|
||||
<a
|
||||
class="link typo p2-medium"
|
||||
href="https://docs.xcp-ng.org?utm_campaign=xo6&utm_term=xcpdoc"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{{ $t('documentation-name', { name: 'XCP-ng' }) }}
|
||||
</a>
|
||||
</MenuItem>
|
||||
<MenuItem :icon="faHeadset">
|
||||
<a
|
||||
class="link typo p2-medium"
|
||||
href="https://vates.tech/pricing-and-support?utm_campaign=xo6&utm_term=pricing"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{{ $t('professional-support') }}
|
||||
</a>
|
||||
</MenuItem>
|
||||
<MenuItem :icon="faArrowRightFromBracket" class="logout" @click="logout()">
|
||||
{{ $t('log-out') }}
|
||||
</VtsMenuItem>
|
||||
</VtsMenuList>
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import AccountMenuTrigger from '@/components/account-menu/AccountMenuTrigger.vue'
|
||||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue'
|
||||
import VtsMenuList from '@core/components/menu/VtsMenuList.vue'
|
||||
import { link, useMenuToggle } from '@core/packages/menu'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import UiAccountMenuButton from '@core/components/ui/account-menu-button/UiAccountMenuButton.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faArrowRightFromBracket, faBook, faHeadset } from '@fortawesome/free-solid-svg-icons'
|
||||
import { objectOmit as omit } from '@vueuse/core'
|
||||
|
||||
defineProps<{
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
const menu = useMenuToggle({
|
||||
placement: 'bottom-end',
|
||||
items: {
|
||||
documentation: link('https://docs.xcp-ng.org?utm_campaign=xo6&utm_term=xcpdoc'),
|
||||
support: link('https://vates.tech/pricing-and-support?utm_campaign=xo6&utm_term=pricing'),
|
||||
logout: link('/signout', { target: '_self' }), // TODO: Fetch the XO 5 mount path from API when available
|
||||
},
|
||||
})
|
||||
// TODO: Fetch the XO 5 mount path from API when available
|
||||
const logout = () => window.location.assign('/signout')
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.link {
|
||||
text-decoration: none;
|
||||
color: var(--color-neutral-txt-primary);
|
||||
/* Make the link take the height of the MenuItem component */
|
||||
padding-block: 1.15rem;
|
||||
/* Make the link take the available width in the MenuItem component */
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.logout {
|
||||
color: var(--color-danger-txt-base);
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<template>
|
||||
<button
|
||||
v-tooltip="selected ? false : { content: $t('account-organization-more'), placement: 'bottom-end' }"
|
||||
:class="{ disabled: isDisabled, selected }"
|
||||
class="account-menu-trigger"
|
||||
type="button"
|
||||
>
|
||||
<UiUserLogo class="logo" size="medium" />
|
||||
<VtsIcon :icon="faAngleDown" class="icon" accent="info" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import UiUserLogo from '@core/components/ui/user-logo/UiUserLogo.vue'
|
||||
import { useContext } from '@core/composables/context.composable'
|
||||
import { DisabledContext } from '@core/context'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { faAngleDown } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
defineProps<{
|
||||
selected?: boolean
|
||||
}>()
|
||||
|
||||
const isDisabled = useContext(DisabledContext)
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
/* COLOR VARIANTS */
|
||||
.account-menu-trigger {
|
||||
--background-color: transparent;
|
||||
--accent-color: var(--color-info-txt-base);
|
||||
|
||||
&:is(:hover, .hover, :focus-visible) {
|
||||
--background-color: var(--color-info-background-hover);
|
||||
--accent-color: var(--color-info-txt-hover);
|
||||
}
|
||||
|
||||
&:is(:active, .pressed) {
|
||||
--background-color: var(--color-info-background-active);
|
||||
--accent-color: var(--color-info-txt-active);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
--background-color: var(--color-info-background-selected);
|
||||
--accent-color: var(--color-info-txt-base);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
--background-color: transparent;
|
||||
--accent-color: var(--color-neutral-txt-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
/* IMPLEMENTATION */
|
||||
.account-menu-trigger {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
border-radius: 0.4rem;
|
||||
border-color: transparent;
|
||||
padding: 0.4rem;
|
||||
outline: none;
|
||||
background-color: var(--background-color);
|
||||
|
||||
&:not(.disabled) {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.logo {
|
||||
border-color: var(--accent-color);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
</style>
|
||||
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,9 +1,19 @@
|
||||
# ChangeLog
|
||||
|
||||
## **5.102.0** (2024-12-30)
|
||||
## **5.102.1** (2025-01-09)
|
||||
|
||||
<img id="latest" src="https://badgen.net/badge/channel/latest/yellow" alt="Channel: latest" />
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- [Plugin/backup-reports] Backup reports were not sent on failure with storage issue on remote (PR [#8229](https://github.com/vatesfr/xen-orchestra/pull/8229))
|
||||
|
||||
### Released packages
|
||||
|
||||
- xo-server-backup-reports 1.4.4
|
||||
|
||||
## **5.102.0** (2024-12-30)
|
||||
|
||||
### Highlights
|
||||
|
||||
- [Backup] Add _Merge backups synchronously_ advanced setting (PR [#8177](https://github.com/vatesfr/xen-orchestra/pull/8177))
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
|
||||
### Enhancements
|
||||
|
||||
- **XO 6**:
|
||||
- [Console]: Displays a loader when the console is loading (PR [#8226](https://github.com/vatesfr/xen-orchestra/pull/8226))
|
||||
|
||||
> Users must be able to say: “Nice enhancement, I'm eager to test it”
|
||||
|
||||
### Bug fixes
|
||||
@@ -31,4 +34,6 @@
|
||||
|
||||
<!--packages-start-->
|
||||
|
||||
- @xen-orchestra/web-core minor
|
||||
|
||||
<!--packages-end-->
|
||||
|
||||
@@ -230,7 +230,7 @@ You can verify that your time is correctly set with the `date` command. To set X
|
||||
|
||||
## Setting a custom NTP server
|
||||
|
||||
By default, XOA is configured to use the standard Debian NTP servers:
|
||||
By default, XOA is configured to use the `systemd-timesyncd` daemon, along with the standard Debian NTP servers:
|
||||
|
||||
```
|
||||
pool 0.debian.pool.ntp.org iburst
|
||||
@@ -239,11 +239,18 @@ pool 2.debian.pool.ntp.org iburst
|
||||
pool 3.debian.pool.ntp.org iburst
|
||||
```
|
||||
|
||||
If you'd like to use your own NTP server or another pool, you can make the changes directly in `/etc/ntp.conf`.
|
||||
If you'd like to use another pool, you can make the changes directly in `/etc/systemd/timesyncd.conf`.
|
||||
|
||||
You will need to be root to edit this file (or use `sudo`). We recommend adding your custom server to the top of the list, leaving the debian server entries if possible.
|
||||
You will need to be root to edit this file (or use `sudo`). We recommend adding your custom server to the top of the list, leaving the Debian server entries if possible.
|
||||
|
||||
For changes to take effect, you will need to restart NTP: `sudo systemctl restart ntp.service`.
|
||||
If you'd like to simply change NTP servers, use the `xoa network ntp` command:
|
||||
|
||||
```console
|
||||
$ xoa network ntp
|
||||
? NTP servers (space separated)
|
||||
```
|
||||
|
||||
For changes to take effect, you will need to restart NTP: `systemctl restart systemd-timesyncd.service`.
|
||||
|
||||
## Restart the service
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xo-server-backup-reports",
|
||||
"version": "1.4.3",
|
||||
"version": "1.4.4",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"description": "Backup reports plugin for XO-Server",
|
||||
"keywords": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
- **UUID**: {{{uuid}}}
|
||||
- **Type**: {{{taskLog.data.type}}}
|
||||
{{>reportTemporalDataMd end=taskLog.end start=taskLog.start}}
|
||||
{{>reportTemporalDataMd end=taskLog.end start=taskLog.start formatDate=../formatDate}}
|
||||
{{>reportWarningsMd task=taskLog}}
|
||||
- **Error**: {{{taskLog.result.message}}}
|
||||
{{else}}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<ul>
|
||||
<li><span style="font-weight: bold">UUID</span>: {{uuid}}</li>
|
||||
<li><span style="font-weight: bold">Type</span>: {{taskLog.data.type}}</li>
|
||||
{{>reportTemporalDataMjml end=taskLog.end start=taskLog.start}}
|
||||
{{>reportTemporalDataMjml end=taskLog.end start=taskLog.start formatDate=../formatDate}}
|
||||
{{>reportWarningsMjml task=taskLog}}
|
||||
<li><span style="font-weight: bold">Error</span>: {{taskLog.result.message}}</li>
|
||||
</ul>
|
||||
|
||||
56
packages/xo-server/src/rest-api/AbstractCollection.mjs
Normal file
56
packages/xo-server/src/rest-api/AbstractCollection.mjs
Normal file
@@ -0,0 +1,56 @@
|
||||
import CM from 'complex-matcher'
|
||||
import { every } from '@vates/predicates'
|
||||
import AbstractEntity from './AbstractEntity.mjs'
|
||||
import pick from 'lodash/pick.js'
|
||||
import { noSuchObject } from 'xo-common/api-errors.js'
|
||||
class AbstractCollection extends AbstractEntity {
|
||||
getObject(uuid) {
|
||||
return this.getApp().getObject(uuid, this.getType())
|
||||
}
|
||||
|
||||
getObjects(filter, limit, fields) {
|
||||
filter = filter !== undefined ? CM.parse(filter).createPredicate() : undefined
|
||||
|
||||
let objects = this.getApp().getObjects({
|
||||
filter: every(obj => obj.type === this.getType(), filter),
|
||||
limit,
|
||||
})
|
||||
|
||||
if (fields === undefined) {
|
||||
objects = Object.keys(objects)
|
||||
} else {
|
||||
objects = Object.values(objects)
|
||||
if (fields !== '*') {
|
||||
const properties = fields.split(',')
|
||||
objects = objects.map(obj => pick(obj, properties))
|
||||
}
|
||||
}
|
||||
|
||||
return objects
|
||||
}
|
||||
|
||||
registerRoutes() {
|
||||
this.getRouter()
|
||||
.param('uuid', async (req, res, next) => {
|
||||
const uuid = req.params.uuid
|
||||
|
||||
try {
|
||||
res.locals.object = await this.getObject(uuid)
|
||||
next()
|
||||
} catch (error) {
|
||||
if (noSuchObject.is(error)) {
|
||||
return next('route')
|
||||
}
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
.get(`/`, async (req, res) => {
|
||||
const objects = await this.getObjects(req.query.filter, req.query.limit, req.query.fields)
|
||||
|
||||
this.sendObjects(objects, req, res)
|
||||
})
|
||||
.get(`/:uuid`, (req, res) => this.sendObject(res.locals.object, req, res))
|
||||
}
|
||||
}
|
||||
|
||||
export default AbstractCollection
|
||||
79
packages/xo-server/src/rest-api/AbstractEntity.mjs
Normal file
79
packages/xo-server/src/rest-api/AbstractEntity.mjs
Normal file
@@ -0,0 +1,79 @@
|
||||
import { Router } from 'express'
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
import AbstractCollection from './AbstractCollection.mjs'
|
||||
import pick from 'lodash/pick.js'
|
||||
|
||||
// @TODO Move to utils folder
|
||||
async function* makeJsonStream(iterable) {
|
||||
yield '['
|
||||
let first = true
|
||||
for await (const object of iterable) {
|
||||
if (first) {
|
||||
first = false
|
||||
yield '\n'
|
||||
} else {
|
||||
yield ',\n'
|
||||
}
|
||||
yield JSON.stringify(object, null, 2)
|
||||
}
|
||||
yield '\n]\n'
|
||||
}
|
||||
|
||||
async function* makeNdJsonStream(iterable) {
|
||||
for await (const object of iterable) {
|
||||
yield JSON.stringify(object)
|
||||
yield '\n'
|
||||
}
|
||||
}
|
||||
// ---------
|
||||
|
||||
class AbstractEntity {
|
||||
#app
|
||||
#type
|
||||
#router
|
||||
constructor(app, type) {
|
||||
this.#app = app
|
||||
this.#type = type
|
||||
this.#router = new Router()
|
||||
}
|
||||
|
||||
getApp() {
|
||||
return this.#app
|
||||
}
|
||||
|
||||
getRouter() {
|
||||
return this.#router
|
||||
}
|
||||
|
||||
getType() {
|
||||
return this.#type
|
||||
}
|
||||
|
||||
registerRoutes() {
|
||||
throw new Error('Need to be implemented by the children entity')
|
||||
}
|
||||
|
||||
registerRouter(router) {
|
||||
this.registerRoutes()
|
||||
|
||||
const prefix = `/${this.getType().toLowerCase()}${this instanceof AbstractCollection ? 's' : ''}`
|
||||
router.use(prefix, this.getRouter())
|
||||
}
|
||||
|
||||
sendObjects(iterable, req, res) {
|
||||
const ndjson = req.headers.accept === 'application/x-ndjson'
|
||||
res.setHeader('content-type', ndjson ? 'application/x-ndjson' : 'application/json')
|
||||
return pipeline((ndjson ? makeNdJsonStream : makeJsonStream)(iterable), res)
|
||||
}
|
||||
|
||||
sendObject(object, req, res) {
|
||||
const fields = req.query.fields
|
||||
if (fields !== undefined && fields !== '*') {
|
||||
object = pick(object, fields.split())
|
||||
}
|
||||
|
||||
res.json(object)
|
||||
}
|
||||
}
|
||||
|
||||
export default AbstractEntity
|
||||
20
packages/xo-server/src/rest-api/dashboard.mjs
Normal file
20
packages/xo-server/src/rest-api/dashboard.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import AbstractEntity from './AbstractEntity.mjs'
|
||||
|
||||
class Dashboard extends AbstractEntity {
|
||||
constructor(app) {
|
||||
super(app, 'dashboard')
|
||||
}
|
||||
|
||||
computeSomeRandomData() {
|
||||
return {
|
||||
nPool: Math.round(Math.random() * 100),
|
||||
nHosts: Math.round(Math.random() * 100),
|
||||
}
|
||||
}
|
||||
|
||||
registerRoutes() {
|
||||
this.getRouter().get('/', (req, res) => this.sendObject(this.computeSomeRandomData(), req, res))
|
||||
}
|
||||
}
|
||||
|
||||
export default Dashboard
|
||||
4
packages/xo-server/src/rest-api/entities.mjs
Normal file
4
packages/xo-server/src/rest-api/entities.mjs
Normal file
@@ -0,0 +1,4 @@
|
||||
export { default as Host } from './host.mjs'
|
||||
export { default as Vm } from './vm.mjs'
|
||||
export { default as User } from './user.mjs'
|
||||
export { default as Dashboard } from './dashboard.mjs'
|
||||
9
packages/xo-server/src/rest-api/host.mjs
Normal file
9
packages/xo-server/src/rest-api/host.mjs
Normal file
@@ -0,0 +1,9 @@
|
||||
import AbstractCollection from './AbstractCollection.mjs'
|
||||
|
||||
class Host extends AbstractCollection {
|
||||
constructor(app) {
|
||||
super(app, 'host')
|
||||
}
|
||||
}
|
||||
|
||||
export default Host
|
||||
14
packages/xo-server/src/rest-api/middleware.mjs
Normal file
14
packages/xo-server/src/rest-api/middleware.mjs
Normal file
@@ -0,0 +1,14 @@
|
||||
import { invalidCredentials } from 'xo-common/api-errors.js'
|
||||
|
||||
export const authenticateUserFromToken = app => async (req, res, next) => {
|
||||
const { cookies, ip } = req
|
||||
try {
|
||||
const user = await app.authenticateUser({ token: cookies.authenticationToken ?? cookies.token }, { ip })
|
||||
return app.runWithApiContext(user, next)
|
||||
} catch (error) {
|
||||
if (invalidCredentials.is(error)) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
41
packages/xo-server/src/rest-api/user.mjs
Normal file
41
packages/xo-server/src/rest-api/user.mjs
Normal file
@@ -0,0 +1,41 @@
|
||||
import pick from 'lodash/pick.js'
|
||||
import AbstractCollection from './AbstractCollection.mjs'
|
||||
import CM from 'complex-matcher'
|
||||
|
||||
class User extends AbstractCollection {
|
||||
constructor(app) {
|
||||
super(app, 'user')
|
||||
}
|
||||
|
||||
async getObject(id) {
|
||||
const user = await this.getApp().getUser(id)
|
||||
delete user.pw_hash
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
async getObjects(filter, limit, fields) {
|
||||
filter = filter !== undefined ? CM.parse(filter).createPredicate() : undefined
|
||||
limit = Number(limit)
|
||||
|
||||
let users = await this.getApp().getAllUsers()
|
||||
if (filter !== undefined) {
|
||||
users = users.filter(filter)
|
||||
}
|
||||
|
||||
if (Number.isInteger(limit)) {
|
||||
users = users.slice(0, limit)
|
||||
}
|
||||
|
||||
if (fields === undefined) {
|
||||
users = users.map(user => user.id)
|
||||
} else if (fields !== '*') {
|
||||
const properties = fields.split(',')
|
||||
users = users.map(obj => pick(obj, properties))
|
||||
}
|
||||
|
||||
return users
|
||||
}
|
||||
}
|
||||
|
||||
export default User
|
||||
20
packages/xo-server/src/rest-api/vm.mjs
Normal file
20
packages/xo-server/src/rest-api/vm.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import AbstractCollection from './AbstractCollection.mjs'
|
||||
|
||||
class Vm extends AbstractCollection {
|
||||
constructor(app) {
|
||||
super(app, 'VM')
|
||||
}
|
||||
|
||||
registerRoutes() {
|
||||
super.registerRoutes()
|
||||
this.getRouter()
|
||||
.get('/foo', (req, res) => {
|
||||
res.json('foo')
|
||||
})
|
||||
.get('/:uuid/name_label', (req, res) => {
|
||||
return res.json(res.locals.object.name_label)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default Vm
|
||||
@@ -1,33 +1,15 @@
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import { createGzip } from 'node:zlib'
|
||||
import { defer } from 'golike-defer'
|
||||
import { every } from '@vates/predicates'
|
||||
import { extractIdsFromSimplePattern } from '@xen-orchestra/backups/extractIdsFromSimplePattern.mjs'
|
||||
import { ifDef } from '@xen-orchestra/defined'
|
||||
import { featureUnauthorized, invalidCredentials, noSuchObject } from 'xo-common/api-errors.js'
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
import { json, Router } from 'express'
|
||||
import { Readable } from 'node:stream'
|
||||
import cloneDeep from 'lodash/cloneDeep.js'
|
||||
import groupBy from 'lodash/groupBy.js'
|
||||
import path from 'node:path'
|
||||
import pDefer from 'promise-toolbox/defer'
|
||||
import pick from 'lodash/pick.js'
|
||||
import semver from 'semver'
|
||||
import * as CM from 'complex-matcher'
|
||||
import { VDI_FORMAT_RAW, VDI_FORMAT_VHD } from '@xen-orchestra/xapi'
|
||||
import { parse } from 'xo-remote-parser'
|
||||
import { Router } from 'express'
|
||||
import * as entities from '../rest-api/entities.mjs'
|
||||
import { authenticateUserFromToken } from '../rest-api/middleware.mjs'
|
||||
|
||||
import {
|
||||
getFromAsyncCache,
|
||||
getUserPublicProperties,
|
||||
isAlarm,
|
||||
isReplicaVm,
|
||||
isSrWritable,
|
||||
vmContainsNoBakTag,
|
||||
} from '../utils.mjs'
|
||||
import { compileXoJsonSchema } from './_xoJsonSchema.mjs'
|
||||
import { createPredicate } from 'value-matcher'
|
||||
// @TODO:
|
||||
// - implement middlewhare to retrieve user from a token
|
||||
// - Do a non XAPI collection test (like users,dashboard, group, backups,...)
|
||||
// - maybe rename AbstractXapiCollection into AbstractCollection? (for users, groups, ...) to be able to extends it?
|
||||
// - expose an action
|
||||
// - handle sync an async actions
|
||||
// - how to handle "/" and "/:uuid" with user permission
|
||||
// - expose openapi + swagger docs
|
||||
|
||||
// E.g: 'value: 0.6\nconfig:\n<variable>\n<name value="cpu_usage"/>\n<alarm_trigger_level value="0.4"/>\n<alarm_trigger_period value ="60"/>\n</variable>';
|
||||
const ALARM_BODY_REGEX = /^value:\s*(Infinity|NaN|-Infinity|\d+(?:\.\d+)?)\s*config:\s*<variable>\s*<name value="(.*?)"/
|
||||
@@ -494,8 +476,6 @@ async function _getDashboardStats(app) {
|
||||
|
||||
const keepNonAlarmMessages = message => message.type === 'message' && !isAlarm(message)
|
||||
export default class RestApi {
|
||||
#api
|
||||
|
||||
constructor(app, { express }) {
|
||||
// don't setup the API if express is not present
|
||||
//
|
||||
@@ -504,64 +484,13 @@ export default class RestApi {
|
||||
return
|
||||
}
|
||||
|
||||
const api = subRouter(express, '/rest/v0')
|
||||
this.#api = api
|
||||
express.use(authenticateUserFromToken(app))
|
||||
|
||||
// register the route BEFORE the authentication middleware because this route does not require authentication
|
||||
api.post('/users/authentication_tokens', json(), async (req, res) => {
|
||||
const authorization = req.headers.authorization ?? ''
|
||||
const [, encodedCredentials] = authorization.split(' ')
|
||||
if (encodedCredentials === undefined) {
|
||||
return res.status(401).json('missing credentials')
|
||||
}
|
||||
const coreRouter = new Router()
|
||||
|
||||
const [username, password] = Buffer.from(encodedCredentials, 'base64').toString().split(':')
|
||||
|
||||
try {
|
||||
const { user } = await app.authenticateUser({ username, password, otp: req.query.otp })
|
||||
const token = await app.createAuthenticationToken({
|
||||
client: req.body.client,
|
||||
userId: user.id,
|
||||
description: req.body.description,
|
||||
expiresIn: req.body.expiresIn,
|
||||
})
|
||||
res.json({ token })
|
||||
} catch (error) {
|
||||
if (invalidCredentials.is(error)) {
|
||||
res.status(401)
|
||||
} else {
|
||||
res.status(400)
|
||||
}
|
||||
res.json(error.message)
|
||||
}
|
||||
})
|
||||
|
||||
api.use((req, res, next) => {
|
||||
const { cookies, ip } = req
|
||||
app.authenticateUser({ token: cookies.authenticationToken ?? cookies.token }, { ip }).then(
|
||||
({ user }) => {
|
||||
if (user.permission === 'admin') {
|
||||
return app.runWithApiContext(user, next)
|
||||
}
|
||||
|
||||
res.sendStatus(401)
|
||||
},
|
||||
error => {
|
||||
if (invalidCredentials.is(error)) {
|
||||
res.sendStatus(401)
|
||||
} else {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const collections = { __proto__: null }
|
||||
|
||||
const withParams = (fn, paramsSchema) => {
|
||||
fn.params = paramsSchema
|
||||
fn.validateParams = compileXoJsonSchema({ type: 'object', properties: cloneDeep(paramsSchema) })
|
||||
return fn
|
||||
for (const entity in entities) {
|
||||
const instance = new entities[entity](app)
|
||||
instance.registerRouter(coreRouter)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1471,32 +1400,7 @@ export default class RestApi {
|
||||
)
|
||||
}
|
||||
|
||||
registerRestApi(spec, base = '/') {
|
||||
for (const path of Object.keys(spec)) {
|
||||
if (path[0] === '_') {
|
||||
const handler = spec[path]
|
||||
this.#api[path.slice(1)](base, json(), async (req, res, next) => {
|
||||
try {
|
||||
const result = await handler(req, res, next)
|
||||
if (result !== undefined) {
|
||||
const isIterable =
|
||||
result !== null && typeof (result[Symbol.iterator] ?? result[Symbol.asyncIterator]) === 'function'
|
||||
if (isIterable) {
|
||||
await sendObjects(result, req, res)
|
||||
} else {
|
||||
res.json(result)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.registerRestApi(spec[path], join(base, path))
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
throw new Error('not implemented')
|
||||
}
|
||||
registerRestApi() {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user