Commit 6e39dd8c authored by Marc Duez's avatar Marc Duez

com.js : rework myConsole > console ( override default javascript console)

parent 19ebae45
......@@ -38,7 +38,7 @@
<body>
<div id="popup-container">
<span class="closeButton" onclick="myConsole.closePopupMsg()">X</span>
<span class="closeButton" onclick="console.closePopupMsg()">X</span>
<div id="popup-msg">
<noscript>
<style type="text/css">
......@@ -231,12 +231,12 @@
<div id="adminSelector" class="selector"><div>
<input type="checkbox" onclick="$('.menu-highlight').toggle()">highlight menu</input><br>
<input type="checkbox" onclick=" this.checked ? $('#fps').css('display', '') : $('#fps').css('display', 'none');">display fps</input></br>
<input type="checkbox" onclick=" this.checked ? myConsole.openLog() : myConsole.closeLog() ;">log</input>
<input type="checkbox" onclick=" this.checked ? console.openLog() : console.closeLog() ;">log</input>
<div class="buttonSelector" onclick="m.changeTimeFormat('delta_date_no_zero', true)"><input type="radio" name="time" value="delta_date_no_zero">day after first sample (no zero)</input></div>
</div></div>
</div>
<div id="logo" style="float: right;" onclick="myConsole.popupMsg(myConsole.msg.welcome)">Vidjil <span class='logo'>(beta)</span></div>
<div id="logo" style="float: right;" onclick="console.log({'type': 'popup', 'default':'welcome'})">Vidjil <span class='logo'>(beta)</span></div>
<div class="menu" style="float: right"> <a href="help" target="_blank">help</a></div>
......@@ -307,16 +307,22 @@
<div id="frame-container"></div>
<div id="data-container">
<span class="closeButton" onclick="myConsole.closeDataBox()">X</span>
<span class="closeButton" onclick="console.closeDataBox()">X</span>
<div id="data-msg"></div>
</div>
<div id="db_div">
<span class="closeButton" onclick="db.close()">X</span>
<div id="db_msg"></div>
</div>
<div id="flash_container"></div>
<div id="log_container"></div>
<form id="form"></form>
......
......@@ -5,7 +5,7 @@ requirejs.config({
jquery: 'jquery-2.1.1.min'
}
});
require(["d3.v3",
"jquery.form",
"StackBlur",
......@@ -35,10 +35,15 @@ require(["d3.v3",
"../crossDomain",
"../pdf",
"../database",
"../conf",
"../stats",
"../shortcut",
"../export"
], function(){
require(["../main"]);
});
try {
require(["../conf"], function(){
require(["../main"]);
})
}catch(err) {
require(["../main"]);
}
});
\ No newline at end of file
......@@ -260,7 +260,7 @@ Builder.prototype = {
.hide('fast')
self.build_settings()
}else{
myConsole.popupMsg("expected input between 0.0001 and 1")
console.log({"type": "popup", "msg": "expected input between 0.0001 and 1"});
}
}
......@@ -535,7 +535,6 @@ Builder.prototype = {
},
toggle_left_container: function () {
console.log("plop")
var self = this
var elem = $("#left-container")
......@@ -659,7 +658,7 @@ Builder.prototype = {
infoTime.appendChild(document.createTextNode("Info"));
infoTime.className = "button_right"
infoTime.onclick = function () {
myConsole.dataBox(self.m.getPointHtmlInfo(self.m.t));
console.dataBox(self.m.getPointHtmlInfo(self.m.t));
}
div_point.appendChild(infoTime)
......
......@@ -97,7 +97,7 @@ Clone.prototype = {
*
* */
changeName: function (newName) {
myConsole.log("changeName() (clone " + this.hash + " <<" + newName + ")");
console.log("changeName() (clone " + this.hash + " <<" + newName + ")");
this.c_name = newName;
this.m.updateElem([this.hash]);
this.m.analysisHasChanged = true
......@@ -354,7 +354,7 @@ Clone.prototype = {
changeTag: function (newTag) {
newTag = "" + newTag
newTag = newTag.replace("tag", "");
myConsole.log("changeTag() (clone " + this.hash + " <<" + newTag + ")");
console.log("changeTag() (clone " + this.hash + " <<" + newTag + ")");
this.tag = newTag;
this.m.updateElem([this.hash]);
this.m.analysisHasChanged = true;
......@@ -546,7 +546,7 @@ Clone.prototype = {
},
unselect: function () {
myConsole.log("unselect() (clone " + this.hash + ")")
console.log("unselect() (clone " + this.hash + ")")
if (this.select) {
this.select = false;
}
......
......@@ -24,17 +24,18 @@
/* Com object display/store system message
*
* */
function Com(flash_id, log_id, popup_id, data_id) {
function Com(flash_id, log_id, popup_id, data_id, default_console) {
this.flash_id = flash_id;
this.log_id = log_id;
this.popup_id = popup_id;
this.data_id = data_id;
this.default = default_console;
this.min_priority = 1; // minimum required to display message
this.min_priority_console = 0;
this.log_container = document.getElementById(this.log_id);
BUTTON_CLOSE_POPUP = "</br></br> <div class='center' > <button onclick='myConsole.closePopupMsg()'>ok</button></div>",
BUTTON_CLOSE_POPUP = "</br></br> <div class='center' > <button onclick='console.closePopupMsg()'>ok</button></div> ",
this.msg = {
"align_error": "Error &ndash; connection to align server ("+return_URL_CGI()+") failed"
......@@ -81,13 +82,13 @@ function Com(flash_id, log_id, popup_id, data_id) {
+ "</br> <a href='http://www.mozilla.org/'> Firefox </a> "
+ "</br> <a href='www.google.com/chrome/'> Chrome </a> "
+ "</br> <a href='http://www.chromium.org/getting-involved/download-chromium'> Chromium </a> "
+ "</br></br> <div class='center' > <button onclick='popupMsg(msg.welcome)'>I want to try anyway</button></div>",
+ "</br></br> <div class='center' > <button onclick='popupMsg(msg.welcome)'>I want to try anyway</button></div> ",
"database_timeout": "Cannot connect database, please retry in a few seconds",
"database_timeout": "Cannot connect database, please retry in a few seconds ",
"save_analysis": "You made some changes in the analysis of the previous patient"
+ "</br>that were not saved (patients → save analysis)."
+ "</br>These changes will now be lost, do you want to proceed anyway?"
+ "</br>These changes will now be lost, do you want to proceed anyway? "
}
......@@ -95,6 +96,28 @@ function Com(flash_id, log_id, popup_id, data_id) {
Com.prototype = {
log: function(obj){
if (typeof obj !== 'object'){
this.default.log(obj)
}else{
var text = ""
if (typeof obj.default != "undefined") text += this.msg[obj.default]
if (typeof obj.msg != "undefined") text += obj.msg
switch (obj.type) {
case "flash":
this.flash(obj.msg, obj.priority)
break;
case "popup":
this.popupMsg(obj.msg)
break;
case "log":
this.customLog(obj.msg, obj.priority)
break;
}
}
},
/* display a flash message if priority level is sufficient
* and print message in log
* */
......@@ -124,7 +147,7 @@ Com.prototype = {
/* print message in log_container if priority level is sufficient
*
* */
log: function(str, priority){
customLog: function(str, priority){
priority = typeof priority !== 'undefined' ? priority : 0;
var self = this;
......@@ -144,7 +167,7 @@ Com.prototype = {
}else{
if (priority >= this.min_priority_console)
console.log(str)
this.default.log(str)
}
},
......
......@@ -88,7 +88,7 @@ Database.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
self.check_cert()
}
......@@ -103,7 +103,7 @@ Database.prototype = {
+ "Your browser currently does not recognize our SSL certificate. </br>"
+ "To use the sample database, you need to accept this certificate and/or tag this website as a trusted one. </br>"
+ "<a href='"+DB_ADDRESS+"'>Follow this link<a/>"
myConsole.popupMsg(msg)
console.log({"type": "popup", "msg": msg})
}
},
......@@ -163,7 +163,7 @@ Database.prototype = {
}
//TODO server need to return message priority too ( 0=console, 1=ok, 2=error)
if (res.message) myConsole.flash("database : " + res.message , 1)
if (res.message) console.log({"type": "flash", "msg": "database : " + res.message , "priority": 1})
return res
......@@ -193,9 +193,9 @@ Database.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
myConsole.popupMsg(request.responseText);
console.log({"type": "popup", "msg": request.responseText})
}
}
});
......@@ -218,7 +218,7 @@ Database.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
var nexts = $('#login_form').attr('action').split("&")
var next = "patient/index"
......@@ -289,9 +289,9 @@ Database.prototype = {
},
error: function (request, status, error) {
if(status==="timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
myConsole.popupMsg(request + " " + status + " " + error);
console.log({"type": "popup", "msg": request + " " + status + " " + error});
}
}
});
......@@ -335,11 +335,11 @@ Database.prototype = {
url: self.db_address + controller_name + "?" + this.argsToStr(args),
xhrFields: {withCredentials: true},
success: function (result) {
myConsole.flash(result)
console.log({"type": "flash", "msg": result , "priority": 1});
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
self.call("patient/index")
}
......@@ -371,13 +371,13 @@ Database.prototype = {
list.appendChild(a);
}
myConsole.closePopupMsg()
if (m.analysisHasChanged){
m.analysisHasChanged = false;
myConsole.popupMsg( myConsole.msg.save_analysis +
"<div class=\'center\'> <button onclick=\'db.load_data("+JSON.stringify(args)+",\""+filename+"\")\'>Continue</button> "
+" <button onclick='myConsole.closePopupMsg()'>Cancel</button> </div>"
)
console.log({"type": "popup",
"default" : "save_analysis",
"msg": "<div class=\'center\'> <button onclick=\'db.load_data("+JSON.stringify(args)+",\""+filename+"\")\'>Continue</button> "
+" <button onclick='console.closePopupMsg()'>Cancel</button> </div>",
"priority": 2});
return
}
......@@ -396,9 +396,9 @@ Database.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout + " - unable to access patient data", 1)
console.log({"type": "flash", "default" : "database_timeout", "msg" : " - unable to access patient data" , "priority": 1});
} else {
myConsole.popupMsg(request.responseText);
console.log({"type": "popup", "msg": request.responseText});
}
}
});
......@@ -418,13 +418,12 @@ Database.prototype = {
load_custom_data: function(args) {
var self=this;
myConsole.closePopupMsg()
if (m.analysisHasChanged){
m.analysisHasChanged = false;
myConsole.popupMsg( myConsole.msg.save_analysis +
"<div class=\'center\'> <button onclick=\'db.load_data("+JSON.stringify(args)+",\""+filename+"\")\'>Continue</button> "
+" <button onclick='myConsole.closePopupMsg()'>Cancel</button> </div>"
)
console.log({"type": "popup",
"default" : "save_analysis",
"msg": "<div class=\'center\'> <button onclick=\'db.load_data("+JSON.stringify(args)+",\""+filename+"\")\'>Continue</button> "
+" <button onclick='console.closePopupMsg()'>Cancel</button> </div>"});
return
}
......@@ -454,9 +453,9 @@ Database.prototype = {
error: function (request, status, error) {
self.m.resume()
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout + " - unable to access patient data", 1)
console.log({"type": "flash", "default" : "database_timeout", "msg": " - unable to access patient data" , "priority": 1});
} else {
myConsole.popupMsg(request.responseText);
console.log({"type": "popup", "msg": request.responseText});
}
}
});
......@@ -477,9 +476,9 @@ Database.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout + " - unable to access saved analysis", 1)
console.log({"type": "flash", "default" : "database_timeout", "msg": " - unable to access patient data" , "priority": 1});
} else {
myConsole.popupMsg(request.responseText);
console.log({"type": "popup", "msg": request.responseText});
}
}
});
......@@ -509,21 +508,21 @@ Database.prototype = {
success: function (result) {
try {
var res = jQuery.parseJSON(result);
if (res.message) myConsole.flash("database : " + res.message , 1)
if (res.message) console.log({"type": "flash", "msg": "database : " + res.message , "priority": 1});
self.m.analysisHasChanged = false
}
catch(err){}
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout + " - unable to save analysis", 2);
console.log({"type": "flash", "default" : "database_timeout", "msg": " - unable to save analysis" , "priority": 2});
} else {
myConsole.flash("server : save analysis error : "+request.responseText, 2);
console.log({"type": "flash", "msg": "server : save analysis error : "+request.responseText , "priority": 2});
}
}
});
}else{
myConsole.flash("server : save analysis error : this file is nor from the database", 2)
console.log({"type": "flash", "msg": "server : save analysis error : this file is nor from the database" , "priority": 2});
}
},
......@@ -739,11 +738,11 @@ Uploader.prototype = {
},
error: function (request, status, error) {
if (status === "timeout") {
myConsole.flash(myConsole.msg.database_timeout, 2)
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
if (status !== "abort"){
self.queue[id].status = "upload_error"
myConsole.flash("upload " + self.queue[id].filename + " : " + status, 2)
console.log({"type": "flash", "msg": "upload " + self.queue[id].filename + " : " + status , "priority": 2});
}
}
self.display();
......@@ -752,7 +751,7 @@ Uploader.prototype = {
},
cancel: function (id) {
myConsole.flash("cancel upload : " + this.queue[id].filename, 1);
console.log({"type": "flash", "msg": "cancel upload : " + this.queue[id].filename, "priority": 1});
this.queue[id].jqXHR.abort()
this.queue[id].status = "canceled"
this.reload(id)
......
......@@ -47,12 +47,11 @@ GermlineList.prototype = {
self.list = jQuery.parseJSON(json);
}
catch(err){
myConsole.flash("germlines.data malformed, use local js file instead (can be outdated) ", 2);
console.log({"type": "flash", "msg": "germlines.data malformed, use local js file instead (can be outdated) " , "priority": 2});
}
},
error: function (request, status, error) {
myConsole.flash("impossible to retrieve germline.data, using local germline.js", 0);
console.log({"type": "flash", "msg": "impossible to retrieve germline.data, using local germline.js", "priority": 0});
},
dataType: "text"
});
......@@ -65,7 +64,7 @@ GermlineList.prototype = {
this.list = germline_data
}
catch(err){
myConsole.popupMsg("Incorrect browser installation, 'js/germline.js' is not found<br />please run 'make' in 'germline/'")
console.log({"type": "popup", "msg": "Incorrect browser installation, 'js/germline.js' is not found<br />please run 'make' in 'germline/'"});
}
},
......@@ -137,7 +136,7 @@ Germline.prototype = {
this.allele[key] = germline[filename][key]
}
}else{
myConsole.flash("warning : this browser version doesn't have the "+filename+" germline file", 2);
console.log({"type": "flash", "msg": "warning : this browser version doesn't have the "+filename+" germline file", "priority": 2});
}
}
}
......
......@@ -311,7 +311,7 @@ Graph.prototype = {
elapsedTime = new Date()
.getTime() - startTime;
myConsole.log("update Graph: " + elapsedTime + "ms", -1);
console.log("update Graph: " + elapsedTime + "ms");
return this
},
......@@ -859,8 +859,6 @@ Graph.prototype = {
if (this.m.samples.order.length >= 3) {
deltas = this.m.dateDiffMinMax()
myConsole.log(deltas)
myConsole.log(deltas.min)
/* only if there are enough different dates */
if ((deltas.min >= 0) && (deltas.max >= 2))
......
......@@ -261,7 +261,7 @@ List.prototype = {
elapsedTime = new Date()
.getTime() - startTime;
myConsole.log("update Liste: " + elapsedTime + "ms", -1);
console.log("update Liste: " + elapsedTime + "ms");
//TODO check order
document.getElementById("list_sort_select").selectedIndex = 0;
......@@ -339,7 +339,7 @@ List.prototype = {
var span_info = document.createElement('span')
span_info.className = "infoBox";
span_info.onclick = function () {
myConsole.dataBox(self.m.clone(cloneID).getHtmlInfo());
console.dataBox(self.m.clone(cloneID).getHtmlInfo());
}
span_info.appendChild(document.createTextNode("I"));
......@@ -421,7 +421,7 @@ List.prototype = {
var span_info = document.createElement('span')
span_info.className = "infoBox";
span_info.onclick = function () {
myConsole.dataBox(self.m.clone(this.parentNode.id2).getHtmlInfo());
console.dataBox(self.m.clone(this.parentNode.id2).getHtmlInfo());
}
span_info.appendChild(document.createTextNode("I"));
......
var myConsole = new Com("flash_container", "log_container", "popup-container", "data-container")
initMenu()
//console = new Com("flash_container", "log_container", "popup-container", "data-container", console)
/* Model
/* Model
*/
var m = new Model();
/* views
/* Views/Modules
*/
var graph = new Graph("visu2",m);
var list_clones = new List("list", "data", m);
......@@ -19,6 +18,8 @@ var pdf = new PDF(m, "visu2_svg")
var report = new Report(m)
var db = new Database("plop!", m);
initMenu();
/*
*/
var shortcut = new Shortcut()
......@@ -52,7 +52,7 @@ function initMenu () {
}
},
error: function() {
myConsole.flash("Files are not available", 1)
console.log({"type": "flash", "msg": "Files are not available" , "priority": 1});
}
});
......@@ -72,13 +72,11 @@ function changeStyle(newStyle){
function loadData() {
myConsole.closePopupMsg()
if (m.analysisHasChanged){
m.analysisHasChanged = false;
myConsole.popupMsg( myConsole.msg.save_analysis +
"<div class=\'center\'> <button onclick=\'loadData()\'>Continue</button> "
+" <button onclick='myConsole.closePopupMsg()'>Cancel</button> </div>"
)
console.log({"type": "popup", "default": "save_analysis",
"msg": "<div class=\'center\'> <button onclick=\'loadData()\'>Continue</button> "
+ " <button onclick='console.closePopupMsg()'>Cancel</button> </div>"});
return
}
......
......@@ -35,7 +35,7 @@ VIDJIL_JSON_VERSION = '2014.09';
*
* */
function Model() {
myConsole.log("creation Model")
console.log("creation Model")
this.view = [];
this.reset();
this.checkBrowser();
......@@ -189,7 +189,7 @@ Model.prototype = {
//wait 1sec to check ssl
setTimeout(function () { db.call("patient/index.html")}, 1000);
}else{
myConsole.popupMsg(myConsole.msg.welcome)
console.log({"type":"popup", "default":"welcome" })
}
},
......@@ -201,7 +201,7 @@ Model.prototype = {
load: function (id, analysis, limit) {
var self = this;
myConsole.log("load()");
console.log("load()");
if (document.getElementById(id)
.files.length === 0) {
......@@ -233,7 +233,7 @@ Model.prototype = {
var input = document.getElementById(analysis)
myConsole.log("loadAnalysis()");
console.log("loadAnalysis()");
if (input.files.length != 0) {
var oFReader = new FileReader();
var oFile = input
......@@ -266,8 +266,8 @@ Model.prototype = {
loadDataUrl: function (url, callback) {
var self = this;
callback = typeof callback !== 'undefined' ? callback : function(){self.loadAnalysisUrl(url)}
myConsole.flash("loadDataUrl: " + url)
console.log({"type": "flash", "msg": "loadDataUrl: " + url , "priority": 1});
var url_split = url.split('/')
......@@ -284,7 +284,7 @@ Model.prototype = {
callback()
},
error: function (request, status, error) {
myConsole.flash("error : can't reach " + url + "file");
console.log({"type": "flash", "msg": "error : can't reach " + url + "file", "priority": 2 });
}
});
......@@ -296,7 +296,7 @@ Model.prototype = {
var self = this;
var url2 = url.replace(new RegExp(".vidjil" + '$'), ".analysis")
myConsole.flash("loadAnalysisUrl: " + url2)
console.log({"type": "flash", "msg": "loadAnalysisUrl: " + url2 , "priority": 1});
var url_split = url2.split('/')
......@@ -328,7 +328,7 @@ Model.prototype = {
try {
var data = jQuery.parseJSON(json_text)
} catch (e) {
myConsole.popupMsg(myConsole.msg.file_error);
console.log({"type": "popup", "default": "file_error"});
return 0
}
}
......@@ -337,7 +337,7 @@ Model.prototype = {
//check version
if ((typeof (data.vidjil_json_version) == 'undefined') || (data.vidjil_json_version < VIDJIL_JSON_VERSION)) {
myConsole.popupMsg(myConsole.msg.version_error);
console.log({"type": "popup", "default": "version_error"});
return 0;
}
self.reset();
......@@ -431,7 +431,7 @@ Model.prototype = {
}
catch (e) {
myConsole.popupMsg(myConsole.msg.parse_error);
console.log({"type": "popup", "default": "parse_error"});
throw e;
return 0
}
......@@ -447,7 +447,7 @@ Model.prototype = {
try {
this.analysis = jQuery.parseJSON(analysis)
} catch (e) {
myConsole.popupMsg(myConsole.msg.file_error);
console.log({"type": "popup", "default": "file_error"});
return 0
}
}else{
......@@ -505,7 +505,7 @@ Model.prototype = {
this.initClones();
this.initData();
}else{
myConsole.flash("invalid version for this .analysis file", 1)
console.log({"type": "flash", "msg": "invalid version for this .analysis file" , "priority": 1});
}
},
......@@ -539,11 +539,10 @@ Model.prototype = {
*
* */
initClones: function () {
myConsole.log("initClones()");
console.log("initClones()");
// time_type to delta_date if we have enough different dates
deltas = this.dateDiffMinMax()
myConsole.log(deltas)
if (deltas.max > 1)
this.changeTimeFormat("delta_date")
......@@ -629,7 +628,7 @@ Model.prototype = {
max.id = id
}
}else{
myConsole.log(" apply analysis : clones "+ c[i].id + " > incorrect expected value", 0)
console.log(" apply analysis : clones "+ c[i].id + " > incorrect expected value", 0)
}
}else{
if (typeof (c[i].tag) != "undefined") {
......@@ -690,7 +689,7 @@ Model.prototype = {
*
* */
saveAnalysis: function () {
myConsole.log("save Analysis (local)", 0)
console.log("save Analysis (local)")
var textToWrite = this.strAnalysis()
var textFileAsBlob = new Blob([textToWrite], {
......@@ -771,7 +770,7 @@ Model.prototype = {
*
* */
resetAnalysis: function () {
myConsole.log("resetAnalysis()");
console.log("resetAnalysis()");
this.analysis = {
clones: [],
cluster: [],
......@@ -1059,7 +1058,7 @@ Model.prototype = {
*
* */
select: function (cloneID) {
myConsole.log("select() (clone " + cloneID + ")");
console.log("select() (clone "