From 535076546971e95675db490a7e828b1fabcd52f3 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 6 Nov 2023 15:33:18 +0100 Subject: [PATCH] refs #4797 style(workerNotificationManager) --- src/components/CrudModel.vue | 1 + .../Card/WorkerNotificationsManager.vue | 158 +++++++----------- 2 files changed, 60 insertions(+), 99 deletions(-) diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 2a4982fce..96d52b98c 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -89,6 +89,7 @@ async function fetch(data) { watch(formData, () => (hasChanges.value = true), { deep: true }); emit('onFetch', data); + return data; } async function reset() { diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 03948318e..1b3cf1704 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -14,35 +14,38 @@ const $props = defineProps({ default: null, }, }); -const entityId = computed(() => $props.id || route.params.id); - -onUpdated(() => console.log('updated')); const route = useRoute(); const { t } = useI18n(); const quasar = useQuasar(); +const entityId = computed(() => $props.id || route.params.id); +const notifications = ref(); async function toggleNotification(notification) { + let data = {}; if (notification.active) { await axios.delete(`NotificationSubscriptions/${notification.id}`); - notification.id = null; - notification.active = false; - return quasar.notify({ - type: 'positive', - message: t('worker.notificationsManager.unsubscribed'), + } else { + const res = await axios.post(`NotificationSubscriptions`, { + notificationFk: notification.notificationFk, + userFk: entityId.value, }); + data = res.data; } - const { data } = await axios.post(`NotificationSubscriptions`, { - notificationFk: notification.notificationFk, - userFk: entityId.value, - }); - notification.id = data.id; + notification.active = !notification.active; quasar.notify({ type: 'positive', - message: t('worker.notificationsManager.subscribed'), + message: t( + `worker.notificationsManager.${notification.active ? 'un' : ''}subscribed` + ), }); + orderNotification(notifications.value); +} + +function orderNotification(data) { + notifications.value = data.sort((notification) => -+notification.active); } @@ -51,98 +54,55 @@ async function toggleNotification(notification) { auto-load data-key="NotificationSubscriptions" :url="`NotificationSubscriptions/${entityId}/getList`" + :default-reset="false" :default-remove="false" + :default-save="false" + @on-fetch="orderNotification" > - - - + + + + + -