Added log system

This commit is contained in:
Pierre 2017-01-22 18:46:06 +01:00
parent 677b4c33d7
commit 979940fdb9
8 changed files with 165 additions and 18 deletions

View File

@ -4,17 +4,69 @@
* @author Pierre HUBERT
*/
/**
ComunicWeb.debug = {
/**
* @var {Object} Internal log variable
*/
__log: {},
/**
* Display message on browser console
*
* @param {String} message The message to show on browser console
*/
ComunicWeb.debug.logMessage = function(message){
logMessage: function(message){
//We check we are not in production mode
if(ComunicWeb.__config.productionMode != 1){
console.log("ComunicWebApp debug message", message);
}
//Save log message
this.saveLogMessage(message);
//Everything seems ok
return 0;
};
},
/**
* Save a new log message
*
* @param {String} message The message to store
*/
saveLogMessage: function(message){
//Get current timestamp
var timeStamp = new Date().getTime();
//Get a random number for log ID
var logElemId = Math.random();
//Save the new message
this.__log[logElemId] = {
timeStamp: timeStamp,
message: message,
}
//Everything seems to be OK
return 0;
},
/**
* Get log content into a String
*
* @return {String} The log parsed into strings
*/
getLogContent: function(){
//Prepare return
var logString = "---ComunicWebApp v"+ComunicWeb.__config.appVersion+" ---\n";
//Process each line of the log
for(i in this.__log){
logString += i + " \t " + this.__log[i].timeStamp + " \t " + this.__log[i].message + "\n";
}
//Return result
return logString;
},
}

View File

@ -70,3 +70,21 @@ ComunicWeb.common.error.fatalError = function(errorMessage, errorCode, errorData
//Make an API request to submit error
this.submitError("fatal", errorMessage, errorCode, errorData);
}
/**
* Handle and show a 404 not found error message
*
* @return {Boolean} True for a success
*/
ComunicWeb.common.error.pageNotFound = function(){
alert("404 not found");
//Report error
var errorData = {
pageURL: location.href,
};
this.submitError("normal", "Page not found", "404", errorData);
//Everything seems to be OK
return true;
}

View File

@ -74,6 +74,11 @@ var ComunicWeb = {
* Handle and show a fatal error
*/
fatalError: function(errorMessage, errorCode, errorData){},
/**
* Handle a 404 not found error
*/
pageNotFound: function(){},
},
/**
@ -87,7 +92,30 @@ var ComunicWeb = {
* Page functions
*/
page: {
/**
* Empty current page
*/
emptyPage: function(createWrapper){},
/**
* Show a full wait splash screen
*/
showWaitSplashScreen: function(){},
/**
* Open a page
*/
openPage: function(pageURI, additionnalData){},
/**
* Prepare a template load by specifying datas
*/
prepareLoadTemplate: function(){},
/**
* Load, parse and show a template
*/
//Not implemented yet
},
/**
@ -99,6 +127,11 @@ var ComunicWeb = {
* Include a Javascript file
*/
includeFile: function(fileURL){},
/**
* Execute some source code contained in a variable
*/
executeJSsource: function(source){},
},
},
@ -106,9 +139,24 @@ var ComunicWeb = {
* Debug functions
*/
debug:{
/**
* @var {Object} Internal log variable
*/
__log: {},
/**
* Display message on browser console
*/
logMessage: function(message){},
/**
* Save a new log message
*/
saveLogMessage: function(message){},
/**
* Get log content in a string
*/
getLogContent: function(){},
}
}

View File

@ -24,3 +24,14 @@ ComunicWeb.common.jsFiles.includeFile = function(fileURL){
//Everything is OK
return true;
}
/**
* Execute some source code contained in a variable
*
* @param {String} source The source code to execute
*/
ComunicWeb.common.jsFiles.executeJSsource = function(source){
var jsSourceContainer = document.createElement("script");
jsSourceContainer.innerHTML = source;
document.body.appendChild(jsSourceContainer);
}

View File

@ -61,8 +61,9 @@ ComunicWeb.common.page = {
* Open a page
*
* @param {String} pageURI The URI to the page
* @param {Object} additionnalData Additionnal data to pass to the new page
*/
openPage: function(pageURI){
openPage: function(pageURI, additionnalData){
//Log message
ComunicWeb.debug.logMessage("Open the following page: " + pageURI);
@ -100,6 +101,13 @@ ComunicWeb.common.page = {
mainConterElem = this.emptyPage(true);
}
//Check if some additionnal data was specified
if(!additionnalData)
additionnalData = {};
//Call the method related to the page
},
/**
@ -116,7 +124,7 @@ ComunicWeb.common.page = {
//Return object
return obj;
}
},
/**
* Load, parse and show a template
@ -124,4 +132,7 @@ ComunicWeb.common.page = {
* @param {Object} targetElem The target element where the template will be applied
* @param {Object} ResumeHERE
*/
//getAndShowTemplate: function(){
//}
};

View File

@ -17,7 +17,8 @@ ComunicWeb.pagesList = {
* 404 Page not found
*/
notFound: {
pageTitle: "404 page not found"
pageTitle: "404 page not found",
methodHandler: "ComunicWeb.common.error.pageNotFound",
}
};

View File

@ -49,3 +49,6 @@ $config['languagesPath'] = "%PATH_ASSETS%js/langs/";
//Production mode
$config['productionMode'] = 0;
//Application version
$config['appVersion'] = "0.1";

View File

@ -41,6 +41,9 @@
//Production mode
productionMode: <?php echo config['productionMode']; ?>,
//AppVersion
appVersion: <?php echo config['appVersion']; ?>,
//Assets URL
assetsURL: "<?php echo config['pathAssets']; ?>",