From 8a3b5751574ac2f8748cbaf2ac3ce0db9171e7ed Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 24 May 2024 00:28:18 +0200 Subject: [PATCH 01/26] fix: refs #6346 fix list and create --- src/pages/Wagon/Type/WagonTypeCreate.vue | 102 ++++++++++------------- src/pages/Wagon/Type/WagonTypeList.vue | 7 ++ 2 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/pages/Wagon/Type/WagonTypeCreate.vue b/src/pages/Wagon/Type/WagonTypeCreate.vue index bc9c1a40c..640ca75c6 100644 --- a/src/pages/Wagon/Type/WagonTypeCreate.vue +++ b/src/pages/Wagon/Type/WagonTypeCreate.vue @@ -4,6 +4,7 @@ import { useRoute, useRouter } from 'vue-router'; import { useQuasar } from 'quasar'; import VnInput from 'src/components/common/VnInput.vue'; +import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; import { useI18n } from 'vue-i18n'; import axios from 'axios'; @@ -12,8 +13,8 @@ onMounted(() => fetch()); onUpdated(() => fetch()); const { t } = useI18n(); +const { notify } = useQuasar(); const route = useRoute(); -const quasar = useQuasar(); const router = useRouter(); const $props = defineProps({ id: { @@ -29,29 +30,19 @@ const divisible = ref(false); const name = ref(''); const colorPickerActive = ref(false); let originalData = { trays: [] }; -let wagonConfig; +let maxTrays, maxWagonHeight, minHeightBetweenTrays; let wagonTypeColors; let currentTrayColorPicked; async function fetch() { try { - await axios.get('WagonConfigs').then(async (res) => { - if (res.data) { - wagonConfig = res.data[0]; - } - }); + ({ + data: [{ maxTrays, maxWagonHeight, minHeightBetweenTrays }], + } = await axios.get('WagonConfigs')); await axios.get(`WagonTypeColors`).then(async (res) => { - if (res.data) { - wagonTypeColors = res.data; - if (!entityId.value) - wagon.value.push({ - id: 0, - position: 0, - color: { ...wagonTypeColors[0] }, - action: 'add', - }); - else { + if ((wagonTypeColors = res.data)) { + if (entityId.value) { await axios .get(`WagonTypeTrays`, { params: { filter: { where: { typeFk: entityId.value } } }, @@ -76,18 +67,23 @@ async function fetch() { }); } }); - } + } else + wagon.value.push({ + id: 0, + position: 0, + color: { ...wagonTypeColors[0] }, + action: 'add', + }); } }); - if (entityId.value) { + if (entityId.value) await axios.get(`WagonTypes/${entityId.value}`).then((res) => { if (res.data) { originalData.name = name.value = res.data.name; originalData.divisible = divisible.value = res.data.divisible; } }); - } } catch (e) { // } @@ -98,27 +94,24 @@ function addTray() { wagon.value.find((tray) => { return tray.position == null; }) - ) { - quasar.notify({ + ) + return notify({ message: t('wagon.warnings.uncompleteTrays'), type: 'warning', }); - return; - } - if (wagon.value.length < wagonConfig.maxTrays) { + if (wagon.value.length < maxTrays) wagon.value.unshift({ id: wagon.value.length, position: null, color: { ...wagonTypeColors[0] }, action: 'delete', }); - } else { - quasar.notify({ + else + notify({ message: t('wagon.warnings.maxTrays'), type: 'warning', }); - } } function deleteTray(trayToDelete) { @@ -127,9 +120,8 @@ function deleteTray(trayToDelete) { } function reorderIds() { - for (let index = wagon.value.length - 1; index >= 0; index--) { + for (let index = wagon.value.length - 1; index >= 0; index--) wagon.value[index].id = index; - } } async function onSubmit() { @@ -153,7 +145,7 @@ async function onSubmit() { } } -function onReset() { +async function onReset() { name.value = entityId.value ? originalData.name : null; divisible.value = entityId.value ? originalData.divisible : false; wagon.value = entityId.value @@ -169,11 +161,8 @@ function onReset() { } function doAction(tray) { - if (tray.action == 'add') { - addTray(); - } else { - deleteTray(tray); - } + if (tray.action == 'add') addTray(); + else deleteTray(tray); } function showColorPicker(tray) { @@ -193,10 +182,8 @@ function updateColor(newColor) { function onPositionBlur(tray) { if (tray.position) { - if (tray.position == '' || tray.position < 0) { - tray.position = null; - return; - } + if (tray.position == '' || tray.position < 0) return (tray.position = null); + tray.position = parseInt(tray.position); wagon.value.sort((a, b) => b.position - a.position); reorderIds(); @@ -204,18 +191,18 @@ function onPositionBlur(tray) { if (exceedMaxHeight(index - 1)) continue; if ( wagon.value[index - 1].position - wagon.value[index].position >= - wagonConfig.minHeightBetweenTrays - ) { + minHeightBetweenTrays + ) continue; - } else { + else { wagon.value[index - 1].position += - wagonConfig.minHeightBetweenTrays - + minHeightBetweenTrays - (wagon.value[index - 1].position - wagon.value[index].position); - quasar.notify({ + notify({ message: t('wagon.warnings.minHeightBetweenTrays') + - wagonConfig.minHeightBetweenTrays + + minHeightBetweenTrays + ' cm', type: 'warning', }); @@ -227,20 +214,19 @@ function onPositionBlur(tray) { } function exceedMaxHeight(pos) { - if (wagon.value[pos].position > wagonConfig.maxWagonHeight) { - wagon.value.splice(pos, 1); - quasar.notify({ - message: - t('wagon.warnings.maxWagonHeight') + wagonConfig.maxWagonHeight + ' cm', - type: 'warning', - }); - return true; - } - return false; + if (wagon.value[pos].position < maxWagonHeight) return false; + + wagon.value.splice(pos, 1); + notify({ + message: t('wagon.warnings.maxWagonHeight') + maxWagonHeight + ' cm', + type: 'warning', + }); + return true; }