Item tags
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
William Buezas 2024-05-03 17:19:13 -03:00
parent 99adc9aa05
commit f3b1de1ee4
3 changed files with 69 additions and 62 deletions

View File

@ -1,5 +1,5 @@
<script setup>
import { ref, onMounted, computed } from 'vue';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
@ -10,65 +10,58 @@ import FetchData from 'components/FetchData.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import axios from 'axios';
import { useArrayData } from 'composables/useArrayData';
const route = useRoute();
const { t } = useI18n();
const itemTagsRef = ref(null);
const tagOptions = ref([]);
const arrayData = useArrayData('ItemTags');
const itemTags = computed(() => {
console.log('arrayData.store.data:: ', arrayData.store.data);
let map = new Map();
(arrayData.store.data || []).forEach((tag) => {
map.set(tag.id, tag);
});
return map;
});
// const getHighestPriority = () => {
// let max = 0;
// console.log('formData:: ', itemTagsRef.value.formData);
// itemTagsRef.value.formData.forEach((tag) => {
// if (tag.priority > max) max = tag.priority;
// });
// return max + 1;
// };
const getHighestPriority = computed(() => {
let max = 0;
if (!itemTagsRef.value || !itemTagsRef.value.length) return max;
console.log('formData:: ', itemTagsRef.value.formData);
itemTagsRef.value.formData.forEach((tag) => {
if (tag.priority > max) max = tag.priority;
});
return max + 1;
});
const valueOptionsMap = ref(new Map());
const getSelectedTagValues = async (tag) => {
try {
console.log('tag:: ', tag);
tag.value = null;
if (!tag.tagFk && tag.tag.isFree) return;
const filter = {
fields: ['value'],
order: 'value ASC',
};
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get(`Tags/${tag.selectedTag.id}/filterValue`, {
const { data } = await axios.get(`Tags/${tag.tagFk}/filterValue`, {
params,
});
tag.valueOptions = data;
valueOptionsMap.value.set(tag.tagFk, data);
} catch (err) {
console.error('Error getting selected tag values');
}
};
onMounted(() => {
// if (itemTagsRef.value) itemTagsRef.value.reload();
console.log('itemTagsRef:: ', itemTagsRef.value.formData);
});
const onItemTagsFetched = async (itemTags) => {
(itemTags || []).forEach((tag) => {
getSelectedTagValues(tag);
});
};
const handleTagSelected = (rows, index, tag) => {
rows[index].tag = tag;
rows[index].tagFk = tag.id;
rows[index].value = null;
getSelectedTagValues(rows[index]);
};
const getHighestPriority = (rows) => {
let max = 0;
rows.forEach((tag) => {
if (tag.priority > max) max = tag.priority;
});
return max + 1;
};
const insertTag = (rows) => {
itemTagsRef.value.insert();
itemTagsRef.value.formData[itemTagsRef.value.formData.length - 1].priority =
getHighestPriority(rows);
};
</script>
<template>
@ -85,14 +78,17 @@ onMounted(() => {
data-key="ItemTags"
model="ItemTags"
url="ItemTags"
save-url="Tags/onSubmit"
auto-load
update-url="Tags/onSubmit"
:data-required="{
$index: undefined,
itemFk: route.params.id,
priority: getHighestPriority,
priority: undefined,
tag: {
isFree: undefined,
value: undefined,
name: undefined,
},
tagFk: undefined,
}"
:default-remove="false"
:filter="{
@ -106,6 +102,8 @@ onMounted(() => {
},
},
}"
auto-load
@on-fetch="onItemTagsFetched"
>
<template #body="{ rows }">
<QCard class="q-pl-lg q-py-md">
@ -115,32 +113,39 @@ onMounted(() => {
class="row q-gutter-md q-mb-md"
>
<VnSelect
:label="t('Tag')"
v-model="row.tagFk"
:label="t('itemTags.tag')"
:options="tagOptions"
:model-value="row.tag"
option-label="name"
option-value="id"
hide-selected
@update:model-value="getSelectedTagValues(row)"
@update:model-value="
($event) => handleTagSelected(rows, index, $event)
"
/>
<VnSelect
v-if="row.tag?.isFree === false"
:key="row.tagFk"
:label="t('Value')"
v-model="row.value"
option-value="value"
:options="valueOptionsMap.get(row.tagFk)"
option-label="value"
option-value="value"
emit-value
use-input
class="col"
:is-clearable="false"
/>
<VnInput
v-if="row.tag?.isFree || row.tag?.isFree == undefined"
v-else-if="
row.tag?.isFree || row.tag?.isFree == undefined
"
v-model="row.value"
:label="t('Value')"
:label="t('itemTags.value')"
:is-clearable="false"
style="width: 100%"
/>
<VnInput
:label="t('Relevancy')"
:label="t('itemTags.relevancy')"
type="number"
v-model="row.priority"
/>
@ -153,37 +158,27 @@ onMounted(() => {
size="sm"
>
<QTooltip>
{{ t('Remove tag') }}
{{ t('itemTags.removeTag') }}
</QTooltip>
</QIcon>
</div>
</VnRow>
<VnRow>
<QIcon
@click="itemTagsRef.insert()"
@click="insertTag(rows)"
class="cursor-pointer"
color="primary"
name="add"
size="sm"
>
<QTooltip>
{{ t('Add tag') }}
{{ t('itemTags.addTag') }}
</QTooltip>
</QIcon>
</VnRow>
</QCard>
</template>
</CrudModel>
<pre>{{ itemTags }}</pre>
</QPage>
</div>
</template>
<i18n>
es:
Remove tag: Quitar etiqueta
Add tag: Añadir etiqueta
Tag: Etiqueta
Value: Valor
Relevancy: Relevancia
</i18n>

View File

@ -34,3 +34,9 @@ lastEntries:
package: Package
freight: Freight
comission: Comission
itemTags:
removeTag: Remove tag
addTag: Add tag
tag: Tag
value: Value
relevancy: Relevancy

View File

@ -34,3 +34,9 @@ lastEntries:
package: Embalaje
freight: Porte
comission: Comisión
itemTags:
removeTag: Quitar etiqueta
addTag: Añadir etiqueta
tag: Etiqueta
value: Valor
relevancy: Relevancia