From 74e06a2b8979c7eaa4f1e0af96b98dc54651937f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 17 Jul 2018 09:23:44 +0200 Subject: [PATCH] Display the posts of a group --- assets/css/pages/groups/sections/posts.css | 5 + assets/js/common/functionsSchema.js | 7 ++ assets/js/components/posts/interface.js | 25 +++++ assets/js/pages/groups/pages/group.js | 15 +++ assets/js/pages/groups/sections/posts.js | 110 +++++++++++++++++++++ system/config/dev.config.php | 2 + 6 files changed, 164 insertions(+) create mode 100644 assets/css/pages/groups/sections/posts.css create mode 100644 assets/js/pages/groups/sections/posts.js diff --git a/assets/css/pages/groups/sections/posts.css b/assets/css/pages/groups/sections/posts.css new file mode 100644 index 00000000..f67ae5a1 --- /dev/null +++ b/assets/css/pages/groups/sections/posts.css @@ -0,0 +1,5 @@ +/** + * Groups posts section stylesheet + * + * @author Pierre HUBERT + */ \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 7029b588..a59ad2fa 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1279,6 +1279,13 @@ var ComunicWeb = { membershipBlock: { //TODO : implement }, + + /** + * Posts sections + */ + posts: { + //TODO : implement + }, }, }, diff --git a/assets/js/components/posts/interface.js b/assets/js/components/posts/interface.js index affa4977..1df7c96a 100644 --- a/assets/js/components/posts/interface.js +++ b/assets/js/components/posts/interface.js @@ -31,6 +31,31 @@ ComunicWeb.components.posts.interface = { }, + /** + * Get a group posts + * + * @param {number} groupID The ID of the target group + * @param {int} lastPostID The ID of the last post loaded + * @param {function} callback + */ + get_group: function(groupID, lastPostID, callback){ + + //Load the previous posts to the loaded post if required + if(lastPostID > 0) + lastPostID--; + + //Prepare the API request + var APIuri = "posts/get_group"; + var params = { + groupID: groupID, + startFrom: lastPostID + }; + + //Make the request + ComunicWeb.common.api.makeAPIrequest(APIuri, params, true, callback); + + }, + /** * Get the list of the latest posts * diff --git a/assets/js/pages/groups/pages/group.js b/assets/js/pages/groups/pages/group.js index 86558ecd..2a8deea4 100644 --- a/assets/js/pages/groups/pages/group.js +++ b/assets/js/pages/groups/pages/group.js @@ -90,6 +90,21 @@ ComunicWeb.pages.groups.pages.group = { ComunicWeb.components.posts.form.display("group", id, postFormCol); } + //Display group posts + var postsRow = createElem2({ + appendTo: target, + type: "div", + class: "row group-page" + }); + + var postsCol = createElem2({ + appendTo: postsRow, + type: "div", + class: "col-md-6" + }); + + ComunicWeb.pages.groups.sections.posts.display(info, postsCol); + } } \ No newline at end of file diff --git a/assets/js/pages/groups/sections/posts.js b/assets/js/pages/groups/sections/posts.js new file mode 100644 index 00000000..767f3118 --- /dev/null +++ b/assets/js/pages/groups/sections/posts.js @@ -0,0 +1,110 @@ +/** + * Groups posts section + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.groups.sections.posts = { + + /** + * ID of the oldest known post + */ + _oldest_post_id: 0, + + /** + * Loading message + */ + _loading_msg: null, + + /** + * Display the section + * + * @param {Object} info Information about the related group + * @param {HTMLElement} target The target for the section + */ + display: function(info, target){ + + //Reset posts counter + this._oldest_post_id = 0; + + //Create posts target + var postsBody = createElem2({ + appendTo: target, + type: "div", + class: "box box-primary" + }); + + var postsBody = createElem2({ + appendTo: postsBody, + type: "div", + class: "box-body" + }); + + //Display loading message + this._loading_msg = ComunicWeb.common.messages.createCalloutElem( + "Loading", "Please wait while we load this group posts...", "info"); + postsBody.appendChild(this._loading_msg); + + this._refresh_list(info, postsBody); + }, + + /** + * Refresh the list of posts of this group + * + * @param {Object} info Information about the group + * @param {HTMLElement} target + */ + _refresh_list: function(info, target){ + + //Get the posts of the group + ComunicWeb.components.posts.interface.get_group(info.id, 0, function(result){ + + ComunicWeb.pages.groups.sections.posts._loading_msg.remove(); + + //Check for errors + if(result.error){ + target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Error", "Could not get this group posts!", "danger")); + return; + } + + + //Display the list of posts + ComunicWeb.pages.groups.sections.posts._display_list(result, target); + }); + + }, + + /** + * Display a list of posts + * + * @param {Array} list The list of posts + * @param {HTMLElement} target The target for the list + */ + _display_list: function(list, target){ + + var oldest_id = 0; + + list.forEach(function(post){ + + if(oldest_id == 0 || post.ID < oldest_id) + oldest_id = post.ID; + + //Display the post + ComunicWeb.components.posts.ui.display_post(post, target); + }); + + if(this._oldest_post_id == 0 && oldest_id == 0){ + + //Display message + var message = ComunicWeb.common.messages.createCalloutElem("No post to display", "This group has not sent any post yet.", "info"); + message.className += " noGroupPosts"; + target.appendChild(message); + + } + + if(this._oldest_post_id == 0 || this._oldest_post_id > oldest_id) + this._oldest_post_id = oldest_id; + }, + +}; \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 78044a69..1434e7b5 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -228,6 +228,7 @@ class Dev { //Groups sections "css/pages/groups/sections/header.css", "css/pages/groups/sections/membershipBlock.css", + "css/pages/groups/sections/posts.css", //Settings page @@ -440,6 +441,7 @@ class Dev { //Groups sections "js/pages/groups/sections/header.js", "js/pages/groups/sections/membershipBlock.js", + "js/pages/groups/sections/posts.js", //User settings page