2021-02-25 12:39:50 +01:00
|
|
|
<template>
|
|
|
|
<ConfirmModal
|
|
|
|
:confirm-text="$t('word.run')"
|
|
|
|
:cancel-text="$t('word.cancel')"
|
|
|
|
size="400"
|
|
|
|
@confirm="runRoutine"
|
|
|
|
@hide="closeModal"
|
|
|
|
>
|
2021-12-10 17:34:44 +01:00
|
|
|
<template #header>
|
2021-02-25 12:39:50 +01:00
|
|
|
<div class="d-flex">
|
2021-06-13 11:16:21 +02:00
|
|
|
<i class="mdi mdi-24px mdi-play mr-1" />
|
|
|
|
<span class="cut-text">{{ $t('word.parameters') }}: {{ localRoutine.name }}</span>
|
2021-02-25 12:39:50 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
2021-12-10 17:34:44 +01:00
|
|
|
<template #body>
|
2021-02-25 12:39:50 +01:00
|
|
|
<div class="content">
|
|
|
|
<form class="form-horizontal">
|
|
|
|
<div
|
2021-04-13 18:05:03 +02:00
|
|
|
v-for="(parameter, i) in inParameters"
|
2021-11-08 15:12:37 +01:00
|
|
|
:key="parameter._antares_id"
|
2021-02-25 12:39:50 +01:00
|
|
|
class="form-group"
|
|
|
|
>
|
2021-06-13 11:16:21 +02:00
|
|
|
<div class="col-4">
|
2021-02-25 12:39:50 +01:00
|
|
|
<label class="form-label">{{ parameter.name }}</label>
|
|
|
|
</div>
|
2021-06-13 11:16:21 +02:00
|
|
|
<div class="col-8">
|
2021-02-25 12:39:50 +01:00
|
|
|
<div class="input-group">
|
|
|
|
<input
|
|
|
|
:ref="i === 0 ? 'firstInput' : ''"
|
2021-04-19 15:40:25 +02:00
|
|
|
v-model="values[`${i}-${parameter.name}`]"
|
2021-02-25 12:39:50 +01:00
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
2021-08-13 16:50:59 +02:00
|
|
|
<span
|
|
|
|
:title="`${parameter.type} ${parameter.length}`"
|
|
|
|
class="input-group-addon field-type cut-text"
|
|
|
|
:class="typeClass(parameter.type)"
|
|
|
|
>
|
2022-04-21 14:39:24 +02:00
|
|
|
{{ parameter.type }} {{ wrapNumber(parameter.length) }}
|
2021-02-25 12:39:50 +01:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2021-12-10 17:34:44 +01:00
|
|
|
</template>
|
2021-02-25 12:39:50 +01:00
|
|
|
</ConfirmModal>
|
|
|
|
</template>
|
|
|
|
|
2022-05-17 19:11:31 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, PropType, Ref, ref } from 'vue';
|
2021-04-10 20:38:46 +02:00
|
|
|
import { NUMBER, FLOAT } from 'common/fieldTypes';
|
2022-06-21 17:54:47 +02:00
|
|
|
import { FunctionInfos, RoutineInfos } from 'common/interfaces/antares';
|
2022-05-17 19:11:31 +02:00
|
|
|
import ConfirmModal from '@/components/BaseConfirmModal.vue';
|
2022-08-03 11:10:16 +02:00
|
|
|
import { useFilters } from '@/composables/useFilters';
|
|
|
|
|
|
|
|
const { wrapNumber } = useFilters();
|
2022-05-17 19:11:31 +02:00
|
|
|
|
|
|
|
const props = defineProps({
|
2022-06-21 17:54:47 +02:00
|
|
|
localRoutine: Object as PropType<RoutineInfos | FunctionInfos>,
|
2022-05-17 19:11:31 +02:00
|
|
|
client: String
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits(['confirm', 'close']);
|
|
|
|
|
|
|
|
const firstInput: Ref<HTMLInputElement[]> = ref(null);
|
|
|
|
const values: Ref<{[key: string]: string}> = ref({});
|
|
|
|
|
|
|
|
const inParameters = computed(() => {
|
|
|
|
return props.localRoutine.parameters.filter(param => param.context === 'IN');
|
|
|
|
});
|
|
|
|
|
|
|
|
const typeClass = (type: string) => {
|
|
|
|
if (type)
|
|
|
|
return `type-${type.toLowerCase().replaceAll(' ', '_').replaceAll('"', '')}`;
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
const runRoutine = () => {
|
|
|
|
const valArr = Object.keys(values.value).reduce((acc, curr, i) => {
|
|
|
|
let qc;
|
|
|
|
switch (props.client) {
|
|
|
|
case 'maria':
|
|
|
|
case 'mysql':
|
|
|
|
qc = '"';
|
|
|
|
break;
|
|
|
|
case 'pg':
|
|
|
|
qc = '\'';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qc = '"';
|
2021-02-25 12:39:50 +01:00
|
|
|
}
|
2022-05-17 19:11:31 +02:00
|
|
|
|
|
|
|
const param = props.localRoutine.parameters.find(param => `${i}-${param.name}` === curr);
|
|
|
|
|
|
|
|
const value = [...NUMBER, ...FLOAT].includes(param.type) ? values.value[curr] : `${qc}${values.value[curr]}${qc}`;
|
|
|
|
acc.push(value);
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
emit('confirm', valArr);
|
|
|
|
};
|
|
|
|
|
|
|
|
const closeModal = () => emit('close');
|
|
|
|
|
|
|
|
const onKey = (e: KeyboardEvent) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.key === 'Escape')
|
|
|
|
closeModal();
|
2021-02-25 12:39:50 +01:00
|
|
|
};
|
2022-05-17 19:11:31 +02:00
|
|
|
|
|
|
|
window.addEventListener('keydown', onKey);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
firstInput.value[0].focus();
|
|
|
|
}, 20);
|
2021-02-25 12:39:50 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.field-type {
|
|
|
|
font-size: 0.6rem;
|
|
|
|
}
|
2021-08-13 16:50:59 +02:00
|
|
|
|
|
|
|
.input-group-addon {
|
|
|
|
max-width: 100px;
|
|
|
|
}
|
2021-02-25 12:39:50 +01:00
|
|
|
</style>
|