From bd888f0f4779ec53851d70bfcd1f1cbfd3ed646c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 20 Jul 2018 13:51:13 +0200 Subject: [PATCH] Can display notifications related to groups posts. --- .../js/components/notifications/dropdown.js | 36 ++++++++++++------- assets/js/components/notifications/ui.js | 11 +++++- assets/js/components/notifications/utils.js | 23 +++++++++++- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/assets/js/components/notifications/dropdown.js b/assets/js/components/notifications/dropdown.js index 915e7299..74897afb 100644 --- a/assets/js/components/notifications/dropdown.js +++ b/assets/js/components/notifications/dropdown.js @@ -166,24 +166,34 @@ ComunicWeb.components.notifications.dropdown = { return; } + //Get information about the groups + var groups_id = ComunicWeb.components.notifications.utils.get_groups_id(result); + getInfoMultipleGroups(groups_id, function(groups){ - //Empty the target list - list.innerHTML = ""; + //Check for errors + if(groups.error) + return notify("Could not get groups information!", "danger"); - //Process the list of notifications - for (var i = 0; i < result.length; i++) { - const notification = result[i]; - - //Display the notification - ComunicWeb.components.notifications.ui.display_notification(notification, list, users); - } + //Empty the target list + list.innerHTML = ""; - //Display a message if there isn't any notification to display - if(result.length == 0){ + //Process the list of notifications + for (var i = 0; i < result.length; i++) { + const notification = result[i]; + + //Display the notification + ComunicWeb.components.notifications.ui.display_notification(notification, list, users, groups); + } - list.innerHTML = "
  • You do not have any notification yet.
  • "; + //Display a message if there isn't any notification to display + if(result.length == 0){ - } + list.innerHTML = "
  • You do not have any notification yet.
  • "; + + } + + }); + }, false); diff --git a/assets/js/components/notifications/ui.js b/assets/js/components/notifications/ui.js index 37629e33..453140b1 100644 --- a/assets/js/components/notifications/ui.js +++ b/assets/js/components/notifications/ui.js @@ -13,8 +13,9 @@ ComunicWeb.components.notifications.ui = { * @param {HTMLElement} target The target of the notification * @param {Object} users Informations about users that might be required * to display the notification + * @param {Object} groups Information about the potential related groups */ - display_notification: function(data, target, users){ + display_notification: function(data, target, users, groups){ //Generate the informations about the notifications var from_user = users["user-"+data.from_user_id]; @@ -49,6 +50,7 @@ ComunicWeb.components.notifications.ui = { message += " "; //Notification target + //User page if(data.from_container_type == "user_page"){ if(data.from_user_id == data.from_container_id) @@ -58,6 +60,13 @@ ComunicWeb.components.notifications.ui = { } + //Group page + if(data.from_container_type == "group_page"){ + message += "on the group "+groups[data.from_container_id].name+"."; + } + + + //Create notification action var action = function(){ diff --git a/assets/js/components/notifications/utils.js b/assets/js/components/notifications/utils.js index 7b9d429d..a0bc88ff 100644 --- a/assets/js/components/notifications/utils.js +++ b/assets/js/components/notifications/utils.js @@ -28,6 +28,27 @@ ComunicWeb.components.notifications.utils = { return users; - } + }, + + /** + * Get the ID of the groups related to the notifications + * + * @param {Array} list The list to process + * @return {Array} The list of target groups IDs + */ + get_groups_id: function(list){ + + var groups = []; + + list.forEach(function(notif){ + + if(!groups.includes(notif.from_container_id) && notif.from_container_type == "group_page") + groups.push(notif.from_container_id); + + }); + + return groups; + + }, } \ No newline at end of file