From 3d1dd2cbed46fa2eef96e39c61abaec59022d74d Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 13 Jun 2017 16:42:09 +0200 Subject: [PATCH] Improved conversations rendering --- assets/css/components/conversations/list.css | 11 +++++ assets/js/common/functionsSchema.js | 5 +++ assets/js/common/shorcuts.js | 2 +- assets/js/components/conversations/list.js | 42 ++++++++++---------- assets/js/user/userInfos.js | 37 ++++++++++++++++- corePage/config/dev.config.php | 1 + 6 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 assets/css/components/conversations/list.css diff --git a/assets/css/components/conversations/list.css b/assets/css/components/conversations/list.css new file mode 100644 index 00000000..a1716009 --- /dev/null +++ b/assets/css/components/conversations/list.css @@ -0,0 +1,11 @@ +/** + * Conversations list + * + * @author Pierre HUBERT + */ + +.conversations-list-box .last-activity { + margin-left: 5px; + color: #777; + font-size: 10px; +} \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 61b19530..33164d9a 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -367,6 +367,11 @@ var ComunicWeb = { * Given a query, search for users and return the result */ search: function(query, afterSearch){}, + + /** + * Given user IDs (in an array) the function return their names in a string + */ + getNames: function(usersID, afterNames){}, }, }, diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index 69c8e6ac..92a19bcd 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -49,6 +49,6 @@ function userID(){ * @param {Boolean} forceRequest Force the request to be made * @return {Boolean} True for a success */ -function getUsersInfos(usersID, afterGetUserInfos, forceRequest){ +function getMultipleUsersInfos(usersID, afterGetUserInfos, forceRequest){ ComunicWeb.user.userInfos.getMultipleUsersInfos(usersID, afterGetUserInfos, forceRequest); } \ No newline at end of file diff --git a/assets/js/components/conversations/list.js b/assets/js/components/conversations/list.js index ed38914d..7fa9ec56 100644 --- a/assets/js/components/conversations/list.js +++ b/assets/js/components/conversations/list.js @@ -22,6 +22,9 @@ ComunicWeb.components.conversations.list = { //Change box title listBox.boxTitle.innerHTML = "Conversations"; + //Change box root elem class + listBox.rootElem.className += " conversations-list-box"; + //Remove footer listBox.boxFooter.remove(); @@ -243,6 +246,19 @@ ComunicWeb.components.conversations.list = { console.log(conversationInfos); //DEBUG - temporary + + //Add conversations last activity + var lastActivityElem = createElem("small", linkElem); + lastActivityElem.className = "pull-right last-activity"; + var lastActivityIcon = createElem("i", lastActivityElem); + lastActivityIcon.className = "fa fa-clock-o"; + var lastActivityValueElem = createElem("span", lastActivityElem); + + //Calculate last conversation activity + var currentTime = ComunicWeb.common.date.time(); + lastActivityValueElem.innerHTML = " "+ComunicWeb.common.date.diffToStr(currentTime - conversationInfos.last_active); + + //Create the conversation name element var conversationNameElem = createElem("strong", linkElem); @@ -274,31 +290,17 @@ ComunicWeb.components.conversations.list = { } //Get users informations - getUsersInfos(firstMembers, function(usersInfo){ - //Prepare conversation name - var conversationName = ""; + ComunicWeb.user.userInfos.getNames(firstMembers, function(usersName){ - //Process users informations - for(i in usersInfo){ - if(usersInfo[i].firstName) - - //Add a coma if required - if(conversationName != "") - conversationName += ", "; - - conversationName += usersInfo[i].firstName + " " + usersInfo[i].lastName; - } - - //For converstions with many members - if(conversationInfos.members.length > 2) - conversationName += ", ..."; + //For conversations with many members (more than 3 - we musn't forget current user) + if(conversationInfos.members.length > 3) + usersName += ", ..."; //Apply conversation name - conversationNameElem.innerHTML = conversationName; - }) + conversationNameElem.innerHTML = usersName; + }); } - //Success return true; } diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index 7ec21560..11e0b8f1 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -164,5 +164,40 @@ ComunicWeb.user.userInfos = { afterSearch(usersInfos); }); }); - } + }, + + /** + * Given user IDs (in an array) the function return their names in a string + * + * @param {Array} usersID The users to return as a string + * @param {Function} afterNames What to do once we have got the names + * @return {Boolean} True for a success + */ + getNames: function(usersID, afterNames){ + //Get users informations + this.getMultipleUsersInfos(usersID, function(usersInfo){ + + //Check for errors + if(usersInfo.error){ + afterNames("Error"); + } + + //Prepare conversation name + var usersName = ""; + + //Process users informations + for(i in usersInfo){ + if(usersInfo[i].firstName) + + //Add a coma if required + if(usersName != "") + usersName += ", "; + + usersName += usersInfo[i].firstName + " " + usersInfo[i].lastName; + } + + //Perform next action with result + afterNames(usersName); + }); + }, } \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 38a91bda..4b65e2d7 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -31,6 +31,7 @@ $config['CSSfiles'] = array( "%PATH_ASSETS%css/components/friends/friendsBar.css", "%PATH_ASSETS%css/components/conversations/manager.css", "%PATH_ASSETS%css/components/conversations/windows.css", + "%PATH_ASSETS%css/components/conversations/list.css", "%PATH_ASSETS%css/components/userSelect/userSelect.css", );