From 979940fdb9d6b8ce73115bb6be17c23c1843d00a Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 22 Jan 2017 18:46:06 +0100 Subject: [PATCH] Added log system --- assets/js/common/debug.js | 78 ++++++++++++++++++++++++----- assets/js/common/errors.js | 18 +++++++ assets/js/common/functionsSchema.js | 48 ++++++++++++++++++ assets/js/common/jsFiles.js | 13 ++++- assets/js/common/page.js | 15 +++++- assets/js/pagesList.js | 3 +- corePage/config/dev.config.php | 5 +- index.php | 3 ++ 8 files changed, 165 insertions(+), 18 deletions(-) diff --git a/assets/js/common/debug.js b/assets/js/common/debug.js index bf6a35eb..f422ab9e 100644 --- a/assets/js/common/debug.js +++ b/assets/js/common/debug.js @@ -4,17 +4,69 @@ * @author Pierre HUBERT */ -/** - * Display message on browser console - * - * @param {String} message The message to show on browser console - */ -ComunicWeb.debug.logMessage = function(message){ - //We check we are not in production mode - if(ComunicWeb.__config.productionMode != 1){ - console.log("ComunicWebApp debug message", message); - } +ComunicWeb.debug = { - //Everything seems ok - return 0; -}; \ No newline at end of file + /** + * @var {Object} Internal log variable + */ + __log: {}, + + /** + * Display message on browser console + * + * @param {String} message The message to show on browser console + */ + 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; + }, + +} diff --git a/assets/js/common/errors.js b/assets/js/common/errors.js index 82069e16..3af55804 100644 --- a/assets/js/common/errors.js +++ b/assets/js/common/errors.js @@ -69,4 +69,22 @@ 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; } \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 2d5b559e..47e0e1dc 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -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(){}, } } \ No newline at end of file diff --git a/assets/js/common/jsFiles.js b/assets/js/common/jsFiles.js index ea356645..349e35ed 100644 --- a/assets/js/common/jsFiles.js +++ b/assets/js/common/jsFiles.js @@ -23,4 +23,15 @@ ComunicWeb.common.jsFiles.includeFile = function(fileURL){ //Everything is OK return true; -} \ No newline at end of file +} + +/** + * 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); +} diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 2beb4a04..ee8c2fd0 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -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); @@ -99,6 +100,13 @@ ComunicWeb.common.page = { if(!mainContenerElem){ 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(){ + + //} }; \ No newline at end of file diff --git a/assets/js/pagesList.js b/assets/js/pagesList.js index d44f4304..a7ce5e07 100644 --- a/assets/js/pagesList.js +++ b/assets/js/pagesList.js @@ -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", } }; \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 98ce7e17..a52e449a 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -48,4 +48,7 @@ $config['JSfiles'] = array( $config['languagesPath'] = "%PATH_ASSETS%js/langs/"; //Production mode -$config['productionMode'] = 0; \ No newline at end of file +$config['productionMode'] = 0; + +//Application version +$config['appVersion'] = "0.1"; \ No newline at end of file diff --git a/index.php b/index.php index 4472fe76..28bb8d0f 100644 --- a/index.php +++ b/index.php @@ -41,6 +41,9 @@ //Production mode productionMode: , + //AppVersion + appVersion: , + //Assets URL assetsURL: "",