0
0
Fork 0

feat: refs #6825 share filters, create popup

This commit is contained in:
Alex Moreno 2024-05-16 13:38:15 +02:00
parent 6f38aeba83
commit 598d116848
8 changed files with 160 additions and 54 deletions

View File

@ -5,13 +5,20 @@
:is=" :is="
(components && components[toComponent.component]) ?? toComponent.component (components && components[toComponent.component]) ?? toComponent.component
" "
v-bind="toComponent.props && toComponent.props(value)" v-bind="
typeof toComponent.attrs == 'function'
? toComponent.attrs(value)
: toComponent.attrs
"
@click="toComponent.event && toComponent.event(value)" @click="toComponent.event && toComponent.event(value)"
v-model="model"
/> />
</span> </span>
</template> </template>
<script setup> <script setup>
import { computed } from 'vue'; import { computed, defineModel } from 'vue';
const model = defineModel();
const $props = defineProps({ const $props = defineProps({
prop: { prop: {
type: Object, type: Object,

View File

@ -111,7 +111,7 @@ async function fetchFilter(val) {
if (new RegExp(/\d/g).test(val)) key = optionValue.value; if (new RegExp(/\d/g).test(val)) key = optionValue.value;
const where = { [key]: { like: `%${val}%` } }; const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
const fetchOptions = { where, order: sortBy, limit }; const fetchOptions = { where, order: sortBy, limit };
if (fields) fetchOptions.fields = fields; if (fields) fetchOptions.fields = fields;
return dataRef.value.fetch(fetchOptions); return dataRef.value.fetch(fetchOptions);

View File

@ -10,6 +10,7 @@ import VnLv from 'components/ui/VnLv.vue';
import VnTableColumn from 'components/common/VnTableColumn.vue'; import VnTableColumn from 'components/common/VnTableColumn.vue';
import VnTableFilter from 'components/common/VnTableFilter.vue'; import VnTableFilter from 'components/common/VnTableFilter.vue';
import VnTableCreate from 'components/common/VnTableCreate.vue';
const $props = defineProps({ const $props = defineProps({
columns: { columns: {
@ -44,6 +45,10 @@ const $props = defineProps({
type: String, type: String,
default: null, default: null,
}, },
create: {
type: Object,
default: null,
},
}); });
const { t } = useI18n(); const { t } = useI18n();
const stateStore = useStateStore(); const stateStore = useStateStore();
@ -53,6 +58,7 @@ const mode = ref('card');
const selected = ref([]); const selected = ref([]);
const params = ref({}); const params = ref({});
const VnPaginateRef = ref(); const VnPaginateRef = ref();
const showForm = ref(false);
const tableModes = [ const tableModes = [
{ {
icon: 'view_column', icon: 'view_column',
@ -73,26 +79,27 @@ onMounted(() => {
}); });
const cardTemplate = computed(() => { const cardTemplate = computed(() => {
let chips = []; const chips = [];
let visible = []; const visible = [];
const create = [];
let title; let title;
let actions; let actions;
for (const col of $props.columns) { for (const col of $props.columns) {
if (col.field == 'tableActions') { if (col.field == 'tableActions') {
actions = col; actions = col;
continue;
} }
if (col.chip) { if (col.chip) {
chips.push(col); chips.push(col);
continue;
} }
if (col.isTitle) { if (col.isTitle) {
title = col; title = col;
continue; }
if (col.create) {
create.push(col);
} }
if (col.cardVisible) visible.push(col); if (col.cardVisible) visible.push(col);
} }
return { chips, title, visible, actions }; return { chips, title, visible, actions, create };
}); });
const rowClickFunction = computed(() => { const rowClickFunction = computed(() => {
@ -105,12 +112,10 @@ const rowClickFunction = computed(() => {
<template> <template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
<QScrollArea class="fit text-grey-8"> <QScrollArea class="fit text-grey-8">
{{ params }}
<VnFilterPanel <VnFilterPanel
:data-key="$attrs['data-key']" :data-key="$attrs['data-key']"
:search-button="true" :search-button="true"
v-model:params="params" v-model="params"
@remove="(key) => console.log('HA LELGADO', key)"
> >
<template #body> <template #body>
<VnTableFilter <VnTableFilter
@ -118,9 +123,10 @@ const rowClickFunction = computed(() => {
:data-key="$attrs['data-key']" :data-key="$attrs['data-key']"
v-for="col of columns" v-for="col of columns"
:key="col.id" :key="col.id"
v-model="params[col.field]" v-model="params[col.columnFilter?.field ?? col.field]"
/> />
</template> </template>
<slot name="moreFilterPanel" :params="params" :columns="columns" />
</VnFilterPanel> </VnFilterPanel>
</QScrollArea> </QScrollArea>
</QDrawer> </QDrawer>
@ -203,7 +209,7 @@ const rowClickFunction = computed(() => {
bordered bordered
flat flat
class="row no-wrap justify-between cursor-pointer" class="row no-wrap justify-between cursor-pointer"
@row-click=" @click="
(_, row) => { (_, row) => {
$props.rowClick && $props.rowClick(row); $props.rowClick && $props.rowClick(row);
} }
@ -254,20 +260,15 @@ const rowClickFunction = computed(() => {
{{ row[cardTemplate.title.field] }} {{ row[cardTemplate.title.field] }}
</QCardSection> </QCardSection>
<!-- Fields --> <!-- Fields -->
<QCardSection class="q-pl-sm q-pr-lg q-py-xs flex-one"> <QCardSection
class="q-pl-sm q-pr-lg q-py-xs flex-one no-pointer-events"
>
<div <div
v-for="col of cardTemplate.visible" v-for="col of cardTemplate.visible"
:key="col.field" :key="col.field"
class="fields" class="fields"
> >
<VnLv <VnLv :label="`${col.label}:`">
v-if="
col.cardVisible &&
!col.isChip &&
col.field != 'tableActions'
"
:label="`${col.label}:`"
>
<template #value> <template #value>
<VnTableColumn :column="col" :row /> <VnTableColumn :column="col" :row />
</template> </template>
@ -297,6 +298,23 @@ const rowClickFunction = computed(() => {
</QTable> </QTable>
</template> </template>
</VnPaginate> </VnPaginate>
<!-- AÑADIR EN EL OBJETO LA POSIBILIDAD DE PONER QUE ESE CAMPO SIRVE PARA LA CREACION Y MOSTARLO EN UN POPUP-->
<!-- AÑADIR SLOT PARA AÑADIR MAS CAMPOS -->
<!-- AÑADIR SLOT SETEAR EL POPUP -->
<QPageSticky v-if="create" :offset="[20, 20]">
<QBtn @click="showForm = !showForm" color="primary" fab icon="add" />
<!-- <QTooltip>
{{ t('New client') }}
</QTooltip> -->
</QPageSticky>
<QDialog v-model="showForm" transition-show="scale" transition-hide="scale">
<VnTableCreate
:columns="cardTemplate.create"
:model="$attrs['data-key'] + 'Create'"
:create="create"
/>
<!-- v-bind="$attrs.create" -->
</QDialog>
</template> </template>
<style lang="scss"> <style lang="scss">
* { * {
@ -421,4 +439,9 @@ const rowClickFunction = computed(() => {
.w-20 { .w-20 {
width: 20%; width: 20%;
} }
.cursor-text {
pointer-events: all;
cursor: text;
}
</style> </style>

View File

@ -1,26 +1,29 @@
<template> <template>
<VnComponent <VnComponent
v-if="column.before" v-if="col.before"
:prop="column.before" :prop="col.before"
:components="components" :components="components"
:value="row" :value="value"
/> />
{{ col?.component }}
<VnComponent <VnComponent
v-if="column.component" v-if="col.component"
:prop="column" :prop="col"
:components="components" :components="components"
:value="row" :value="value"
v-model="model"
/> />
<span v-else>{{ dashIfEmpty(row[column.field]) }}</span> <!-- ?? [defaultComponent] -->
<span v-else>{{ dashIfEmpty(row[col.field]) }}</span>
<VnComponent <VnComponent
v-if="column.after" v-if="col.after"
:prop="column.after" :prop="col.after"
:components="components" :components="components"
:value="row" :value="value"
/> />
</template> </template>
<script setup> <script setup>
import { markRaw } from 'vue'; import { markRaw, computed, defineModel } from 'vue';
import { QIcon, QCheckbox } from 'quasar'; import { QIcon, QCheckbox } from 'quasar';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
@ -30,6 +33,23 @@ import VnInput from 'components/common/VnInput.vue';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import VnComponent from 'components/common/VnComponent.vue'; import VnComponent from 'components/common/VnComponent.vue';
const model = defineModel();
const $props = defineProps({
column: {
type: Object,
required: true,
},
row: {
type: Object,
required: true,
},
default: {
type: [Object, String],
required: false,
default: null,
},
});
const components = { const components = {
input: markRaw(VnInput), input: markRaw(VnInput),
number: markRaw(VnInput), number: markRaw(VnInput),
@ -39,14 +59,15 @@ const components = {
icon: markRaw(QIcon), icon: markRaw(QIcon),
}; };
defineProps({ const value = computed(() =>
column: { $props.column.format ? $props.column.format($props.row) : $props.row
type: Object, );
required: true,
}, const col = computed(() => {
row: { const newColumn = { ...$props.column };
type: Object, console.log('newColumn: ', newColumn);
required: true, console.log('newColumn.componen: ', newColumn.component);
}, if ($props.default && !newColumn.component) newColumn.component = $props.default;
return newColumn;
}); });
</script> </script>

View File

@ -0,0 +1,34 @@
<script setup>
import FormModelPopup from 'components/FormModelPopup.vue';
import VnTableColumn from 'components/common/VnTableColumn.vue';
const $props = defineProps({
columns: {
type: Object,
required: true,
},
create: {
type: Object,
required: true,
},
});
</script>
<template>
<FormModelPopup v-bind="{ ...$attrs, ...$props.create }">
<template #form-inputs="{ data }">
<VnTableColumn
v-for="column of $props.columns"
:key="column.field"
:column="{
...(column ?? column.create),
...{
attrs: column,
},
}"
:row="{}"
default="input"
v-model="data[column.field]"
/>
</template>
</FormModelPopup>
</template>

View File

@ -1,5 +1,4 @@
<template> <template>
{{ model }}
<div <div
v-if="showTitle && column" v-if="showTitle && column"
class="q-pt-sm q-px-sm ellipsis" class="q-pt-sm q-px-sm ellipsis"
@ -16,7 +15,7 @@
v-if="columnFilter?.component" v-if="columnFilter?.component"
:is="isBasicComponent?.component ?? columnFilter.component" :is="isBasicComponent?.component ?? columnFilter.component"
v-model="model" v-model="model"
v-bind="{ ...columnFilter.attrs, ...isBasicComponent?.attrs }" v-bind="{ ...isBasicComponent?.attrs, ...columnFilter.attrs }"
v-on="isBasicComponent?.event ?? columnFilter.event" v-on="isBasicComponent?.event ?? columnFilter.event"
dense dense
/> />
@ -57,10 +56,6 @@ const $props = defineProps({
type: String, type: String,
required: true, required: true,
}, },
addModel: {
type: Object,
default: () => {},
},
}); });
const model = defineModel(); const model = defineModel();
const arrayData = useArrayData($props.dataKey); const arrayData = useArrayData($props.dataKey);

View File

@ -8,7 +8,7 @@ import useRedirect from 'src/composables/useRedirect';
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue'; import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
const { t } = useI18n(); const { t } = useI18n();
const params = defineModel('params'); const params = defineModel();
const props = defineProps({ const props = defineProps({
dataKey: { dataKey: {
type: String, type: String,
@ -165,7 +165,7 @@ const customTags = computed(() =>
async function remove(key) { async function remove(key) {
userParams.value[key] = null; userParams.value[key] = null;
delete params.value[key]; params.value[key] = undefined;
console.log('key: ', key); console.log('key: ', key);
console.log('params: ', params.value); console.log('params: ', params.value);
await arrayData.applyFilter({ params: userParams.value }); await arrayData.applyFilter({ params: userParams.value });

View File

@ -292,6 +292,7 @@ const columns = computed(() => [
label: t('customer.extendedList.tableVisibleColumns.name'), label: t('customer.extendedList.tableVisibleColumns.name'),
name: 'name', name: 'name',
isTitle: true, isTitle: true,
create: true,
}, },
{ {
align: 'left', align: 'left',
@ -301,9 +302,25 @@ const columns = computed(() => [
}, },
{ {
align: 'left', align: 'left',
field: 'salesPerson', field: 'salesPersonFk',
label: t('customer.extendedList.tableVisibleColumns.salesPersonFk'), label: t('customer.extendedList.tableVisibleColumns.salesPersonFk'),
name: 'salesPersonFk', name: 'salesPersonFk',
columnFilter: {
component: 'select',
attrs: {
url: 'Workers/activeWithInheritedRole',
fields: ['id', 'name'],
where: { role: 'salesPerson' },
},
},
create: {
component: 'select',
attrs: {
url: 'Workers/activeWithInheritedRole',
fields: ['id', 'name'],
where: { role: 'salesPerson' },
},
},
}, },
{ {
align: 'left', align: 'left',
@ -379,7 +396,7 @@ const columns = computed(() => [
field: 'created', field: 'created',
label: t('customer.extendedList.tableVisibleColumns.created'), label: t('customer.extendedList.tableVisibleColumns.created'),
name: 'created', name: 'created',
format: (value) => toDate(value), format: ({ created }) => toDate(created),
}, },
{ {
align: 'left', align: 'left',
@ -541,11 +558,20 @@ const selectSalesPersonId = (id) => (selectedSalesPersonId.value = id);
<VnTable <VnTable
data-key="CustomerExtendedList" data-key="CustomerExtendedList"
url="Clients/extendedListFilter" url="Clients/extendedListFilter"
url-create="Clients/createWithUser"
:create="{
urlCreate: 'Clients/createWithUser',
title: 'Create client',
formInitialData: {
active: true,
isEqualizated: false,
},
}"
order="id DESC" order="id DESC"
:columns="columns" :columns="columns"
default-mode="card" default-mode="card"
auto-load
redirect="customer" redirect="customer"
auto-load
> >
<!-- <!--
default-mode="table" default-mode="table"