/*jshint node: true, -W106 */
'use strict';

/*
* Name : socket.js
* Module : Lib::PresentationTier::Routes
* Location : /lib/presentationTier
*
* History :
* 
* Version   Date         Programmer         Description
* =========================================================
* 0.0.1     2015-05-18   Samuele Zanella    Initial code
* =========================================================
*/

var Express = require('express');

function setAppExpressAndViewEngine(){
	var app = Express();
    app.set('view engine', 'ejs');
    app.set('views', __dirname + '/views');

    app.use(function (req, res, next) {
		console.log('Using the Norris module');
		next();
	});

    return app;
}

function Routes(exprApp, norrisNamespace) {
	if(exprApp===undefined || norrisNamespace===undefined || exprApp.lazyrouter===undefined ||
		typeof norrisNamespace !=='string' || norrisNamespace.length < 2 ||
		norrisNamespace.indexOf('/')!==0) {
		console.log('Error: 911');
		return;
	}
	
	this._norrisNamespace = norrisNamespace;

	this._exprApp=exprApp;

	this._app = setAppExpressAndViewEngine();

    this._app.use('/',Express.static(__dirname + '/../../frontend/app/views'));
    
    this._exprApp.use(this._norrisNamespace, this._app);
    
    console.log('end config routes \n'+ __dirname + '/views'+'  \n'+this._norrisNamespace+'\n'+__dirname + '/../../frontend/app/views');
}

Routes.prototype.addRoutingPath = function(namespace, filename) {
	console.log(namespace);
	console.log(typeof namespace);
	console.log(namespace.length);
	console.log(namespace.indexOf('/'));
	console.log(filename);
	console.log(typeof filename);
	console.log(filename.length);
	if(namespace===undefined || typeof namespace !=='string' || namespace.length < 2 ||
		namespace.indexOf('/')!==0 || filename === undefined || typeof filename !== 'string' ||
		filename.length <= 0) {
		console.log('Error: addRoutingPath');
		return false;
	}
	var nspNorris=this._norrisNamespace;
	var handle = function (req, res) {
		var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
		var norrisNamespace=req.protocol + '://' + req.get('host')+nspNorris;
		res.render(filename,{fullURL:fullUrl, norrisNamespace : norrisNamespace});
	};
	this._app.get(namespace, handle);
	return true;
};

module.exports = Routes;
@@ -880,25 +880,25 @@
 ce.length %3C 
-2
+1
  %7C%7C%0A%09%09norris
@@ -1449,25 +1449,63 @@
 ole.log(
-namespace
+'1');%0A%09console.log(namespace);%0A%09console.log('2'
 );%0A%09cons
@@ -1523,32 +1523,51 @@
 eof namespace);%0A
+%09console.log('3');%0A
 %09console.log(nam
@@ -1582,16 +1582,35 @@
 ength);%0A
+%09console.log('4');%0A
 %09console
@@ -1639,16 +1639,35 @@
 ('/'));%0A
+%09console.log('5');%0A
 %09console
@@ -1674,32 +1674,51 @@
 .log(filename);%0A
+%09console.log('6');%0A
 %09console.log(typ
@@ -1724,32 +1724,51 @@
 peof filename);%0A
+%09console.log('7');%0A
 %09console.log(fil
@@ -1862,17 +1862,17 @@
 ength %3C 
-2
+1
  %7C%7C%0A%09%09na

fix logs