forked from verdnatura/salix-front
refs #4797 feat(WorkerNotification): use Maps
This commit is contained in:
parent
5350765469
commit
e8aef29512
|
@ -13,5 +13,6 @@
|
||||||
],
|
],
|
||||||
"[vue]": {
|
"[vue]": {
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
}
|
},
|
||||||
|
"cSpell.words": ["axios"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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,34 +64,53 @@ function orderNotification(data) {
|
||||||
:default-reset="false"
|
:default-reset="false"
|
||||||
:default-remove="false"
|
:default-remove="false"
|
||||||
:default-save="false"
|
:default-save="false"
|
||||||
@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">
|
||||||
<QCard
|
<TransitionGroup>
|
||||||
v-for="notification in notifications"
|
<QCard
|
||||||
:key="notification.notificationFk"
|
v-for="notification in notifications"
|
||||||
class="q-pa-md"
|
:key="notification.notificationFk"
|
||||||
>
|
class="q-pa-md"
|
||||||
<QItem>
|
>
|
||||||
<QItemSection avatar>
|
<QItem>
|
||||||
<QBtn
|
<QItemSection avatar>
|
||||||
round
|
<QBtn
|
||||||
icon="mail"
|
round
|
||||||
:color="notification.active ? 'green' : 'orange'"
|
icon="mail"
|
||||||
@click="toggleNotification(notification)"
|
:color="notification.active ? 'green' : 'grey'"
|
||||||
|
/>
|
||||||
|
</QItemSection>
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ notification.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption>
|
||||||
|
{{ notification.description }}
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
<QToggle
|
||||||
|
checked-icon="check"
|
||||||
|
unchecked-icon="close"
|
||||||
|
v-model="notification.active"
|
||||||
|
color="green"
|
||||||
|
@update:model-value="toggleNotification(notification)"
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
</QItem>
|
||||||
<QItemSection>
|
</QCard>
|
||||||
<QItemLabel>{{ notification.name }}</QItemLabel>
|
</TransitionGroup>
|
||||||
<QItemLabel caption>
|
|
||||||
{{ notification.description }}
|
|
||||||
</QItemLabel>
|
|
||||||
</QItemSection>
|
|
||||||
</QItem>
|
|
||||||
</QCard>
|
|
||||||
</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>
|
||||||
|
|
Loading…
Reference in New Issue