mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Can get information about multiple groups and cache them.
This commit is contained in:
		@@ -1013,6 +1013,13 @@ var ComunicWeb = {
 | 
			
		||||
			utils: {
 | 
			
		||||
				//TODO : implement
 | 
			
		||||
			},
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * Groups information
 | 
			
		||||
			 */
 | 
			
		||||
			info: {
 | 
			
		||||
				//TODO : implement
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		/**
 | 
			
		||||
 
 | 
			
		||||
@@ -151,3 +151,23 @@ function openConversation(id){
 | 
			
		||||
function notify(message, type, duration, title){
 | 
			
		||||
    ComunicWeb.common.notificationSystem.showNotification(message, type, duration, title)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get information about a single group
 | 
			
		||||
 * 
 | 
			
		||||
 * @param {Number} id The ID of the group to fetch
 | 
			
		||||
 * @param {Function} callback
 | 
			
		||||
 */
 | 
			
		||||
function getInfoGroup(id, callback){
 | 
			
		||||
    ComunicWeb.components.groups.info.getInfo(id, callback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get information about multiple groups
 | 
			
		||||
 * 
 | 
			
		||||
 * @param {Array} IDs The IDs of the groups to get information about
 | 
			
		||||
 * @param {Function} callback Callback to call once we have information about the group
 | 
			
		||||
 */
 | 
			
		||||
function getInfoMultipleGroups(IDs, callback){
 | 
			
		||||
    ComunicWeb.components.groups.info.getInfoMultiple(IDs, callback);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										113
									
								
								assets/js/components/groups/info.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								assets/js/components/groups/info.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Groups information management
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
ComunicWeb.components.groups.info = {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Group information cache
 | 
			
		||||
	 */
 | 
			
		||||
	_cache: {},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information about a single group
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Number} id The ID of the target group
 | 
			
		||||
	 * @param {Function} callback
 | 
			
		||||
	 */
 | 
			
		||||
	getInfo: function(id, callback){
 | 
			
		||||
 | 
			
		||||
		//First, check if the group is cached or not
 | 
			
		||||
		if(this._cache[id])
 | 
			
		||||
			return callback(this._cache[id]);
 | 
			
		||||
		
 | 
			
		||||
		//Then query the server, if required
 | 
			
		||||
		ComunicWeb.components.groups.interface.getInfo(id, function(result){
 | 
			
		||||
 | 
			
		||||
			//Check for errors
 | 
			
		||||
			if(result.error)
 | 
			
		||||
				return callback(result);
 | 
			
		||||
 | 
			
		||||
			//Save group information
 | 
			
		||||
			ComunicWeb.components.groups.info._cache[id] = result;
 | 
			
		||||
 | 
			
		||||
			//Call callback
 | 
			
		||||
			callback(result);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information about a multiple groups
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Array} list The list of the IDs of the group to get information about
 | 
			
		||||
	 * @param {Function} callback
 | 
			
		||||
	 */
 | 
			
		||||
	getInfoMultiple: function(list, callback){
 | 
			
		||||
 | 
			
		||||
		//First, check which group are unknown in the cache
 | 
			
		||||
		var toFetch = Array();
 | 
			
		||||
 | 
			
		||||
		list.forEach(function(id){
 | 
			
		||||
			if(!ComunicWeb.components.groups.info._cache[id])
 | 
			
		||||
				toFetch.push(id);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if(toFetch.length == 0){
 | 
			
		||||
			this.getInfoMultiplePreCallback(list, callback);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Perform the request over the server
 | 
			
		||||
		ComunicWeb.components.groups.interface.getInfoMultiple(toFetch, function(result){
 | 
			
		||||
 | 
			
		||||
			//Check for errors
 | 
			
		||||
			if(result.error)
 | 
			
		||||
				return notify("Could not get information about the groups!", "danger");
 | 
			
		||||
			
 | 
			
		||||
			//Process the list of groups
 | 
			
		||||
			for(i in result){
 | 
			
		||||
				
 | 
			
		||||
				//Save group information in the cache
 | 
			
		||||
				ComunicWeb.components.groups.info._cache[result[i].id] = result[i];
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			//Call callback
 | 
			
		||||
			ComunicWeb.components.groups.info.getInfoMultiplePreCallback(list, callback);
 | 
			
		||||
 | 
			
		||||
		});
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get multiple information pre-callback
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Array} list The list of the IDs of teh group to get information about
 | 
			
		||||
	 * @param {Function} callback
 | 
			
		||||
	 */
 | 
			
		||||
	getInfoMultiplePreCallback: function(list, callback){
 | 
			
		||||
 | 
			
		||||
		var groupInfo = {};
 | 
			
		||||
 | 
			
		||||
		list.forEach(function(id){
 | 
			
		||||
			groupInfo[id] = ComunicWeb.components.groups.info._cache[id];
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Call callback
 | 
			
		||||
		callback(groupInfo);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Clear cache
 | 
			
		||||
	 */
 | 
			
		||||
	clearCache: function(){
 | 
			
		||||
		this._cache = {};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//Register cache cleaner
 | 
			
		||||
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.groups.info.clearCache");
 | 
			
		||||
@@ -64,6 +64,21 @@ ComunicWeb.components.groups.interface = {
 | 
			
		||||
		ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information about multiple groups
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Array} list The IDs of the groups to get
 | 
			
		||||
	 * @param {Function} callback
 | 
			
		||||
	 */
 | 
			
		||||
	getInfoMultiple: function(list, callback){
 | 
			
		||||
		//Perform the request over the API
 | 
			
		||||
		var apiURI = "groups/get_multiple_info";
 | 
			
		||||
		var params = {
 | 
			
		||||
			list: list
 | 
			
		||||
		};
 | 
			
		||||
		ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get advanced information about a group
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -392,6 +392,7 @@ class Dev {
 | 
			
		||||
			//Groups component
 | 
			
		||||
			"js/components/groups/interface.js",
 | 
			
		||||
			"js/components/groups/utils.js",
 | 
			
		||||
			"js/components/groups/info.js",
 | 
			
		||||
 | 
			
		||||
			//Virtual directory component
 | 
			
		||||
			"js/components/virtualDirectory/interface.js",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user