mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 13:59:23 +00:00
Added cache system
This commit is contained in:
parent
aa74943b01
commit
f750165c3e
88
assets/js/common/cacheManager.js
Normal file
88
assets/js/common/cacheManager.js
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Global cache management system
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.common.cacheManager = {
|
||||
/**
|
||||
* @var {Array} cachesArray An array that contains all the functions that can empty caches
|
||||
*/
|
||||
__cachesCleaners: [],
|
||||
|
||||
/**
|
||||
* @var {Array} intervalsList A list of all created intervals
|
||||
*/
|
||||
__intervalsList: [],
|
||||
|
||||
/**
|
||||
* Register a new cache cleaner
|
||||
*
|
||||
* @param {Function} cacheCleaner The cache cleaner to register
|
||||
* @param {Boolean} persistant If it is set to true, the cache will have to be cleaned only on user logout
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
registerCacheCleaner: function(cacheCleaner, persistant){
|
||||
|
||||
//Add the function to the list
|
||||
this.__cachesCleaners.push([cacheCleaner, persistant]);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Register a new interval
|
||||
*
|
||||
* @param {Interval} interval The interval to register
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
registerInterval: function(interval){
|
||||
//Add the interval to the list
|
||||
this.__intervalsList.push(interval);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean the caches
|
||||
*
|
||||
* @param {Boolean} allCaches Specify wether persistent caches has to be cleaned or not
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
cleanCaches: function(allCaches){
|
||||
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("Empty all caches");
|
||||
|
||||
//Process each cleaning function
|
||||
for(i in this.__cachesCleaners){
|
||||
if(allCaches || !this.__cachesCleaners[i][1])
|
||||
eval(this.__cachesCleaners[i][0]+"()");
|
||||
}
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unset all intervals
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
cleanIntervals: function(){
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("Unset all intervals");
|
||||
|
||||
//Process each cleaning function
|
||||
for(i in this.__intervalsList){
|
||||
//if(allCaches || !this.__intervalsList[i][1])
|
||||
clearInterval(this.__intervalsList[i]);
|
||||
}
|
||||
|
||||
//Success
|
||||
return true
|
||||
}
|
||||
}
|
@ -30,12 +30,17 @@ var ComunicWeb = {
|
||||
/**
|
||||
* Initializate the application
|
||||
*/
|
||||
init: function(){},
|
||||
init: function(openPage){},
|
||||
|
||||
/**
|
||||
* Restart the application
|
||||
*/
|
||||
restart: function(){},
|
||||
|
||||
/**
|
||||
* Reset the application
|
||||
*/
|
||||
reset: function(complete, openPage){},
|
||||
},
|
||||
|
||||
/**
|
||||
@ -48,6 +53,13 @@ var ComunicWeb = {
|
||||
makeAPIrequest: function(apiURI, params, requireLoginTokens, nextAction){},
|
||||
},
|
||||
|
||||
/**
|
||||
* Global cache management system
|
||||
*/
|
||||
cacheManager:{
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Langs functions
|
||||
*/
|
||||
@ -203,6 +215,11 @@ var ComunicWeb = {
|
||||
*/
|
||||
getRequest: function(url, cache, GETnextAction){},
|
||||
|
||||
/**
|
||||
* Empty network cache
|
||||
*/
|
||||
emptyCache: function(){},
|
||||
|
||||
/**
|
||||
* Update the status of the network
|
||||
*/
|
||||
@ -372,6 +389,11 @@ var ComunicWeb = {
|
||||
* Given user IDs (in an array) the function return their names in a string
|
||||
*/
|
||||
getNames: function(usersID, afterNames){},
|
||||
|
||||
/**
|
||||
* Empty users cache
|
||||
*/
|
||||
emptyCache: function(){},
|
||||
},
|
||||
},
|
||||
|
||||
@ -481,14 +503,14 @@ var ComunicWeb = {
|
||||
* Friends list caching system
|
||||
*/
|
||||
list:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Friends bar
|
||||
*/
|
||||
bar:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
},
|
||||
|
||||
@ -514,13 +536,22 @@ var ComunicWeb = {
|
||||
* Conversations windows manager
|
||||
*/
|
||||
windows:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Interface between conversation UI and the API
|
||||
*/
|
||||
interface:{},
|
||||
interface:{
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Opened conversations caching system
|
||||
*/
|
||||
cachingOpened:{
|
||||
//TODO : implement
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -64,6 +64,18 @@ ComunicWeb.common.network = {
|
||||
xhrRequest.send(null);
|
||||
},
|
||||
|
||||
/**
|
||||
* Empty network cache
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
emptyCache: function(){
|
||||
this.cache = {};
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the status of the network
|
||||
*
|
||||
@ -102,5 +114,5 @@ ComunicWeb.common.network = {
|
||||
//Make sure the error message is visible on the screen
|
||||
byId("networkErrorMessage").style.display = "block";
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
@ -47,7 +47,7 @@ ComunicWeb.common.page = {
|
||||
this.emptyPage();
|
||||
|
||||
//Log message
|
||||
ComunicWeb.debug.logMessage("Display a wait splash screen the screen.");
|
||||
ComunicWeb.debug.logMessage("Display a wait splash screen on the screen.");
|
||||
|
||||
//Create message element (if required)
|
||||
if(message){
|
||||
|
@ -8,9 +8,10 @@ ComunicWeb.common.system = {
|
||||
/**
|
||||
* Initializate the application
|
||||
*
|
||||
* @param {String} Specify a page to open
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
init: function(){
|
||||
init: function(openPage){
|
||||
|
||||
//Display Comunic logo
|
||||
ComunicWeb.debug.displayComunicLogo();
|
||||
@ -30,7 +31,7 @@ ComunicWeb.common.system = {
|
||||
ComunicWeb.common.page.emptyPage();
|
||||
|
||||
//Show a wait splash screen
|
||||
ComunicWeb.common.page.showWaitSplashScreen();
|
||||
ComunicWeb.common.page.showWaitSplashScreen("Starting up...");
|
||||
|
||||
/**
|
||||
* Language initator
|
||||
@ -45,11 +46,16 @@ ComunicWeb.common.system = {
|
||||
/**
|
||||
* Open a page
|
||||
*/
|
||||
//Get current page URI
|
||||
var currentPage = ComunicWeb.common.url.getCurrentWebsiteURL();
|
||||
if(!openPage){
|
||||
//Get current page URI
|
||||
var currentPage = ComunicWeb.common.url.getCurrentWebsiteURL();
|
||||
|
||||
//Open a page
|
||||
ComunicWeb.common.page.openPage(currentPage);
|
||||
//Open a page
|
||||
ComunicWeb.common.page.openPage(currentPage);
|
||||
}
|
||||
else
|
||||
//Open specified page
|
||||
ComunicWeb.common.page.openPage(openPage);
|
||||
|
||||
//End of init
|
||||
ComunicWeb.debug.logMessage("Application is ready !");
|
||||
@ -66,8 +72,9 @@ ComunicWeb.common.system = {
|
||||
var autoRefresh = setInterval((function(){
|
||||
ComunicWeb.user.userLogin.refreshLoginState();
|
||||
}), 20000);
|
||||
ComunicWeb.common.cacheManager.registerInterval(autoRefresh);
|
||||
|
||||
//Sucess
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
@ -82,5 +89,29 @@ ComunicWeb.common.system = {
|
||||
|
||||
//Reload the page
|
||||
location.href = document.location;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the application
|
||||
*
|
||||
* @param {Boolean} complete Specify wether the cache cleaning has to be complete or not (for logout)
|
||||
* @param {String} openPage Specify a page to open once the application is restarted
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
reset: function(complete, openPage){
|
||||
//Show a wait splashscreen message
|
||||
ComunicWeb.common.page.showWaitSplashScreen("Reset the application in progress...");
|
||||
|
||||
//Clear intervals
|
||||
ComunicWeb.common.cacheManager.cleanIntervals();
|
||||
|
||||
//Clean caches
|
||||
ComunicWeb.common.cacheManager.cleanCaches(complete);
|
||||
|
||||
//Init the page again
|
||||
this.init(openPage);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
};
|
41
assets/js/components/conversations/cachingOpened.js
Normal file
41
assets/js/components/conversations/cachingOpened.js
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Opened conversations caching system
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.components.conversations.cachingOpened = {
|
||||
|
||||
__varName: "opened-conversations-ids",
|
||||
|
||||
/**
|
||||
* Add a new conversation ID in the list
|
||||
*
|
||||
* @param {Integer} conversationID The ID of the conversation to add
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get all conversations ID in the list
|
||||
*
|
||||
* @return {Array} An array with all opened conversations ID
|
||||
*/
|
||||
|
||||
/**
|
||||
* Empty the storage
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
emptyStorage: function(){
|
||||
|
||||
//Remove variables for session storage
|
||||
sessionStorage.removeItem(this.__varName);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Register cache cleaner
|
||||
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.conversations.cachingOpened.emptyStorage", true);
|
@ -182,7 +182,9 @@ ComunicWeb.components.conversations.list = {
|
||||
infos.listBox.rootElem.remove();
|
||||
|
||||
//Open the conversation (under construction)
|
||||
console.log("Open conversation ID: " + response.conversationID);
|
||||
ComunicWeb.components.conversations.manager.openConversation({
|
||||
conversationID: response.conversationID
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
@ -255,8 +257,10 @@ ComunicWeb.components.conversations.list = {
|
||||
//Remove conversations list
|
||||
listBox.rootElem.remove();
|
||||
|
||||
//Show conversation
|
||||
console.log("Open conversation ID: " + conversationInfos.ID);
|
||||
//Open conversation
|
||||
ComunicWeb.components.conversations.manager.openConversation({
|
||||
conversationID: conversationInfos.ID
|
||||
});
|
||||
}
|
||||
|
||||
//Add conversations last activity
|
||||
|
@ -79,4 +79,34 @@ ComunicWeb.components.conversations.manager = {
|
||||
ComunicWeb.components.conversations.list.display(this);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Open a conversation accordingly to specified informations
|
||||
*
|
||||
* @param {Object} infos Informations about the conversation to open
|
||||
* @info {Integer} conversationID The ID of the conversation to open
|
||||
* @return {Boolean} True or false depending of the success of the operation
|
||||
*/
|
||||
openConversation: function(infos){
|
||||
|
||||
//We check if a conversation ID was specified or not
|
||||
if(infos.conversationID){
|
||||
ComunicWeb.debug.logMessage("Open a conversation based on its ID");
|
||||
var conversationID = infos.conversationID;
|
||||
}
|
||||
else {
|
||||
//It is an error
|
||||
ComunicWeb.debug.logMessage("Don't know which conversation to open !");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("Opening conversation " + conversationID);
|
||||
|
||||
//Save conversation ID in session storage
|
||||
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
}
|
@ -62,8 +62,9 @@ ComunicWeb.components.friends.bar = {
|
||||
this.refresh(listFriendsElem);
|
||||
|
||||
//Remove previously existing interval
|
||||
if(this.refreshInterval)
|
||||
if(this.refreshInterval){
|
||||
clearInterval(this.refreshInterval);
|
||||
}
|
||||
|
||||
//Make the friend bar automaticaly refreshed
|
||||
this.refreshInterval = setInterval(function(){
|
||||
|
@ -89,4 +89,21 @@ ComunicWeb.components.friends.list = {
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Empty friends cache list
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
emptyCache: function(){
|
||||
|
||||
//Empty cache
|
||||
this.__list = {};
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//Register cache cleaner
|
||||
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.friends.list.emptyCache");
|
@ -20,11 +20,8 @@ ComunicWeb.pages.logout = {
|
||||
//Perform logout
|
||||
ComunicWeb.user.userLogin.logoutUser();
|
||||
|
||||
//Show a success notification
|
||||
ComunicWeb.common.notificationSystem.showNotification("Good bye, you successfully terminated your session !", "success", 3);
|
||||
|
||||
//Open login page
|
||||
ComunicWeb.common.page.openPage("home");
|
||||
//Clean all caches
|
||||
ComunicWeb.common.system.reset(true, "home");
|
||||
|
||||
//Remove overlay
|
||||
screenOverlay.remove();
|
||||
|
@ -200,4 +200,19 @@ ComunicWeb.user.userInfos = {
|
||||
afterNames(usersName);
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty users cache
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
emptyCache: function(){
|
||||
this.usersInfos = {};
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//Register cache cleaner
|
||||
ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.user.userInfos.emptyCache");
|
@ -56,6 +56,7 @@ $config['JSfiles'] = array(
|
||||
"%PATH_ASSETS%js/common/functionsSchema.js",
|
||||
|
||||
//App scripts
|
||||
"%PATH_ASSETS%js/common/cacheManager.js",
|
||||
"%PATH_ASSETS%js/common/network.js",
|
||||
"%PATH_ASSETS%js/pagesList.js",
|
||||
"%PATH_ASSETS%js/common/api.js",
|
||||
@ -84,6 +85,7 @@ $config['JSfiles'] = array(
|
||||
"%PATH_ASSETS%js/components/conversations/list.js",
|
||||
"%PATH_ASSETS%js/components/conversations/windows.js",
|
||||
"%PATH_ASSETS%js/components/conversations/interface.js",
|
||||
"%PATH_ASSETS%js/components/conversations/cachingOpened.js",
|
||||
"%PATH_ASSETS%js/components/userSelect/userSelect.js",
|
||||
|
||||
//User scripts
|
||||
|
Loading…
Reference in New Issue
Block a user