4797-workerNotificationManager #107

Merged
alexm merged 9 commits from 4797-workerNotificationManager into dev 2023-11-10 09:39:53 +00:00
3 changed files with 88 additions and 50 deletions
Showing only changes of commit e8aef29512 - Show all commits

View File

@ -13,5 +13,6 @@
], ],
"[vue]": { "[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode" "editor.defaultFormatter": "esbenp.prettier-vscode"
} },
"cSpell.words": ["axios"]
alexm marked this conversation as resolved
Review

Este archivo seguro que hay que subirlo?

Este archivo seguro que hay que subirlo?
Review

Creo que se puede poner a nivel de usuario.
Pero por si alguien mas lo usa. Que todos tengamos que darle la primera vez a que no te lo marque

Creo que se puede poner a nivel de usuario. Pero por si alguien mas lo usa. Que todos tengamos que darle la primera vez a que no te lo marque
Review

Creo que se puede poner a nivel de usuario.
Pero por si alguien mas lo usa. Que todos tengamos que darle la primera vez a que no te lo marque

Creo que se puede poner a nivel de usuario. Pero por si alguien mas lo usa. Que todos tengamos que darle la primera vez a que no te lo marque
} }

View File

@ -249,9 +249,6 @@ function goToAction() {
.grid-style-transition { .grid-style-transition {
transition: transform 0.28s, background-color 0.28s; transition: transform 0.28s, background-color 0.28s;
} }
.maxwidth {
width: 100%;
}
</style> </style>
<i18n> <i18n>

View File

@ -1,7 +1,7 @@
<script setup> <script setup>
import axios from 'axios'; import axios from 'axios';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { computed, onMounted, onUpdated, ref } from 'vue'; import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
@ -19,33 +19,40 @@ const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const quasar = useQuasar(); const quasar = useQuasar();
const entityId = computed(() => $props.id || route.params.id); const entityId = computed(() => $props.id || route.params.id);
const notifications = ref(); const active = ref();
const available = ref();
async function toggleNotification(notification) { async function toggleNotification(notification) {
let data = {}; if (!notification.active) {
if (notification.active) {
await axios.delete(`NotificationSubscriptions/${notification.id}`); await axios.delete(`NotificationSubscriptions/${notification.id}`);
swapEntry(active.value, available.value, notification.notificationFk);
} else { } else {
const res = await axios.post(`NotificationSubscriptions`, { const { data } = await axios.post(`NotificationSubscriptions`, {
notificationFk: notification.notificationFk, notificationFk: notification.notificationFk,
userFk: entityId.value, userFk: entityId.value,
}); });
data = res.data; notification.id = data.id;
swapEntry(available.value, active.value, notification.notificationFk);
} }
notification.id = data.id;
notification.active = !notification.active;
quasar.notify({ quasar.notify({
type: 'positive', type: 'positive',
message: t( message: t(
`worker.notificationsManager.${notification.active ? 'un' : ''}subscribed` `worker.notificationsManager.${notification.active ? '' : 'un'}subscribed`
), ),
}); });
orderNotification(notifications.value);
} }
function orderNotification(data) { const swapEntry = (from, to, key) => {
notifications.value = data.sort((notification) => -+notification.active); const element = from.get(key);
to.set(key, element);
from.delete(key);
};
function setNotifications(data) {
active.value = new Map(data.active);
available.value = new Map(data.available);
} }
</script> </script>
@ -57,11 +64,18 @@ function orderNotification(data) {
:default-reset="false" :default-reset="false"
:default-remove="false" :default-remove="false"
:default-save="false" :default-save="false"
alexm marked this conversation as resolved
Review

NotificationSubscriptions aparece 4 veces en este fichero, como verias de hacer una const para que sólo esté 1 vez?

NotificationSubscriptions aparece 4 veces en este fichero, como verias de hacer una const para que sólo esté 1 vez?
@on-fetch="orderNotification" @on-fetch="setNotifications"
> >
<template #body> <template #body>
<div> <div
v-for="(notifications, index) in [
[...active.values()],
[...available.values()],
]"
:key="notifications"
>
<QList class="notificationList"> <QList class="notificationList">
<TransitionGroup>
<QCard <QCard
v-for="notification in notifications" v-for="notification in notifications"
:key="notification.notificationFk" :key="notification.notificationFk"
@ -72,8 +86,7 @@ function orderNotification(data) {
<QBtn <QBtn
round round
icon="mail" icon="mail"
:color="notification.active ? 'green' : 'orange'" :color="notification.active ? 'green' : 'grey'"
@click="toggleNotification(notification)"
/> />
</QItemSection> </QItemSection>
<QItemSection> <QItemSection>
@ -82,9 +95,22 @@ function orderNotification(data) {
{{ notification.description }} {{ notification.description }}
</QItemLabel> </QItemLabel>
</QItemSection> </QItemSection>
<QToggle
checked-icon="check"
unchecked-icon="close"
v-model="notification.active"
color="green"
@update:model-value="toggleNotification(notification)"
/>
</QItem> </QItem>
</QCard> </QCard>
</TransitionGroup>
</QList> </QList>
<QSeparator
color="primary"
class="q-my-lg"
v-if="!index && available.size && active.size"
/>
</div> </div>
</template> </template>
</CrudModel> </CrudModel>
@ -92,17 +118,31 @@ function orderNotification(data) {
<style lang="scss" scoped> <style lang="scss" scoped>
.notificationList { .notificationList {
// display: grid; display: grid;
// grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
// grid-gap: 10px; grid-gap: 10px;
display: flex;
flex-direction: row; /* we will explain what these classes do next! */
justify-content: space-evenly; .v-enter-active,
gap: 15px; .v-leave-active {
width: 100%; transition: opacity 0.5s ease;
> .q-card { }
flex: 1;
width: 100%; .v-enter-from,
.v-leave-to {
opacity: 0;
}
}
@media (max-width: $breakpoint-md) {
.notificationList {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: $breakpoint-xs) {
.notificationList {
grid-template-columns: repeat(1, 1fr);
} }
} }
</style> </style>