From baaf6b6c74c338b68f02cd84414c2e3913d4664d Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 23 Nov 2022 14:50:05 +0100 Subject: [PATCH 01/32] refs #4797 @6h --- src/i18n/en/index.js | 10 ++ src/i18n/es/index.js | 5 + src/pages/Worker/Card/WorkerCard.vue | 6 + src/pages/Worker/Card/WorkerDescriptor.vue | 4 +- .../Card/WorkerNotificationsManager.vue | 170 ++++++++++++++++++ src/router/modules/worker.js | 8 + 6 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 src/pages/Worker/Card/WorkerNotificationsManager.vue diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 5d41cf88a..18fcf78c3 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -255,6 +255,7 @@ export default { list: 'List', basicData: 'Basic data', summary: 'Summary', + notifications: 'Notifications', }, list: { name: 'Name', @@ -288,6 +289,15 @@ export default { role: 'Role', sipExtension: 'Extension', }, + notificationsManager: { + activeNotifications: 'Active notifications', + availableNotifications: 'Available notifications', + table: { + name: 'Permission description', + subscribed: 'Subscribed', + role: 'Necessary role', + } + }, }, components: { topbar: {}, diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index 2b810b399..c079c0629 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -253,6 +253,7 @@ export default { list: 'Listado', basicData: 'Datos básicos', summary: 'Resumen', + notifications: 'Notificaciones' }, list: { name: 'Nombre', @@ -286,6 +287,10 @@ export default { role: 'Rol', sipExtension: 'Extensión', }, + notificationsManager: { + activeNotifications: 'Notificaciones activas', + availableNotifications: 'Notificaciones disponibles', + }, }, components: { topbar: {}, diff --git a/src/pages/Worker/Card/WorkerCard.vue b/src/pages/Worker/Card/WorkerCard.vue index b014e9b7f..23677f0f6 100644 --- a/src/pages/Worker/Card/WorkerCard.vue +++ b/src/pages/Worker/Card/WorkerCard.vue @@ -18,6 +18,12 @@ const { t } = useI18n(); {{ t('worker.pageTitles.basicData') }} + + + + + {{ t('worker.pageTitles.notifications') }} + diff --git a/src/pages/Worker/Card/WorkerDescriptor.vue b/src/pages/Worker/Card/WorkerDescriptor.vue index 1308264c0..5746f220a 100644 --- a/src/pages/Worker/Card/WorkerDescriptor.vue +++ b/src/pages/Worker/Card/WorkerDescriptor.vue @@ -1,5 +1,5 @@ + diff --git a/src/router/modules/worker.js b/src/router/modules/worker.js index d5703d04b..0c5e45b42 100644 --- a/src/router/modules/worker.js +++ b/src/router/modules/worker.js @@ -41,6 +41,14 @@ export default { }, component: () => import('src/pages/Worker/Card/WorkerSummary.vue'), }, + { + name: 'WorkerNotificationsManager', + path: 'notifications', + meta: { + title: 'notifications' + }, + component: () => import('src/pages/Worker/Card/WorkerNotificationsManager.vue'), + }, ] }, ] -- 2.40.1 From 7d198a819b37acbb372fdc9e9bfc56df729a1e89 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 23 Nov 2022 14:58:57 +0100 Subject: [PATCH 02/32] add icons --- src/pages/Worker/Card/WorkerNotificationsManager.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 6e18df124..19728db17 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -154,6 +154,9 @@ async function fetch() { {{ props.row.notification.description }} Date: Thu, 24 Nov 2022 09:32:15 +0100 Subject: [PATCH 03/32] refs #4797 @2,30h --- src/i18n/en/index.js | 7 +- src/i18n/es/index.js | 2 + .../Card/WorkerNotificationsManager.vue | 187 ++++++++++++++---- 3 files changed, 152 insertions(+), 44 deletions(-) diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 18fcf78c3..f36636139 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -292,11 +292,8 @@ export default { notificationsManager: { activeNotifications: 'Active notifications', availableNotifications: 'Available notifications', - table: { - name: 'Permission description', - subscribed: 'Subscribed', - role: 'Necessary role', - } + subscribed: 'Subscribed to the notification', + unsubscribed: 'Unsubscribed from the notification', }, }, components: { diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index c079c0629..22044e7cc 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -290,6 +290,8 @@ export default { notificationsManager: { activeNotifications: 'Notificaciones activas', availableNotifications: 'Notificaciones disponibles', + subscribed: 'Te has suscrito a la notificación', + unsubscribed: 'Te has dado de baja de la notificación', }, }, components: { diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 19728db17..eca1c38de 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -2,6 +2,7 @@ import { onMounted, computed, ref } from 'vue'; import { useRoute } from 'vue-router'; import { useI18n } from 'vue-i18n'; +import { useQuasar } from 'quasar'; import { useSession } from 'src/composables/useSession'; import axios from 'axios'; @@ -18,8 +19,7 @@ onMounted(async () => await fetch()); const route = useRoute(); const { t } = useI18n(); const { getToken } = useSession(); - -t == t; +const quasar = useQuasar(); const entityId = computed(() => { return $props.id || route.params.id; @@ -47,6 +47,9 @@ const workerFilter = { }, ], }; + +const notificationAcls = ref([]); + async function fetch() { const { data } = await axios.get(`Workers/${entityId.value}`, { params: { @@ -81,14 +84,15 @@ async function fetch() { data.subscribedNotifs = subscribedNotifs.data; const filterAcl = { - where: { - roleFk: data.user.roleFk, - }, include: [ { relation: 'notification', scope: { - relation: 'notificationSubscription', + include: [ + { + relation: 'subscription', + }, + ], }, }, { @@ -106,13 +110,121 @@ async function fetch() { }, }); - data.notifsAcl = notifsAcl.data; + let notifications = []; + + notifsAcl.data.forEach((acl) => { + let notification = { + id: acl.notification.id, + name: acl.notification.name, + description: acl.notification.description, + active: false, + allowed: false, + }; + + if (acl.roleFk == data.user.roleFk) { + notification.allowed = true; + } else { + notification.allowed = false; + } + + if (data.subscribedNotifs.length > 0) { + data.subscribedNotifs.forEach((sub) => { + if (sub.notificationFk == acl.notification.id) { + if (notification.allowed) { + notification.active = true; + } + } + }); + } + + // Check if notification is already in the array + let found = false; + notifications.forEach((notif) => { + if (notif.id == notification.id) { + found = true; + } + }); + + if (!found) { + if (!notification.allowed) { + notification.active = null; + } + notifications.push(notification); + } else { + // Check if current notification is allowed and the other one is not + // If so, replace the existing one with the current one + notifications.forEach((notif) => { + if (notif.id == notification.id) { + if (notification.allowed && !notif.allowed) { + notif.allowed = true; + notif.active = notification.active; + } + } + }); + } + }); + notificationAcls.value = notifications; + sortNotifs(); } catch (e) { console.log(e); } worker.value = data; } + +function sortNotifs() { + notificationAcls.value.sort((a, b) => { + if (a.allowed && !b.allowed) { + return -1; + } else if (!a.allowed && b.allowed) { + return 1; + } else { + if (a.active && !b.active) { + return 1; + } else if (!a.active && b.active) { + return -1; + } else { + return 0; + } + } + }); +} + +async function toggleNotif(notif, chip) { + if (chip) { + notif.active = !notif.active; + } + if (notif.active) { + await axios.post( + `NotificationSubscriptions`, + { + notificationFk: notif.id, + userFk: entityId.value, + }, + { + headers: { + Authorization: getToken(), + }, + } + ); + quasar.notify({ + type: 'positive', + message: t('worker.notificationsManager.subscribed'), + }); + } else { + await axios.post(`NotificationSubscriptions/deleteSubscription`, { + notificationId: notif.id + '', + userId: entityId.value, + headers: { + Authorization: getToken(), + }, + }); + quasar.notify({ + type: 'positive', + message: t('worker.notificationsManager.unsubscribed'), + }); + } +} -- 2.40.1 From b155547702236bb278da006f504c4a0c603434a0 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 24 Nov 2022 10:05:46 +0100 Subject: [PATCH 04/32] refs #4797 @30min disable modifications if user is not the one editing --- .../Worker/Card/WorkerNotificationsManager.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index eca1c38de..6d302717c 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -49,8 +49,13 @@ const workerFilter = { }; const notificationAcls = ref([]); +const allowedEditing = ref(false); async function fetch() { + const token = await getToken(); + + const tokenUser = await axios.get(`AccessTokens/${token}/user`); + const { data } = await axios.get(`Workers/${entityId.value}`, { params: { filter: JSON.stringify(workerFilter), @@ -137,7 +142,6 @@ async function fetch() { }); } - // Check if notification is already in the array let found = false; notifications.forEach((notif) => { if (notif.id == notification.id) { @@ -151,8 +155,6 @@ async function fetch() { } notifications.push(notification); } else { - // Check if current notification is allowed and the other one is not - // If so, replace the existing one with the current one notifications.forEach((notif) => { if (notif.id == notification.id) { if (notification.allowed && !notif.allowed) { @@ -169,6 +171,10 @@ async function fetch() { console.log(e); } + if (tokenUser.data.id == data.user.id) { + allowedEditing.value = true; + } + worker.value = data; } @@ -238,6 +244,7 @@ async function toggleNotif(notif, chip) {
Date: Fri, 25 Nov 2022 11:41:24 +0100 Subject: [PATCH 05/32] allow only the user to modify itself --- src/pages/Worker/Card/WorkerNotificationsManager.vue | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 6d302717c..5877ae411 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -1,8 +1,9 @@