several changes

This commit is contained in:
William Buezas 2024-05-28 09:30:13 -03:00
parent 7cd2bf2319
commit b783adfc31
6 changed files with 42 additions and 22 deletions

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref } from 'vue'; import { computed } from 'vue';
import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useWeekdayStore } from 'src/stores/useWeekdayStore';
@ -14,12 +14,12 @@ const emit = defineEmits(['update:wdays']);
const weekdayStore = useWeekdayStore(); const weekdayStore = useWeekdayStore();
const selectedWDays = ref(props.wdays); const selectedWDays = computed({
get: () => props.wdays,
set: (value) => emit('update:wdays', value),
});
const toggleDay = (index) => { const toggleDay = (index) => (selectedWDays.value[index] = !selectedWDays.value[index]);
selectedWDays.value[index] = !selectedWDays.value[index];
emit('update:wdays', selectedWDays.value);
};
</script> </script>
<template> <template>

View File

@ -67,7 +67,7 @@ const exclusionGeoCreate = async () => {
await axios.post('Zones/exclusionGeo', params); await axios.post('Zones/exclusionGeo', params);
} else { } else {
const params = { const params = {
zoneExclusionFk: props.event?.id, zoneExclusionFk: props.event?.zoneExclusionFk,
geoIds: tickedNodes.value, geoIds: tickedNodes.value,
}; };
await axios.post('Zones/updateExclusionGeo', params); await axios.post('Zones/updateExclusionGeo', params);
@ -103,9 +103,8 @@ const onSubmit = async () => {
const deleteEvent = async () => { const deleteEvent = async () => {
try { try {
if (!props.event) return; if (!props.event) return;
await axios.delete( const exclusionId = props.event?.zoneExclusionFk || props.event?.id;
`Zones/${route.params.id}/exclusions/${props.event?.zoneExclusionFk}` await axios.delete(`Zones/${route.params.id}/exclusions/${exclusionId}`);
);
await refetchEvents(); await refetchEvents();
} catch (err) { } catch (err) {
console.error('Error deleting event: ', err); console.error('Error deleting event: ', err);
@ -120,6 +119,7 @@ const refetchEvents = async () => {
}; };
onMounted(() => { onMounted(() => {
console.log('event.eventType: ', props.eventType);
if (props.event) { if (props.event) {
dated.value = props.event?.dated; dated.value = props.event?.dated;
excludeType.value = excludeType.value =
@ -160,9 +160,9 @@ onMounted(() => {
</div> </div>
<div v-if="excludeType === 'specificLocations'"> <div v-if="excludeType === 'specificLocations'">
<ZoneLocationsTree <ZoneLocationsTree
:toggle-indeterminate="false"
:root-label="t('eventsExclusionForm.rootTreeLabel')" :root-label="t('eventsExclusionForm.rootTreeLabel')"
v-model:tickedNodes="tickedNodes" v-model:tickedNodes="tickedNodes"
show-search-bar
> >
<template #content="{ node }"> <template #content="{ node }">
<span>{{ node.name }}</span> <span>{{ node.name }}</span>

View File

@ -1,7 +1,6 @@
<script setup> <script setup>
import { ref, computed, onMounted } from 'vue'; import { ref, computed, onMounted } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnInput from 'src/components/common/VnInput.vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
@ -9,6 +8,7 @@ import FormPopup from 'components/FormPopup.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue'; import VnInputDate from 'src/components/common/VnInputDate.vue';
import VnWeekdayPicker from 'src/components/common/VnWeekdayPicker.vue'; import VnWeekdayPicker from 'src/components/common/VnWeekdayPicker.vue';
import VnInputTime from 'components/common/VnInputTime.vue'; import VnInputTime from 'components/common/VnInputTime.vue';
import VnInput from 'src/components/common/VnInput.vue';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useWeekdayStore } from 'src/stores/useWeekdayStore';
@ -43,7 +43,7 @@ const weekdayStore = useWeekdayStore();
const { openConfirmationModal } = useVnConfirm(); const { openConfirmationModal } = useVnConfirm();
const isNew = computed(() => props.isNewMode); const isNew = computed(() => props.isNewMode);
const eventInclusionFormData = ref({}); const eventInclusionFormData = ref({ wdays: [] });
const _inclusionType = ref('indefinitely'); const _inclusionType = ref('indefinitely');
const inclusionType = computed({ const inclusionType = computed({
@ -217,7 +217,7 @@ onMounted(() => {
v-close-popup v-close-popup
/> />
<QBtn <QBtn
v-if="!isNew && isExclusion === 'event'" v-if="!isNew && eventType === 'event'"
:label="t('globals.delete')" :label="t('globals.delete')"
color="primary" color="primary"
flat flat

View File

@ -96,12 +96,13 @@ const deleteEvent = async (id) => {
} }
}; };
const openIncludeForm = (event) => { const openInclusionForm = (event) => {
formName.value = 'include'; formName.value = 'include';
emit('openZoneForm', { emit('openZoneForm', {
date: event.dated, date: event.dated,
event, event,
isNewMode: false, isNewMode: false,
eventType: 'event',
}); });
}; };
@ -135,7 +136,7 @@ onMounted(async () => {
}}</span> }}</span>
<QList> <QList>
<QItem v-for="(event, index) in events" :key="index" class="event-card"> <QItem v-for="(event, index) in events" :key="index" class="event-card">
<QItemSection left @click="openIncludeForm(event)"> <QItemSection left @click="openInclusionForm(event)">
<div v-if="event.type == 'day'" class="q-mb-xs"> <div v-if="event.type == 'day'" class="q-mb-xs">
{{ toDateFormat(event.dated) }} {{ toDateFormat(event.dated) }}
</div> </div>
@ -173,7 +174,7 @@ onMounted(async () => {
<span class="color-vn-text"> {{ dashIfEmpty(event.m3Max) }}</span> <span class="color-vn-text"> {{ dashIfEmpty(event.m3Max) }}</span>
</span> </span>
</QItemSection> </QItemSection>
<QItemSection side @click="openIncludeForm(event)"> <QItemSection side @click="openInclusionForm(event)">
<QBtn <QBtn
icon="delete" icon="delete"
flat flat

View File

@ -3,6 +3,8 @@ import { onMounted, ref, computed, watch, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import VnInput from 'src/components/common/VnInput.vue';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import axios from 'axios'; import axios from 'axios';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
@ -16,6 +18,10 @@ const props = defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
showSearchBar: {
type: Boolean,
default: false,
},
}); });
const emit = defineEmits(['update:tickedNodes']); const emit = defineEmits(['update:tickedNodes']);
@ -131,17 +137,20 @@ watch(storeData, async (val) => {
formatNodeSelected(n); formatNodeSelected(n);
}); });
} else { } else {
for (let n of state.get('Tree')) { if (!props.showSearchBar)
await fetchNodeLeaves(n); for (let n of state.get('Tree')) await fetchNodeLeaves(n);
}
expanded.value = [null, ...fetchedNodeKeys]; expanded.value = [null, ...fetchedNodeKeys];
} }
previousExpandedNodes.value = new Set(expanded.value); previousExpandedNodes.value = new Set(expanded.value);
}); });
const reFetch = async () => {
await arrayData.fetch({ append: false });
};
onMounted(async () => { onMounted(async () => {
if (store.userParams?.search) { if (store.userParams?.search) {
await arrayData.fetch({ append: false }); await reFetch();
return; return;
} }
const stateTree = state.get('Tree'); const stateTree = state.get('Tree');
@ -174,6 +183,16 @@ onUnmounted(() => {
</script> </script>
<template> <template>
<VnInput
v-if="showSearchBar"
v-model="store.userParams.search"
:placeholder="t('globals.search')"
@keydown.enter.prevent="reFetch()"
>
<template #prepend>
<QIcon class="cursor-pointer" name="search" />
</template>
</VnInput>
<QTree <QTree
ref="treeRef" ref="treeRef"
:nodes="nodes" :nodes="nodes"

View File

@ -9,7 +9,7 @@ import { useArrayData } from 'src/composables/useArrayData';
const props = defineProps({ const props = defineProps({
dataKey: { dataKey: {
type: Number, type: String,
required: true, required: true,
}, },
}); });