/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { defineComponent, PropType, ref, computed, onMounted, watch } from 'vue' import Modal from '@/components/modal' import { useI18n } from 'vue-i18n' import { NForm, NFormItem, NInput, NSelect, NSwitch, NInputNumber, NDynamicInput, NCheckbox } from 'naive-ui' import { queryTenantList } from '@/service/modules/tenants' import { SaveForm, WorkflowDefinition, WorkflowInstance } from './types' import { useRoute } from 'vue-router' import { verifyName } from '@/service/modules/process-definition' import './x6-style.scss' import { positiveIntegerRegex } from '@/utils/regex' const props = { visible: { type: Boolean as PropType, default: false }, // If this prop is passed, it means from definition detail definition: { type: Object as PropType, default: undefined }, instance: { type: Object as PropType, default: undefined } } interface Tenant { tenantCode: string id: number } export default defineComponent({ name: 'dag-save-modal', props, emits: ['update:show', 'save'], setup(props, context) { const route = useRoute() const { t } = useI18n() const projectCode = Number(route.params.projectCode) const tenants = ref([]) const tenantsDropdown = computed(() => { if (tenants.value) { return tenants.value .map((t) => ({ label: t.tenantCode, value: t.tenantCode })) .concat({ label: 'default', value: 'default' }) } return [] }) onMounted(() => { queryTenantList().then((res: any) => { tenants.value = res }) }) const formValue = ref({ name: '', description: '', tenantCode: 'default', timeoutFlag: false, timeout: 0, globalParams: [], release: false, sync: false }) const formRef = ref() const rule = { name: { required: true, message: t('project.dag.dag_name_empty') }, timeout: { validator() { if ( formValue.value.timeoutFlag && !positiveIntegerRegex.test(String(formValue.value.timeout)) ) { return new Error(t('project.dag.positive_integer')) } } }, globalParams: { validator() { const props = new Set() for (const param of formValue.value.globalParams) { const prop = param.value if (!prop) { return new Error(t('project.dag.prop_empty')) } if (props.has(prop)) { return new Error(t('project.dag.prop_repeat')) } props.add(prop) } } } } const onSubmit = () => { formRef.value.validate(async (valid: any) => { if (!valid) { const params = { name: formValue.value.name } if ( props.definition?.processDefinition.name !== formValue.value.name ) { verifyName(params, projectCode).then(() => context.emit('save', formValue.value) ) } else { context.emit('save', formValue.value) } } }) } const onCancel = () => { context.emit('update:show', false) } const updateModalData = () => { const process = props.definition?.processDefinition if (process) { formValue.value.name = process.name formValue.value.description = process.description formValue.value.tenantCode = process.tenantCode || 'default' if (process.timeout && process.timeout > 0) { formValue.value.timeoutFlag = true formValue.value.timeout = process.timeout } formValue.value.globalParams = process.globalParamList.map((param) => ({ key: param.prop, value: param.value })) } } onMounted(() => updateModalData()) watch( () => props.definition?.processDefinition, () => updateModalData() ) return () => ( {formValue.value.timeoutFlag && ( '分' }} /> )} {props.definition && !props.instance && ( {t('project.dag.online_directly')} )} {props.instance && ( {t('project.dag.update_directly')} )} ) } })