From 8bf9fff7dcb922058623b911d7bf1af21f94c986 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 26 Apr 2021 00:48:31 +0200 Subject: [PATCH] Triggering notifications for children of alert entities. Showing icons in alert entity search to distinguish networks and channels. --- assets/components/alerts/search.vue | 35 +++++++++++++++++----- assets/components/header/notifications.vue | 14 +++++---- assets/img/icons/device_hub.svg | 5 ++++ assets/img/icons/earth.svg | 5 ++++ assets/img/icons/lan2.svg | 5 ++++ assets/img/icons/sphere.svg | 5 ++++ assets/js/curate.js | 5 +++- assets/js/main.js | 3 ++ assets/js/ui/actions.js | 1 + src/alerts.js | 24 +++++++++++---- 10 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 assets/img/icons/device_hub.svg create mode 100644 assets/img/icons/earth.svg create mode 100644 assets/img/icons/lan2.svg create mode 100644 assets/img/icons/sphere.svg diff --git a/assets/components/alerts/search.vue b/assets/components/alerts/search.vue index c5a61899..93e9ab85 100644 --- a/assets/components/alerts/search.vue +++ b/assets/components/alerts/search.vue @@ -13,15 +13,29 @@ class="nolist" >
  • {{ actor.name }}
  • + @click="selectResult(result)" + > + + + + + {{ result.name }} + @@ -123,4 +137,9 @@ export default { height: 2rem; margin: 0 .5rem 0 0; } + +.icon { + fill: var(--shadow); + margin: -.1rem .75rem 0 0; +} diff --git a/assets/components/header/notifications.vue b/assets/components/header/notifications.vue index 85ff5619..e603a887 100644 --- a/assets/components/header/notifications.vue +++ b/assets/components/header/notifications.vue @@ -26,10 +26,10 @@ >Alert
    - No notifications + >No notifications
      New 
      • + +device_hub + + diff --git a/assets/img/icons/earth.svg b/assets/img/icons/earth.svg new file mode 100644 index 00000000..e3279ab3 --- /dev/null +++ b/assets/img/icons/earth.svg @@ -0,0 +1,5 @@ + + +earth + + diff --git a/assets/img/icons/lan2.svg b/assets/img/icons/lan2.svg new file mode 100644 index 00000000..f50962ea --- /dev/null +++ b/assets/img/icons/lan2.svg @@ -0,0 +1,5 @@ + + +lan2 + + diff --git a/assets/img/icons/sphere.svg b/assets/img/icons/sphere.svg new file mode 100644 index 00000000..28df81d2 --- /dev/null +++ b/assets/img/icons/sphere.svg @@ -0,0 +1,5 @@ + + +sphere + + diff --git a/assets/js/curate.js b/assets/js/curate.js index c99ad999..ae79f5b8 100644 --- a/assets/js/curate.js +++ b/assets/js/curate.js @@ -200,7 +200,10 @@ function curateNotification(notification) { const curatedNotification = notification; curatedNotification.scene = curateRelease(notification.scene); - curatedNotification.alert = curateAlert(notification.alert.alert || notification.alert); + + if (notification.alert) { + curatedNotification.alert = curateAlert(notification.alert.alert || notification.alert); + } return curatedNotification; } diff --git a/assets/js/main.js b/assets/js/main.js index 7a8749ca..9473eecb 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -94,6 +94,9 @@ async function init() { config, }; }, + computed: { + theme() { return this.$store.state.ui.theme; }, + }, watch: { pageTitle(title) { if (title) { diff --git a/assets/js/ui/actions.js b/assets/js/ui/actions.js index 79191cfc..88afbe27 100644 --- a/assets/js/ui/actions.js +++ b/assets/js/ui/actions.js @@ -41,6 +41,7 @@ function initUiActions(store, _router) { ) { notifications( first: 10 + orderBy: CREATED_AT_DESC ) { id sceneId diff --git a/src/alerts.js b/src/alerts.js index 00cf2a96..cd58a142 100644 --- a/src/alerts.js +++ b/src/alerts.js @@ -57,7 +57,6 @@ async function notify(scenes) { LEFT JOIN users ON users.id = alerts.user_id LEFT JOIN releases_tags ON releases_tags.release_id = releases.id /* match updated IDs from input */ - WHERE users.id = :userId WHERE (releases.id = ANY(:sceneIds)) /* match tags */ AND (NOT EXISTS (SELECT alerts_tags.alert_id @@ -88,9 +87,25 @@ async function notify(scenes) { FROM alerts_entities WHERE alerts_entities.alert_id = alerts.id)) OR (releases.entity_id - = ANY(array(SELECT alerts_entities.entity_id - FROM alerts_entities - WHERE alerts_entities.alert_id = alerts.id)))) + = ANY(array( + /* include children of entities */ + WITH RECURSIVE included AS ( + SELECT entities.* + FROM alerts_entities + LEFT JOIN entities ON entities.id = alerts_entities.entity_id + WHERE alerts_entities.alert_id = alerts.id + + UNION ALL + + SELECT entities.* + FROM entities + INNER JOIN included ON included.id = entities.parent_id + ) + + SELECT included.id + FROM included + GROUP BY included.id + )))) GROUP BY releases.id, users.id, alerts.id; `, { sceneIds: scenes.map(scene => scene.id), @@ -117,7 +132,6 @@ async function updateNotification(notificationId, notification, sessionUser) { }); } - async function updateNotifications(notification, sessionUser) { console.log(notification, sessionUser.id);