Connections view #130

Merged
jsegarra merged 5 commits from wbuezas/hedera-web-mindshore:feature/connections-view into beta 2025-03-28 13:33:10 +00:00
1 changed files with 77 additions and 21 deletions
Showing only changes of commit b691bf2cf4 - Show all commits

View File

@ -12,12 +12,49 @@ import { useAppStore } from 'stores/app';
import { storeToRefs } from 'pinia';
const { t } = useI18n();
const jApi = inject('jApi');
const api = inject('api');
const router = useRouter();
const userStore = useUserStore();
const appStore = useAppStore();
const { isHeaderMounted } = storeToRefs(appStore);
const filter = {
include: [
{
relation: 'visitUser',
scope: {
include: [
{
relation: 'visitAccess',
scope: {
fields: ['id', 'agentFk'],
include: [
{
relation: 'visitAgent',
scope: {
fields: [
'platform',
'browser',
'version'
]
}
}
]
}
},
{
relation: 'user',
scope: {
fields: ['id', 'nickname', 'name']
}
}
],
fields: ['userFk', 'stamp', 'accessFk']
}
}
],
order: 'lastUpdate DESC'
};
const connections = ref([]);
const loading = ref(false);
const intervalId = ref(null);
@ -25,20 +62,36 @@ const intervalId = ref(null);
const getConnections = async () => {
try {
loading.value = true;
connections.value = await jApi.query(
`SELECT vu.userFk userId, vu.stamp, u.nickname, s.lastUpdate,
a.platform, a.browser, a.version, u.name user
FROM userSession s
JOIN visitUser vu ON vu.id = s.userVisitFk
JOIN visitAccess ac ON ac.id = vu.accessFk
JOIN visitAgent a ON a.id = ac.agentFk
JOIN visit v ON v.id = a.visitFk
JOIN account.user u ON u.id = vu.userFk
ORDER BY lastUpdate DESC`
);
loading.value = false;
const { data } = await api.get('/userSessions', {
params: { filter: JSON.stringify(filter) }
});
if (!data) {
connections.value = [];
return;
}
const formattedConnections = data

Esto se podría simplificar
connections.value = data .map(({ visitUser = {}, ...rest }) => ({ ...rest, user: visitUser.user, stamp: visitUser.stamp, visitAgent: visitUser.visitAccess?.visitAgent })) .filter(({ user }) => user);

Esto se podría simplificar `connections.value = data .map(({ visitUser = {}, ...rest }) => ({ ...rest, user: visitUser.user, stamp: visitUser.stamp, visitAgent: visitUser.visitAccess?.visitAgent })) .filter(({ user }) => user); `

Aplicado.

Commit: d9445f72e3

Aplicado. Commit: https://gitea.verdnatura.es/verdnatura/hedera-web/commit/d9445f72e3353d6b7d072c9a8add59a9447311b1

En loopback se pueden crear scopes, de esta manera, no haria falta pasarle el filter.
Ahora ya está fusionada en salix, pero bueno, lo dejo como comentario a futuro

En loopback se pueden crear scopes, de esta manera, no haria falta pasarle el filter. Ahora ya está fusionada en salix, pero bueno, lo dejo como comentario a futuro
.map(connection => {
const { visitUser = {}, ...rest } = connection;
const { visitAccess, user, stamp } = visitUser;
const { visitAgent } = visitAccess || {};
return {
...rest,
user,
stamp,
visitAgent
};
})
.filter(connection => connection.user);
connections.value = formattedConnections;
} catch (error) {
console.error('Error getting connections:', error);
} finally {
loading.value = false;
}
};
@ -89,11 +142,11 @@ onBeforeUnmount(() => clearInterval(intervalId.value));
<CardList
v-for="(connection, index) in connections"
:key="index"
:to="{ name: 'accessLog', params: { id: connection.userId } }"
:to="{ name: 'accessLog', params: { id: connection.user?.id } }"
>
<template #content>
<span class="text-bold q-mb-sm">
{{ connection.nickname }}
{{ connection.user?.nickname }}
</span>
<span>
{{
@ -109,13 +162,14 @@ onBeforeUnmount(() => clearInterval(intervalId.value));
>
<span
v-if="

Esto se podria simplificar, porque el uso x6 de connection.visitagent no mola
Seria una funcion en el v-if y otra funcion a la que le pases connection y te lo devuelva formateado
Otra opcion es
const renderAgentDetails = (connection) => { const agent = connection.visitAgent; return agent?.platform && agent?.browser && agent?.version ? h('span', ${agent.platform} - ${agent.browser} - ${agent.version}) : null; };

<component :is="renderAgentDetails(connection)" />

Esto se podria simplificar, porque el uso x6 de connection.visitagent no mola Seria una funcion en el v-if y otra funcion a la que le pases connection y te lo devuelva formateado Otra opcion es `const renderAgentDetails = (connection) => { const agent = connection.visitAgent; return agent?.platform && agent?.browser && agent?.version ? h('span', `${agent.platform} - ${agent.browser} - ${agent.version}`) : null; };` ` <component :is="renderAgentDetails(connection)" />`

Aplicado.

Commit: 365d4d31e1

Aplicado. Commit: https://gitea.verdnatura.es/verdnatura/hedera-web/commit/365d4d31e105d5ccb748c046ce01b3db53eddc45
connection.platform &&
connection.browser &&
connection.version
connection.visitAgent?.platform &&
connection.visitAgent?.browser &&
connection.visitAgent?.version
"
>
{{ connection.platform }} - {{ connection.browser }} -
{{ connection.version }}
{{ connection.visitAgent?.platform }} -
{{ connection.visitAgent?.browser }} -
{{ connection.visitAgent?.version }}
</span>
</template>
<template #actions>
@ -123,7 +177,9 @@ onBeforeUnmount(() => clearInterval(intervalId.value));
icon="people"
flat
rounded
@click.stop.prevent="supplantUser(connection.user)"
@click.stop.prevent="
supplantUser(connection.user?.name)
"
>
<QTooltip>
{{ t('supplantUser') }}