Commit 30c18fc0 authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-c/notify_server_error' into 'dev'

Feature c/notify server error

See merge request !136
parents 207059b4 72a077b4
Pipeline #43641 failed with stages
in 5 minutes
......@@ -65,6 +65,7 @@ function loadAfterConf() {
"../crossDomain",
"../database",
"../shortcut",
"../notification",
"../export",
"../similarity",
"../tools",
......
......@@ -400,9 +400,9 @@ Database.prototype = {
//
this.fixed_header()
adress=DB_ADDRESS + 'notification/get_active_notifications'
// New page displayed, attempt to display header and login notifications
this.loadNotifications();
this.loadNotifications(adress);
$("#menu-container").addClass('disabledClass');
......@@ -986,39 +986,17 @@ Database.prototype = {
// periodically query the server for notifications
// And loads them into elements with id 'header_messages' and 'login_messages'
// TODO : Tidy up
loadNotifications: function() {
loadNotifications: function(adress) {
var self = this;
if (DB_ADDRESS !== "") {
if (adress !== "") {
$.ajax({
type: "GET",
crossDomain: true,
url: DB_ADDRESS + 'notification/get_active_notifications',
url: adress,
xhrFields: {withCredentials: true},
timeout: DB_TIMEOUT_CALL,
success: function (result) {
var messages;
try {
messages = JSON.parse(result);
var header_messages = [];
var login_messages = [];
for (var i = 0; i < messages.length; ++i) {
if (messages[i].notification.message_type == 'header') {
header_messages.push(messages[i]);
} else if (messages[i].notification.message_type == 'login') {
login_messages.push(messages[i]);
}
}
//TODO see if we can remove this hard coupling to classes
var hm = $('#header_messages');
self.integrateMessages(hm, header_messages);
var lm = $('#login_messages');
self.integrateMessages(lm, login_messages);
} catch (err) {
console.log("ERROR: " + err);
}
notification.parse_notification(result)
},
error: function (request, status, error) {
......@@ -1026,7 +1004,6 @@ Database.prototype = {
console.log({"type": "flash", "default" : "database_timeout", "priority": 2});
} else {
console.log("unable to get notifications");
console.log(DB_ADDRESS + ": " + error);
}
}
});
......@@ -1035,42 +1012,6 @@ Database.prototype = {
}
},
// takes a jQuery elem
integrateMessages: function(elem, messages, classNames) {
var message, preformat;
// empty container because prototype is destined to be called periodically
elem.empty();
//set default classes if they are undefined
classNames = classNames === undefined ? {'urgent': 'urgent_message', 'info': 'info_message'} : classNames;
if (messages.length > 0) {
for (var i=0; i < messages.length; ++i) {
display_title = ""
if (messages[i].notification.message_type == 'login')
{
display_title += messages[i].notification.creation_datetime.split(' ')[0] + ' : '
}
display_title += messages[i].notification.title
message = document.createElement('div');
message.className = classNames[messages[i].notification.priority] + " notification";
$(message).attr('onclick', "db.call('notification/index', {'id': '" + messages[i].notification.id + "'})");
$(message).append(
// message is sanitized by the server so we unescape the string to include links and formatting
document.createTextNode(unescape(display_title))
);
elem.append(message);
}
elem.fadeIn();
} else {
// No messages to display so hide message container
elem.fadeOut();
}
},
//affiche la fenetre de dialogue avec le serveur et affiche ses réponses
display: function (msg) {
this.div.style.display = "block";
......
......@@ -46,6 +46,7 @@ setCrossDomainModel(m);
* This links the model to a patient database (possibly the one defined in config.js)
*/
var db = new Database(m);
var notification = new Notification(m)
try {
/* Views
......@@ -127,7 +128,8 @@ db.ajax_indicator_stop();
// Load regularly notifications
(function worker(){
db.loadNotifications();
adress = config.db_address + 'notification/get_active_notifications'
db.loadNotifications(adress);
setTimeout(worker, NOTIFICATION_PERIOD);
})();
......
function Notification(m) {
this.m = m;
}
Notification.prototype = {
parse_notification: function (result) {
var messages;
try {
messages = JSON.parse(result);
var header_messages = [];
var login_messages = [];
for (var i = 0; i < messages.length; ++i) {
if (messages[i].notification.message_type == 'header') {
header_messages.push(messages[i]);
} else if (messages[i].notification.message_type == 'login') {
login_messages.push(messages[i]);
}
}
//TODO see if we can remove this hard coupling to classes
var hm = $('#header_messages');
this.integrateMessages(hm, header_messages);
var lm = $('#login_messages');
this.integrateMessages(lm, login_messages);
} catch (err) {
console.log("Notification Error: " + err);
}
},
integrateMessages: function(elem, messages, classNames) {
var message, preformat;
// empty container because prototype is destined to be called periodically
elem.empty();
//set default classes if they are undefined
classNames = classNames === undefined ? {'urgent': 'urgent_message', 'info': 'info_message'} : classNames;
if (messages.length > 0) {
for (var i=0; i < messages.length; ++i) {
display_title = ""
if (messages[i].notification.message_type == 'login')
{
display_title += messages[i].notification.creation_datetime.split(' ')[0] + ' : '
}
display_title += messages[i].notification.title
message = document.createElement('div');
message.className = classNames[messages[i].notification.priority] + " notification";
$(message).attr('onclick', "db.call('notification/index', {'id': '" + messages[i].notification.id + "'})");
// message is sanitized by the server so we unescape the string to include links and formatting
$(message).append(document.createTextNode(unescape(display_title)));
elem.append(message);
}
elem.fadeIn();
} else {
// No messages to display so hide message container
elem.fadeOut();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment