|
@@ -1,15 +1,19 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
import {computed, nextTick, reactive, ref, watch} from 'vue'
|
|
import {computed, nextTick, reactive, ref, watch} from 'vue'
|
|
import {useGettext} from 'vue3-gettext'
|
|
import {useGettext} from 'vue3-gettext'
|
|
-import {Form, message} from 'ant-design-vue'
|
|
|
|
|
|
+import {Form, message, notification} from 'ant-design-vue'
|
|
import gettext from '@/gettext'
|
|
import gettext from '@/gettext'
|
|
import domain from '@/api/domain'
|
|
import domain from '@/api/domain'
|
|
|
|
+import NodeSelector from '@/components/NodeSelector/NodeSelector.vue'
|
|
|
|
+import {useSettingsStore} from '@/pinia'
|
|
|
|
|
|
const {$gettext} = useGettext()
|
|
const {$gettext} = useGettext()
|
|
|
|
|
|
const props = defineProps(['visible', 'name'])
|
|
const props = defineProps(['visible', 'name'])
|
|
const emit = defineEmits(['update:visible', 'duplicated'])
|
|
const emit = defineEmits(['update:visible', 'duplicated'])
|
|
|
|
|
|
|
|
+const settings = useSettingsStore()
|
|
|
|
+
|
|
const show = computed({
|
|
const show = computed({
|
|
get() {
|
|
get() {
|
|
return props.visible
|
|
return props.visible
|
|
@@ -19,7 +23,7 @@ const show = computed({
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-const modelRef = reactive({name: ''})
|
|
|
|
|
|
+const modelRef = reactive({name: '', target: []})
|
|
|
|
|
|
const rulesRef = reactive({
|
|
const rulesRef = reactive({
|
|
name: [
|
|
name: [
|
|
@@ -28,6 +32,12 @@ const rulesRef = reactive({
|
|
message: () => $gettext('Please input name, ' +
|
|
message: () => $gettext('Please input name, ' +
|
|
'this will be used as the filename of the new configuration!')
|
|
'this will be used as the filename of the new configuration!')
|
|
}
|
|
}
|
|
|
|
+ ],
|
|
|
|
+ target: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ message: () => $gettext('Please select at least one node!')
|
|
|
|
+ }
|
|
]
|
|
]
|
|
})
|
|
})
|
|
|
|
|
|
@@ -35,16 +45,42 @@ const {validate, validateInfos, clearValidate} = Form.useForm(modelRef, rulesRef
|
|
|
|
|
|
const loading = ref(false)
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
+const node_map = reactive({})
|
|
|
|
+
|
|
function onSubmit() {
|
|
function onSubmit() {
|
|
validate().then(async () => {
|
|
validate().then(async () => {
|
|
loading.value = true
|
|
loading.value = true
|
|
|
|
|
|
- domain.duplicate(props.name, {name: modelRef.name}).then(() => {
|
|
|
|
- message.success($gettext('Duplicated successfully'))
|
|
|
|
- show.value = false
|
|
|
|
- emit('duplicated')
|
|
|
|
- }).catch((e: any) => {
|
|
|
|
- message.error($gettext(e?.message ?? 'Server error'))
|
|
|
|
|
|
+ modelRef.target.forEach(id => {
|
|
|
|
+ if (id === 0) {
|
|
|
|
+ domain.duplicate(props.name, {name: modelRef.name}).then(() => {
|
|
|
|
+ message.success($gettext('Duplicate to local successfully'))
|
|
|
|
+ show.value = false
|
|
|
|
+ emit('duplicated')
|
|
|
|
+ }).catch((e: any) => {
|
|
|
|
+ message.error($gettext(e?.message ?? 'Server error'))
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ // get source content
|
|
|
|
+ domain.get(props.name).then(r => {
|
|
|
|
+ domain.save(modelRef.name, {
|
|
|
|
+ name: modelRef.name,
|
|
|
|
+ content: r.config
|
|
|
|
+ }, {headers: {'X-Node-ID': id}}).then(() => {
|
|
|
|
+ notification.success({
|
|
|
|
+ message: $gettext('Duplicate successfully'),
|
|
|
|
+ description:
|
|
|
|
+ $gettext('Duplicate %{conf_name} to %{node_name} successfully',
|
|
|
|
+ {conf_name: props.name, node_name: node_map[id]})
|
|
|
|
+ })
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ notification.error({
|
|
|
|
+ message: $gettext('Duplicate failed'),
|
|
|
|
+ description: $gettext(e.message)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
|
|
loading.value = false
|
|
loading.value = false
|
|
@@ -54,6 +90,7 @@ function onSubmit() {
|
|
watch(() => props.visible, (v) => {
|
|
watch(() => props.visible, (v) => {
|
|
if (v) {
|
|
if (v) {
|
|
modelRef.name = ''
|
|
modelRef.name = ''
|
|
|
|
+ modelRef.target = [0]
|
|
nextTick(() => clearValidate())
|
|
nextTick(() => clearValidate())
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -65,11 +102,14 @@ watch(() => gettext.current, () => {
|
|
|
|
|
|
<template>
|
|
<template>
|
|
<a-modal :title="$gettext('Duplicate')" v-model:visible="show" @ok="onSubmit"
|
|
<a-modal :title="$gettext('Duplicate')" v-model:visible="show" @ok="onSubmit"
|
|
- :confirm-loading="loading">
|
|
|
|
|
|
+ :confirm-loading="loading" :mask="null">
|
|
<a-form layout="vertical">
|
|
<a-form layout="vertical">
|
|
<a-form-item :label="$gettext('Name')" v-bind="validateInfos.name">
|
|
<a-form-item :label="$gettext('Name')" v-bind="validateInfos.name">
|
|
<a-input v-model:value="modelRef.name"/>
|
|
<a-input v-model:value="modelRef.name"/>
|
|
</a-form-item>
|
|
</a-form-item>
|
|
|
|
+ <a-form-item v-if="!settings.is_remote" :label="$gettext('Target')" v-bind="validateInfos.target">
|
|
|
|
+ <node-selector v-model:target="modelRef.target" :map="node_map"/>
|
|
|
|
+ </a-form-item>
|
|
</a-form>
|
|
</a-form>
|
|
</a-modal>
|
|
</a-modal>
|
|
</template>
|
|
</template>
|