feat(VnLog): refs #6994 add descriptors

This commit is contained in:
Alex Moreno 2025-03-07 14:01:36 +01:00
parent 0f64efd20b
commit 80eebef931
4 changed files with 69 additions and 59 deletions

View File

@ -66,11 +66,15 @@ updateValue();
:title="type === 'string' && value.length > maxStrLen ? value : ''" :title="type === 'string' && value.length > maxStrLen ? value : ''"
:class="{ :class="{
[cssClass]: t !== '', [cssClass]: t !== '',
'json-link': descriptorStore.has(name), 'link json-link': descriptorStore.has(name),
}" }"
> >
{{ name }} {{ t }}
<component v-if="value.id" :is="descriptorStore.has(name)" :id="value.id" /> <component
v-if="value.val && descriptorStore.has(name)"
:is="descriptorStore.has(name)"
:id="value.val"
/>
</span> </span>
</template> </template>
@ -94,4 +98,7 @@ updateValue();
color: #cd7c7c; color: #cd7c7c;
font-style: italic; font-style: italic;
} }
.json-link {
text-decoration: underline;
}
</style> </style>

View File

@ -561,7 +561,7 @@ watch(
}}: }}:
</span> </span>
<VnJsonValue <VnJsonValue
:value="value.val" :value="prop.val"
:name="prop.name" :name="prop.name"
/> />
</QItem> </QItem>
@ -599,17 +599,36 @@ watch(
/> />
<span v-if="log.props.length" class="attributes"> <span v-if="log.props.length" class="attributes">
<span <span
class="expanded-json q-pa-none" v-if="!log.expand"
:class=" class="q-pa-none text-grey"
log.expand >
? 'column' <span
: 'row no-wrap ellipsis' v-for="(prop, propIndex) in log.props"
" :key="propIndex"
style=" class="basic-json"
text-overflow: ellipsis; >
overflow: hidden; <span
white-space: nowrap; class="json-field"
" :title="prop.name"
>
{{ prop.nameI18n }}:
</span>
<VnJsonValue
:value="prop.val"
:name="prop.name"
/>
<span
v-if="
propIndex <
log.props.length - 1
"
>,&nbsp;
</span>
</span>
</span>
<span
v-if="log.expand"
class="expanded-json column q-pa-none"
> >
<div <div
v-for="( v-for="(
@ -624,32 +643,7 @@ watch(
> >
{{ prop.nameI18n }}: {{ prop.nameI18n }}:
</span> </span>
<VnJsonValue <span v-if="log.action == 'update'">
:value="prop.val"
:name="prop.name"
/>
<span
v-if="
prop2Index <
log.props.length &&
!log.expand
"
class="q-mr-xs"
>,
</span>
<span
v-if="prop.val.id && log.expand"
class="id-value"
>
#{{ prop.val.id }}
</span>
<span
v-if="
log.action == 'update' &&
log.expand
"
>
<VnJsonValue <VnJsonValue
:value="prop.old" :value="prop.old"
:name="prop.name" :name="prop.name"
@ -662,7 +656,8 @@ watch(
</span> </span>
<VnJsonValue <VnJsonValue
:value="prop.val.val" :value="prop.val"
:name="prop.name"
/> />
<span <span
v-if="prop.val.id" v-if="prop.val.id"
@ -673,7 +668,8 @@ watch(
</span> </span>
<span v-else="prop.old.val"> <span v-else="prop.old.val">
<VnJsonValue <VnJsonValue
:value="prop.val.val" :value="prop.val"
:name="prop.name"
/> />
<span <span
v-if="prop.old.id" v-if="prop.old.id"

View File

@ -1,37 +1,37 @@
import { ref, defineAsyncComponent } from 'vue'; import { defineAsyncComponent } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useStateStore } from 'stores/useStateStore';
const { descriptors, setDescriptors } = useStateStore();
export const useDescriptorStore = defineStore('descriptorStore', () => { export const useDescriptorStore = defineStore('descriptorStore', () => {
const descriptors = ref({}); function get() {
if (Object.keys(descriptors).length) return descriptors;
function set() { const currentDescriptors = {};
const files = import.meta.glob(`src/**/*DescriptorProxy.vue`); const files = import.meta.glob(`/src/**/*DescriptorProxy.vue`);
const moduleParser = { const moduleParser = {
user: 'account', account: 'user',
client: 'customer', client: 'customer',
}; };
for (const file in files) { for (const file in files) {
console.log('fasd', file.split('/').at(-1).slice(0, -19).toLowerCase());
const name = file.split('/').at(-1).slice(0, -19).toLowerCase(); const name = file.split('/').at(-1).slice(0, -19).toLowerCase();
const descriptor = moduleParser[name] ?? name; const descriptor = moduleParser[name] ?? name;
//Ver pq no funciona account//user currentDescriptors[descriptor + 'Fk'] = defineAsyncComponent(
descriptors.value[descriptor + 'Fk'] = defineAsyncComponent(() => () => import(/* @vite-ignore */ file),
import(file)
); );
} }
} setDescriptors(currentDescriptors);
return currentDescriptors;
function get() {
if (!Object.keys(descriptors.value).length) set();
} }
function has(name) { function has(name) {
get(); console.log('get(): ', get());
console.log('descriptors.value: ', descriptors.value); return get()[name];
return descriptors.value[name];
} }
return { return {
has, has,
get,
}; };
}); });

View File

@ -8,6 +8,7 @@ export const useStateStore = defineStore('stateStore', () => {
const rightAdvancedDrawer = ref(false); const rightAdvancedDrawer = ref(false);
const subToolbar = ref(false); const subToolbar = ref(false);
const cardDescriptor = ref(null); const cardDescriptor = ref(null);
const descriptors = ref({});
function cardDescriptorChangeValue(descriptor) { function cardDescriptorChangeValue(descriptor) {
cardDescriptor.value = descriptor; cardDescriptor.value = descriptor;
@ -52,6 +53,10 @@ export const useStateStore = defineStore('stateStore', () => {
return subToolbar.value; return subToolbar.value;
} }
function setDescriptors(value) {
descriptors.value = value;
}
return { return {
cardDescriptor, cardDescriptor,
cardDescriptorChangeValue, cardDescriptorChangeValue,
@ -68,5 +73,7 @@ export const useStateStore = defineStore('stateStore', () => {
isSubToolbarShown, isSubToolbarShown,
toggleSubToolbar, toggleSubToolbar,
rightDrawerChangeValue, rightDrawerChangeValue,
descriptors,
setDescriptors,
}; };
}); });