mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Added log system
This commit is contained in:
		@@ -4,17 +4,69 @@
 | 
				
			|||||||
 * @author Pierre HUBERT
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ComunicWeb.debug = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var {Object} Internal log variable
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    __log: {},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Display message on browser console
 | 
					     * Display message on browser console
 | 
				
			||||||
     * 
 | 
					     * 
 | 
				
			||||||
     * @param {String} message The message to show 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
 | 
					        //We check we are not in production mode
 | 
				
			||||||
        if(ComunicWeb.__config.productionMode != 1){
 | 
					        if(ComunicWeb.__config.productionMode != 1){
 | 
				
			||||||
            console.log("ComunicWebApp debug message", message);
 | 
					            console.log("ComunicWebApp debug message", message);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Save log message
 | 
				
			||||||
 | 
					        this.saveLogMessage(message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Everything seems ok
 | 
					        //Everything seems ok
 | 
				
			||||||
        return 0;
 | 
					        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;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,3 +70,21 @@ ComunicWeb.common.error.fatalError = function(errorMessage, errorCode, errorData
 | 
				
			|||||||
    //Make an API request to submit error
 | 
					    //Make an API request to submit error
 | 
				
			||||||
	this.submitError("fatal", errorMessage, errorCode, errorData);
 | 
						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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -74,6 +74,11 @@ var ComunicWeb = {
 | 
				
			|||||||
             * Handle and show a fatal error
 | 
					             * Handle and show a fatal error
 | 
				
			||||||
             */
 | 
					             */
 | 
				
			||||||
            fatalError: function(errorMessage, errorCode, errorData){},
 | 
					            fatalError: function(errorMessage, errorCode, errorData){},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /**
 | 
				
			||||||
 | 
					             * Handle a 404 not found error
 | 
				
			||||||
 | 
					             */
 | 
				
			||||||
 | 
					            pageNotFound: function(){},
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
@@ -87,7 +92,30 @@ var ComunicWeb = {
 | 
				
			|||||||
         * Page functions
 | 
					         * Page functions
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        page: {
 | 
					        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
 | 
					             * Include a Javascript file
 | 
				
			||||||
             */
 | 
					             */
 | 
				
			||||||
            includeFile: function(fileURL){},
 | 
					            includeFile: function(fileURL){},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /**
 | 
				
			||||||
 | 
					             * Execute some source code contained in a variable
 | 
				
			||||||
 | 
					             */
 | 
				
			||||||
 | 
					            executeJSsource: function(source){},
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -106,9 +139,24 @@ var ComunicWeb = {
 | 
				
			|||||||
     * Debug functions
 | 
					     * Debug functions
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    debug:{
 | 
					    debug:{
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * @var {Object} Internal log variable
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        __log: {},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * Display message on browser console
 | 
					         * Display message on browser console
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        logMessage: function(message){},
 | 
					        logMessage: function(message){},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Save a new log message
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        saveLogMessage: function(message){},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Get log content in a string
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        getLogContent: function(){},
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -24,3 +24,14 @@ ComunicWeb.common.jsFiles.includeFile = function(fileURL){
 | 
				
			|||||||
    //Everything is OK
 | 
					    //Everything is OK
 | 
				
			||||||
    return true;
 | 
					    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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,8 +61,9 @@ ComunicWeb.common.page = {
 | 
				
			|||||||
     * Open a page
 | 
					     * Open a page
 | 
				
			||||||
     * 
 | 
					     * 
 | 
				
			||||||
     * @param {String} pageURI The URI to the 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
 | 
					        //Log message
 | 
				
			||||||
        ComunicWeb.debug.logMessage("Open the following page: " + pageURI);
 | 
					        ComunicWeb.debug.logMessage("Open the following page: " + pageURI);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,6 +101,13 @@ ComunicWeb.common.page = {
 | 
				
			|||||||
            mainConterElem = this.emptyPage(true);
 | 
					            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 object
 | 
				
			||||||
        return obj;
 | 
					        return obj;
 | 
				
			||||||
    }
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Load, parse and show a template
 | 
					     * 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} targetElem The target element where the template will be applied
 | 
				
			||||||
     * @param {Object} ResumeHERE
 | 
					     * @param {Object} ResumeHERE
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					    //getAndShowTemplate: function(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -17,7 +17,8 @@ ComunicWeb.pagesList = {
 | 
				
			|||||||
     * 404 Page not found
 | 
					     * 404 Page not found
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    notFound: {
 | 
					    notFound: {
 | 
				
			||||||
        pageTitle: "404 page not found"
 | 
					        pageTitle: "404 page not found",
 | 
				
			||||||
 | 
					        methodHandler: "ComunicWeb.common.error.pageNotFound",
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -49,3 +49,6 @@ $config['languagesPath'] = "%PATH_ASSETS%js/langs/";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//Production mode
 | 
					//Production mode
 | 
				
			||||||
$config['productionMode'] = 0;
 | 
					$config['productionMode'] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//Application version
 | 
				
			||||||
 | 
					$config['appVersion'] = "0.1";
 | 
				
			||||||
@@ -41,6 +41,9 @@
 | 
				
			|||||||
                //Production mode
 | 
					                //Production mode
 | 
				
			||||||
                productionMode: <?php echo config['productionMode']; ?>,
 | 
					                productionMode: <?php echo config['productionMode']; ?>,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //AppVersion
 | 
				
			||||||
 | 
					                appVersion: <?php echo config['appVersion']; ?>,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                //Assets URL
 | 
					                //Assets URL
 | 
				
			||||||
                assetsURL: "<?php echo config['pathAssets']; ?>",
 | 
					                assetsURL: "<?php echo config['pathAssets']; ?>",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user