refs #4797 feat(workerNotification): add cards
gitea/salix-front/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-11-06 08:32:03 +01:00
parent cc13e3935e
commit 4de39452ca
1 changed files with 52 additions and 57 deletions

View File

@ -5,6 +5,8 @@ import { computed, onMounted, onUpdated, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import CrudModel from 'components/CrudModel.vue';
const $props = defineProps({ const $props = defineProps({
id: { id: {
type: Number, type: Number,
@ -14,75 +16,60 @@ const $props = defineProps({
}); });
const entityId = computed(() => $props.id || route.params.id); const entityId = computed(() => $props.id || route.params.id);
onMounted(() => fetch());
onUpdated(() => console.log('updated')); onUpdated(() => console.log('updated'));
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const quasar = useQuasar(); const quasar = useQuasar();
const notifications = ref([]); async function toggleNotification(notification) {
if (notification.active) {
async function fetch() { await axios.delete(`NotificationSubscriptions/${notification.id}`);
try {
await axios
.get(`NotificationSubscriptions/${entityId.value}/getList`)
.then(async (res) => {
if (res.data) {
notifications.value = res.data;
}
});
} catch (e) {
//
}
}
async function disableNotification(notification) {
await axios
.delete(`NotificationSubscriptions/${notification.id}`)
.catch(() => (notification.active = true))
.then((res) => {
if (res.data) {
notification.id = null; notification.id = null;
notification.active = false; notification.active = false;
quasar.notify({ return quasar.notify({
type: 'positive', type: 'positive',
message: t('worker.notificationsManager.unsubscribed'), message: t('worker.notificationsManager.unsubscribed'),
}); });
} }
});
}
async function toggleNotification(notification) { const { data } = await axios.post(`NotificationSubscriptions`, {
if (!notification.active) {
await disableNotification(notification);
} else {
await axios
.post(`NotificationSubscriptions`, {
notificationFk: notification.notificationFk, notificationFk: notification.notificationFk,
userFk: entityId.value, userFk: entityId.value,
}) });
.catch(() => (notification.active = false))
.then((res) => { notification.id = data.id;
if (res.data) {
notification.id = res.data.id;
quasar.notify({ quasar.notify({
type: 'positive', type: 'positive',
message: t('worker.notificationsManager.subscribed'), message: t('worker.notificationsManager.subscribed'),
}); });
}
});
}
} }
</script> </script>
<template> <template>
<CrudModel auto-load :url="`NotificationSubscriptions/${entityId}/getList`"> <CrudModel
auto-load
data-key="NotificationSubscriptions"
:url="`NotificationSubscriptions/${entityId}/getList`"
:default-remove="false"
>
<template #body="{ rows }"> <template #body="{ rows }">
<QList v-for="row in rows" :key="row.id"> <QList class="notificationList">
<QCard> <QCard v-for="row in rows" :key="row.id" class="q-pa-md">
<QCardSection horizontal> <QItem>
{{ row }} <QItemSection avatar>
</QCardSection> <QBtn
round
icon="mail"
:color="row.active ? 'green' : 'orange'"
@click="toggleNotification(row)"
/>
</QItemSection>
<QItemSection>
<QItemLabel>{{ row.name }}</QItemLabel>
<QItemLabel caption> {{ row.description }} </QItemLabel>
</QItemSection>
</QItem>
</QCard> </QCard>
</QList> </QList>
</template> </template>
@ -151,3 +138,11 @@ async function toggleNotification(notification) {
</QCard> </QCard>
</QPage> --> </QPage> -->
</template> </template>
<style scoped>
.notificationList {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
}
</style>